FifeGUI 0.2.0
A C++ GUI library designed for games.
window.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_WINDOW_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_WINDOW_HPP_
7
8#include <string>
9
10#include "fifechan/mouselistener.hpp"
11#include "fifechan/platform.hpp"
12#include "fifechan/widgets/container.hpp"
13
14namespace fcn
15{
21 class FIFEGUI_API Window : public Container, public MouseListener
22 {
23 public:
24 Window();
25
32 explicit Window(std::string const & caption);
33
34 ~Window() override;
35
36 Window(Window const &) = delete;
37 Window& operator=(Window const &) = delete;
38 Window(Window&&) = delete;
39 Window& operator=(Window&&) = delete;
40
47 void setCaption(std::string const & caption);
48
55 std::string const & getCaption() const;
56
63 void setAlignment(Graphics::Alignment alignment);
64
72
79 void setTitleBarHeight(unsigned int height);
80
87 unsigned int getTitleBarHeight() const;
88
90 void setInnerBorderSize(unsigned int border);
91
93 unsigned int getInnerBorderSize() const;
94
101 void setMovable(bool movable);
102
109 bool isMovable() const;
110
118 void setOpaque(bool opaque) override;
119
126 bool isOpaque() const override;
127
129 virtual void drawInnerBorder(Graphics* graphics);
130
131 // Inherited from Container
132
133 // virtual void resizeToContent();
134 void adjustSize() override;
135 // virtual void expandContent();
136 Rectangle getChildrenArea() override;
137
138 // Inherited from Widget
139
140 void draw(Graphics* graphics) override;
141
142 // Inherited from MouseListener
143
144 void mousePressed(MouseEvent& mouseEvent) override;
145
146 void mouseDragged(MouseEvent& mouseEvent) override;
147
148 void mouseReleased(MouseEvent& mouseEvent) override;
149
150 protected:
154 std::string mCaption;
155
159 Graphics::Alignment mAlignment{Graphics::Alignment::Center};
160
164 unsigned int mTitleBarHeight{16};
165
169 unsigned int mInnerBorderSize{1};
170
174 bool mMovable{true};
175
182
189
193 bool mMoved{false};
194 };
195} // namespace fcn
196
197#endif // INCLUDE_FIFECHAN_WIDGETS_WINDOW_HPP_
Container()
Constructor.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
Alignment
Alignments for text drawing.
Definition graphics.hpp:63
Represents a mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
Definition window.cpp:172
void adjustSize() override
Adjust the size of the container after layout computations.
Definition window.cpp:207
bool mMoved
True if the window is being moved, false otherwise.
Definition window.hpp:193
bool mMovable
True if the window is movable, false otherwise.
Definition window.hpp:174
unsigned int getTitleBarHeight() const
Gets the title bar height.
Definition window.cpp:41
unsigned int mTitleBarHeight
Holds the title bar height of the window.
Definition window.hpp:164
void setMovable(bool movable)
Sets the window to be movable or not.
Definition window.cpp:228
void setTitleBarHeight(unsigned int height)
Sets the title bar height.
Definition window.cpp:36
void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
Definition window.cpp:66
unsigned int getInnerBorderSize() const
Get the size of the inner border (pixels).
Definition window.cpp:51
Graphics::Alignment mAlignment
Holds the alignment of the caption.
Definition window.hpp:159
std::string mCaption
Holds the caption of the window.
Definition window.hpp:154
bool isMovable() const
Checks if the window is movable.
Definition window.cpp:233
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
Definition window.cpp:217
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
Definition window.cpp:189
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
Definition window.cpp:194
bool isOpaque() const override
Checks if the window is opaque.
Definition window.cpp:243
int mDragOffsetX
Holds a drag offset as an x coordinate where the drag of the window started if the window is being dr...
Definition window.hpp:181
void setInnerBorderSize(unsigned int border)
Set the size of the inner border (pixels).
Definition window.cpp:46
virtual void drawInnerBorder(Graphics *graphics)
Draw the inner border (override to customize appearance).
Definition window.cpp:76
void draw(Graphics *graphics) override
Draws the widget.
Definition window.cpp:103
unsigned int mInnerBorderSize
Holds the size of the inner border.
Definition window.hpp:169
std::string const & getCaption() const
Gets the caption of the window.
Definition window.cpp:61
void setCaption(std::string const &caption)
Sets the caption of the window.
Definition window.cpp:56
Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
Definition window.cpp:71
int mDragOffsetY
Holds a drag offset as an y coordinate where the drag of the window started if the window is being dr...
Definition window.hpp:188
void setOpaque(bool opaque) override
Sets the window to be opaque or not.
Definition window.cpp:238