ManaPlus
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes
ScrollArea Class Reference

#include <scrollarea.h>

Inheritance diagram for ScrollArea:
BasicContainer MouseListener WidgetListener Widget WidgetDeathListener Widget2

Public Types

enum  ScrollPolicy { SHOW_ALWAYS = 0, SHOW_NEVER, SHOW_AUTO }
 

Public Member Functions

 ScrollArea (Widget2 *const widget2, Widget *const widget, const Opaque opaque, const std::string &skin)
 
 ~ScrollArea ()
 
void logic ()
 
void updateAlpha ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void drawFrame (Graphics *const graphics)
 
void safeDrawFrame (Graphics *const graphics)
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
void mouseMoved (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
Rect getVerticalBarDimension () const
 
Rect getHorizontalBarDimension () const
 
Rect getVerticalMarkerDimension ()
 
Rect getHorizontalMarkerDimension ()
 
Rect getUpButtonDimension () const
 
Rect getDownButtonDimension () const
 
Rect getLeftButtonDimension () const
 
Rect getRightButtonDimension () const
 
void setContent (Widget *widget)
 
WidgetgetContent ()
 
void setHorizontalScrollPolicy (const ScrollPolicy hPolicy)
 
ScrollPolicy getHorizontalScrollPolicy () const
 
void setVerticalScrollPolicy (const ScrollPolicy vPolicy)
 
ScrollPolicy getVerticalScrollPolicy () const
 
void setScrollPolicy (const ScrollPolicy hPolicy, const ScrollPolicy vPolicy)
 
void setVerticalScrollAmount (const int vScroll)
 
int getVerticalScrollAmount () const
 
void setHorizontalScrollAmount (int hScroll)
 
int getHorizontalScrollAmount () const
 
void setScrollAmount (const int hScroll, const int vScroll)
 
int getHorizontalMaxScroll ()
 
int getVerticalMaxScroll ()
 
void setScrollbarWidth (const int width)
 
int getScrollbarWidth () const
 
void setLeftButtonScrollAmount (const int amount)
 
void setRightButtonScrollAmount (const int amount)
 
void setUpButtonScrollAmount (const int amount)
 
void setDownButtonScrollAmount (const int amount)
 
int getLeftButtonScrollAmount () const
 
int getRightButtonScrollAmount () const
 
int getUpButtonScrollAmount () const
 
int getDownButtonScrollAmount () const
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
Rect getChildrenArea ()
 
WidgetgetWidgetAt (int x, int y)
 
void setWidth (int width)
 
void setHeight (int height)
 
void setDimension (const Rect &dimension)
 
void mouseWheelMovedUp (MouseEvent &event)
 
void mouseWheelMovedDown (MouseEvent &event)
 
bool isSelectable () const
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Protected Types

enum  BUTTON_DIR {
  UP = 0, DOWN, LEFT, RIGHT,
  BUTTONS_DIR
}
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 

Protected Member Functions

void init (std::string skinName)
 
void checkPolicies ()
 
void drawButton (Graphics *const graphics, const BUTTON_DIR dir)
 
void calcButton (Graphics *const graphics, const BUTTON_DIR dir)
 
void drawVBar (Graphics *const graphics) const
 
void drawHBar (Graphics *const graphics) const
 
void drawVMarker (Graphics *const graphics)
 
void drawHMarker (Graphics *const graphics)
 
void calcVBar (const Graphics *const graphics)
 
void calcHBar (const Graphics *const graphics)
 
void calcVMarker (Graphics *const graphics)
 
void calcHMarker (Graphics *const graphics)
 
ImagegetImageByState (Rect &dim, const BUTTON_DIR dir)
 
void updateCalcFlag (const Graphics *const graphics)
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 

Protected Attributes

ImageCollectionmVertexes
 
ImageCollectionmVertexes2
 
ScrollPolicy mHPolicy
 
ScrollPolicy mVPolicy
 
int mVScroll
 
int mHScroll
 
int mScrollbarWidth
 
int mUpButtonScrollAmount
 
int mDownButtonScrollAmount
 
int mLeftButtonScrollAmount
 
int mRightButtonScrollAmount
 
int mHorizontalMarkerDragOffset
 
int mVerticalMarkerDragOffset
 
int mX
 
int mY
 
int mClickX
 
int mClickY
 
int mXOffset
 
int mYOffset
 
int mDrawWidth
 
int mDrawHeight
 
bool mVBarVisible
 
bool mHBarVisible
 
bool mUpButtonPressed
 
bool mDownButtonPressed
 
bool mLeftButtonPressed
 
bool mRightButtonPressed
 
bool mIsVerticalMarkerDragged
 
bool mIsHorizontalMarkerDragged
 
Opaque mOpaque
 
bool mHasMouse
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Static Protected Attributes

static int instances = 0
 
static float mAlpha = 1.0
 
static bool mShowButtons = true
 
static int mMarkerSize = 0
 
static int mScrollbarSize = 12
 
static ImageRect background
 
static ImageRect vMarker
 
static ImageRect vMarkerHi
 
static ImageRect vBackground
 
static ImageRect hBackground
 
static Imagebuttons [4][2]
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 

Detailed Description

A scroll area.

Contrary to Guichan's scroll area, this scroll area takes ownership over its content. However, it won't delete a previously set content widget when setContent is called!

Definition at line 90 of file scrollarea.h.

Member Enumeration Documentation

◆ BUTTON_DIR

enum ScrollArea::BUTTON_DIR
protected
Enumerator
UP 
DOWN 
LEFT 
RIGHT 
BUTTONS_DIR 

Definition at line 433 of file scrollarea.h.

◆ ScrollPolicy

Scrollpolicies for the horizontal and vertical scrollbar. The policies are:

SHOW_ALWAYS - Always show the scrollbars no matter what. SHOW_NEVER - Never show the scrollbars no matter waht. SHOW_AUTO - Show the scrollbars only when needed. That is if the content grows larger then the ScrollArea.

Enumerator
SHOW_ALWAYS 
SHOW_NEVER 
SHOW_AUTO 

Definition at line 104 of file scrollarea.h.

Constructor & Destructor Documentation

◆ ScrollArea()

ScrollArea::ScrollArea ( Widget2 *const  widget2,
Widget *const  widget,
const Opaque  opaque,
const std::string &  skin 
)

Definition at line 104 of file scrollarea.cpp.

References Widget::addMouseListener(), init(), mOpaque, and setContent().

107  :
108  BasicContainer(widget2),
109  MouseListener(),
110  WidgetListener(),
115  mVScroll(0),
116  mHScroll(0),
117  mScrollbarWidth(12),
124  mX(0),
125  mY(0),
126  mClickX(0),
127  mClickY(0),
128  mXOffset(0),
129  mYOffset(0),
130  mDrawWidth(0),
131  mDrawHeight(0),
132  mVBarVisible(false),
133  mHBarVisible(false),
134  mUpButtonPressed(false),
135  mDownButtonPressed(false),
136  mLeftButtonPressed(false),
137  mRightButtonPressed(false),
141  mHasMouse(false)
142 {
143  setContent(widget);
144  addMouseListener(this);
145  mOpaque = opaque;
146  init(skin);
147 }
ImageCollection * mVertexes2
Definition: scrollarea.h:483
bool mRightButtonPressed
Definition: scrollarea.h:577
int mHScroll
Definition: scrollarea.h:503
int mScrollbarWidth
Definition: scrollarea.h:508
int mXOffset
Definition: scrollarea.h:544
int mUpButtonScrollAmount
Definition: scrollarea.h:513
Opaque mOpaque
Definition: scrollarea.h:593
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:587
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
int mDrawHeight
Definition: scrollarea.h:547
bool mLeftButtonPressed
Definition: scrollarea.h:572
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:582
bool mHasMouse
Definition: scrollarea.h:595
bool mVBarVisible
Definition: scrollarea.h:552
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
int mHorizontalMarkerDragOffset
Definition: scrollarea.h:533
int mRightButtonScrollAmount
Definition: scrollarea.h:528
void setContent(Widget *widget)
ImageCollection * mVertexes
Definition: scrollarea.h:482
bool mDownButtonPressed
Definition: scrollarea.h:567
const bool Opaque_true
Definition: opaque.h:29
int mLeftButtonScrollAmount
Definition: scrollarea.h:523
int mVScroll
Definition: scrollarea.h:498
bool mUpButtonPressed
Definition: scrollarea.h:562
void init(std::string skinName)
Definition: scrollarea.cpp:181
int mDownButtonScrollAmount
Definition: scrollarea.h:518
BasicContainer(const Widget2 *const widget)
ScrollPolicy mHPolicy
Definition: scrollarea.h:488
bool mHBarVisible
Definition: scrollarea.h:557
int mYOffset
Definition: scrollarea.h:545
int mDrawWidth
Definition: scrollarea.h:546
int mVerticalMarkerDragOffset
Definition: scrollarea.h:538

◆ ~ScrollArea()

ScrollArea::~ScrollArea ( )

Destructor. Also deletes the content.

Definition at line 149 of file scrollarea.cpp.

References background, buttons, BUTTONS_DIR, Image::decRef(), delete2, getContent(), gui, hBackground, instances, mVertexes, mVertexes2, Gui::removeDragged(), setContent(), Theme::unloadRect(), UP, vBackground, vMarker, and vMarkerHi.

150 {
151  if (gui != nullptr)
152  gui->removeDragged(this);
153 
154  // Garbage collection
155  delete getContent();
156 
157  instances--;
158  if (instances == 0)
159  {
161  Theme::unloadRect(vMarker, 0, 8);
165  for (int i = 0; i < 2; i ++)
166  {
167  for (int f = UP; f < BUTTONS_DIR; f ++)
168  {
169  if (buttons[f][i] != nullptr)
170  buttons[f][i]->decRef();
171  }
172  }
173  }
174 
177 
178  setContent(nullptr);
179 }
ImageCollection * mVertexes2
Definition: scrollarea.h:483
Gui * gui
Definition: gui.cpp:110
#define delete2(var)
Definition: delete2.h:24
static ImageRect vBackground
Definition: scrollarea.h:478
static ImageRect vMarkerHi
Definition: scrollarea.h:477
static ImageRect vMarker
Definition: scrollarea.h:476
static Image * buttons[4][2]
Definition: scrollarea.h:480
static ImageRect hBackground
Definition: scrollarea.h:479
static int instances
Definition: scrollarea.h:470
static ImageRect background
Definition: scrollarea.h:475
void setContent(Widget *widget)
ImageCollection * mVertexes
Definition: scrollarea.h:482
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:914
void decRef()
Definition: image.cpp:522
Widget * getContent()

Member Function Documentation

◆ calcButton()

void ScrollArea::calcButton ( Graphics *const  graphics,
const BUTTON_DIR  dir 
)
protected

Definition at line 544 of file scrollarea.cpp.

References calcTileCollection(), getImageByState(), mVertexes, Rect::x, and Rect::y.

Referenced by draw().

546 {
547  Rect dim;
548  const Image *const image = getImageByState(dim, dir);
549 
550  if (image != nullptr)
551  {
552  static_cast<Graphics*>(graphics)->calcTileCollection(
553  mVertexes, image, dim.x, dim.y);
554  }
555 }
void void calcTileCollection(ImageCollection *restrict const vertCol, const Image *restrict const image, int x, int y) restrict2 override final
Definition: rect.h:72
Image * getImageByState(Rect &dim, const BUTTON_DIR dir)
Definition: scrollarea.cpp:503
int x
Definition: rect.h:208
int y
Definition: rect.h:213
ImageCollection * mVertexes
Definition: scrollarea.h:482
Definition: image.h:61

◆ calcHBar()

void ScrollArea::calcHBar ( const Graphics *const  graphics)
protected

Definition at line 635 of file scrollarea.cpp.

References Graphics::calcPattern(), getHorizontalBarDimension(), Image::getWidth(), ImageRect::grid, hBackground, Rect::height, mVertexes, Rect::width, Rect::x, and Rect::y.

Referenced by draw().

636 {
637  const Rect &dim = getHorizontalBarDimension();
638 
639  if (hBackground.grid[4] != nullptr)
640  {
641  graphics->calcPattern(mVertexes,
642  hBackground.grid[4],
643  dim.x, dim.y,
644  dim.width, dim.height);
645  }
646 
647  if (hBackground.grid[3] != nullptr)
648  {
649  graphics->calcPattern(mVertexes,
650  hBackground.grid[3],
651  dim.x, dim.y,
652  hBackground.grid[3]->getWidth(), dim.height);
653  }
654 
655  if (hBackground.grid[5] != nullptr)
656  {
657  graphics->calcPattern(mVertexes,
658  hBackground.grid[5],
659  dim.x + dim.width - hBackground.grid[5]->getWidth(),
660  dim.y,
661  hBackground.grid[5]->getWidth(),
662  dim.height);
663  }
664 }
int width
Definition: rect.h:218
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:997
Definition: rect.h:72
int x
Definition: rect.h:208
Image * grid[9]
Definition: imagerect.h:41
int y
Definition: rect.h:213
int height
Definition: rect.h:223
static ImageRect hBackground
Definition: scrollarea.h:479
virtual void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
ImageCollection * mVertexes
Definition: scrollarea.h:482
int getWidth() const A_INLINE
Definition: image.h:116

◆ calcHMarker()

void ScrollArea::calcHMarker ( Graphics *const  graphics)
protected

Definition at line 723 of file scrollarea.cpp.

References Graphics::calcWindow(), getHorizontalMarkerDimension(), Rect::height, Widget::mDimension, mHasMouse, mScrollbarWidth, mVertexes, mY, vMarker, vMarkerHi, Rect::width, Rect::x, and Rect::y.

Referenced by draw().

724 {
725  const Rect dim = getHorizontalMarkerDimension();
726 
727  if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
728  {
729  graphics->calcWindow(mVertexes,
730  dim.x, dim.y,
731  dim.width, dim.height,
732  vMarkerHi);
733  }
734  else
735  {
736  graphics->calcWindow(mVertexes,
737  dim.x, dim.y,
738  dim.width, dim.height,
739  vMarker);
740  }
741 }
int width
Definition: rect.h:218
Rect getHorizontalMarkerDimension()
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mHasMouse
Definition: scrollarea.h:595
int x
Definition: rect.h:208
static ImageRect vMarkerHi
Definition: scrollarea.h:477
int y
Definition: rect.h:213
static ImageRect vMarker
Definition: scrollarea.h:476
int height
Definition: rect.h:223
ImageCollection * mVertexes
Definition: scrollarea.h:482
Rect mDimension
Definition: widget.h:1100
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0

◆ calcVBar()

void ScrollArea::calcVBar ( const Graphics *const  graphics)
protected

Definition at line 580 of file scrollarea.cpp.

References Graphics::calcPattern(), Image::getHeight(), getVerticalBarDimension(), ImageRect::grid, Rect::height, mVertexes, vBackground, Rect::width, Rect::x, and Rect::y.

Referenced by draw().

581 {
582  const Rect &dim = getVerticalBarDimension();
583 
584  if (vBackground.grid[4] != nullptr)
585  {
586  graphics->calcPattern(mVertexes,
587  vBackground.grid[4],
588  dim.x, dim.y,
589  dim.width, dim.height);
590  }
591  if (vBackground.grid[1] != nullptr)
592  {
593  graphics->calcPattern(mVertexes,
594  vBackground.grid[1],
595  dim.x, dim.y,
596  dim.width, vBackground.grid[1]->getHeight());
597  }
598  if (vBackground.grid[7] != nullptr)
599  {
600  graphics->calcPattern(mVertexes,
601  vBackground.grid[7],
602  dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
603  dim.width, vBackground.grid[7]->getHeight());
604  }
605 }
int width
Definition: rect.h:218
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:977
Definition: rect.h:72
static ImageRect vBackground
Definition: scrollarea.h:478
int x
Definition: rect.h:208
Image * grid[9]
Definition: imagerect.h:41
int y
Definition: rect.h:213
int height
Definition: rect.h:223
virtual void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
ImageCollection * mVertexes
Definition: scrollarea.h:482
int getHeight() const A_INLINE
Definition: image.h:122

◆ calcVMarker()

void ScrollArea::calcVMarker ( Graphics *const  graphics)
protected

Definition at line 684 of file scrollarea.cpp.

References Graphics::calcWindow(), getVerticalMarkerDimension(), Rect::height, Widget::mDimension, mHasMouse, mScrollbarWidth, mVertexes, mX, vMarker, vMarkerHi, Rect::width, Rect::x, and Rect::y.

Referenced by draw().

685 {
686  const Rect &dim = getVerticalMarkerDimension();
687 
688  if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
689  {
690  graphics->calcWindow(mVertexes,
691  dim.x, dim.y,
692  dim.width, dim.height,
693  vMarkerHi);
694  }
695  else
696  {
697  graphics->calcWindow(mVertexes,
698  dim.x, dim.y,
699  dim.width, dim.height,
700  vMarker);
701  }
702 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
Rect getVerticalMarkerDimension()
bool mHasMouse
Definition: scrollarea.h:595
int x
Definition: rect.h:208
static ImageRect vMarkerHi
Definition: scrollarea.h:477
int y
Definition: rect.h:213
static ImageRect vMarker
Definition: scrollarea.h:476
int height
Definition: rect.h:223
ImageCollection * mVertexes
Definition: scrollarea.h:482
Rect mDimension
Definition: widget.h:1100
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0

◆ checkPolicies()

void ScrollArea::checkPolicies ( )
protected

Checks the policies for the scroll bars.

Definition at line 1382 of file scrollarea.cpp.

References getContent(), Widget::getHeight(), Widget::getWidth(), mHBarVisible, mHPolicy, mScrollbarWidth, mVBarVisible, mVPolicy, SHOW_ALWAYS, SHOW_AUTO, and SHOW_NEVER.

Referenced by getHorizontalMaxScroll(), getVerticalMaxScroll(), logic(), setContent(), setDimension(), setHeight(), setHorizontalScrollPolicy(), setScrollPolicy(), setVerticalScrollPolicy(), and setWidth().

1383 {
1384  const int w = getWidth();
1385  const int h = getHeight();
1386 
1387  mHBarVisible = false;
1388  mVBarVisible = false;
1389 
1390  const Widget *const content = getContent();
1391  if (content == nullptr)
1392  {
1395  return;
1396  }
1397 
1398  if (mHPolicy == SHOW_AUTO &&
1399  mVPolicy == SHOW_AUTO)
1400  {
1401  if (content->getWidth() <= w
1402  && content->getHeight() <= h)
1403  {
1404  mHBarVisible = false;
1405  mVBarVisible = false;
1406  }
1407 
1408  if (content->getWidth() > w)
1409  {
1410  mHBarVisible = true;
1411  }
1412 
1413  if ((content->getHeight() > h)
1414  || (mHBarVisible && content->getHeight()
1415  > h - mScrollbarWidth))
1416  {
1417  mVBarVisible = true;
1418  }
1419 
1420  if (mVBarVisible && content->getWidth() > w - mScrollbarWidth)
1421  mHBarVisible = true;
1422 
1423  return;
1424  }
1425 
1426  switch (mHPolicy)
1427  {
1428  case SHOW_NEVER:
1429  mHBarVisible = false;
1430  break;
1431 
1432  case SHOW_ALWAYS:
1433  mHBarVisible = true;
1434  break;
1435 
1436  case SHOW_AUTO:
1437  if (mVPolicy == SHOW_NEVER)
1438  {
1439  mHBarVisible = (content->getWidth() > w);
1440  }
1441  else // (mVPolicy == SHOW_ALWAYS)
1442  {
1443  mHBarVisible = (content->getWidth()
1444  > w - mScrollbarWidth);
1445  }
1446  break;
1447 
1448  default:
1449  break;
1450  }
1451 
1452  switch (mVPolicy)
1453  {
1454  case SHOW_NEVER:
1455  mVBarVisible = false;
1456  break;
1457 
1458  case SHOW_ALWAYS:
1459  mVBarVisible = true;
1460  break;
1461 
1462  case SHOW_AUTO:
1463  if (mHPolicy == SHOW_NEVER)
1464  {
1465  mVBarVisible = (content->getHeight() > h);
1466  }
1467  else // (mHPolicy == SHOW_ALWAYS)
1468  {
1469  mVBarVisible = (content->getHeight()
1470  > h - mScrollbarWidth);
1471  }
1472  break;
1473  default:
1474  break;
1475  }
1476 }
int getWidth() const
Definition: widget.h:220
int mScrollbarWidth
Definition: scrollarea.h:508
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
bool mVBarVisible
Definition: scrollarea.h:552
Definition: widget.h:97
int getHeight() const
Definition: widget.h:239
ScrollPolicy mHPolicy
Definition: scrollarea.h:488
bool mHBarVisible
Definition: scrollarea.h:557
Widget * getContent()

◆ draw()

void ScrollArea::draw ( Graphics *const  graphics)
virtual

Draws the scroll area.

Implements Widget.

Definition at line 343 of file scrollarea.cpp.

References BLOCK_END, BLOCK_START, calcButton(), calcHBar(), calcHMarker(), calcVBar(), calcVMarker(), ImageCollection::clear(), DOWN, BasicContainer::drawChildren(), Graphics::drawTileCollection(), Graphics::finalize(), Graphics::getRedraw(), LEFT, mHBarVisible, mOpaque, Widget::mRedraw, mShowButtons, mVBarVisible, mVertexes, Opaque_false, RIGHT, Graphics::setRedraw(), UP, updateAlpha(), and updateCalcFlag().

344 {
345  BLOCK_START("ScrollArea::draw")
347  {
348  if (mOpaque == Opaque_false)
349  updateCalcFlag(graphics);
350  // need add caching or remove calc calls.
351 // if (mRedraw)
352  {
353  mVertexes->clear();
354  if (mVBarVisible)
355  {
356  if (mShowButtons)
357  {
358  calcButton(graphics, UP);
359  calcButton(graphics, DOWN);
360  }
361  calcVBar(graphics);
362  calcVMarker(graphics);
363  }
364 
365  if (mHBarVisible)
366  {
367  if (mShowButtons)
368  {
369  calcButton(graphics, LEFT);
370  calcButton(graphics, RIGHT);
371  }
372  calcHBar(graphics);
373  calcHMarker(graphics);
374  }
375  graphics->finalize(mVertexes);
376  }
377  graphics->drawTileCollection(mVertexes);
378  }
379 
380  updateAlpha();
381 
382  if (mRedraw)
383  {
384  const bool redraw = graphics->getRedraw();
385  graphics->setRedraw(true);
386  drawChildren(graphics);
387  graphics->setRedraw(redraw);
388  }
389  else
390  {
391  drawChildren(graphics);
392  }
393  mRedraw = false;
394  BLOCK_END("ScrollArea::draw")
395 }
void calcVBar(const Graphics *const graphics)
Definition: scrollarea.cpp:580
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
Opaque mOpaque
Definition: scrollarea.h:593
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void calcButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:544
void calcVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:684
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
bool mVBarVisible
Definition: scrollarea.h:552
void calcHBar(const Graphics *const graphics)
Definition: scrollarea.cpp:635
void calcHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:723
const bool Opaque_false
Definition: opaque.h:29
bool getRedraw() const
Definition: graphics.h:286
ImageCollection * mVertexes
Definition: scrollarea.h:482
virtual void drawChildren(Graphics *const graphics)
bool mRedraw
Definition: widget.h:1163
static bool mShowButtons
Definition: scrollarea.h:472
void setRedraw(const bool n)
Definition: graphics.h:283
bool mHBarVisible
Definition: scrollarea.h:557
void updateCalcFlag(const Graphics *const graphics)
Definition: scrollarea.cpp:429
void updateAlpha()
Definition: scrollarea.cpp:319

◆ drawButton()

void ScrollArea::drawButton ( Graphics *const  graphics,
const BUTTON_DIR  dir 
)
protected

Definition at line 534 of file scrollarea.cpp.

References Graphics::drawImage(), getImageByState(), Rect::x, and Rect::y.

Referenced by safeDraw().

536 {
537  Rect dim;
538  const Image *const image = getImageByState(dim, dir);
539 
540  if (image != nullptr)
541  graphics->drawImage(image, dim.x, dim.y);
542 }
Definition: rect.h:72
Image * getImageByState(Rect &dim, const BUTTON_DIR dir)
Definition: scrollarea.cpp:503
int x
Definition: rect.h:208
int y
Definition: rect.h:213
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61

◆ drawFrame()

void ScrollArea::drawFrame ( Graphics *const  graphics)
virtual

Draws the background and border of the scroll area.

Reimplemented from Widget.

Definition at line 455 of file scrollarea.cpp.

References background, BLOCK_END, BLOCK_START, Graphics::calcWindow(), ImageCollection::clear(), Graphics::drawTileCollection(), Graphics::finalize(), Rect::height, Widget::mDimension, Widget::mFrameSize, mOpaque, Widget::mRedraw, mVertexes2, Opaque_true, updateCalcFlag(), and Rect::width.

456 {
457  BLOCK_START("ScrollArea::drawFrame")
458  if (mOpaque == Opaque_true)
459  {
460  const int bs = mFrameSize * 2;
461  const int w = mDimension.width + bs;
462  const int h = mDimension.height + bs;
463 
464  updateCalcFlag(graphics);
465 
466  if (mRedraw)
467  {
468  mVertexes2->clear();
469  graphics->calcWindow(mVertexes2,
470  0, 0,
471  w, h,
472  background);
473  graphics->finalize(mVertexes2);
474  }
475  graphics->drawTileCollection(mVertexes2);
476  }
477  BLOCK_END("ScrollArea::drawFrame")
478 }
ImageCollection * mVertexes2
Definition: scrollarea.h:483
int width
Definition: rect.h:218
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
Opaque mOpaque
Definition: scrollarea.h:593
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
static ImageRect background
Definition: scrollarea.h:475
const bool Opaque_true
Definition: opaque.h:29
bool mRedraw
Definition: widget.h:1163
Rect mDimension
Definition: widget.h:1100
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
void updateCalcFlag(const Graphics *const graphics)
Definition: scrollarea.cpp:429

◆ drawHBar()

void ScrollArea::drawHBar ( Graphics *const  graphics) const
protected

Definition at line 607 of file scrollarea.cpp.

References Graphics::drawPattern(), getHorizontalBarDimension(), Image::getWidth(), ImageRect::grid, hBackground, Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by safeDraw().

608 {
609  const Rect &dim = getHorizontalBarDimension();
610 
611  if (hBackground.grid[4] != nullptr)
612  {
613  graphics->drawPattern(hBackground.grid[4],
614  dim.x, dim.y,
615  dim.width, dim.height);
616  }
617 
618  if (hBackground.grid[3] != nullptr)
619  {
620  graphics->drawPattern(hBackground.grid[3],
621  dim.x, dim.y,
622  hBackground.grid[3]->getWidth(), dim.height);
623  }
624 
625  if (hBackground.grid[5] != nullptr)
626  {
627  graphics->drawPattern(hBackground.grid[5],
628  dim.x + dim.width - hBackground.grid[5]->getWidth(),
629  dim.y,
630  hBackground.grid[5]->getWidth(),
631  dim.height);
632  }
633 }
int width
Definition: rect.h:218
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:997
Definition: rect.h:72
int x
Definition: rect.h:208
Image * grid[9]
Definition: imagerect.h:41
int y
Definition: rect.h:213
int height
Definition: rect.h:223
static ImageRect hBackground
Definition: scrollarea.h:479
int getWidth() const A_INLINE
Definition: image.h:116
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0

◆ drawHMarker()

void ScrollArea::drawHMarker ( Graphics *const  graphics)
protected

Definition at line 704 of file scrollarea.cpp.

References Graphics::drawImageRect(), getHorizontalMarkerDimension(), Rect::height, Widget::mDimension, mHasMouse, mScrollbarWidth, mY, vMarker, vMarkerHi, Rect::width, Rect::x, and Rect::y.

Referenced by safeDraw().

705 {
706  const Rect dim = getHorizontalMarkerDimension();
707 
708  if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
709  {
710  graphics->drawImageRect(dim.x, dim.y,
711  dim.width, dim.height,
712  vMarkerHi);
713  }
714  else
715  {
716  graphics->drawImageRect(
717  dim.x, dim.y,
718  dim.width, dim.height,
719  vMarker);
720  }
721 }
int width
Definition: rect.h:218
Rect getHorizontalMarkerDimension()
int mScrollbarWidth
Definition: scrollarea.h:508
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
Definition: rect.h:72
bool mHasMouse
Definition: scrollarea.h:595
int x
Definition: rect.h:208
static ImageRect vMarkerHi
Definition: scrollarea.h:477
int y
Definition: rect.h:213
static ImageRect vMarker
Definition: scrollarea.h:476
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

◆ drawVBar()

void ScrollArea::drawVBar ( Graphics *const  graphics) const
protected

Definition at line 557 of file scrollarea.cpp.

References Graphics::drawPattern(), Image::getHeight(), getVerticalBarDimension(), ImageRect::grid, Rect::height, vBackground, Rect::width, Rect::x, and Rect::y.

Referenced by safeDraw().

558 {
559  const Rect &dim = getVerticalBarDimension();
560 
561  if (vBackground.grid[4] != nullptr)
562  {
563  graphics->drawPattern(vBackground.grid[4],
564  dim.x, dim.y, dim.width, dim.height);
565  }
566  if (vBackground.grid[1] != nullptr)
567  {
568  graphics->drawPattern(vBackground.grid[1],
569  dim.x, dim.y,
570  dim.width, vBackground.grid[1]->getHeight());
571  }
572  if (vBackground.grid[7] != nullptr)
573  {
574  graphics->drawPattern(vBackground.grid[7],
575  dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
576  dim.width, vBackground.grid[7]->getHeight());
577  }
578 }
int width
Definition: rect.h:218
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:977
Definition: rect.h:72
static ImageRect vBackground
Definition: scrollarea.h:478
int x
Definition: rect.h:208
Image * grid[9]
Definition: imagerect.h:41
int y
Definition: rect.h:213
int height
Definition: rect.h:223
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
int getHeight() const A_INLINE
Definition: image.h:122

◆ drawVMarker()

void ScrollArea::drawVMarker ( Graphics *const  graphics)
protected

Definition at line 666 of file scrollarea.cpp.

References Graphics::drawImageRect(), getVerticalMarkerDimension(), Rect::height, Widget::mDimension, mHasMouse, mScrollbarWidth, mX, vMarker, vMarkerHi, Rect::width, Rect::x, and Rect::y.

Referenced by safeDraw().

667 {
668  const Rect &dim = getVerticalMarkerDimension();
669 
670  if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
671  {
672  graphics->drawImageRect(dim.x, dim.y,
673  dim.width, dim.height,
674  vMarkerHi);
675  }
676  else
677  {
678  graphics->drawImageRect(dim.x, dim.y,
679  dim.width, dim.height,
680  vMarker);
681  }
682 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
Definition: rect.h:72
Rect getVerticalMarkerDimension()
bool mHasMouse
Definition: scrollarea.h:595
int x
Definition: rect.h:208
static ImageRect vMarkerHi
Definition: scrollarea.h:477
int y
Definition: rect.h:213
static ImageRect vMarker
Definition: scrollarea.h:476
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

◆ getChildrenArea()

Rect ScrollArea::getChildrenArea ( )
virtual

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.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its contant 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.
See also
BasicContainer
BasicContainer::getChildrenArea
BasicContainer::drawChildren

Reimplemented from BasicContainer.

Definition at line 1322 of file scrollarea.cpp.

References Widget::getHeight(), Widget::getWidth(), Rect::height, mHBarVisible, mScrollbarWidth, mVBarVisible, and Rect::width.

Referenced by getDownButtonScrollAmount(), getHorizontalMarkerDimension(), getHorizontalMaxScroll(), getVerticalMarkerDimension(), getVerticalMaxScroll(), getWidgetAt(), mousePressed(), mouseWheelMovedDown(), and mouseWheelMovedUp().

1323 {
1324  const Rect area = Rect(0, 0,
1327 
1328  if (area.width < 0 || area.height < 0)
1329  return Rect();
1330 
1331  return area;
1332 }
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
int getHeight() const
Definition: widget.h:239
bool mHBarVisible
Definition: scrollarea.h:557

◆ getContent()

Widget * ScrollArea::getContent ( )

Gets the content.

Returns
The content of the scroll area.

Definition at line 1207 of file scrollarea.cpp.

References BasicContainer::mWidgets.

Referenced by checkPolicies(), getHorizontalMaxScroll(), getVerticalMaxScroll(), getWidgetAt(), isOpaque(), logic(), showWidgetPart(), ShortcutWindow::widgetHidden(), widgetResized(), ~ScrollArea(), and Setup_Colors::~Setup_Colors().

1208 {
1209  if (!mWidgets.empty())
1210  return *mWidgets.begin();
1211 
1212  return nullptr;
1213 }
WidgetList mWidgets

◆ getDownButtonDimension()

Rect ScrollArea::getDownButtonDimension ( ) const

Definition at line 1144 of file scrollarea.cpp.

References Rect::height, Widget::mDimension, mHBarVisible, mScrollbarWidth, mShowButtons, mVBarVisible, and Rect::width.

Referenced by getImageByState(), isOpaque(), and mousePressed().

1145 {
1146  if (!mVBarVisible || !mShowButtons)
1147  return Rect(0, 0, 0, 0);
1148 
1149  if (mHBarVisible)
1150  {
1154  mScrollbarWidth);
1155  }
1156 
1160  mScrollbarWidth);
1161 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getDownButtonScrollAmount()

int ScrollArea::getDownButtonScrollAmount ( ) const
inline

Gets the amount to scroll in pixels when the down scroll button is pushed.

Returns
The amount to scroll in pixels.
See also
setDownButtonScrollAmount

Definition at line 410 of file scrollarea.h.

References A_WARN_UNUSED, getChildrenArea(), getWidgetAt(), isSelectable(), mDownButtonScrollAmount, mouseWheelMovedDown(), mouseWheelMovedUp(), noexcept2, setDimension(), setHeight(), setWidth(), showWidgetPart(), x, and y.

411  { return mDownButtonScrollAmount; }
int mDownButtonScrollAmount
Definition: scrollarea.h:518

◆ getHorizontalBarDimension()

Rect ScrollArea::getHorizontalBarDimension ( ) const

Definition at line 997 of file scrollarea.cpp.

References Rect::height, Widget::mDimension, mHBarVisible, mScrollbarWidth, mShowButtons, mVBarVisible, and Rect::width.

Referenced by calcHBar(), drawHBar(), isOpaque(), mouseDragged(), and mousePressed().

998 {
999  if (!mHBarVisible)
1000  return Rect(0, 0, 0, 0);
1001 
1002  const int width = mShowButtons ? mScrollbarWidth : 0;
1003  if (mVBarVisible)
1004  {
1005  return Rect(width,
1007  mDimension.width - 2 * width - mScrollbarWidth,
1008  mScrollbarWidth);
1009  }
1010 
1011  return Rect(width,
1013  mDimension.width - 2 * width,
1014  mScrollbarWidth);
1015 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getHorizontalMarkerDimension()

Rect ScrollArea::getHorizontalMarkerDimension ( )

Definition at line 1074 of file scrollarea.cpp.

References getChildrenArea(), getHorizontalMaxScroll(), Widget::getWidth(), Rect::height, Widget::mDimension, mHBarVisible, mHScroll, mMarkerSize, mScrollbarWidth, mShowButtons, mVBarVisible, BasicContainer::mWidgets, and Rect::width.

Referenced by calcHMarker(), drawHMarker(), isOpaque(), mouseDragged(), and mousePressed().

1075 {
1076  if (!mHBarVisible)
1077  return Rect(0, 0, 0, 0);
1078 
1079  int length, pos;
1080  int width;
1081  const int w2 = mShowButtons
1082  ? mScrollbarWidth : mMarkerSize / 2;
1083  const Widget *content;
1084  if (!mWidgets.empty())
1085  content = *mWidgets.begin();
1086  else
1087  content = nullptr;
1088 
1089  if (mVBarVisible)
1090  width = mDimension.width - 2 * w2 - mScrollbarWidth;
1091  else
1092  width = mDimension.width - w2 - mScrollbarWidth;
1093 
1094  const int maxH = getHorizontalMaxScroll();
1095  if (mMarkerSize != 0 && maxH != 0)
1096  {
1097  pos = (mHScroll * width / maxH - mMarkerSize / 2);
1098  length = mMarkerSize;
1099  }
1100  else
1101  {
1102  if (content != nullptr)
1103  {
1104  const int w3 = content->getWidth();
1105  if (w3 != 0)
1106  length = (width * getChildrenArea().width) / w3;
1107  else
1108  length = width;
1109  }
1110  else
1111  {
1112  length = width;
1113  }
1114 
1115  if (length < mScrollbarWidth)
1116  length = mScrollbarWidth;
1117 
1118  if (length > width)
1119  length = width;
1120 
1121  if (maxH != 0)
1122  {
1123  pos = ((width - length) * mHScroll) / maxH;
1124  }
1125  else
1126  {
1127  pos = 0;
1128  }
1129  }
1130 
1131  return Rect(w2 + pos, mDimension.height - mScrollbarWidth,
1132  length, mScrollbarWidth);
1133 }
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
int mHScroll
Definition: scrollarea.h:503
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
Rect getChildrenArea()
static int mMarkerSize
Definition: scrollarea.h:473
Definition: widget.h:97
static bool mShowButtons
Definition: scrollarea.h:472
WidgetList mWidgets
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557
int getHorizontalMaxScroll()

◆ getHorizontalMaxScroll()

int ScrollArea::getHorizontalMaxScroll ( )

Gets the maximum amount of horizontal scroll.

Returns
The horizontal max scroll.

Definition at line 1266 of file scrollarea.cpp.

References checkPolicies(), getChildrenArea(), getContent(), Widget::getFrameSize(), Widget::getWidth(), and Rect::width.

Referenced by getHorizontalMarkerDimension(), getHorizontalScrollAmount(), mouseDragged(), mouseReleased(), and setHorizontalScrollAmount().

1267 {
1268  checkPolicies();
1269 
1270  const Widget *const content = getContent();
1271  if (content == nullptr)
1272  return 0;
1273 
1274  const int value = content->getWidth() - getChildrenArea().width +
1275  2 * content->getFrameSize();
1276 
1277  if (value < 0)
1278  return 0;
1279 
1280  return value;
1281 }
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
unsigned int getFrameSize() const
Definition: widget.h:183
Rect getChildrenArea()
void checkPolicies()
Definition: widget.h:97
Widget * getContent()

◆ getHorizontalScrollAmount()

int ScrollArea::getHorizontalScrollAmount ( ) const
inline

Gets the amount that is scrolled horizontally.

Returns
The scroll amount on horizontal scroll.
See also
setHorizontalScrollAmount, setScrollAmount

Definition at line 290 of file scrollarea.h.

References getHorizontalMaxScroll(), getVerticalMaxScroll(), mHScroll, setScrollAmount(), and setScrollbarWidth().

291  { return mHScroll; }
int mHScroll
Definition: scrollarea.h:503

◆ getHorizontalScrollPolicy()

ScrollPolicy ScrollArea::getHorizontalScrollPolicy ( ) const
inline

Gets the horizontal scrollbar policy. See enum with policies.

Returns
The policy for the horizontal scrollbar policy.
See also
setHorizontalScrollPolicy, setScrollPolicy

Definition at line 229 of file scrollarea.h.

References mHPolicy, and setVerticalScrollPolicy().

230  { return mHPolicy; }
ScrollPolicy mHPolicy
Definition: scrollarea.h:488

◆ getImageByState()

Image * ScrollArea::getImageByState ( Rect dim,
const BUTTON_DIR  dir 
)
protected

Definition at line 503 of file scrollarea.cpp.

References buttons, BUTTONS_DIR, CAST_SIZE, CAST_U32, DOWN, getDownButtonDimension(), getLeftButtonDimension(), getRightButtonDimension(), getUpButtonDimension(), LEFT, Logger::log(), logger, mDownButtonPressed, mLeftButtonPressed, mRightButtonPressed, mUpButtonPressed, RIGHT, Catch::toString(), and UP.

Referenced by calcButton(), and drawButton().

504 {
505  int state = 0;
506 
507  switch (dir)
508  {
509  case UP:
510  state = mUpButtonPressed ? 1 : 0;
511  dim = getUpButtonDimension();
512  break;
513  case DOWN:
514  state = mDownButtonPressed ? 1 : 0;
515  dim = getDownButtonDimension();
516  break;
517  case LEFT:
518  state = mLeftButtonPressed ? 1 : 0;
519  dim = getLeftButtonDimension();
520  break;
521  case RIGHT:
522  state = mRightButtonPressed ? 1 : 0;
523  dim = getRightButtonDimension();
524  break;
525  case BUTTONS_DIR:
526  default:
527  logger->log("ScrollArea::drawButton unknown dir: "
528  + toString(CAST_U32(dir)));
529  return nullptr;
530  }
531  return buttons[CAST_SIZE(dir)][state];
532 }
Rect getDownButtonDimension() const
#define CAST_U32
Definition: cast.h:30
bool mRightButtonPressed
Definition: scrollarea.h:577
bool mLeftButtonPressed
Definition: scrollarea.h:572
Logger * logger
Definition: logger.cpp:88
Rect getRightButtonDimension() const
static Image * buttons[4][2]
Definition: scrollarea.h:480
Rect getUpButtonDimension() const
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
bool mDownButtonPressed
Definition: scrollarea.h:567
bool mUpButtonPressed
Definition: scrollarea.h:562
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:264
Rect getLeftButtonDimension() const

◆ getLeftButtonDimension()

Rect ScrollArea::getLeftButtonDimension ( ) const

Definition at line 1163 of file scrollarea.cpp.

References Rect::height, Widget::mDimension, mHBarVisible, mScrollbarWidth, and mShowButtons.

Referenced by getImageByState(), isOpaque(), and mousePressed().

1164 {
1165  if (!mHBarVisible || !mShowButtons)
1166  return Rect(0, 0, 0, 0);
1167 
1168  return Rect(0, mDimension.height - mScrollbarWidth,
1170 }
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
int height
Definition: rect.h:223
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getLeftButtonScrollAmount()

int ScrollArea::getLeftButtonScrollAmount ( ) const
inline

Gets the amount to scroll in pixels when the left scroll button is pushed.

Returns
The amount to scroll in pixels.
See also
setLeftButtonScrollAmount

Definition at line 380 of file scrollarea.h.

References mLeftButtonScrollAmount.

381  { return mLeftButtonScrollAmount; }
int mLeftButtonScrollAmount
Definition: scrollarea.h:523

◆ getRightButtonDimension()

Rect ScrollArea::getRightButtonDimension ( ) const

Definition at line 1172 of file scrollarea.cpp.

References Rect::height, Widget::mDimension, mHBarVisible, mScrollbarWidth, mShowButtons, mVBarVisible, and Rect::width.

Referenced by getImageByState(), isOpaque(), and mousePressed().

1173 {
1174  if (!mHBarVisible || !mShowButtons)
1175  return Rect(0, 0, 0, 0);
1176 
1177  if (mVBarVisible)
1178  {
1179  return Rect(mDimension.width - mScrollbarWidth*2,
1182  mScrollbarWidth);
1183  }
1184 
1188  mScrollbarWidth);
1189 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getRightButtonScrollAmount()

int ScrollArea::getRightButtonScrollAmount ( ) const
inline

Gets the amount to scroll in pixels when the right scroll button is pushed.

Returns
The amount to scroll in pixels.
See also
setRightButtonScrollAmount

Definition at line 390 of file scrollarea.h.

References mRightButtonScrollAmount.

391  { return mRightButtonScrollAmount; }
int mRightButtonScrollAmount
Definition: scrollarea.h:528

◆ getScrollbarWidth()

int ScrollArea::getScrollbarWidth ( ) const
inline

Gets the width of the scroll bars.

Returns
the width of the ScrollBar.
See also
setScrollbarWidth

Definition at line 330 of file scrollarea.h.

References mScrollbarWidth.

331  { return mScrollbarWidth; }
int mScrollbarWidth
Definition: scrollarea.h:508

◆ getUpButtonDimension()

Rect ScrollArea::getUpButtonDimension ( ) const

Definition at line 1135 of file scrollarea.cpp.

References Widget::mDimension, mScrollbarWidth, mShowButtons, mVBarVisible, and Rect::width.

Referenced by getImageByState(), isOpaque(), and mousePressed().

1136 {
1137  if (!mVBarVisible || !mShowButtons)
1138  return Rect(0, 0, 0, 0);
1139 
1140  return Rect(mDimension.width - mScrollbarWidth, 0,
1142 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100

◆ getUpButtonScrollAmount()

int ScrollArea::getUpButtonScrollAmount ( ) const
inline

Gets the amount to scroll in pixels when the up scroll button is pushed.

Returns
The amount to scroll in pixels.
See also
setUpButtonScrollAmount

Definition at line 400 of file scrollarea.h.

References mUpButtonScrollAmount.

401  { return mUpButtonScrollAmount; }
int mUpButtonScrollAmount
Definition: scrollarea.h:513

◆ getVerticalBarDimension()

Rect ScrollArea::getVerticalBarDimension ( ) const

Definition at line 977 of file scrollarea.cpp.

References Rect::height, Widget::mDimension, mHBarVisible, mScrollbarWidth, mShowButtons, mVBarVisible, and Rect::width.

Referenced by calcVBar(), drawVBar(), isOpaque(), mouseDragged(), and mousePressed().

978 {
979  if (!mVBarVisible)
980  return Rect(0, 0, 0, 0);
981 
982  const int height = mShowButtons ? mScrollbarWidth : 0;
983  if (mHBarVisible)
984  {
986  height,
988  mDimension.height - 2 * height - mScrollbarWidth);
989  }
990 
992  height,
994  mDimension.height - 2 * height);
995 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
static bool mShowButtons
Definition: scrollarea.h:472
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getVerticalMarkerDimension()

Rect ScrollArea::getVerticalMarkerDimension ( )

Definition at line 1017 of file scrollarea.cpp.

References getChildrenArea(), Widget::getHeight(), getVerticalMaxScroll(), Rect::height, Widget::mDimension, mHBarVisible, mMarkerSize, mScrollbarWidth, mShowButtons, mVBarVisible, mVScroll, BasicContainer::mWidgets, and Rect::width.

Referenced by calcVMarker(), drawVMarker(), isOpaque(), mouseDragged(), and mousePressed().

1018 {
1019  if (!mVBarVisible)
1020  return Rect(0, 0, 0, 0);
1021 
1022  int length, pos;
1023  int height;
1024  const int h2 = mShowButtons
1025  ? mScrollbarWidth : mMarkerSize / 2;
1026  const Widget *content;
1027  if (!mWidgets.empty())
1028  content = *mWidgets.begin();
1029  else
1030  content = nullptr;
1031 
1032  if (mHBarVisible)
1033  height = mDimension.height - 2 * h2 - mScrollbarWidth;
1034  else
1035  height = mDimension.height - 2 * h2;
1036 
1037  const int maxV = getVerticalMaxScroll();
1038  if ((mMarkerSize != 0) && (maxV != 0))
1039  {
1040  pos = (mVScroll * height / maxV - mMarkerSize / 2);
1041  length = mMarkerSize;
1042  }
1043  else
1044  {
1045  if (content != nullptr)
1046  {
1047  const int h3 = content->getHeight();
1048  if (h3 != 0)
1049  length = (height * getChildrenArea().height) / h3;
1050  else
1051  length = height;
1052  }
1053  else
1054  {
1055  length = height;
1056  }
1057 
1058  if (length < mScrollbarWidth)
1059  length = mScrollbarWidth;
1060 
1061  if (length > height)
1062  length = height;
1063 
1064  if (maxV != 0)
1065  pos = ((height - length) * mVScroll) / maxV;
1066  else
1067  pos = 0;
1068  }
1069 
1070  return Rect(mDimension.width - mScrollbarWidth, h2 + pos,
1071  mScrollbarWidth, length);
1072 }
int width
Definition: rect.h:218
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: rect.h:72
int getVerticalMaxScroll()
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
Rect getChildrenArea()
static int mMarkerSize
Definition: scrollarea.h:473
Definition: widget.h:97
int mVScroll
Definition: scrollarea.h:498
int getHeight() const
Definition: widget.h:239
static bool mShowButtons
Definition: scrollarea.h:472
WidgetList mWidgets
Rect mDimension
Definition: widget.h:1100
bool mHBarVisible
Definition: scrollarea.h:557

◆ getVerticalMaxScroll()

int ScrollArea::getVerticalMaxScroll ( )

Gets the maximum amount of vertical scroll.

Returns
The vertical max scroll.

Definition at line 1283 of file scrollarea.cpp.

References checkPolicies(), getChildrenArea(), getContent(), Widget::getFrameSize(), Widget::getHeight(), and Rect::height.

Referenced by ChatTab::addNewRow(), NpcDialog::addText(), NpcDialog::buildLayout(), ChatTab::chatLog(), getHorizontalScrollAmount(), getVerticalMarkerDimension(), UpdaterWindow::logic(), mouseDragged(), mouseReleased(), setVerticalScrollAmount(), WhoIsOnline::updateWindow(), and TabbedArea::widgetResized().

1284 {
1285  checkPolicies();
1286 
1287  const Widget *const content = getContent();
1288  if (content == nullptr)
1289  return 0;
1290 
1291  int value;
1292 
1293  value = content->getHeight() - getChildrenArea().height +
1294  2 * content->getFrameSize();
1295 
1296  if (value < 0)
1297  return 0;
1298 
1299  return value;
1300 }
unsigned int getFrameSize() const
Definition: widget.h:183
int height
Definition: rect.h:223
Rect getChildrenArea()
void checkPolicies()
Definition: widget.h:97
int getHeight() const
Definition: widget.h:239
Widget * getContent()

◆ getVerticalScrollAmount()

int ScrollArea::getVerticalScrollAmount ( ) const
inline

Gets the amount that is scrolled vertically.

Returns
The scroll amount on vertical scroll.
See also
setVerticalScrollAmount, setScrollAmount

Definition at line 273 of file scrollarea.h.

References mVScroll, and setHorizontalScrollAmount().

Referenced by ChatTab::addNewRow(), ChatTab::chatLog(), ChatTab::scroll(), WhoIsOnline::updateWindow(), and TabbedArea::widgetResized().

274  { return mVScroll; }
int mVScroll
Definition: scrollarea.h:498

◆ getVerticalScrollPolicy()

ScrollPolicy ScrollArea::getVerticalScrollPolicy ( ) const
inline

Gets the vertical scrollbar policy. See enum with policies.

Returns
The policy for the vertical scrollbar.
See also
setVerticalScrollPolicy, setScrollPolicy

Definition at line 246 of file scrollarea.h.

References mVPolicy, setScrollPolicy(), and setVerticalScrollAmount().

247  { return mVPolicy; }
ScrollPolicy mVPolicy
Definition: scrollarea.h:493

◆ getWidgetAt()

Widget * ScrollArea::getWidgetAt ( int  x,
int  y 
)
virtual

Gets a widget from a certain position in the widget. This function is used to decide which gets mouse input, thus it can be overloaded to change that behaviour.

NOTE: This always returns NULL if the widget is not a container.

Parameters
xThe x coordinate of the widget to get.
yThe y coordinate of the widget to get.
Returns
The widget at the specified coodinate, NULL if no widget is found.

Reimplemented from BasicContainer.

Definition at line 1334 of file scrollarea.cpp.

References getChildrenArea(), and getContent().

Referenced by getDownButtonScrollAmount().

1335 {
1336  if (getChildrenArea().isPointInRect(x, y))
1337  return getContent();
1338 
1339  return nullptr;
1340 }
Rect getChildrenArea()
Widget * getContent()

◆ init()

void ScrollArea::init ( std::string  skinName)
protected

Initializes the scroll area.

Definition at line 181 of file scrollarea.cpp.

References background, buttonFiles, buttons, BUTTONS_DIR, Skin::getBorder(), Skin::getOption(), Theme::getThemePath(), ImageRect::grid, hBackground, Resource::incRef(), instances, Theme::load(), Theme::loadRect(), mMarkerSize, mOpaque, mScrollbarSize, mScrollbarWidth, mShowButtons, setDownButtonScrollAmount(), setLeftButtonScrollAmount(), setOpaque(), setRightButtonScrollAmount(), setUpButtonScrollAmount(), theme, Theme::unload(), UP, vBackground, vMarker, and vMarkerHi.

Referenced by ScrollArea().

182 {
184 
189 
190  if (instances == 0)
191  {
192  for (int f = 0; f < 9; f ++)
193  {
194  background.grid[f] = nullptr;
195  vMarker.grid[f] = nullptr;
196  vMarkerHi.grid[f] = nullptr;
197  vBackground.grid[f] = nullptr;
198  hBackground.grid[f] = nullptr;
199  }
200 
201  // +++ here probably need move background from static
202  if (skinName.empty())
203  skinName = "scroll_background.xml";
204  if (theme != nullptr)
205  {
207  skinName,
208  "scroll_background.xml",
209  0,
210  8);
212  "scroll.xml",
213  "",
214  0,
215  8);
217  "scroll_highlighted.xml",
218  "scroll.xml",
219  0,
220  8);
222  "scroll_vbackground.xml",
223  "",
224  0,
225  8);
227  "scroll_hbackground.xml",
228  "",
229  0,
230  8);
231  }
232 
233  for (int i = 0; i < 2; i ++)
234  {
235  Skin *skin = nullptr;
236  if (theme != nullptr)
237  {
238  skin = theme->load(buttonFiles[i],
239  "scrollbuttons.xml",
240  true,
242  }
243  if (skin != nullptr)
244  {
245  const ImageRect &rect = skin->getBorder();
246  for (int f = UP; f < BUTTONS_DIR; f ++)
247  {
248  if (rect.grid[f] != nullptr)
249  rect.grid[f]->incRef();
250  buttons[f][i] = rect.grid[f];
251  }
252  if (i == 0)
253  {
254  mShowButtons = (skin->getOption("showbuttons", 1) == 1);
255  mMarkerSize = skin->getOption("markersize", 0);
256  mScrollbarSize = skin->getOption("scrollbarsize", 12);
257  }
258  }
259  else
260  {
261  for (int f = UP; f < BUTTONS_DIR; f ++)
262  buttons[f][i] = nullptr;
263  }
264  if (theme != nullptr)
265  theme->unload(skin);
266  }
267  }
269  instances++;
270 }
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:882
void setLeftButtonScrollAmount(const int amount)
Definition: scrollarea.h:340
int mScrollbarWidth
Definition: scrollarea.h:508
Definition: skin.h:35
void unload(Skin *const skin)
Definition: theme.cpp:249
Opaque mOpaque
Definition: scrollarea.h:593
static std::string getThemePath()
Definition: theme.h:66
static std::string const buttonFiles[2]
Definition: scrollarea.cpp:98
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
static ImageRect vBackground
Definition: scrollarea.h:478
int getOption(const std::string &name) const
Definition: skin.h:105
void setOpaque(Opaque opaque)
Definition: scrollarea.cpp:497
void setRightButtonScrollAmount(const int amount)
Definition: scrollarea.h:350
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
static ImageRect vMarkerHi
Definition: scrollarea.h:477
static ImageRect vMarker
Definition: scrollarea.h:476
static int mScrollbarSize
Definition: scrollarea.h:474
static Image * buttons[4][2]
Definition: scrollarea.h:480
static ImageRect hBackground
Definition: scrollarea.h:479
static int instances
Definition: scrollarea.h:470
static ImageRect background
Definition: scrollarea.h:475
static int mMarkerSize
Definition: scrollarea.h:473
virtual void incRef()
Definition: resource.cpp:37
Theme * theme
Definition: theme.cpp:61
void setDownButtonScrollAmount(const int amount)
Definition: scrollarea.h:370
static bool mShowButtons
Definition: scrollarea.h:472
void setUpButtonScrollAmount(const int amount)
Definition: scrollarea.h:360

◆ isOpaque()

bool ScrollArea::isOpaque ( ) const
inline

◆ isSelectable()

bool ScrollArea::isSelectable ( ) const
virtual

Reimplemented from Widget.

Definition at line 1478 of file scrollarea.cpp.

References Widget::isSelectable(), mHBarVisible, and mVBarVisible.

Referenced by getDownButtonScrollAmount().

1479 {
1480  if (mVBarVisible || mHBarVisible)
1481  return true;
1482  return Widget::isSelectable();
1483 }
virtual bool isSelectable() const
Definition: widget.h:944
bool mVBarVisible
Definition: scrollarea.h:552
bool mHBarVisible
Definition: scrollarea.h:557

◆ logic()

void ScrollArea::logic ( )
virtual

Logic function optionally adapts width or height of contents. This depends on the scrollbar settings.

Reimplemented from BasicContainer.

Definition at line 272 of file scrollarea.cpp.

References BLOCK_END, BLOCK_START, checkPolicies(), getContent(), Widget::getFrameSize(), Rect::height, Widget::isVisible(), Widget::logic(), Widget::mDimension, mDownButtonPressed, mDownButtonScrollAmount, mHBarVisible, mHPolicy, mHScroll, mLeftButtonPressed, mLeftButtonScrollAmount, mRightButtonPressed, mRightButtonScrollAmount, mScrollbarWidth, mUpButtonPressed, mUpButtonScrollAmount, mVBarVisible, mVPolicy, mVScroll, Widget::setHeight(), setHorizontalScrollAmount(), Widget::setPosition(), setVerticalScrollAmount(), Widget::setWidth(), SHOW_NEVER, and Rect::width.

Referenced by ChatTab::addNewRow(), ChatTab::chatLog(), WhoIsOnline::logic(), and UpdaterWindow::logic().

273 {
274  BLOCK_START("ScrollArea::logic")
275  if (!isVisible())
276  {
277  BLOCK_END("ScrollArea::logic")
278  return;
279  }
280 
281  checkPolicies();
282 
285 
286  Widget *const content = getContent();
287  if (content != nullptr)
288  {
289  unsigned int frameSize = content->getFrameSize();
290  content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize);
291  content->logic();
292 
293  // When no scrollbar in a certain direction,
294  // adapt content size to match the content dimension exactly.
295  frameSize = 2 * content->getFrameSize();
297  {
298  content->setWidth((mVBarVisible ? (mDimension.width
299  - mScrollbarWidth) : mDimension.width) - frameSize);
300  }
302  {
303  content->setHeight((mHBarVisible ? (mDimension.height
304  - mScrollbarWidth) : mDimension.height) - frameSize);
305  }
306  }
307 
308  if (mUpButtonPressed)
310  else if (mDownButtonPressed)
312  else if (mLeftButtonPressed)
314  else if (mRightButtonPressed)
316  BLOCK_END("ScrollArea::logic")
317 }
int width
Definition: rect.h:218
bool mRightButtonPressed
Definition: scrollarea.h:577
int mHScroll
Definition: scrollarea.h:503
int mScrollbarWidth
Definition: scrollarea.h:508
int mUpButtonScrollAmount
Definition: scrollarea.h:513
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
bool mLeftButtonPressed
Definition: scrollarea.h:572
#define BLOCK_END(name)
Definition: perfomance.h:79
void setVerticalScrollAmount(const int vScroll)
bool mVBarVisible
Definition: scrollarea.h:552
int height
Definition: rect.h:223
int mRightButtonScrollAmount
Definition: scrollarea.h:528
void checkPolicies()
bool isVisible() const
Definition: widget.h:377
bool mDownButtonPressed
Definition: scrollarea.h:567
Definition: widget.h:97
int mLeftButtonScrollAmount
Definition: scrollarea.h:523
int mVScroll
Definition: scrollarea.h:498
bool mUpButtonPressed
Definition: scrollarea.h:562
void setHorizontalScrollAmount(int hScroll)
int mDownButtonScrollAmount
Definition: scrollarea.h:518
Rect mDimension
Definition: widget.h:1100
ScrollPolicy mHPolicy
Definition: scrollarea.h:488
bool mHBarVisible
Definition: scrollarea.h:557
Widget * getContent()

◆ mouseDragged()

void ScrollArea::mouseDragged ( MouseEvent event)
virtual

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

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 933 of file scrollarea.cpp.

References getHorizontalBarDimension(), getHorizontalMarkerDimension(), getHorizontalMaxScroll(), getVerticalBarDimension(), getVerticalMarkerDimension(), getVerticalMaxScroll(), Rect::height, mHorizontalMarkerDragOffset, mIsHorizontalMarkerDragged, mIsVerticalMarkerDragged, Widget::mRedraw, mVerticalMarkerDragOffset, setHorizontalScrollAmount(), setVerticalScrollAmount(), Rect::width, Rect::x, and Rect::y.

Referenced by isOpaque().

934 {
936  {
937  const Rect barDim = getVerticalBarDimension();
938 
939  const int pos = event.getY() - barDim.y
941  const int length = getVerticalMarkerDimension().height;
942 
943  if ((barDim.height - length) > 0)
944  {
946  / (barDim.height - length));
947  }
948  else
949  {
951  }
952  }
953 
955  {
956  const Rect barDim = getHorizontalBarDimension();
957 
958  const int pos = event.getX() - barDim.x
960  const int length = getHorizontalMarkerDimension().width;
961 
962  if ((barDim.width - length) > 0)
963  {
965  / (barDim.width - length));
966  }
967  else
968  {
970  }
971  }
972 
973  event.consume();
974  mRedraw = true;
975 }
int width
Definition: rect.h:218
Rect getHorizontalMarkerDimension()
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:997
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:587
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:977
Definition: rect.h:72
Rect getVerticalMarkerDimension()
void setVerticalScrollAmount(const int vScroll)
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:582
int getVerticalMaxScroll()
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223
int mHorizontalMarkerDragOffset
Definition: scrollarea.h:533
bool mRedraw
Definition: widget.h:1163
void setHorizontalScrollAmount(int hScroll)
int mVerticalMarkerDragOffset
Definition: scrollarea.h:538
int getHorizontalMaxScroll()

◆ mouseEntered()

void ScrollArea::mouseEntered ( MouseEvent event)
virtual

Called when the mouse enteres the widget area.

Reimplemented from MouseListener.

Definition at line 749 of file scrollarea.cpp.

References mHasMouse.

Referenced by isOpaque().

750 {
751  mHasMouse = true;
752 }
bool mHasMouse
Definition: scrollarea.h:595

◆ mouseExited()

void ScrollArea::mouseExited ( MouseEvent event)
virtual

Called when the mouse leaves the widget area.

Reimplemented from MouseListener.

Definition at line 754 of file scrollarea.cpp.

References mHasMouse.

Referenced by isOpaque().

755 {
756  mHasMouse = false;
757 }
bool mHasMouse
Definition: scrollarea.h:595

◆ mouseMoved()

void ScrollArea::mouseMoved ( MouseEvent event)
virtual

Called when the mouse moves in the widget area.

Reimplemented from MouseListener.

Definition at line 743 of file scrollarea.cpp.

References mX, and mY.

Referenced by isOpaque().

744 {
745  mX = event.getX();
746  mY = event.getY();
747 }

◆ mousePressed()

void ScrollArea::mousePressed ( MouseEvent event)
virtual

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
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 776 of file scrollarea.cpp.

References CAST_S32, MouseEvent::getButton(), getChildrenArea(), getDownButtonDimension(), getHorizontalBarDimension(), getHorizontalMarkerDimension(), getLeftButtonDimension(), getRightButtonDimension(), getUpButtonDimension(), getVerticalBarDimension(), getVerticalMarkerDimension(), MouseButton::LEFT, mClickX, mClickY, mDownButtonPressed, mDownButtonScrollAmount, mHorizontalMarkerDragOffset, mHScroll, mIsHorizontalMarkerDragged, mIsVerticalMarkerDragged, mLeftButtonPressed, mLeftButtonScrollAmount, mRightButtonPressed, mRightButtonScrollAmount, mUpButtonPressed, mUpButtonScrollAmount, mVerticalMarkerDragOffset, mVScroll, setHorizontalScrollAmount(), setVerticalScrollAmount(), x, Rect::x, y, and Rect::y.

Referenced by isOpaque().

777 {
778  const int x = event.getX();
779  const int y = event.getY();
780 
781  if (getUpButtonDimension().isPointInRect(x, y))
782  {
785  mUpButtonPressed = true;
786  event.consume();
787  }
788  else if (getDownButtonDimension().isPointInRect(x, y))
789  {
792  mDownButtonPressed = true;
793  event.consume();
794  }
795  else if (getLeftButtonDimension().isPointInRect(x, y))
796  {
799  mLeftButtonPressed = true;
800  event.consume();
801  }
802  else if (getRightButtonDimension().isPointInRect(x, y))
803  {
806  mRightButtonPressed = true;
807  event.consume();
808  }
809  else if (getVerticalMarkerDimension().isPointInRect(x, y))
810  {
813 
815  event.consume();
816  }
817  else if (getVerticalBarDimension().isPointInRect(x, y))
818  {
819  if (y < getVerticalMarkerDimension().y)
820  {
822  - CAST_S32(getChildrenArea().height * 0.1));
823  }
824  else
825  {
827  + CAST_S32(getChildrenArea().height * 0.1));
828  }
829  event.consume();
830  }
831  else if (getHorizontalMarkerDimension().isPointInRect(x, y))
832  {
834  mIsVerticalMarkerDragged = false;
836  event.consume();
837  }
838  else if (getHorizontalBarDimension().isPointInRect(x, y))
839  {
840  if (x < getHorizontalMarkerDimension().x)
841  {
843  - CAST_S32(getChildrenArea().width * 0.1));
844  }
845  else
846  {
848  + CAST_S32(getChildrenArea().width * 0.1));
849  }
850  event.consume();
851  }
852 
853  if (event.getButton() == MouseButton::LEFT &&
854  !event.isConsumed())
855  {
856  mClickX = event.getX();
857  mClickY = event.getY();
858  }
859 }
Rect getDownButtonDimension() const
Rect getHorizontalMarkerDimension()
bool mRightButtonPressed
Definition: scrollarea.h:577
int mHScroll
Definition: scrollarea.h:503
int mUpButtonScrollAmount
Definition: scrollarea.h:513
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:997
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:587
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:977
MouseButtonT getButton() const
Definition: mouseevent.h:115
Rect getVerticalMarkerDimension()
bool mLeftButtonPressed
Definition: scrollarea.h:572
void setVerticalScrollAmount(const int vScroll)
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:582
int x
Definition: rect.h:208
#define CAST_S32
Definition: cast.h:29
int y
Definition: rect.h:213
Rect getRightButtonDimension() const
Rect getChildrenArea()
int mHorizontalMarkerDragOffset
Definition: scrollarea.h:533
int mRightButtonScrollAmount
Definition: scrollarea.h:528
Rect getUpButtonDimension() const
bool mDownButtonPressed
Definition: scrollarea.h:567
int mLeftButtonScrollAmount
Definition: scrollarea.h:523
int mVScroll
Definition: scrollarea.h:498
bool mUpButtonPressed
Definition: scrollarea.h:562
void setHorizontalScrollAmount(int hScroll)
int mDownButtonScrollAmount
Definition: scrollarea.h:518
int mVerticalMarkerDragOffset
Definition: scrollarea.h:538
Rect getLeftButtonDimension() const

◆ mouseReleased()

void ScrollArea::mouseReleased ( MouseEvent event)
virtual

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

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 861 of file scrollarea.cpp.

References MouseEvent::getButton(), getHorizontalMaxScroll(), getVerticalMaxScroll(), InputGuiEvent::isConsumed(), MouseButton::LEFT, mClickX, mClickY, mDownButtonPressed, mHScroll, mIsHorizontalMarkerDragged, mIsVerticalMarkerDragged, mLeftButtonPressed, Widget::mMouseConsume, Widget::mRedraw, mRightButtonPressed, mUpButtonPressed, mVScroll, setHorizontalScrollAmount(), and setVerticalScrollAmount().

Referenced by isOpaque().

862 {
863  if (event.getButton() == MouseButton::LEFT &&
864  mClickX != 0 &&
865  mClickY != 0)
866  {
867  if (!event.isConsumed())
868  {
869 #ifdef ANDROID
870  int dx = mClickX - event.getX();
871  int dy = mClickY - event.getY();
872 #else // ANDROID
873 
874  int dx = event.getX() - mClickX;
875  int dy = event.getY() - mClickY;
876 #endif // ANDROID
877 
878  if ((dx < 20 && dx > 0) || (dx > -20 && dx < 0))
879  dx = 0;
880 
881  if ((dy < 20 && dy > 0) || (dy > -20 && dy < 0))
882  dy = 0;
883 
884  if (abs(dx) > abs(dy))
885  {
886  int s = mHScroll + dx;
887  if (s < 0)
888  {
889  s = 0;
890  }
891  else
892  {
893  const int maxH = getHorizontalMaxScroll();
894  if (s > maxH)
895  s = maxH;
896  }
897 
899  }
900  else if (dy != 0)
901  {
902  int s = mVScroll + dy;
903  if (s < 0)
904  {
905  s = 0;
906  }
907  else
908  {
909  const int maxV = getVerticalMaxScroll();
910  if (s > maxV)
911  s = maxV;
912  }
913 
915  }
916  mClickX = 0;
917  mClickY = 0;
918  if (mMouseConsume && ((dx != 0) || (dy != 0)))
919  event.consume();
920  }
921  }
922  mUpButtonPressed = false;
923  mDownButtonPressed = false;
924  mLeftButtonPressed = false;
925  mRightButtonPressed = false;
927  mIsVerticalMarkerDragged = false;
928  if (mMouseConsume)
929  event.consume();
930  mRedraw = true;
931 }
bool mRightButtonPressed
Definition: scrollarea.h:577
int mHScroll
Definition: scrollarea.h:503
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:587
MouseButtonT getButton() const
Definition: mouseevent.h:115
bool mLeftButtonPressed
Definition: scrollarea.h:572
void setVerticalScrollAmount(const int vScroll)
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:582
int getVerticalMaxScroll()
bool mMouseConsume
Definition: widget.h:1161
bool isConsumed() const
bool mDownButtonPressed
Definition: scrollarea.h:567
int mVScroll
Definition: scrollarea.h:498
bool mUpButtonPressed
Definition: scrollarea.h:562
bool mRedraw
Definition: widget.h:1163
void setHorizontalScrollAmount(int hScroll)
int getHorizontalMaxScroll()

◆ mouseWheelMovedDown()

void ScrollArea::mouseWheelMovedDown ( MouseEvent event)
virtual

Called when the mouse wheel has moved down on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 1371 of file scrollarea.cpp.

References getChildrenArea(), InputGuiEvent::isConsumed(), mVScroll, and setVerticalScrollAmount().

Referenced by getDownButtonScrollAmount().

1372 {
1373  if (event.isConsumed())
1374  return;
1375 
1377  + getChildrenArea().height / 8);
1378 
1379  event.consume();
1380 }
void setVerticalScrollAmount(const int vScroll)
Rect getChildrenArea()
bool isConsumed() const
int mVScroll
Definition: scrollarea.h:498

◆ mouseWheelMovedUp()

void ScrollArea::mouseWheelMovedUp ( MouseEvent event)
virtual

Called when the mouse wheel has moved up on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 1360 of file scrollarea.cpp.

References getChildrenArea(), InputGuiEvent::isConsumed(), mVScroll, and setVerticalScrollAmount().

Referenced by getDownButtonScrollAmount().

1361 {
1362  if (event.isConsumed())
1363  return;
1364 
1366  - getChildrenArea().height / 8);
1367 
1368  event.consume();
1369 }
void setVerticalScrollAmount(const int vScroll)
Rect getChildrenArea()
bool isConsumed() const
int mVScroll
Definition: scrollarea.h:498

◆ safeDraw()

void ScrollArea::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 397 of file scrollarea.cpp.

References BLOCK_END, BLOCK_START, DOWN, drawButton(), drawHBar(), drawHMarker(), drawVBar(), drawVMarker(), LEFT, mHBarVisible, Widget::mRedraw, mShowButtons, mVBarVisible, RIGHT, BasicContainer::safeDrawChildren(), UP, and updateAlpha().

398 {
399  BLOCK_START("ScrollArea::draw")
400  if (mVBarVisible)
401  {
402  if (mShowButtons)
403  {
404  drawButton(graphics, UP);
405  drawButton(graphics, DOWN);
406  }
407  drawVBar(graphics);
408  drawVMarker(graphics);
409  }
410 
411  if (mHBarVisible)
412  {
413  if (mShowButtons)
414  {
415  drawButton(graphics, LEFT);
416  drawButton(graphics, RIGHT);
417  }
418  drawHBar(graphics);
419  drawHMarker(graphics);
420  }
421 
422  updateAlpha();
423 
424  safeDrawChildren(graphics);
425  mRedraw = false;
426  BLOCK_END("ScrollArea::draw")
427 }
void drawVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:666
void drawButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:534
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void drawVBar(Graphics *const graphics) const
Definition: scrollarea.cpp:557
bool mVBarVisible
Definition: scrollarea.h:552
void drawHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:704
void drawHBar(Graphics *const graphics) const
Definition: scrollarea.cpp:607
bool mRedraw
Definition: widget.h:1163
static bool mShowButtons
Definition: scrollarea.h:472
bool mHBarVisible
Definition: scrollarea.h:557
virtual void safeDrawChildren(Graphics *const graphics)
void updateAlpha()
Definition: scrollarea.cpp:319

◆ safeDrawFrame()

void ScrollArea::safeDrawFrame ( Graphics *const  graphics)
virtual

Reimplemented from Widget.

Definition at line 480 of file scrollarea.cpp.

References background, BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Rect::height, Widget::mDimension, Widget::mFrameSize, mOpaque, Opaque_true, updateCalcFlag(), and Rect::width.

481 {
482  BLOCK_START("ScrollArea::drawFrame")
483  if (mOpaque == Opaque_true)
484  {
485  const int bs = mFrameSize * 2;
486  const int w = mDimension.width + bs;
487  const int h = mDimension.height + bs;
488 
489  updateCalcFlag(graphics);
490  graphics->drawImageRect(0, 0,
491  w, h,
492  background);
493  }
494  BLOCK_END("ScrollArea::drawFrame")
495 }
int width
Definition: rect.h:218
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
Opaque mOpaque
Definition: scrollarea.h:593
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
static ImageRect background
Definition: scrollarea.h:475
const bool Opaque_true
Definition: opaque.h:29
Rect mDimension
Definition: widget.h:1100
void updateCalcFlag(const Graphics *const graphics)
Definition: scrollarea.cpp:429

◆ setContent()

void ScrollArea::setContent ( Widget widget)

Sets the content.

Parameters
widgetThe content of the scroll area.

Definition at line 1191 of file scrollarea.cpp.

References BasicContainer::add(), checkPolicies(), BasicContainer::clear(), and Widget::setPosition().

Referenced by isOpaque(), ScrollArea(), ShopWindow::updateSelection(), Setup_Colors::valueChanged(), and ~ScrollArea().

1192 {
1193  if (widget != nullptr)
1194  {
1195  clear();
1196  add(widget);
1197  widget->setPosition(0, 0);
1198  }
1199  else
1200  {
1201  clear();
1202  }
1203 
1204  checkPolicies();
1205 }
virtual void clear()
void add(Widget *const widget)
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void checkPolicies()

◆ setDimension()

void ScrollArea::setDimension ( const Rect dimension)

Definition at line 1354 of file scrollarea.cpp.

References checkPolicies(), and Widget::setDimension().

Referenced by getDownButtonScrollAmount(), and WhoIsOnline::postInit().

1355 {
1356  Widget::setDimension(dimension);
1357  checkPolicies();
1358 }
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
void checkPolicies()

◆ setDownButtonScrollAmount()

void ScrollArea::setDownButtonScrollAmount ( const int  amount)
inline

Sets the amount to scroll in pixels when the down scroll button is pushed.

Parameters
amountThe amount to scroll in pixels.
See also
getDownButtonScrollAmount

Definition at line 370 of file scrollarea.h.

References mDownButtonScrollAmount.

Referenced by init().

371  { mDownButtonScrollAmount = amount; }
int mDownButtonScrollAmount
Definition: scrollarea.h:518

◆ setHeight()

void ScrollArea::setHeight ( int  height)

◆ setHorizontalScrollAmount()

void ScrollArea::setHorizontalScrollAmount ( int  hScroll)

Sets the amount to scroll horizontally.

Parameters
hScrollThe amount to scroll.
See also
getHorizontalScrollAmount

Definition at line 1248 of file scrollarea.cpp.

References getHorizontalMaxScroll(), and mHScroll.

Referenced by getVerticalScrollAmount(), logic(), mouseDragged(), mousePressed(), mouseReleased(), setScrollAmount(), and showWidgetPart().

1249 {
1250  const int max = getHorizontalMaxScroll();
1251 
1252  mHScroll = hScroll;
1253 
1254  if (hScroll > max)
1255  mHScroll = max;
1256  else if (hScroll < 0)
1257  mHScroll = 0;
1258 }
int mHScroll
Definition: scrollarea.h:503
int getHorizontalMaxScroll()

◆ setHorizontalScrollPolicy()

void ScrollArea::setHorizontalScrollPolicy ( const ScrollPolicy  hPolicy)

◆ setLeftButtonScrollAmount()

void ScrollArea::setLeftButtonScrollAmount ( const int  amount)
inline

Sets the amount to scroll in pixels when the left scroll button is pushed.

Parameters
amountThe amount to scroll in pixels.
See also
getLeftButtonScrollAmount

Definition at line 340 of file scrollarea.h.

References mLeftButtonScrollAmount.

Referenced by init().

341  { mLeftButtonScrollAmount = amount; }
int mLeftButtonScrollAmount
Definition: scrollarea.h:523

◆ setOpaque()

void ScrollArea::setOpaque ( Opaque  opaque)

Sets whether the widget should draw its background or not.

Definition at line 497 of file scrollarea.cpp.

References mOpaque, Opaque_true, and Widget::setFrameSize().

Referenced by init().

498 {
499  mOpaque = opaque;
500  setFrameSize(mOpaque == Opaque_true ? 2 : 0);
501 }
Opaque mOpaque
Definition: scrollarea.h:593
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:167
const bool Opaque_true
Definition: opaque.h:29

◆ setRightButtonScrollAmount()

void ScrollArea::setRightButtonScrollAmount ( const int  amount)
inline

Sets the amount to scroll in pixels when the right scroll button is pushed.

Parameters
amountThe amount to scroll in pixels.
See also
getRightButtonScrollAmount

Definition at line 350 of file scrollarea.h.

References mRightButtonScrollAmount.

Referenced by init().

351  { mRightButtonScrollAmount = amount; }
int mRightButtonScrollAmount
Definition: scrollarea.h:528

◆ setScrollAmount()

void ScrollArea::setScrollAmount ( const int  hScroll,
const int  vScroll 
)

Sets the amount to scroll horizontally and vertically.

Parameters
hScrollThe amount to scroll on horizontal scroll.
vScrollThe amount to scroll on vertical scroll.
See also
getHorizontalScrollAmount, getVerticalScrollAmount

Definition at line 1260 of file scrollarea.cpp.

References setHorizontalScrollAmount(), and setVerticalScrollAmount().

Referenced by ChatTab::ChatTab(), and getHorizontalScrollAmount().

1261 {
1262  setHorizontalScrollAmount(hScroll);
1263  setVerticalScrollAmount(vScroll);
1264 }
void setVerticalScrollAmount(const int vScroll)
void setHorizontalScrollAmount(int hScroll)

◆ setScrollbarWidth()

void ScrollArea::setScrollbarWidth ( const int  width)

Sets the width of the scroll bars.

Parameters
widthThe width of the scroll bars.
See also
getScrollbarWidth

Definition at line 1302 of file scrollarea.cpp.

References mScrollbarWidth.

Referenced by getHorizontalScrollAmount().

1303 {
1304  if (width > 0)
1305  mScrollbarWidth = width;
1306 }
int mScrollbarWidth
Definition: scrollarea.h:508

◆ setScrollPolicy()

void ScrollArea::setScrollPolicy ( const ScrollPolicy  hPolicy,
const ScrollPolicy  vPolicy 
)

Sets the horizontal and vertical scrollbar policy.

Parameters
hPolicyThe policy for the horizontal scrollbar.
vPolicyThe policy for the vertical scrollbar.
See also
getVerticalScrollPolicy, getHorizontalScrollPolicy

Definition at line 1227 of file scrollarea.cpp.

References checkPolicies(), mHPolicy, and mVPolicy.

Referenced by ChatTab::ChatTab(), getVerticalScrollPolicy(), NpcDialog::NpcDialog(), and Setup_Colors::Setup_Colors().

1229 {
1230  mHPolicy = hPolicy;
1231  mVPolicy = vPolicy;
1232  checkPolicies();
1233 }
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
void checkPolicies()
ScrollPolicy mHPolicy
Definition: scrollarea.h:488

◆ setUpButtonScrollAmount()

void ScrollArea::setUpButtonScrollAmount ( const int  amount)
inline

Sets the amount to scroll in pixels when the up scroll button is pushed.

Parameters
amountThe amount to scroll in pixels.
See also
getUpButtonScrollAmount

Definition at line 360 of file scrollarea.h.

References mUpButtonScrollAmount.

Referenced by init().

361  { mUpButtonScrollAmount = amount; }
int mUpButtonScrollAmount
Definition: scrollarea.h:513

◆ setVerticalScrollAmount()

void ScrollArea::setVerticalScrollAmount ( const int  vScroll)

◆ setVerticalScrollPolicy()

void ScrollArea::setVerticalScrollPolicy ( const ScrollPolicy  vPolicy)

Sets the vertical scrollbar policy. See enum with policies.

Parameters
vPolicyThe policy for the vertical scrollbar.
See also
getVerticalScrollPolicy

Definition at line 1221 of file scrollarea.cpp.

References checkPolicies(), and mVPolicy.

Referenced by SkillDialog::addDefaultTab(), SocialTab::createControls(), getHorizontalScrollPolicy(), SkillDialog::loadXmlFile(), NpcDialog::NpcDialog(), PopupMenu::PopupMenu(), EmoteWindow::postInit(), SetupTabScroll::SetupTabScroll(), StatsPage::StatsPage(), and StatsPageBasic::StatsPageBasic().

1222 {
1223  mVPolicy = vPolicy;
1224  checkPolicies();
1225 }
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
void checkPolicies()

◆ setWidth()

void ScrollArea::setWidth ( int  width)

Definition at line 1342 of file scrollarea.cpp.

References checkPolicies(), and Widget::setWidth().

Referenced by PopupList::adjustSize(), getDownButtonScrollAmount(), Setup_Video::Setup_Video(), PopupMenu::showPopup(), and SetupTabScroll::widgetResized().

1343 {
1344  Widget::setWidth(width);
1345  checkPolicies();
1346 }
void setWidth(const int width)
Definition: widget.cpp:132
void checkPolicies()

◆ showWidgetPart()

void ScrollArea::showWidgetPart ( Widget *const  widget,
const Rect area 
)
virtual

Shows a certain part of a widget in the basic container. Used when widgets want a specific part to be visible in its parent. An example is a TextArea that wants a specific part of its text to be visible when a TextArea is a child of a ScrollArea.

Parameters
widgetThe widget whom wants a specific part of itself to be visible.
areaThe rectangle to be visible.

Reimplemented from BasicContainer.

Definition at line 1308 of file scrollarea.cpp.

References getContent(), Widget::getFrameSize(), Widget::getX(), Widget::getY(), setHorizontalScrollAmount(), setVerticalScrollAmount(), and BasicContainer::showWidgetPart().

Referenced by getDownButtonScrollAmount().

1309 {
1310  const Widget *const content = getContent();
1311  if (widget != content || (content == nullptr))
1312  return;
1313 
1314  BasicContainer::showWidgetPart(widget, area);
1315 
1317  - content->getX());
1319  - content->getY());
1320 }
void showWidgetPart(Widget *const widget, const Rect &area)
int getY() const
Definition: widget.h:287
void setVerticalScrollAmount(const int vScroll)
unsigned int getFrameSize() const
Definition: widget.h:183
int getX() const
Definition: widget.h:268
Definition: widget.h:97
void setHorizontalScrollAmount(int hScroll)
Widget * getContent()

◆ updateAlpha()

void ScrollArea::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 319 of file scrollarea.cpp.

References background, Theme::getMinimumOpacity(), ImageRect::grid, Settings::guiAlpha, hBackground, mAlpha, Image::setAlpha(), settings, theme, vBackground, vMarker, and vMarkerHi.

Referenced by draw(), and safeDraw().

320 {
321  const float alpha = std::max(settings.guiAlpha,
323 
324  if (alpha != mAlpha)
325  {
326  mAlpha = alpha;
327  for (int a = 0; a < 9; a++)
328  {
329  if (background.grid[a] != nullptr)
331  if (hBackground.grid[a] != nullptr)
333  if (vBackground.grid[a] != nullptr)
335  if (vMarker.grid[a] != nullptr)
337  if (vMarkerHi.grid[a] != nullptr)
339  }
340  }
341 }
float getMinimumOpacity() const
Definition: theme.h:123
static ImageRect vBackground
Definition: scrollarea.h:478
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Image * grid[9]
Definition: imagerect.h:41
static ImageRect vMarkerHi
Definition: scrollarea.h:477
static float mAlpha
Definition: scrollarea.h:471
static ImageRect vMarker
Definition: scrollarea.h:476
static ImageRect hBackground
Definition: scrollarea.h:479
static ImageRect background
Definition: scrollarea.h:475
Theme * theme
Definition: theme.cpp:61
float guiAlpha
Definition: settings.h:129

◆ updateCalcFlag()

void ScrollArea::updateCalcFlag ( const Graphics *const  graphics)
protected

Definition at line 429 of file scrollarea.cpp.

References Graphics::getRedraw(), Graphics::getTopClip(), Rect::height, mDrawHeight, mDrawWidth, Widget::mRedraw, mXOffset, mYOffset, Rect::width, ClipRect::xOffset, and ClipRect::yOffset.

Referenced by draw(), drawFrame(), and safeDrawFrame().

430 {
431  if (!mRedraw)
432  {
433  // because we don't know where parent windows was moved,
434  // need recalc vertexes
435  const ClipRect &rect = graphics->getTopClip();
436  if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
437  {
438  mRedraw = true;
439  mXOffset = rect.xOffset;
440  mYOffset = rect.yOffset;
441  }
442  else if (rect.width != mDrawWidth || rect.height != mDrawHeight)
443  {
444  mRedraw = true;
445  mDrawWidth = rect.width;
446  mDrawHeight = rect.height;
447  }
448  else if (graphics->getRedraw())
449  {
450  mRedraw = true;
451  }
452  }
453 }
int width
Definition: rect.h:218
ClipRect & getTopClip() const
Definition: graphics.h:280
int mXOffset
Definition: scrollarea.h:544
int mDrawHeight
Definition: scrollarea.h:547
int yOffset
Definition: cliprect.h:126
int xOffset
Definition: cliprect.h:121
int height
Definition: rect.h:223
bool getRedraw() const
Definition: graphics.h:286
bool mRedraw
Definition: widget.h:1163
int mYOffset
Definition: scrollarea.h:545
int mDrawWidth
Definition: scrollarea.h:546

◆ widgetMoved()

void ScrollArea::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 771 of file scrollarea.cpp.

References Widget::mRedraw.

Referenced by isOpaque().

772 {
773  mRedraw = true;
774 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void ScrollArea::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 759 of file scrollarea.cpp.

References getContent(), Rect::height, Widget::mDimension, Widget::mFrameSize, Widget::mRedraw, Widget::setSize(), and Rect::width.

Referenced by isOpaque().

760 {
761  mRedraw = true;
762  const unsigned int frameSize = 2 * mFrameSize;
763  Widget *const content = getContent();
764  if (content != nullptr)
765  {
766  content->setSize(mDimension.width - frameSize,
767  mDimension.height - frameSize);
768  }
769 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int width
Definition: rect.h:218
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
Definition: widget.h:97
bool mRedraw
Definition: widget.h:1163
Rect mDimension
Definition: widget.h:1100
Widget * getContent()

Field Documentation

◆ background

ImageRect ScrollArea::background
staticprotected

Definition at line 475 of file scrollarea.h.

Referenced by drawFrame(), init(), safeDrawFrame(), updateAlpha(), and ~ScrollArea().

◆ buttons

Image * ScrollArea::buttons
staticprotected

Definition at line 480 of file scrollarea.h.

Referenced by getImageByState(), init(), and ~ScrollArea().

◆ hBackground

ImageRect ScrollArea::hBackground
staticprotected

Definition at line 479 of file scrollarea.h.

Referenced by calcHBar(), drawHBar(), init(), updateAlpha(), and ~ScrollArea().

◆ instances

int ScrollArea::instances = 0
staticprotected

Definition at line 470 of file scrollarea.h.

Referenced by init(), and ~ScrollArea().

◆ mAlpha

float ScrollArea::mAlpha = 1.0
staticprotected

Definition at line 471 of file scrollarea.h.

Referenced by updateAlpha().

◆ mClickX

int ScrollArea::mClickX
protected

Definition at line 542 of file scrollarea.h.

Referenced by mousePressed(), and mouseReleased().

◆ mClickY

int ScrollArea::mClickY
protected

Definition at line 543 of file scrollarea.h.

Referenced by mousePressed(), and mouseReleased().

◆ mDownButtonPressed

bool ScrollArea::mDownButtonPressed
protected

True if the down button is pressed, false otherwise.

Definition at line 567 of file scrollarea.h.

Referenced by getImageByState(), logic(), mousePressed(), and mouseReleased().

◆ mDownButtonScrollAmount

int ScrollArea::mDownButtonScrollAmount
protected

Holds the down button scroll amount.

Definition at line 518 of file scrollarea.h.

Referenced by getDownButtonScrollAmount(), logic(), mousePressed(), and setDownButtonScrollAmount().

◆ mDrawHeight

int ScrollArea::mDrawHeight
protected

Definition at line 547 of file scrollarea.h.

Referenced by updateCalcFlag().

◆ mDrawWidth

int ScrollArea::mDrawWidth
protected

Definition at line 546 of file scrollarea.h.

Referenced by updateCalcFlag().

◆ mHasMouse

bool ScrollArea::mHasMouse
protected

◆ mHBarVisible

bool ScrollArea::mHBarVisible
protected

◆ mHorizontalMarkerDragOffset

int ScrollArea::mHorizontalMarkerDragOffset
protected

Holds the horizontal markers drag offset.

Definition at line 533 of file scrollarea.h.

Referenced by mouseDragged(), and mousePressed().

◆ mHPolicy

ScrollPolicy ScrollArea::mHPolicy
protected

Holds the horizontal scroll bar policy.

Definition at line 488 of file scrollarea.h.

Referenced by checkPolicies(), getHorizontalScrollPolicy(), logic(), setHorizontalScrollPolicy(), and setScrollPolicy().

◆ mHScroll

int ScrollArea::mHScroll
protected

Holds the horizontal scroll amount.

Definition at line 503 of file scrollarea.h.

Referenced by getHorizontalMarkerDimension(), getHorizontalScrollAmount(), logic(), mousePressed(), mouseReleased(), and setHorizontalScrollAmount().

◆ mIsHorizontalMarkerDragged

bool ScrollArea::mIsHorizontalMarkerDragged
protected

True if the horizontal marked is dragged.

Definition at line 587 of file scrollarea.h.

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

◆ mIsVerticalMarkerDragged

bool ScrollArea::mIsVerticalMarkerDragged
protected

True if the vertical marked is dragged.

Definition at line 582 of file scrollarea.h.

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

◆ mLeftButtonPressed

bool ScrollArea::mLeftButtonPressed
protected

True if the left button is pressed, false otherwise.

Definition at line 572 of file scrollarea.h.

Referenced by getImageByState(), logic(), mousePressed(), and mouseReleased().

◆ mLeftButtonScrollAmount

int ScrollArea::mLeftButtonScrollAmount
protected

Holds the left button scroll amount.

Definition at line 523 of file scrollarea.h.

Referenced by getLeftButtonScrollAmount(), logic(), mousePressed(), and setLeftButtonScrollAmount().

◆ mMarkerSize

int ScrollArea::mMarkerSize = 0
staticprotected

Definition at line 473 of file scrollarea.h.

Referenced by getHorizontalMarkerDimension(), getVerticalMarkerDimension(), and init().

◆ mOpaque

Opaque ScrollArea::mOpaque
protected

True if the scroll area should be opaque (that is display its background), false otherwise.

Definition at line 593 of file scrollarea.h.

Referenced by draw(), drawFrame(), init(), isOpaque(), safeDrawFrame(), ScrollArea(), and setOpaque().

◆ mRightButtonPressed

bool ScrollArea::mRightButtonPressed
protected

True if the right button is pressed, false otherwise.

Definition at line 577 of file scrollarea.h.

Referenced by getImageByState(), logic(), mousePressed(), and mouseReleased().

◆ mRightButtonScrollAmount

int ScrollArea::mRightButtonScrollAmount
protected

Holds the right button scroll amount.

Definition at line 528 of file scrollarea.h.

Referenced by getRightButtonScrollAmount(), logic(), mousePressed(), and setRightButtonScrollAmount().

◆ mScrollbarSize

int ScrollArea::mScrollbarSize = 12
staticprotected

Definition at line 474 of file scrollarea.h.

Referenced by init().

◆ mScrollbarWidth

int ScrollArea::mScrollbarWidth
protected

◆ mShowButtons

bool ScrollArea::mShowButtons = true
staticprotected

◆ mUpButtonPressed

bool ScrollArea::mUpButtonPressed
protected

True if the up button is pressed, false otherwise.

Definition at line 562 of file scrollarea.h.

Referenced by getImageByState(), logic(), mousePressed(), and mouseReleased().

◆ mUpButtonScrollAmount

int ScrollArea::mUpButtonScrollAmount
protected

Holds the up button scroll amount.

Definition at line 513 of file scrollarea.h.

Referenced by getUpButtonScrollAmount(), logic(), mousePressed(), and setUpButtonScrollAmount().

◆ mVBarVisible

bool ScrollArea::mVBarVisible
protected

◆ mVertexes

ImageCollection* ScrollArea::mVertexes
protected

Definition at line 482 of file scrollarea.h.

Referenced by calcButton(), calcHBar(), calcHMarker(), calcVBar(), calcVMarker(), draw(), and ~ScrollArea().

◆ mVertexes2

ImageCollection* ScrollArea::mVertexes2
protected

Definition at line 483 of file scrollarea.h.

Referenced by drawFrame(), and ~ScrollArea().

◆ mVerticalMarkerDragOffset

int ScrollArea::mVerticalMarkerDragOffset
protected

Holds the vertical markers drag offset.

Definition at line 538 of file scrollarea.h.

Referenced by mouseDragged(), and mousePressed().

◆ mVPolicy

ScrollPolicy ScrollArea::mVPolicy
protected

Holds the vertical scroll bar policy.

Definition at line 493 of file scrollarea.h.

Referenced by checkPolicies(), getVerticalScrollPolicy(), logic(), setScrollPolicy(), and setVerticalScrollPolicy().

◆ mVScroll

int ScrollArea::mVScroll
protected

◆ mX

int ScrollArea::mX
protected

Definition at line 540 of file scrollarea.h.

Referenced by calcVMarker(), drawVMarker(), and mouseMoved().

◆ mXOffset

int ScrollArea::mXOffset
protected

Definition at line 544 of file scrollarea.h.

Referenced by updateCalcFlag().

◆ mY

int ScrollArea::mY
protected

Definition at line 541 of file scrollarea.h.

Referenced by calcHMarker(), drawHMarker(), and mouseMoved().

◆ mYOffset

int ScrollArea::mYOffset
protected

Definition at line 545 of file scrollarea.h.

Referenced by updateCalcFlag().

◆ vBackground

ImageRect ScrollArea::vBackground
staticprotected

Definition at line 478 of file scrollarea.h.

Referenced by calcVBar(), drawVBar(), init(), updateAlpha(), and ~ScrollArea().

◆ vMarker

ImageRect ScrollArea::vMarker
staticprotected

◆ vMarkerHi

ImageRect ScrollArea::vMarkerHi
staticprotected

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