1 /* 2 * Xournal++ 3 * 4 * Base class for Background paints (This class fills the background) 5 * 6 * @author Xournal++ Team 7 * https://github.com/xournalpp/xournalpp 8 * 9 * @license GNU GPLv2 or later 10 */ 11 12 #pragma once 13 14 #include <gtk/gtk.h> 15 16 #include "model/PageRef.h" 17 #include "util/Color.h" 18 19 #include "BackgroundConfig.h" 20 21 class BaseBackgroundPainter { 22 public: 23 BaseBackgroundPainter(); 24 virtual ~BaseBackgroundPainter(); 25 26 public: 27 virtual void paint(cairo_t* cr, PageRef page, BackgroundConfig* config); 28 virtual void paint(); 29 30 /** 31 * Reset all used configuration values 32 */ 33 virtual void resetConfig(); 34 35 /** 36 * Set a factor to draw the lines bolder, for previews 37 */ 38 void setLineWidthFactor(double factor); 39 40 protected: 41 void paintBackgroundColor(); 42 43 /** 44 * Choose between color1 and color2 based on the page's background brightness. 45 * 46 * @param color1 A color intended for light backgrounds. 47 * @param color2 A color intended for dark backgrounds. 48 * 49 * @return color1 if the page background is light, else, color2. 50 */ 51 Color alternativeColor(Color color1, Color color2) const; 52 53 /** 54 * Determines and returns the primary foreground color to use for this page. 55 * 56 * @return the primary foreground color for the page. 57 */ 58 Color getForegroundColor1() const; 59 60 /** 61 * Determines and returns the secondary foreground color to use for this page. 62 * 63 * @return the secondary foreground color for the page. 64 */ 65 Color getForegroundColor2() const; 66 67 private: 68 protected: 69 BackgroundConfig* config = nullptr; 70 PageRef page; 71 cairo_t* cr = nullptr; 72 73 double width = 0; 74 double height = 0; 75 76 // Drawing attributes 77 // ParserKey=Value 78 protected: 79 Color defaultForegroundColor1{0U}; 80 Color defaultAlternativeForegroundColor1{0U}; 81 82 Color defaultForegroundColor2{0U}; 83 Color defaultAlternativeForegroundColor2{0U}; 84 85 Color foregroundColor1{0U}; 86 Color foregroundColor2{0U}; 87 88 double lineWidth = 0; 89 90 double drawRaster1 = 1; 91 92 double margin1 = 0; 93 94 /** 95 * rm=1 96 * Round margin = 0 => No rounding 97 * Round margin = 1 => Round to next grid etc. 98 * Todo(fabian): use enum RoundMargin : bool{ DoNotRound = false, RoundToNextGrid = true}; 99 */ 100 int roundMargin = 0; 101 102 /** 103 * Line width factor, to use to draw Previews 104 */ 105 double lineWidthFactor = 1; 106 }; 107