bWidgets
Core widget toolkit designed for Blender
bwPainter.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <vector>
6
7#include "bwGradient.h"
8#include "bwIconInterface.h"
9
10namespace bWidgets {
11
12class bwPaintEngine;
13class bwPolygon;
14class bwStyle;
15class bwWidgetBaseStyle;
16
18 NONE = 0,
19 BOTTOM_LEFT = (1 << 0),
20 BOTTOM_RIGHT = (1 << 1),
21 TOP_LEFT = (1 << 2),
22 TOP_RIGHT = (1 << 3),
23 /* Convenience */
25};
26
27enum class TextAlignment {
28 LEFT,
29 CENTER,
30 RIGHT,
31};
32
33enum class Direction {
34 UP,
35 DOWN,
36 LEFT,
37 RIGHT,
38};
39
40class bwPainter {
41 public:
42 enum class DrawType {
43 FILLED,
44 OUTLINE,
45 LINE,
46 };
47
48 bwPainter();
49
50 void drawPolygon(const bwPolygon& poly);
51 void drawText(const std::string& text,
52 const bwRectanglePixel& rectangle,
53 const TextAlignment align) const;
54 void drawIcon(const bwIconInterface&, const bwRectanglePixel&) const;
55
56 void setActiveColor(const bwColor& color);
57 auto getActiveColor() const -> const bwColor&;
58 auto getVertexColor(const size_t vertex_index) const -> const bwColor&;
59
60 void setContentMask(const bwRectanglePixel& value);
61 auto getContentMask() const -> const bwRectanglePixel&;
62
63 void enableGradient(const bwGradient& gradient);
64 auto isGradientEnabled() const -> bool;
65
66 void drawTextAndIcon(const std::string& text,
67 const bwIconInterface* icon,
68 const bwRectanglePixel& rectangle,
69 const TextAlignment alignment,
70 float dpi_fac) const;
71
72 // Primitives
73 void drawRoundbox(const bwRectanglePixel& rect, unsigned int corners, const float radius);
74 void drawRectangle(const bwRectanglePixel& rect);
75 void drawRoundboxWidgetBase(const bwWidgetBaseStyle& base_style,
76 const bwStyle& style,
77 const bwRectanglePixel& rectangle,
78 const bwGradient& gradient,
79 const float radius);
80 void drawCheckMark(const bwRectanglePixel& rect);
81 void drawTriangle(const bwRectanglePixel& rect, Direction direction);
82 void drawLine(const bwPoint& from, const bwPoint& to);
83
84 static std::unique_ptr<bwPaintEngine> s_paint_engine;
85
86 bool use_antialiasing{false};
88
89 private:
90 void fillVertexColorsWithGradient(const bwPolygon& polygon,
91 const bwRectanglePixel& bounding_box);
92
93 bwColor active_color;
94 std::vector<bwColor> vert_colors;
95 std::unique_ptr<bwGradient> active_gradient;
96 bwRectanglePixel content_mask;
97};
98
99} // namespace bWidgets
Definition: bwColor.h:5
Simple class for calculating colors for gradient fills.
Definition: bwGradient.h:14
Interface to reference icons from within bWidgets.
Definition: bwIconInterface.h:22
Main interface to implement any drawing of geometry or text.
Definition: bwPaintEngine.h:31
Definition: bwPainter.h:40
auto getVertexColor(const size_t vertex_index) const -> const bwColor &
Definition: bwPainter.cc:83
void drawLine(const bwPoint &from, const bwPoint &to)
Definition: bwPainter.cc:194
void drawCheckMark(const bwRectanglePixel &rect)
Definition: bwPainter.cc:141
bwPainter()
Definition: bwPainter.cc:20
void enableGradient(const bwGradient &gradient)
Definition: bwPainter.cc:98
void drawPolygon(const bwPolygon &poly)
Definition: bwPainter.cc:34
void drawRectangle(const bwRectanglePixel &rect)
Definition: bwPainter.cc:411
void drawIcon(const bwIconInterface &, const bwRectanglePixel &) const
Definition: bwPainter.cc:61
void drawRoundbox(const bwRectanglePixel &rect, unsigned int corners, const float radius)
Definition: bwPainter.cc:388
void setActiveColor(const bwColor &color)
Definition: bwPainter.cc:72
void drawTriangle(const bwRectanglePixel &rect, Direction direction)
Definition: bwPainter.cc:159
bool use_antialiasing
Definition: bwPainter.h:86
DrawType active_drawtype
Definition: bwPainter.h:87
void drawRoundboxWidgetBase(const bwWidgetBaseStyle &base_style, const bwStyle &style, const bwRectanglePixel &rectangle, const bwGradient &gradient, const float radius)
Definition: bwPainter.cc:451
void setContentMask(const bwRectanglePixel &value)
Definition: bwPainter.cc:88
auto getContentMask() const -> const bwRectanglePixel &
Definition: bwPainter.cc:93
void drawText(const std::string &text, const bwRectanglePixel &rectangle, const TextAlignment align) const
Definition: bwPainter.cc:48
DrawType
Definition: bwPainter.h:42
static std::unique_ptr< bwPaintEngine > s_paint_engine
Definition: bwPainter.h:84
void drawTextAndIcon(const std::string &text, const bwIconInterface *icon, const bwRectanglePixel &rectangle, const TextAlignment alignment, float dpi_fac) const
Definition: bwPainter.cc:112
auto getActiveColor() const -> const bwColor &
Definition: bwPainter.cc:78
auto isGradientEnabled() const -> bool
Definition: bwPainter.cc:107
Definition: bwPoint.h:7
Definition: bwPolygon.h:11
Definition: bwStyle.h:10
Properties for typical widgets with roundbox corners.
Definition: bwWidgetBaseStyle.h:14
Definition: bwContext.h:3
Direction
Definition: bwPainter.h:33
TextAlignment
Definition: bwPainter.h:27
RoundboxCorner
Definition: bwPainter.h:17
@ TOP_RIGHT
Definition: bwPainter.h:22
@ NONE
Definition: bwPainter.h:18
@ ALL
Definition: bwPainter.h:24
@ BOTTOM_LEFT
Definition: bwPainter.h:19
@ BOTTOM_RIGHT
Definition: bwPainter.h:20
@ TOP_LEFT
Definition: bwPainter.h:21