FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::Window Class Reference

#include <window.hpp>

Inheritance diagram for fcn::Window:
fcn::Container fcn::MouseListener fcn::Widget

Public Member Functions

void adjustSize () override
void draw (Graphics *graphics) override
virtual void drawInnerBorder (Graphics *graphics)
Graphics::Alignment getAlignment () const
std::string const & getCaption () const
Rectangle getChildrenArea () override
unsigned int getInnerBorderSize () const
unsigned int getTitleBarHeight () const
bool isMovable () const
bool isOpaque () const override
void mouseDragged (MouseEvent &mouseEvent) override
void mousePressed (MouseEvent &mouseEvent) override
void mouseReleased (MouseEvent &mouseEvent) override
Window & operator= (Window &&)=delete
Window & operator= (Window const &)=delete
void setAlignment (Graphics::Alignment alignment)
void setCaption (std::string const &caption)
void setInnerBorderSize (unsigned int border)
void setMovable (bool movable)
void setOpaque (bool opaque) override
void setTitleBarHeight (unsigned int height)
 Window (std::string const &caption)
 Window (Window &&)=delete
 Window (Window const &)=delete
Public Member Functions inherited from fcn::Container
virtual void add (Widget *widget)
virtual void add (Widget *widget, int x, int y)
void addContainerListener (ContainerListener *containerListener)
virtual void addWidget (std::unique_ptr< Widget > widget)
virtual void addWidget (std::unique_ptr< Widget > widget, int x, int y)
 Container ()
 Container (Container &&)=delete
 Container (Container const &)=delete
void expandContent ()
void expandContent (bool recursion) override
WidgetfindWidgetById (std::string const &id) override
WidgetgetBackgroundWidget ()
WidgetgetChild (unsigned int index) const
virtual unsigned int getHorizontalSpacing () const
virtual LayoutPolicy getLayout () const
virtual unsigned int getVerticalSpacing () const
bool isLayouted () override
virtual bool isUniformSize () const
Containeroperator= (Container &&)=delete
Containeroperator= (Container const &)=delete
void remove (Widget *widget) override
void removeAllChildren () override
void removeContainerListener (ContainerListener *containerListener)
void resizeToContent ()
void resizeToContent (bool recursion) override
void setBackgroundWidget (Widget *widget)
virtual void setHorizontalSpacing (unsigned int spacing)
virtual void setLayout (LayoutPolicy policy)
virtual void setUniformSize (bool uniform)
virtual void setVerticalSpacing (unsigned int spacing)
Public Member Functions inherited from fcn::Widget
virtual void _draw (Graphics *graphics)
virtual FocusHandler_getFocusHandler ()
virtual std::list< FocusListener * > const & _getFocusListeners ()
virtual FocusHandler_getInternalFocusHandler ()
virtual std::list< KeyListener * > const & _getKeyListeners ()
virtual std::list< MouseListener * > const & _getMouseListeners ()
virtual void _logic ()
virtual void _setFocusHandler (FocusHandler *focusHandler)
virtual void _setParent (Widget *parent)
void adaptLayout ()
virtual void adaptLayout (bool top)
void addActionListener (ActionListener *actionListener)
void addDeathListener (DeathListener *deathListener)
void addFocusListener (FocusListener *focusListener)
void addKeyListener (KeyListener *keyListener)
void addMouseListener (MouseListener *mouseListener)
void addWidgetListener (WidgetListener *widgetListener)
virtual void drawBorder (Graphics *graphics)
virtual void drawOutline (Graphics *graphics)
virtual void drawSelectionFrame (Graphics *graphics)
void expandContent ()
virtual void focusNext ()
virtual void focusPrevious ()
virtual void fontChanged ()
virtual void getAbsolutePosition (int &x, int &y) const
std::string const & getActionEventId () const
Color const & getBackgroundColor () const
Color const & getBaseColor () const
Color const & getBorderColor () const
unsigned int getBorderSize () const
unsigned int getChildrenCount () const
Rectangle const & getDimension () const
Size const & getFixedSize () const
FontgetFont () const
Color const & getForegroundColor () const
int getHeight () const
std::string const & getId () const
void getLastPosition (int &x, int &y) const
int getMarginBottom () const
int getMarginLeft () const
int getMarginRight () const
int getMarginTop () const
Size const & getMaxSize () const
Size const & getMinSize () const
Color const & getOutlineColor () const
unsigned int getOutlineSize () const
unsigned int getPaddingBottom () const
unsigned int getPaddingLeft () const
unsigned int getPaddingRight () const
unsigned int getPaddingTop () const
virtual WidgetgetParent () const
Color const & getSelectionColor () const
SelectionMode getSelectionMode () const
virtual WidgetgetTop () const
unsigned int getVisibleChildrenCount () const
WidgetgetWidgetAt (int x, int y)
virtual WidgetgetWidgetAt (int x, int y, Widget *exclude)
std::list< Widget * > getWidgetsIn (Rectangle const &area)
virtual std::list< Widget * > getWidgetsIn (Rectangle const &area, Widget *ignore)
int getWidth () const
int getX () const
int getY () const
bool isEnabled () const
bool isFixedSize () const
bool isFocusable () const
virtual bool isFocused () const
bool isHorizontalExpand () const
bool isLastPositionSet () const
virtual bool isModalFocusable () const
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocusable () const
virtual bool isModalMouseInputFocused () const
bool isSetVisible () const
bool isTabInEnabled () const
bool isTabOutEnabled () const
bool isVerticalExpand () const
bool isVisible () const
virtual void logic ()
virtual void moveToBottom (Widget *widget)
virtual void moveToTop (Widget *widget)
Widgetoperator= (Widget &&)=delete
Widgetoperator= (Widget const &)=delete
virtual void releaseModalFocus ()
virtual void releaseModalMouseInputFocus ()
void removeActionListener (ActionListener *actionListener)
void removeDeathListener (DeathListener *deathListener)
void removeFocusListener (FocusListener *focusListener)
void removeKeyListener (KeyListener *keyListener)
void removeMouseListener (MouseListener *mouseListener)
void removeWidgetListener (WidgetListener *widgetListener)
virtual void requestFocus ()
virtual void requestModalFocus ()
virtual void requestModalMouseInputFocus ()
virtual void requestMoveToBottom ()
virtual void requestMoveToTop ()
void resizeToContent ()
void setActionEventId (std::string const &actionEventId)
virtual void setBackgroundColor (Color const &color)
virtual void setBaseColor (Color const &color)
virtual void setBorderColor (Color const &color)
void setBorderSize (unsigned int size)
void setDimension (Rectangle const &dimension)
void setEnabled (bool enabled)
void setFixedSize (Size const &size)
void setFocusable (bool focusable)
virtual void setFont (Font *font)
virtual void setForegroundColor (Color const &color)
void setHeight (int height)
void setHorizontalExpand (bool expand)
void setId (std::string const &id)
void setInternalFocusHandler (FocusHandler *internalFocusHandler)
void setLastPosition (int x, int y)
void setMargin (int margin)
void setMarginBottom (int margin)
void setMarginLeft (int margin)
void setMarginRight (int margin)
void setMarginTop (int margin)
void setMaxSize (Size const &size)
void setMinSize (Size const &size)
virtual void setOutlineColor (Color const &color)
void setOutlineSize (unsigned int size)
void setPadding (unsigned int padding)
void setPaddingBottom (unsigned int padding)
void setPaddingLeft (unsigned int padding)
void setPaddingRight (unsigned int padding)
void setPaddingTop (unsigned int padding)
void setPosition (int x, int y)
virtual void setSelectionColor (Color const &color)
virtual void setSelectionMode (SelectionMode mode)
void setSize (int width, int height)
void setTabInEnabled (bool enabled)
void setTabOutEnabled (bool enabled)
void setVerticalExpand (bool expand)
void setVisible (bool visible)
void setWidth (int width)
void setX (int x)
void setY (int y)
virtual void showPart (Rectangle rectangle)
virtual void showWidgetPart (Widget *widget, Rectangle area)
 Widget ()
 Widget (Widget &&)=delete
 Widget (Widget const &)=delete
Public Member Functions inherited from fcn::MouseListener
virtual void mouseClicked (MouseEvent &mouseEvent)
virtual void mouseEntered (MouseEvent &mouseEvent)
virtual void mouseExited (MouseEvent &mouseEvent)
 MouseListener (MouseListener &&)=default
 MouseListener (MouseListener const &)=default
virtual void mouseMoved (MouseEvent &mouseEvent)
virtual void mouseWheelMovedDown (MouseEvent &mouseEvent)
virtual void mouseWheelMovedLeft (MouseEvent &mouseEvent)
virtual void mouseWheelMovedRight (MouseEvent &mouseEvent)
virtual void mouseWheelMovedUp (MouseEvent &mouseEvent)
MouseListener & operator= (MouseListener &&)=default
MouseListener & operator= (MouseListener const &)=default

Protected Attributes

Graphics::Alignment mAlignment {Graphics::Alignment::Center}
std::string mCaption
int mDragOffsetX {0}
int mDragOffsetY {0}
unsigned int mInnerBorderSize {1}
bool mMovable {true}
bool mMoved {false}
unsigned int mTitleBarHeight {16}
Protected Attributes inherited from fcn::Container
WidgetmBackgroundWidget {nullptr}
ContainerListenerList mContainerListeners
unsigned int mHorizontalSpacing {2}
LayoutPolicy mLayout {LayoutPolicy::Absolute}
bool mOpaque {true}
bool mUniform {false}
unsigned int mVerticalSpacing {2}
Protected Attributes inherited from fcn::Widget
std::string mActionEventId
std::list< ActionListener * > mActionListeners
Color mBackgroundColor {0xf9fafb}
Color mBaseColor {0xe5e7eb}
Color mBorderColor {0xd1d5db}
unsigned int mBorderSize {0}
std::list< Widget * > mChildren
FontmCurrentFont {nullptr}
std::list< DeathListener * > mDeathListeners
Rectangle mDimension
bool mEnabled {true}
Size mFixedSize {-1, -1}
bool mFixedSizeUsed {false}
bool mFocusable {false}
FocusHandlermFocusHandler {nullptr}
std::list< FocusListener * > mFocusListeners
Color mForegroundColor {0x1f2933}
bool mHExpand {false}
std::string mId
FocusHandlermInternalFocusHandler {nullptr}
std::list< KeyListener * > mKeyListeners
int mLastX {0}
int mLastY {0}
int mMarginBottom {0}
int mMarginLeft {0}
int mMarginRight {0}
int mMarginTop {0}
Size mMaxSize {std::numeric_limits<int>::max(), std::numeric_limits<int>::max()}
Size mMinSize {0, 0}
std::list< MouseListener * > mMouseListeners
Rectangle mOffsetRect
Color mOutlineColor {0x9ca3af}
unsigned int mOutlineSize {0}
unsigned int mPaddingBottom {0}
unsigned int mPaddingLeft {0}
unsigned int mPaddingRight {0}
unsigned int mPaddingTop {0}
WidgetmParent {nullptr}
Color mSelectionColor {0x3b82f6}
SelectionMode mSelectionMode {SelectionMode::None}
bool mTabIn {true}
bool mTabOut {true}
bool mVExpand {false}
bool mVisible {true}
std::list< WidgetListener * > mWidgetListeners

Additional Inherited Members

Public Types inherited from fcn::Container
enum class  LayoutPolicy : uint8_t {
  Absolute , AutoSize , Vertical , Horizontal ,
  Circular
}
Public Types inherited from fcn::Widget
enum class  SelectionMode : uint8_t { None = 0 , Border = 1 , Background = 2 }
Static Public Member Functions inherited from fcn::Widget
static DeathListener_getGuiDeathListener ()
static VisibilityEventHandler_getVisibilityEventHandler ()
static void _setGuiDeathListener (DeathListener *deathListener)
static void _setVisibilityEventHandler (VisibilityEventHandler *visibilityEventHandler)
static void setGlobalFont (Font *font)
static bool widgetExists (Widget const *widget)
Protected Types inherited from fcn::Container
using ContainerListenerIterator = ContainerListenerList::iterator
using ContainerListenerList = std::list<ContainerListener*>
Protected Member Functions inherited from fcn::Container
void distributeWidgetAddedEvent (Widget *source)
void distributeWidgetRemovedEvent (Widget *source)
Protected Member Functions inherited from fcn::Widget
void add (Widget *widget)
void calculateSize ()
void distributeActionEvent ()
void distributeAncestorHiddenEvent (Widget *ancestor)
void distributeAncestorMovedEvent (Widget *ancestor)
void distributeAncestorShownEvent (Widget *ancestor)
void distributeHiddenEvent ()
void distributeMovedEvent ()
void distributeResizedEvent ()
void distributeShownEvent ()
std::list< Widget * > const & getChildren () const
void resizeToChildren ()
Protected Member Functions inherited from fcn::MouseListener
 MouseListener ()=default
Static Protected Attributes inherited from fcn::Widget
static DefaultFont mDefaultFont
static FontmGlobalFont = nullptr
static DeathListenermGuiDeathListener = nullptr
static VisibilityEventHandlermVisibilityEventHandler = nullptr
static std::list< Widget * > mWidgetInstances

Detailed Description

A movable container window that can hold other widgets.

Definition at line 21 of file window.hpp.

Constructor & Destructor Documentation

◆ Window() [1/2]

fcn::Window::Window ( )

Definition at line 17 of file window.cpp.

◆ Window() [2/2]

fcn::Window::Window ( std::string const & caption)
explicit

Constructor.

The window will be automatically resized in height to fit the caption.

Parameters
captionthe caption of the window.

Definition at line 25 of file window.cpp.

References fcn::Widget::addMouseListener(), fcn::Widget::setBorderSize(), setCaption(), and fcn::Widget::setPadding().

Member Function Documentation

◆ adjustSize()

◆ draw()

void fcn::Window::draw ( Graphics * graphics)
overridevirtual

Draws the widget.

The call to draw is initiated by the widget's parent. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension. If a widget has children, the parent's draw function will always be called before the children's draw functions are called.

NOTE: A widget with children won't draw its children unless the children area given by Widget::getChildrenArea returns a none empty rectangle inside the widgets dimension. The children area is considered relative to the widget's position.

Parameters
Graphics & RenderingA graphics object to draw with.
See also
getChildrenArea, drawOutline, drawBorder

Reimplemented from fcn::Container.

Definition at line 103 of file window.cpp.

References fcn::Color::a, fcn::Widget::drawBorder(), drawInnerBorder(), fcn::Graphics::drawText(), fcn::Graphics::fillRectangle(), getAlignment(), fcn::Widget::getBaseColor(), fcn::Widget::getBorderSize(), getCaption(), fcn::Widget::getFont(), fcn::Widget::getForegroundColor(), fcn::Font::getHeight(), fcn::Widget::getHeight(), getInnerBorderSize(), fcn::Widget::getPaddingLeft(), fcn::Widget::getPaddingRight(), fcn::Widget::getPaddingTop(), getTitleBarHeight(), fcn::Widget::getWidth(), isOpaque(), fcn::Container::mBackgroundWidget, fcn::Graphics::popClipArea(), fcn::Graphics::pushClipArea(), fcn::Graphics::setColor(), and fcn::Graphics::setFont().

◆ drawInnerBorder()

◆ getAlignment()

Graphics::Alignment fcn::Window::getAlignment ( ) const

Gets the alignment of the caption.

Returns
The alignment of caption.
See also
setAlignment, Graphics

Definition at line 71 of file window.cpp.

References mAlignment.

Referenced by draw().

◆ getCaption()

std::string const & fcn::Window::getCaption ( ) const

Gets the caption of the window.

Returns
the caption of the window.
See also
setCaption

Definition at line 61 of file window.cpp.

References mCaption.

Referenced by draw().

◆ getChildrenArea()

Rectangle fcn::Window::getChildrenArea ( )
overridevirtual

Gets the area of the widget occupied by the widget's children.

By default this method returns an empty rectangle as not all widgets are containers. If you want to make a container this method should return the area where the children resides. This method is used when drawing children of a widget when computing clip rectangles for the children.

NOTE: The returned rectangle should be relative to the widget, i.e a rectangle with x and y coordinate (0,0) and with width and height the same as the widget will let the children draw themselves in the whole widget.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its constant and that view is the children area. The size of a ScrollArea's children area might vary depending on if the scroll bars of the ScrollArea is shown or not.

Returns
The area of the widget occupied by the widget's children.

Reimplemented from fcn::Container.

Definition at line 217 of file window.cpp.

References fcn::Widget::getBorderSize(), fcn::Widget::getHeight(), getInnerBorderSize(), fcn::Widget::getPaddingBottom(), fcn::Widget::getPaddingLeft(), fcn::Widget::getPaddingRight(), fcn::Widget::getPaddingTop(), getTitleBarHeight(), fcn::Widget::getWidth(), fcn::Rectangle::height, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

◆ getInnerBorderSize()

unsigned int fcn::Window::getInnerBorderSize ( ) const

Get the size of the inner border (pixels).

Definition at line 51 of file window.cpp.

References mInnerBorderSize.

Referenced by adjustSize(), draw(), drawInnerBorder(), and getChildrenArea().

◆ getTitleBarHeight()

unsigned int fcn::Window::getTitleBarHeight ( ) const

Gets the title bar height.

Returns
The title bar height.
See also
setTitleBarHeight

Definition at line 41 of file window.cpp.

References mTitleBarHeight.

Referenced by adjustSize(), draw(), drawInnerBorder(), getChildrenArea(), and mousePressed().

◆ isMovable()

bool fcn::Window::isMovable ( ) const

Checks if the window is movable.

Returns
True if the window is movable, false otherwise.
See also
setMovable

Definition at line 233 of file window.cpp.

References mMovable.

Referenced by mouseDragged().

◆ isOpaque()

bool fcn::Window::isOpaque ( ) const
overridevirtual

Checks if the window is opaque.

Returns
True if the window is opaque, false otherwise.
See also
setOpaque

Reimplemented from fcn::Container.

Definition at line 243 of file window.cpp.

References fcn::Container::mOpaque.

Referenced by draw().

◆ mouseDragged()

void fcn::Window::mouseDragged ( MouseEvent & mouseEvent)
overridevirtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 194 of file window.cpp.

References fcn::InputEvent::consume(), fcn::Event::getSource(), fcn::MouseEvent::getX(), fcn::Widget::getX(), fcn::MouseEvent::getY(), fcn::Widget::getY(), fcn::InputEvent::isConsumed(), isMovable(), mDragOffsetX, mDragOffsetY, mMoved, and fcn::Widget::setPosition().

◆ mousePressed()

void fcn::Window::mousePressed ( MouseEvent & mouseEvent)
overridevirtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 172 of file window.cpp.

References fcn::Widget::getBorderSize(), fcn::Widget::getPaddingTop(), fcn::Widget::getParent(), fcn::Event::getSource(), getTitleBarHeight(), fcn::MouseEvent::getX(), fcn::MouseEvent::getY(), mDragOffsetX, mDragOffsetY, mMoved, and fcn::Widget::moveToTop().

◆ mouseReleased()

void fcn::Window::mouseReleased ( MouseEvent & mouseEvent)
overridevirtual

Called when a mouse button has been released on the widget area.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 189 of file window.cpp.

References mMoved.

◆ setAlignment()

void fcn::Window::setAlignment ( Graphics::Alignment alignment)

Sets the alignment of the caption.

Parameters
alignmentThe alignment of the caption.
See also
getAlignment, Graphics

Definition at line 66 of file window.cpp.

References mAlignment.

◆ setCaption()

void fcn::Window::setCaption ( std::string const & caption)

Sets the caption of the window.

Parameters
captionThe caption of the window.
See also
getCaption

Definition at line 56 of file window.cpp.

References mCaption.

Referenced by Window().

◆ setInnerBorderSize()

void fcn::Window::setInnerBorderSize ( unsigned int border)

Set the size of the inner border (pixels).

Definition at line 46 of file window.cpp.

References mInnerBorderSize.

◆ setMovable()

void fcn::Window::setMovable ( bool movable)

Sets the window to be movable or not.

Parameters
movableTrue if the window should be movable, false otherwise.
See also
isMovable

Definition at line 228 of file window.cpp.

References mMovable.

◆ setOpaque()

void fcn::Window::setOpaque ( bool opaque)
overridevirtual

Sets the window to be opaque or not.

An opaque window will draw it's background and it's content. A non opaque window will only draw it's content.

Parameters
opaqueTrue if the window should be opaque, false otherwise.
See also
isOpaque

Reimplemented from fcn::Container.

Definition at line 238 of file window.cpp.

References fcn::Container::mOpaque.

◆ setTitleBarHeight()

void fcn::Window::setTitleBarHeight ( unsigned int height)

Sets the title bar height.

Parameters
heightThe title height value.
See also
getTitleBarHeight

Definition at line 36 of file window.cpp.

References mTitleBarHeight.

Member Data Documentation

◆ mAlignment

Graphics::Alignment fcn::Window::mAlignment {Graphics::Alignment::Center}
protected

Holds the alignment of the caption.

Definition at line 159 of file window.hpp.

Referenced by getAlignment(), and setAlignment().

◆ mCaption

std::string fcn::Window::mCaption
protected

Holds the caption of the window.

Definition at line 154 of file window.hpp.

Referenced by adjustSize(), getCaption(), and setCaption().

◆ mDragOffsetX

int fcn::Window::mDragOffsetX {0}
protected

Holds a drag offset as an x coordinate where the drag of the window started if the window is being dragged.

It's used to move the window correctly when dragged.

Definition at line 181 of file window.hpp.

Referenced by mouseDragged(), and mousePressed().

◆ mDragOffsetY

int fcn::Window::mDragOffsetY {0}
protected

Holds a drag offset as an y coordinate where the drag of the window started if the window is being dragged.

It's used to move the window correctly when dragged.

Definition at line 188 of file window.hpp.

Referenced by mouseDragged(), and mousePressed().

◆ mInnerBorderSize

unsigned int fcn::Window::mInnerBorderSize {1}
protected

Holds the size of the inner border.

Definition at line 169 of file window.hpp.

Referenced by getInnerBorderSize(), and setInnerBorderSize().

◆ mMovable

bool fcn::Window::mMovable {true}
protected

True if the window is movable, false otherwise.

Definition at line 174 of file window.hpp.

Referenced by isMovable(), and setMovable().

◆ mMoved

bool fcn::Window::mMoved {false}
protected

True if the window is being moved, false otherwise.

Definition at line 193 of file window.hpp.

Referenced by mouseDragged(), mousePressed(), and mouseReleased().

◆ mTitleBarHeight

unsigned int fcn::Window::mTitleBarHeight {16}
protected

Holds the title bar height of the window.

Definition at line 164 of file window.hpp.

Referenced by getTitleBarHeight(), and setTitleBarHeight().


The documentation for this class was generated from the following files: