| 1 | // Aseprite UI Library |
| 2 | // Copyright (C) 2020-2022 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2017 David Capello |
| 4 | // |
| 5 | // This file is released under the terms of the MIT license. |
| 6 | // Read LICENSE.txt for more information. |
| 7 | |
| 8 | #ifndef UI_THEME_H_INCLUDED |
| 9 | #define UI_THEME_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "gfx/border.h" |
| 13 | #include "gfx/color.h" |
| 14 | #include "gfx/rect.h" |
| 15 | #include "gfx/size.h" |
| 16 | #include "ui/base.h" |
| 17 | #include "ui/cursor_type.h" |
| 18 | #include "ui/style.h" |
| 19 | |
| 20 | namespace gfx { |
| 21 | class Region; |
| 22 | } |
| 23 | |
| 24 | namespace os { |
| 25 | class Font; |
| 26 | class Surface; |
| 27 | } |
| 28 | |
| 29 | namespace ui { |
| 30 | |
| 31 | class Cursor; |
| 32 | class Graphics; |
| 33 | class PaintEvent; |
| 34 | class SizeHintEvent; |
| 35 | class Widget; |
| 36 | class Theme; |
| 37 | |
| 38 | void set_theme(Theme* theme, const int uiscale); |
| 39 | Theme* get_theme(); |
| 40 | |
| 41 | struct PaintWidgetPartInfo { |
| 42 | gfx::Color bgColor; |
| 43 | int styleFlags; // ui::Style::Layer flags |
| 44 | const std::string* text; |
| 45 | int mnemonic; |
| 46 | |
| 47 | PaintWidgetPartInfo(); |
| 48 | PaintWidgetPartInfo(const Widget* widget); |
| 49 | |
| 50 | static int getStyleFlagsForWidget(const Widget* widget); |
| 51 | }; |
| 52 | |
| 53 | class Theme { |
| 54 | friend void set_theme(Theme* theme, const int uiscale); |
| 55 | public: |
| 56 | Theme(); |
| 57 | virtual ~Theme(); |
| 58 | |
| 59 | virtual os::Font* getDefaultFont() const = 0; |
| 60 | virtual os::Font* getWidgetFont(const Widget* widget) const = 0; |
| 61 | |
| 62 | virtual ui::Cursor* getStandardCursor(CursorType type) = 0; |
| 63 | virtual void initWidget(Widget* widget) = 0; |
| 64 | virtual void getWindowMask(Widget* widget, gfx::Region& region) = 0; |
| 65 | virtual void setDecorativeWidgetBounds(Widget* widget); |
| 66 | virtual int getScrollbarSize() = 0; |
| 67 | virtual gfx::Size getEntryCaretSize(Widget* widget) = 0; |
| 68 | |
| 69 | virtual void paintEntry(PaintEvent& ev) = 0; |
| 70 | virtual void paintListBox(PaintEvent& ev) = 0; |
| 71 | virtual void (PaintEvent& ev) = 0; |
| 72 | virtual void (PaintEvent& ev) = 0; |
| 73 | virtual void paintSlider(PaintEvent& ev) = 0; |
| 74 | virtual void paintComboBoxEntry(PaintEvent& ev) = 0; |
| 75 | virtual void paintTextBox(PaintEvent& ev) = 0; |
| 76 | virtual void paintViewViewport(PaintEvent& ev) = 0; |
| 77 | |
| 78 | virtual void paintWidgetPart(Graphics* g, |
| 79 | const Style* style, |
| 80 | const gfx::Rect& bounds, |
| 81 | const PaintWidgetPartInfo& info); |
| 82 | |
| 83 | // Default implementation to draw widgets with new ui::Styles |
| 84 | virtual void paintWidget(Graphics* g, |
| 85 | const Widget* widget, |
| 86 | const Style* style, |
| 87 | const gfx::Rect& bounds); |
| 88 | |
| 89 | virtual void paintScrollBar(Graphics* g, |
| 90 | const Widget* widget, |
| 91 | const Style* style, |
| 92 | const Style* thumbStyle, |
| 93 | const gfx::Rect& bounds, |
| 94 | const gfx::Rect& thumbBounds); |
| 95 | |
| 96 | virtual void paintTooltip(Graphics* g, |
| 97 | const Widget* widget, |
| 98 | const Style* style, |
| 99 | const Style* arrowStyle, |
| 100 | const gfx::Rect& bounds, |
| 101 | const int arrowAlign, |
| 102 | const gfx::Rect& target); |
| 103 | |
| 104 | void paintTextBoxWithStyle(Graphics* g, |
| 105 | const Widget* widget); |
| 106 | |
| 107 | virtual gfx::Size calcSizeHint(const Widget* widget, |
| 108 | const Style* style); |
| 109 | virtual gfx::Border calcBorder(const Widget* widget, |
| 110 | const Style* style); |
| 111 | virtual void calcSlices(const Widget* widget, |
| 112 | const Style* style, |
| 113 | gfx::Size& topLeft, |
| 114 | gfx::Size& center, |
| 115 | gfx::Size& bottomRight); |
| 116 | virtual void calcTextInfo(const Widget* widget, |
| 117 | const Style* style, |
| 118 | const gfx::Rect& bounds, |
| 119 | gfx::Rect& textBounds, int& textAlign); |
| 120 | virtual gfx::Color calcBgColor(const Widget* widget, |
| 121 | const Style* style); |
| 122 | |
| 123 | static void drawSlices(Graphics* g, |
| 124 | os::Surface* sheet, |
| 125 | const gfx::Rect& rc, |
| 126 | const gfx::Rect& sprite, |
| 127 | const gfx::Rect& slices, |
| 128 | const gfx::Color color, |
| 129 | const bool drawCenter = true); |
| 130 | |
| 131 | static void drawTextBox(Graphics* g, const Widget* textbox, |
| 132 | int* w, int* h, gfx::Color bg, gfx::Color fg); |
| 133 | |
| 134 | protected: |
| 135 | virtual void onRegenerateTheme() = 0; |
| 136 | |
| 137 | private: |
| 138 | void regenerateTheme(); |
| 139 | void paintLayer(Graphics* g, |
| 140 | const Style* style, |
| 141 | const Style::Layer& layer, |
| 142 | const std::string& text, |
| 143 | const int mnemonic, |
| 144 | gfx::Rect& rc, |
| 145 | gfx::Color& bgColor); |
| 146 | void measureLayer(const Widget* widget, |
| 147 | const Style* style, |
| 148 | const Style::Layer& layer, |
| 149 | gfx::Border& borderHint, |
| 150 | gfx::Rect& textHint, int& textAlign, |
| 151 | gfx::Size& iconHint, int& iconAlign); |
| 152 | void calcWidgetMetrics(const Widget* widget, |
| 153 | const Style* style, |
| 154 | gfx::Size& sizeHint, |
| 155 | gfx::Border& borderHint, |
| 156 | gfx::Rect& textHint, int& textAlign); |
| 157 | }; |
| 158 | |
| 159 | } // namespace ui |
| 160 | |
| 161 | #endif |
| 162 | |