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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 /* _______ __ __ __ ______ __ __ _______ __ __
24  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
25  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
26  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
27  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
28  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
29  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
30  *
31  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
32  *
33  *
34  * Per Larsson a.k.a finalman
35  * Olof Naessén a.k.a jansem/yakslem
36  *
37  * Visit: http://guichan.sourceforge.net
38  *
39  * License: (BSD)
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  * notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  * notice, this list of conditions and the following disclaimer in
47  * the documentation and/or other materials provided with the
48  * distribution.
49  * 3. Neither the name of Guichan nor the names of its contributors may
50  * be used to endorse or promote products derived from this software
51  * without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
59  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  */
65 
66 #ifndef GUI_WIDGETS_SCROLLAREA_H
67 #define GUI_WIDGETS_SCROLLAREA_H
68 
70 
72 
75 
76 #include "localconsts.h"
77 
78 class Image;
79 class ImageCollection;
80 
91  public MouseListener,
92  public WidgetListener
93 {
94  public:
105  {
109  };
110 
111  ScrollArea(Widget2 *const widget2,
112  Widget *const widget,
113  const Opaque opaque,
114  const std::string &skin);
115 
117 
118 
122 
127  void logic() override final;
128 
132  void updateAlpha();
133 
137  void draw(Graphics *const graphics) override final A_NONNULL(2);
138 
139  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
140 
144  void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
145 
146  void safeDrawFrame(Graphics *const graphics) override final
147  A_NONNULL(2);
148 
152  void setOpaque(Opaque opaque);
153 
158  { return mOpaque == Opaque_true; }
159 
163  void mouseMoved(MouseEvent& event) override final;
164 
168  void mouseEntered(MouseEvent& event) override final;
169 
173  void mouseExited(MouseEvent& event) override final;
174 
175  void mousePressed(MouseEvent& event) override final;
176 
177  void mouseReleased(MouseEvent& event) override final;
178 
179  void mouseDragged(MouseEvent &event) override final;
180 
181  void widgetResized(const Event &event) override final;
182 
183  void widgetMoved(const Event &event) override final;
184 
186 
188 
190 
192 
193  Rect getUpButtonDimension() const;
194 
196 
198 
200 
206  void setContent(Widget* widget);
207 
213  Widget* getContent();
214 
221  void setHorizontalScrollPolicy(const ScrollPolicy hPolicy);
222 
230  { return mHPolicy; }
231 
238  void setVerticalScrollPolicy(const ScrollPolicy vPolicy);
239 
247  { return mVPolicy; }
248 
256  void setScrollPolicy(const ScrollPolicy hPolicy,
257  const ScrollPolicy vPolicy);
258 
265  void setVerticalScrollAmount(const int vScroll);
266 
274  { return mVScroll; }
275 
282  void setHorizontalScrollAmount(int hScroll);
283 
291  { return mHScroll; }
292 
300  void setScrollAmount(const int hScroll, const int vScroll);
301 
308 
314  int getVerticalMaxScroll();
315 
322  void setScrollbarWidth(const int width);
323 
330  int getScrollbarWidth() const
331  { return mScrollbarWidth; }
332 
340  void setLeftButtonScrollAmount(const int amount)
341  { mLeftButtonScrollAmount = amount; }
342 
350  void setRightButtonScrollAmount(const int amount)
351  { mRightButtonScrollAmount = amount; }
352 
360  void setUpButtonScrollAmount(const int amount)
361  { mUpButtonScrollAmount = amount; }
362 
370  void setDownButtonScrollAmount(const int amount)
371  { mDownButtonScrollAmount = amount; }
372 
381  { return mLeftButtonScrollAmount; }
382 
391  { return mRightButtonScrollAmount; }
392 
401  { return mUpButtonScrollAmount; }
402 
411  { return mDownButtonScrollAmount; }
412 
413  void showWidgetPart(Widget *const widget,
414  const Rect &area) override final;
415 
416  Rect getChildrenArea() override final;
417 
418  Widget *getWidgetAt(int x, int y) override final;
419 
420  void setWidth(int width);
421 
422  void setHeight(int height);
423 
424  void setDimension(const Rect& dimension);
425 
426  void mouseWheelMovedUp(MouseEvent& event) override final;
427 
428  void mouseWheelMovedDown(MouseEvent& event) override final;
429 
430  bool isSelectable() const noexcept2 override final A_WARN_UNUSED;
431 
432  protected:
434  {
435  UP = 0,
440  };
441 
445  void init(std::string skinName);
446 
450  void checkPolicies();
451 
452  void drawButton(Graphics *const graphics,
453  const BUTTON_DIR dir) A_NONNULL(2);
454  void calcButton(Graphics *const graphics,
455  const BUTTON_DIR dir) A_NONNULL(2);
456  void drawVBar(Graphics *const graphics) const A_NONNULL(2);
457  void drawHBar(Graphics *const graphics) const A_NONNULL(2);
458  void drawVMarker(Graphics *const graphics) A_NONNULL(2);
459  void drawHMarker(Graphics *const graphics) A_NONNULL(2);
460 
461  void calcVBar(const Graphics *const graphics) A_NONNULL(2);
462  void calcHBar(const Graphics *const graphics) A_NONNULL(2);
463  void calcVMarker(Graphics *const graphics) A_NONNULL(2);
464  void calcHMarker(Graphics *const graphics) A_NONNULL(2);
465 
466  Image *getImageByState(Rect &dim, const BUTTON_DIR dir);
467 
468  void updateCalcFlag(const Graphics *const graphics) A_NONNULL(2);
469 
470  static int instances;
471  static float mAlpha;
472  static bool mShowButtons;
473  static int mMarkerSize;
474  static int mScrollbarSize;
480  static Image *buttons[4][2];
481 
484 
489 
494 
498  int mVScroll;
499 
503  int mHScroll;
504 
509 
514 
519 
524 
529 
534 
539 
540  int mX;
541  int mY;
542  int mClickX;
543  int mClickY;
544  int mXOffset;
545  int mYOffset;
548 
553 
558 
563 
568 
573 
578 
583 
588 
594 
595  bool mHasMouse;
596 };
597 
598 #endif // GUI_WIDGETS_SCROLLAREA_H
void drawVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:666
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
Rect getDownButtonDimension() const
ImageCollection * mVertexes2
Definition: scrollarea.h:483
void setLeftButtonScrollAmount(const int amount)
Definition: scrollarea.h:340
Rect getHorizontalMarkerDimension()
bool mRightButtonPressed
Definition: scrollarea.h:577
int mHScroll
Definition: scrollarea.h:503
ScrollPolicy getHorizontalScrollPolicy() const
Definition: scrollarea.h:229
void calcVBar(const Graphics *const graphics)
Definition: scrollarea.cpp:580
int mScrollbarWidth
Definition: scrollarea.h:508
ScrollPolicy getVerticalScrollPolicy() const
Definition: scrollarea.h:246
#define A_NONNULLPOINTER
Definition: localconsts.h:257
int mXOffset
Definition: scrollarea.h:544
int getHorizontalScrollAmount() const
Definition: scrollarea.h:290
int mUpButtonScrollAmount
Definition: scrollarea.h:513
Rect getHorizontalBarDimension() const
Definition: scrollarea.cpp:997
Opaque mOpaque
Definition: scrollarea.h:593
bool mIsHorizontalMarkerDragged
Definition: scrollarea.h:587
ScrollPolicy mVPolicy
Definition: scrollarea.h:493
void drawButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:534
void widgetMoved(const Event &event)
Definition: scrollarea.cpp:771
Rect getVerticalBarDimension() const
Definition: scrollarea.cpp:977
void setScrollPolicy(const ScrollPolicy hPolicy, const ScrollPolicy vPolicy)
int mDrawHeight
Definition: scrollarea.h:547
Definition: rect.h:72
void mouseMoved(MouseEvent &event)
Definition: scrollarea.cpp:743
void showWidgetPart(Widget *const widget, const Rect &area)
#define A_WARN_UNUSED
Definition: localconsts.h:152
Rect getVerticalMarkerDimension()
#define final
Definition: localconsts.h:45
void setDimension(const Rect &dimension)
void setWidth(int width)
bool mLeftButtonPressed
Definition: scrollarea.h:572
void calcButton(Graphics *const graphics, const BUTTON_DIR dir)
Definition: scrollarea.cpp:544
void setVerticalScrollAmount(const int vScroll)
bool isOpaque() const
Definition: scrollarea.h:157
Widget * getWidgetAt(int x, int y)
void setHeight(int height)
#define A_NONNULL(...)
Definition: localconsts.h:159
void setScrollbarWidth(const int width)
static ImageRect vBackground
Definition: scrollarea.h:478
bool mIsVerticalMarkerDragged
Definition: scrollarea.h:582
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
Image * getImageByState(Rect &dim, const BUTTON_DIR dir)
Definition: scrollarea.cpp:503
bool mHasMouse
Definition: scrollarea.h:595
void setOpaque(Opaque opaque)
Definition: scrollarea.cpp:497
int getVerticalMaxScroll()
void drawVBar(Graphics *const graphics) const
Definition: scrollarea.cpp:557
void calcVMarker(Graphics *const graphics)
Definition: scrollarea.cpp:684
int getScrollbarWidth() const
Definition: scrollarea.h:330
bool mVBarVisible
Definition: scrollarea.h:552
void setRightButtonScrollAmount(const int amount)
Definition: scrollarea.h:350
void mouseDragged(MouseEvent &event)
Definition: scrollarea.cpp:933
void calcHBar(const Graphics *const graphics)
Definition: scrollarea.cpp:635
void mouseReleased(MouseEvent &event)
Definition: scrollarea.cpp:861
ScrollArea(Widget2 *const widget2, Widget *const widget, const Opaque opaque, const std::string &skin)
Definition: scrollarea.cpp:104
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
static ImageRect vMarkerHi
Definition: scrollarea.h:477
void drawHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:704
void safeDraw(Graphics *const graphics)
Definition: scrollarea.cpp:397
static float mAlpha
Definition: scrollarea.h:471
void calcHMarker(Graphics *const graphics)
Definition: scrollarea.cpp:723
static ImageRect vMarker
Definition: scrollarea.h:476
void drawHBar(Graphics *const graphics) const
Definition: scrollarea.cpp:607
void mouseWheelMovedUp(MouseEvent &event)
Rect getRightButtonDimension() const
void widgetResized(const Event &event)
Definition: scrollarea.cpp:759
static int mScrollbarSize
Definition: scrollarea.h:474
void safeDrawFrame(Graphics *const graphics)
Definition: scrollarea.cpp:480
static Image * buttons[4][2]
Definition: scrollarea.h:480
static ImageRect hBackground
Definition: scrollarea.h:479
Rect getChildrenArea()
static int instances
Definition: scrollarea.h:470
void mouseWheelMovedDown(MouseEvent &event)
static ImageRect background
Definition: scrollarea.h:475
int mHorizontalMarkerDragOffset
Definition: scrollarea.h:533
int mRightButtonScrollAmount
Definition: scrollarea.h:528
void setContent(Widget *widget)
void drawFrame(Graphics *const graphics)
Definition: scrollarea.cpp:455
static int mMarkerSize
Definition: scrollarea.h:473
Rect getUpButtonDimension() const
void mouseEntered(MouseEvent &event)
Definition: scrollarea.cpp:749
void checkPolicies()
void mousePressed(MouseEvent &event)
Definition: scrollarea.cpp:776
ImageCollection * mVertexes
Definition: scrollarea.h:482
bool mDownButtonPressed
Definition: scrollarea.h:567
Definition: widget.h:97
int getUpButtonScrollAmount() const
Definition: scrollarea.h:400
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
Definition: event.h:77
void setScrollAmount(const int hScroll, const int vScroll)
void draw(Graphics *const graphics)
Definition: scrollarea.cpp:343
Definition: image.h:61
void setDownButtonScrollAmount(const int amount)
Definition: scrollarea.h:370
void setHorizontalScrollAmount(int hScroll)
static bool mShowButtons
Definition: scrollarea.h:472
void mouseExited(MouseEvent &event)
Definition: scrollarea.cpp:754
int getDownButtonScrollAmount() const
Definition: scrollarea.h:410
bool isSelectable() const
#define override
Definition: localconsts.h:46
void init(std::string skinName)
Definition: scrollarea.cpp:181
int mDownButtonScrollAmount
Definition: scrollarea.h:518
int getLeftButtonScrollAmount() const
Definition: scrollarea.h:380
ScrollPolicy mHPolicy
Definition: scrollarea.h:488
bool mHBarVisible
Definition: scrollarea.h:557
int mYOffset
Definition: scrollarea.h:545
int mDrawWidth
Definition: scrollarea.h:546
#define noexcept2
Definition: localconsts.h:49
int mVerticalMarkerDragOffset
Definition: scrollarea.h:538
Rect getLeftButtonDimension() const
int getRightButtonScrollAmount() const
Definition: scrollarea.h:390
void updateCalcFlag(const Graphics *const graphics)
Definition: scrollarea.cpp:429
void updateAlpha()
Definition: scrollarea.cpp:319
void logic()
Definition: scrollarea.cpp:272
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
Widget * getContent()
void setUpButtonScrollAmount(const int amount)
Definition: scrollarea.h:360
int getHorizontalMaxScroll()