6#include "fifechan/widgets/window.hpp"
13#include "fifechan/exception.hpp"
14#include "fifechan/font.hpp"
15#include "fifechan/graphics.hpp"
16#include "fifechan/mouseinput.hpp"
28 Window::Window(std::string
const & caption)
37 Window::~Window() =
default;
85 highlightColor = faceColor + 0x303030;
86 highlightColor.
a = alpha;
87 shadowColor = faceColor - 0x303030;
88 shadowColor.
a = alpha;
98 graphics->
drawLine(x + i, y + i, width - i, y + i);
99 graphics->
drawLine(x + i, y + i + 1, x + i, height - i - 1);
101 graphics->
drawLine(width - i, y + i + 1, width - i, height - i);
102 graphics->
drawLine(x + i, height - i, width - i - 1, height - i);
109 Color highlightColor;
112 highlightColor = faceColor + 0x303030;
113 highlightColor.
a = alpha;
114 shadowColor = faceColor - 0x303030;
115 shadowColor.
a = alpha;
121 int const contentWidth = std::max(0,
getWidth() - (2 * borderSize));
122 int const contentHeight = std::max(0,
getHeight() - (2 * borderSize));
124 if (
isOpaque() && contentWidth > 0 && contentHeight > 0) {
130 Rectangle const rec(borderSize, borderSize, contentWidth, contentHeight);
148 case Graphics::Alignment::Left:
151 case Graphics::Alignment::Center:
154 case Graphics::Alignment::Right:
162 borderSize + paddingLeft,
163 borderSize + paddingTop,
164 std::max(0,
getWidth() - (2 * borderSize) - paddingLeft - paddingRight),
230 rec.
x = borderSize + paddingLeft + innerBorder;
231 rec.
y = borderSize + paddingTop + innerBorder + titleBarHeight;
232 rec.
width = std::max(0,
getWidth() - (2 * borderSize) - paddingLeft - paddingRight - (2 * innerBorder));
234 0,
getHeight() - (2 * borderSize) - paddingTop - paddingBottom - (2 * innerBorder) - titleBarHeight);
uint8_t a
Alpha color component (0-255).
bool mOpaque
True if the container is opaque, false otherwise.
Widget * mBackgroundWidget
Optional widget that is rendered behind other children as the container background.
Widget * getSource() const
Gets the source widget of the event.
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Alignment
Horizontal alignments for text drawing.
virtual void popClipArea()
Removes the top most clip area from the stack.
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
Represents a mouse event.
int getX() const
Gets the x coordinate of the mouse event.
int getY() const
Gets the y coordinate of the mouse event.
Represents a rectangular area (X, Y, Width, Height).
int width
Holds the width of the rectangle.
int y
Holds the x coordinate of the rectangle.
int x
Holds the x coordinate of the rectangle.
int height
Holds the height of the rectangle.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed down on the widget area.
void adjustSize() override
Adjust the size of the container after layout computations.
bool mMoved
True if the window is being moved, false otherwise.
bool mMovable
True if the window is movable, false otherwise.
unsigned int getTitleBarHeight() const
Gets the title bar height.
unsigned int mTitleBarHeight
Holds the title bar height of the window.
void setMovable(bool movable)
Sets the window to be movable or not.
void setTitleBarHeight(unsigned int height)
Sets the title bar height.
void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
unsigned int getInnerBorderSize() const
Get the size of the inner border (pixels).
Graphics::Alignment mAlignment
Holds the alignment of the caption.
std::string mCaption
Holds the caption of the window.
bool isMovable() const
Checks if the window is movable.
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
bool isOpaque() const override
Checks if the window is opaque.
int mDragOffsetX
Holds a drag offset as an x coordinate where the drag of the window started if the window is being dr...
void setInnerBorderSize(unsigned int border)
Set the size of the inner border (pixels).
virtual void drawInnerBorder(Graphics *graphics)
Draw the inner border (override to customize appearance).
void draw(Graphics *graphics) override
Draws the widget.
unsigned int mInnerBorderSize
Holds the size of the inner border.
std::string const & getCaption() const
Gets the caption of the window.
void setCaption(std::string const &caption)
Sets the caption of the window.
Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
int mDragOffsetY
Holds a drag offset as an y coordinate where the drag of the window started if the window is being dr...
void setOpaque(bool opaque) override
Sets the window to be opaque or not.
Used replacement tokens by configure_file():
void throwException(std::string const &message, std::source_location location=std::source_location::current())
Throw an Exception capturing the current source location.