ManaPlus
scrollarea.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /* _______ __ __ __ ______ __ __ _______ __ __
25  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
26  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
27  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
28  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
29  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
30  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
31  *
32  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
33  *
34  *
35  * Per Larsson a.k.a finalman
36  * Olof Naessén a.k.a jansem/yakslem
37  *
38  * Visit: http://guichan.sourceforge.net
39  *
40  * License: (BSD)
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  * notice, this list of conditions and the following disclaimer in
48  * the documentation and/or other materials provided with the
49  * distribution.
50  * 3. Neither the name of Guichan nor the names of its contributors may
51  * be used to endorse or promote products derived from this software
52  * without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
60  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
61  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 #ifndef GUI_WIDGETS_SCROLLAREA_H
68 #define GUI_WIDGETS_SCROLLAREA_H
69 
71 
73 
76 
77 #include "localconsts.h"
78 
79 class Image;
80 class ImageCollection;
81 
92  public MouseListener,
93  public WidgetListener
94 {
95  public:
106  {
109  SHOW_AUTO
110  };
111 
112  ScrollArea(Widget2 *const widget2,
113  Widget *const widget,
114  const Opaque opaque,
115  const std::string &skin);
116 
118 
119 
123 
128  void logic() override final;
129 
133  void updateAlpha();
134 
138  void draw(Graphics *const graphics) override final A_NONNULL(2);
139 
140  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
141 
145  void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
146 
147  void safeDrawFrame(Graphics *const graphics) override final
148  A_NONNULL(2);
149 
153  void setOpaque(Opaque opaque);
154 
159  { return mOpaque == Opaque_true; }
160 
164  void mouseMoved(MouseEvent& event) override final;
165 
169  void mouseEntered(MouseEvent& event) override final;
170 
174  void mouseExited(MouseEvent& event) override final;
175 
176  void mousePressed(MouseEvent& event) override final;
177 
178  void mouseReleased(MouseEvent& event) override final;
179 
180  void mouseDragged(MouseEvent &event) override final;
181 
182  void widgetResized(const Event &event) override final;
183 
184  void widgetMoved(const Event &event) override final;
185 
187 
189 
191 
193 
194  Rect getUpButtonDimension() const;
195 
197 
199 
201 
207  void setContent(Widget* widget);
208 
214  Widget* getContent();
215 
222  void setHorizontalScrollPolicy(const ScrollPolicy hPolicy);
223 
231  { return mHPolicy; }
232 
239  void setVerticalScrollPolicy(const ScrollPolicy vPolicy);
240 
248  { return mVPolicy; }
249 
257  void setScrollPolicy(const ScrollPolicy hPolicy,
258  const ScrollPolicy vPolicy);
259 
266  void setVerticalScrollAmount(const int vScroll);
267 
275  { return mVScroll; }
276 
283  void setHorizontalScrollAmount(int hScroll);
284 
292  { return mHScroll; }
293 
301  void setScrollAmount(const int hScroll, const int vScroll);
302 
309 
315  int getVerticalMaxScroll();
316 
323  void setScrollbarWidth(const int width);
324 
331  int getScrollbarWidth() const
332  { return mScrollbarWidth; }
333 
341  void setLeftButtonScrollAmount(const int amount)
342  { mLeftButtonScrollAmount = amount; }
343 
351  void setRightButtonScrollAmount(const int amount)
352  { mRightButtonScrollAmount = amount; }
353 
361  void setUpButtonScrollAmount(const int amount)
362  { mUpButtonScrollAmount = amount; }
363 
371  void setDownButtonScrollAmount(const int amount)
372  { mDownButtonScrollAmount = amount; }
373 
382  { return mLeftButtonScrollAmount; }
383 
392  { return mRightButtonScrollAmount; }
393 
402  { return mUpButtonScrollAmount; }
403 
412  { return mDownButtonScrollAmount; }
413 
414  void showWidgetPart(Widget *const widget,
415  const Rect &area) override final;
416 
418 
419  Widget *getWidgetAt(int x, int y) override final;
420 
421  void setWidth(int width);
422 
423  void setHeight(int height);
424 
425  void setDimension(const Rect& dimension);
426 
428 
430 
432 
433  protected:
435  {
436  UP = 0,
441  };
442 
446  void init(std::string skinName);
447 
451  void checkPolicies();
452 
453  void drawButton(Graphics *const graphics,
454  const BUTTON_DIR dir) A_NONNULL(2);
455  void calcButton(Graphics *const graphics,
456  const BUTTON_DIR dir) A_NONNULL(2);
457  void drawVBar(Graphics *const graphics) const A_NONNULL(2);
458  void drawHBar(Graphics *const graphics) const A_NONNULL(2);
459  void drawVMarker(Graphics *const graphics) A_NONNULL(2);
460  void drawHMarker(Graphics *const graphics) A_NONNULL(2);
461 
462  void calcVBar(const Graphics *const graphics) A_NONNULL(2);
463  void calcHBar(const Graphics *const graphics) A_NONNULL(2);
464  void calcVMarker(Graphics *const graphics) A_NONNULL(2);
465  void calcHMarker(Graphics *const graphics) A_NONNULL(2);
466 
467  Image *getImageByState(Rect &dim, const BUTTON_DIR dir);
468 
469  void updateCalcFlag(const Graphics *const graphics) A_NONNULL(2);
470 
471  static int instances;
472  static float mAlpha;
473  static bool mShowButtons;
474  static int mMarkerSize;
475  static int mScrollbarSize;
481  static Image *buttons[4][2];
482 
485 
490 
495 
499  int mVScroll;
500 
504  int mHScroll;
505 
510 
515 
520 
525 
530 
535 
540 
541  int mX;
542  int mY;
543  int mClickX;
544  int mClickY;
545  int mXOffset;
546  int mYOffset;
549 
554 
559 
564 
569 
574 
579 
584 
589 
595 
596  bool mHasMouse;
597 };
598 
599 #endif // GUI_WIDGETS_SCROLLAREA_H
Definition: event.h:79
Definition: rect.h:74
int getScrollbarWidth() const
Definition: scrollarea.h:331
int mDrawHeight
Definition: scrollarea.h:548
static ImageRect vMarkerHi
Definition: scrollarea.h:478
Rect getHorizontalMarkerDimension()
bool mLeftButtonPressed
Definition: scrollarea.h:573
bool mRightButtonPressed
Definition: scrollarea.h:578
bool isSelectable() const
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
void setVerticalScrollAmount(const int vScroll)
void drawVBar(Graphics *const graphics) const
Definition: scrollarea.cpp:557
void calcVBar(const Graphics *const graphics)
Definition: scrollarea.cpp:580
ScrollPolicy getHorizontalScrollPolicy() const
Definition: scrollarea.h:230
int mDrawWidth
Definition: scrollarea.h:547
Widget * getWidgetAt(int x, int y)
void setScrollPolicy(const ScrollPolicy hPolicy, const ScrollPolicy vPolicy)
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:588
void safeDraw(Graphics *const graphics)
Definition: scrollarea.cpp:398
ScrollPolicy mHPolicy
Definition: scrollarea.h:489
void calcHBar(const Graphics *const graphics)
Definition: scrollarea.cpp:635
bool mDownButtonPressed
Definition: scrollarea.h:568
int mVScroll
Definition: scrollarea.h:499
int getVerticalMaxScroll()
int mYOffset
Definition: scrollarea.h:546
static ImageRect hBackground
Definition: scrollarea.h:480
int mHScroll
Definition: scrollarea.h:504
ScrollPolicy mVPolicy
Definition: scrollarea.h:494
void mouseExited(MouseEvent &event)
Definition: scrollarea.cpp:754
int getDownButtonScrollAmount() const
Definition: scrollarea.h:411
void setUpButtonScrollAmount(const int amount)
Definition: scrollarea.h:361
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
static ImageRect vMarker
Definition: scrollarea.h:477
void mouseMoved(MouseEvent &event)
Definition: scrollarea.cpp:743
void mouseEntered(MouseEvent &event)
Definition: scrollarea.cpp:749
Opaque mOpaque
Definition: scrollarea.h:594
Rect getLeftButtonDimension() const
void calcButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:544
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:975
int getLeftButtonScrollAmount() const
Definition: scrollarea.h:381
void draw(Graphics *const graphics)
Definition: scrollarea.cpp:344
void updateAlpha()
Definition: scrollarea.cpp:320
int mScrollbarWidth
Definition: scrollarea.h:509
void safeDrawFrame(Graphics *const graphics)
Definition: scrollarea.cpp:480
void mouseReleased(MouseEvent &event)
Definition: scrollarea.cpp:861
int getRightButtonScrollAmount() const
Definition: scrollarea.h:391
void setRightButtonScrollAmount(const int amount)
Definition: scrollarea.h:351
static int mMarkerSize
Definition: scrollarea.h:474
int mXOffset
Definition: scrollarea.h:545
static float mAlpha
Definition: scrollarea.h:472
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:583
void mousePressed(MouseEvent &event)
Definition: scrollarea.cpp:776
int mLeftButtonScrollAmount
Definition: scrollarea.h:524
int mRightButtonScrollAmount
Definition: scrollarea.h:529
void drawVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:666
bool mHasMouse
Definition: scrollarea.h:596
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:995
static ImageRect background
Definition: scrollarea.h:476
void setDownButtonScrollAmount(const int amount)
Definition: scrollarea.h:371
void setScrollAmount(const int hScroll, const int vScroll)
void setWidth(int width)
void drawFrame(Graphics *const graphics)
Definition: scrollarea.cpp:456
void setContent(Widget *widget)
ImageCollection * mVertexes2
Definition: scrollarea.h:484
void widgetResized(const Event &event)
Definition: scrollarea.cpp:759
void mouseDragged(MouseEvent &event)
Definition: scrollarea.cpp:933
Widget * getContent()
static int instances
Definition: scrollarea.h:471
ImageCollection * mVertexes
Definition: scrollarea.h:483
Rect getDownButtonDimension() const
Image * getImageByState(Rect &dim, const BUTTON_DIR dir)
Definition: scrollarea.cpp:503
void widgetMoved(const Event &event)
Definition: scrollarea.cpp:771
bool isOpaque() const
Definition: scrollarea.h:158
void checkPolicies()
bool mUpButtonPressed
Definition: scrollarea.h:563
int mUpButtonScrollAmount
Definition: scrollarea.h:514
void calcVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:684
void init(std::string skinName)
Definition: scrollarea.cpp:182
int mHorizontalMarkerDragOffset
Definition: scrollarea.h:534
int getVerticalScrollAmount() const
Definition: scrollarea.h:274
void logic()
Definition: scrollarea.cpp:273
bool mHBarVisible
Definition: scrollarea.h:558
ScrollArea(Widget2 *const widget2, Widget *const widget, const Opaque opaque, const std::string &skin)
Definition: scrollarea.cpp:105
int mVerticalMarkerDragOffset
Definition: scrollarea.h:539
Rect getUpButtonDimension() const
void mouseWheelMovedUp(MouseEvent &event)
void drawHBar(Graphics *const graphics) const
Definition: scrollarea.cpp:607
static int mScrollbarSize
Definition: scrollarea.h:475
void setHeight(int height)
int getUpButtonScrollAmount() const
Definition: scrollarea.h:401
void setScrollbarWidth(const int width)
void mouseWheelMovedDown(MouseEvent &event)
int mDownButtonScrollAmount
Definition: scrollarea.h:519
void calcHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:723
static ImageRect vBackground
Definition: scrollarea.h:479
void setHorizontalScrollAmount(int hScroll)
static bool mShowButtons
Definition: scrollarea.h:473
Rect getChildrenArea()
void drawHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:704
void setOpaque(Opaque opaque)
Definition: scrollarea.cpp:497
Rect getVerticalMarkerDimension()
void setLeftButtonScrollAmount(const int amount)
Definition: scrollarea.h:341
void showWidgetPart(Widget *const widget, const Rect &area)
ScrollPolicy getVerticalScrollPolicy() const
Definition: scrollarea.h:247
void updateCalcFlag(const Graphics *const graphics)
Definition: scrollarea.cpp:430
int getHorizontalMaxScroll()
int getHorizontalScrollAmount() const
Definition: scrollarea.h:291
void setDimension(const Rect &dimension)
void drawButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:534
bool mVBarVisible
Definition: scrollarea.h:553
Rect getRightButtonDimension() const
static Image * buttons[4][2]
Definition: scrollarea.h:481
Definition: widget.h:99
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
const bool Opaque_true
Definition: opaque.h:30
bool Opaque
Definition: opaque.h:30