FifeGUI 0.3.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// Standard library includes
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/listeners/mouselistener.hpp"
16#include "fifechan/widgets/container.hpp"
17
18namespace fcn
19{
25 class FIFEGUI_API Window : public Container, public MouseListener
26 {
27 public:
28 Window();
29
37 explicit Window(std::string const & caption);
38
39 ~Window() override;
40
41 Window(Window const &) = delete;
42 Window& operator=(Window const &) = delete;
43 Window(Window&&) = delete;
44 Window& operator=(Window&&) = delete;
45
52 void setCaption(std::string const & caption);
53
60 std::string const & getCaption() const;
61
68 void setAlignment(Graphics::Alignment alignment);
69
77
84 void setTitleBarHeight(unsigned int height);
85
92 unsigned int getTitleBarHeight() const;
93
100 void setInnerBorderSize(unsigned int border);
101
108 unsigned int getInnerBorderSize() const;
109
116 void setMovable(bool movable);
117
124 bool isMovable() const;
125
135 void setOpaque(bool opaque) override;
136
143 bool isOpaque() const override;
144
146 virtual void drawInnerBorder(Graphics* graphics);
147
148 // Inherited from Container
149
150 // virtual void resizeToContent();
151 void adjustSize() override;
152 // virtual void expandContent();
153 Rectangle getChildrenArea() override;
154
155 // Inherited from Widget
156
157 void draw(Graphics* graphics) override;
158
159 // Inherited from MouseListener
160
161 void mousePressed(MouseEvent& mouseEvent) override;
162
163 void mouseDragged(MouseEvent& mouseEvent) override;
164
165 void mouseReleased(MouseEvent& mouseEvent) override;
166
167 protected:
171 std::string mCaption;
172
176 Graphics::Alignment mAlignment{Graphics::Alignment::Center};
177
181 unsigned int mTitleBarHeight{16};
182
186 unsigned int mInnerBorderSize{1};
187
191 bool mMovable{true};
192
199
206
210 bool mMoved{false};
211 };
212} // namespace fcn
213
214#endif // INCLUDE_FIFECHAN_WIDGETS_WINDOW_HPP_
Container()
Constructor.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Alignment
Horizontal alignments for text drawing.
Definition graphics.hpp:64
Represents a mouse event.
MouseListener(MouseListener const &)=default
Copy constructor.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed down on the widget area.
Definition window.cpp:174
void adjustSize() override
Adjust the size of the container after layout computations.
Definition window.cpp:209
bool mMoved
True if the window is being moved, false otherwise.
Definition window.hpp:210
bool mMovable
True if the window is movable, false otherwise.
Definition window.hpp:191
unsigned int getTitleBarHeight() const
Gets the title bar height.
Definition window.cpp:44
unsigned int mTitleBarHeight
Holds the title bar height of the window.
Definition window.hpp:181
void setMovable(bool movable)
Sets the window to be movable or not.
Definition window.cpp:238
void setTitleBarHeight(unsigned int height)
Sets the title bar height.
Definition window.cpp:39
void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
Definition window.cpp:69
unsigned int getInnerBorderSize() const
Get the size of the inner border (pixels).
Definition window.cpp:54
Graphics::Alignment mAlignment
Holds the alignment of the caption.
Definition window.hpp:176
std::string mCaption
Holds the caption of the window.
Definition window.hpp:171
bool isMovable() const
Checks if the window is movable.
Definition window.cpp:243
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
Definition window.cpp:219
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
Definition window.cpp:191
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
Definition window.cpp:196
bool isOpaque() const override
Checks if the window is opaque.
Definition window.cpp:253
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:198
void setInnerBorderSize(unsigned int border)
Set the size of the inner border (pixels).
Definition window.cpp:49
virtual void drawInnerBorder(Graphics *graphics)
Draw the inner border (override to customize appearance).
Definition window.cpp:79
void draw(Graphics *graphics) override
Draws the widget.
Definition window.cpp:106
unsigned int mInnerBorderSize
Holds the size of the inner border.
Definition window.hpp:186
std::string const & getCaption() const
Gets the caption of the window.
Definition window.cpp:64
void setCaption(std::string const &caption)
Sets the caption of the window.
Definition window.cpp:59
Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
Definition window.cpp:74
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:205
void setOpaque(bool opaque) override
Sets the window to be opaque or not.
Definition window.cpp:248
Used replacement tokens by configure_file():