486 lines
14 KiB
C++
486 lines
14 KiB
C++
/* _______ __ __ __ ______ __ __ _______ __ __
|
|
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
|
|
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
|
|
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
|
|
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
|
|
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
|
|
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
|
|
*
|
|
* Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson
|
|
*
|
|
* Js_./
|
|
* Per Larsson a.k.a finalman _RqZ{a<^_aa
|
|
* Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
|
|
* _Qhm`] _f "'c 1!5m
|
|
* Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
|
|
* .)j(] .d_/ '-( P . S
|
|
* License: (BSD) <Td/Z <fP"5(\"??"\a. .L
|
|
* Redistribution and use in source and _dV>ws?a-?' ._/L #'
|
|
* binary forms, with or without )4d[#7r, . ' )d`)[
|
|
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
|
|
* that the following conditions are met: j<<WP+k/);. _W=j f
|
|
* 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
|
|
* retain the above copyright notice, ]E.pYY(Q]>. a J@\
|
|
* this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
|
|
* following disclaimer. 4'_uomm\. )L);-4 (3=
|
|
* 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
|
|
* reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
|
|
* this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
|
|
* following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
|
|
* documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
|
|
* provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
|
|
* 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
|
|
* names of its contributors may be used =3)= _f (_yQmWW$#( "
|
|
* to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
|
|
* from this software without specific (js, \[QQW$QWW#?!V"".
|
|
* prior written permission. ]y:.<\.. .
|
|
* -]n w/ ' [.
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
|
|
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef GCN_SCROLLAREA_HPP
|
|
#define GCN_SCROLLAREA_HPP
|
|
|
|
#include "guisan/basiccontainer.hpp"
|
|
#include "guisan/mouselistener.hpp"
|
|
#include "guisan/platform.hpp"
|
|
|
|
namespace gcn
|
|
{
|
|
/**
|
|
* A ScrollArea in which another Widget can be added. It the other Widget
|
|
* is bigger then the ScrollArea, the ScrollArea will only display the part
|
|
* of the Widget that fits the ScrollArea and make it possible to scroll
|
|
* to the other areas of the Widget.
|
|
*
|
|
* NOTE: A TextBox or a ListBox looks really ugly unless they exist in a
|
|
* ScrollArea.
|
|
*/
|
|
class GCN_CORE_DECLSPEC ScrollArea :
|
|
public BasicContainer,
|
|
public MouseListener
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
ScrollArea();
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param content the content of the ScrollArea.
|
|
*/
|
|
ScrollArea(Widget* content);
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param content the content of the ScrollArea.
|
|
* @param hPolicy the policy for the horizontal scrollbar. See enum with
|
|
* policies.
|
|
* @param vPolicy the policy for the vertical scrollbar. See enum with
|
|
* policies.
|
|
*/
|
|
ScrollArea(Widget* content, unsigned int hPolicy, unsigned int vPolicy);
|
|
|
|
/**
|
|
* Destructor.
|
|
*/
|
|
virtual ~ScrollArea();
|
|
|
|
/**
|
|
* Sets the content.
|
|
*
|
|
* @param widget the content of the ScrollArea.
|
|
*/
|
|
void setContent(Widget* widget);
|
|
|
|
/**
|
|
* Gets the content.
|
|
*
|
|
* @return the content of the ScrollArea.
|
|
*/
|
|
Widget* getContent();
|
|
|
|
/**
|
|
* Sets the horizontal scrollbar policy. See enum with policies.
|
|
*
|
|
* @param hPolicy the policy for the horizontal scrollbar. See enum with
|
|
* policies.
|
|
*/
|
|
void setHorizontalScrollPolicy(unsigned int hPolicy);
|
|
|
|
/**
|
|
* Gets the horizontal scrollbar policy. See enum with policies.
|
|
*
|
|
* @return the policy for the horizontal scrollbar policy. See enum with
|
|
* policies.
|
|
*/
|
|
[[nodiscard]] unsigned int getHorizontalScrollPolicy() const;
|
|
|
|
/**
|
|
* Sets the vertical scrollbar policy. See enum with policies.
|
|
*
|
|
* @param vPolicy the policy for the vertical scrollbar. See enum with
|
|
* policies.
|
|
*/
|
|
void setVerticalScrollPolicy(unsigned int vPolicy);
|
|
|
|
/**
|
|
* Gets the vertical scrollbar policy. See enum with policies.
|
|
*
|
|
* @return the policy for the vertical scrollbar. See enum with
|
|
* policies.
|
|
*/
|
|
[[nodiscard]] unsigned int getVerticalScrollPolicy() const;
|
|
|
|
/**
|
|
* Sets the horizontal and vertical scrollbar policy. See enum with policies.
|
|
*
|
|
* @param hPolicy the policy for the horizontal scrollbar. See enum with
|
|
* policies.
|
|
* @param vPolicy the policy for the vertical scrollbar. See enum with
|
|
* policies.
|
|
*/
|
|
void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy);
|
|
|
|
/**
|
|
* Sets the amount to scroll vertically.
|
|
*
|
|
* @param vScroll the amount to scroll.
|
|
*/
|
|
void setVerticalScrollAmount(int vScroll);
|
|
|
|
/**
|
|
* Gets the amount that is scrolled vertically.
|
|
* @return the scroll amount on vertical scroll.
|
|
*/
|
|
[[nodiscard]] int getVerticalScrollAmount() const;
|
|
|
|
/**
|
|
* Sets the amount to scroll horizontally.
|
|
*
|
|
* @param hScroll the amount to scroll.
|
|
*/
|
|
void setHorizontalScrollAmount(int hScroll);
|
|
|
|
/**
|
|
* Gets the amount that is scrolled horizontally.
|
|
*
|
|
* @return the scroll amount on horizontal scroll.
|
|
*/
|
|
[[nodiscard]] int getHorizontalScrollAmount() const;
|
|
|
|
/**
|
|
* Sets the amount to scroll horizontally and vertically.
|
|
*
|
|
* @param hScroll the amount to scroll on horizontal scroll.
|
|
* @param vScroll the amount to scroll on vertical scroll.
|
|
*/
|
|
void setScrollAmount(int hScroll, int vScroll);
|
|
|
|
/**
|
|
* Gets the maximum amount of horizontal scroll.
|
|
*
|
|
* @return the horizontal max scroll.
|
|
*/
|
|
int getHorizontalMaxScroll();
|
|
|
|
/**
|
|
* Gets the maximum amount of vertical scroll.
|
|
*
|
|
* @return the vertical max scroll.
|
|
*/
|
|
int getVerticalMaxScroll();
|
|
|
|
/**
|
|
* Sets the width.
|
|
*
|
|
* @param width the width of the ScrollBar.
|
|
*/
|
|
void setScrollbarWidth(int width);
|
|
|
|
/**
|
|
* Gets the width.
|
|
|
|
* @return the width of the ScrollBar.
|
|
*/
|
|
[[nodiscard]] int getScrollbarWidth() const;
|
|
|
|
/**
|
|
* Sets the amount to scroll in pixels when the left scroll button is
|
|
* pushed.
|
|
*/
|
|
void setLeftButtonScrollAmount(int amount);
|
|
|
|
/**
|
|
* Sets the amount to scroll in pixels when the right scroll button is
|
|
* pushed.
|
|
*/
|
|
void setRightButtonScrollAmount(int amount);
|
|
|
|
/**
|
|
* Sets the amount to scroll in pixels when the up scroll button is
|
|
* pushed.
|
|
*/
|
|
void setUpButtonScrollAmount(int amount);
|
|
|
|
/**
|
|
* Sets the amount to scroll in pixels when the down scroll button is
|
|
* pushed.
|
|
*/
|
|
void setDownButtonScrollAmount(int amount);
|
|
|
|
/**
|
|
* Gets the amount to scroll in pixels when the left scroll button is
|
|
* pushed.
|
|
*
|
|
* @return the amount to scroll when the left scroll button is pushed.
|
|
*/
|
|
[[nodiscard]] int getLeftButtonScrollAmount() const;
|
|
|
|
/**
|
|
* Gets the amount to scroll in pixels when the right scroll button is
|
|
* pushed.
|
|
*
|
|
* @return the amount to scroll when the right scroll button is pushed.
|
|
*/
|
|
[[nodiscard]] int getRightButtonScrollAmount() const;
|
|
|
|
/**
|
|
* Gets the amount to scroll in pixels when the up scroll button is
|
|
* pushed.
|
|
*
|
|
* @return the amount to scroll when the up scroll button is pushed.
|
|
*/
|
|
[[nodiscard]] int getUpButtonScrollAmount() const;
|
|
|
|
/**
|
|
* Gets the amount to scroll in pixels when the down scroll button is
|
|
* pushed.
|
|
*
|
|
* @return the amount to scroll when the down scroll button is pushed.
|
|
*/
|
|
[[nodiscard]] int getDownButtonScrollAmount() const;
|
|
|
|
|
|
// Inherited from BasicContainer
|
|
|
|
void showWidgetPart(Widget* widget, Rectangle area) override;
|
|
|
|
Rectangle getChildrenArea() override;
|
|
|
|
Widget* getWidgetAt(int x, int y) override;
|
|
|
|
|
|
// Inherited from Widget
|
|
|
|
void draw(Graphics* graphics) override;
|
|
|
|
void drawBorder(Graphics* graphics) override;
|
|
|
|
void logic() override;
|
|
|
|
void setWidth(int width) override;
|
|
|
|
void setHeight(int height) override;
|
|
|
|
void setDimension(const Rectangle& dimension) override;
|
|
|
|
|
|
// Inherited from MouseListener
|
|
|
|
void mousePressed(MouseEvent& mouseEvent) override;
|
|
|
|
void mouseReleased(MouseEvent& mouseEvent) override;
|
|
|
|
void mouseDragged(MouseEvent& mouseEvent) override;
|
|
|
|
void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
|
|
|
|
void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
|
|
|
|
|
|
/**
|
|
* Scroll policies 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 what.
|
|
* SHOW_AUTO - Show the scrollbars only when needed. That is if the
|
|
* content grows larger then the ScrollArea.
|
|
*/
|
|
enum
|
|
{
|
|
SHOW_ALWAYS,
|
|
SHOW_NEVER,
|
|
SHOW_AUTO
|
|
};
|
|
|
|
protected:
|
|
/**
|
|
* Draws the background of the ScrollArea
|
|
* (the area behind the content).
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawBackground(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the up button.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawUpButton(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the down button.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawDownButton(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the left button.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawLeftButton(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the right button.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawRightButton(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the vertical scrollbar.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawVBar(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the horizontal scrollbar.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawHBar(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the vertical marker.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawVMarker(Graphics* graphics);
|
|
|
|
/**
|
|
* Draws the horizontal marker.
|
|
*
|
|
* @param graphics a Graphics object to draw with.
|
|
*/
|
|
virtual void drawHMarker(Graphics* graphics);
|
|
|
|
/**
|
|
* Checks the policies for the scrollbars.
|
|
*/
|
|
virtual void checkPolicies();
|
|
|
|
/**
|
|
* Gets the up button dimension.
|
|
*
|
|
* @return the dimension of the up button.
|
|
*/
|
|
Rectangle getUpButtonDimension() const;
|
|
|
|
/**
|
|
* Gets the down button dimension.
|
|
*
|
|
* @return the dimension of the down button.
|
|
*/
|
|
Rectangle getDownButtonDimension() const;
|
|
|
|
/**
|
|
* Gets the left button dimension.
|
|
*
|
|
* @return the dimension of the left button.
|
|
*/
|
|
Rectangle getLeftButtonDimension() const;
|
|
|
|
/**
|
|
* Gets the right button dimension.
|
|
*
|
|
* @return the dimension of the right button.
|
|
*/
|
|
Rectangle getRightButtonDimension() const;
|
|
|
|
/**
|
|
* Gets the vertical scrollbar dimension.
|
|
*
|
|
* @return the dimension of the vertical scrollbar.
|
|
*/
|
|
Rectangle getVerticalBarDimension() const;
|
|
|
|
/**
|
|
* Gets the horizontal scrollbar dimension.
|
|
*
|
|
* @return the dimension of the horizontal scrollbar.
|
|
*/
|
|
Rectangle getHorizontalBarDimension() const;
|
|
|
|
/**
|
|
* Gets the vertical marker dimension.
|
|
*
|
|
* @return the dimension of the vertical marker.
|
|
*/
|
|
Rectangle getVerticalMarkerDimension();
|
|
|
|
/**
|
|
* Gets the horizontal marker dimension.
|
|
*
|
|
* @return the dimension of the horizontal marker.
|
|
*/
|
|
Rectangle getHorizontalMarkerDimension();
|
|
|
|
int mVScroll;
|
|
int mHScroll;
|
|
int mScrollbarWidth;
|
|
unsigned int mHPolicy;
|
|
unsigned int mVPolicy;
|
|
bool mVBarVisible{};
|
|
bool mHBarVisible{};
|
|
bool mUpButtonPressed;
|
|
bool mDownButtonPressed;
|
|
bool mLeftButtonPressed;
|
|
bool mRightButtonPressed;
|
|
int mUpButtonScrollAmount;
|
|
int mDownButtonScrollAmount;
|
|
int mLeftButtonScrollAmount;
|
|
int mRightButtonScrollAmount;
|
|
bool mIsVerticalMarkerDragged;
|
|
bool mIsHorizontalMarkerDragged;
|
|
int mHorizontalMarkerDragOffset{};
|
|
int mVerticalMarkerDragOffset{};
|
|
};
|
|
}
|
|
|
|
#endif // end GCN_SCROLLAREA_HPP
|