Planeshift

pawscrollbar.h

Go to the documentation of this file.
00001 /*
00002  * pawscrollbar.h - Author: Andrew Craig
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 // pawscrollbar.h: interface for the pawscrollbar class.
00020 //
00022 
00023 #ifndef PAWS_SCROLLBAR_HEADER
00024 #define PAWS_SCROLLBAR_HEADER
00025 
00026 #include "pawswidget.h"
00027 
00028 struct iVirtualClock;
00029 class pawsButton;
00030 
00035 class pawsThumb : public pawsWidget
00036 {
00037 public:
00038     pawsThumb()
00039     {
00040         factory = "pawsThumb";
00041     };
00042     pawsThumb(const pawsThumb &origin): pawsWidget(origin)
00043     {
00044 
00045     }
00046     bool OnMouseUp(int button, int modifiers, int x, int y)
00047     {
00048         if(parent)
00049             return parent->OnMouseUp(button, modifiers, x, y);
00050         else
00051             return false;
00052     }
00053 
00054     void OnLostFocus()
00055     {
00056         OnMouseUp(0,0,0,0);
00057         pawsWidget::OnLostFocus();
00058     }
00059 
00060 };
00061 CREATE_PAWS_FACTORY(pawsThumb);
00064 class pawsScrollBar : public pawsWidget
00065 {
00066 public:
00067     pawsScrollBar();
00068     pawsScrollBar(const pawsScrollBar &origin);
00069     virtual ~pawsScrollBar();
00070 
00071     virtual bool Setup(iDocumentNode* node);
00072     virtual bool PostSetup();
00073     virtual bool OnMouseDown(int button, int modifiers, int x, int y);
00074     virtual bool OnMouseUp(int button, int modifiers, int x, int y);
00075 
00076     /* This is used to register child button presses.
00077      * In the scroll bar case it will catch the up and down arrows.
00078      * @param button The mouse button that was pressed.
00079      * @param widget The child Widget that was pressed.
00080      * @return true if the scroll bar handled the button.
00081      */
00082     virtual bool OnButtonPressed(int button, int keyModifier, pawsWidget* widget);
00083 
00084     virtual bool OnButtonReleased(int button, int keyModifier, pawsWidget* widget);
00085 
00089     virtual void SetMaxValue(float value);
00090     virtual float GetMaxValue()
00091     {
00092         return maxValue;
00093     }
00094 
00098     virtual void SetMinValue(float value);
00099     virtual float GetMinValue()
00100     {
00101         return minValue;
00102     }
00103 
00107     virtual void EnableValueLimit(bool limited);
00108 
00116     virtual void SetCurrentValue(float value, bool triggerEvent = true, bool publish=true);
00117 
00121     virtual float GetCurrentValue();
00122 
00126     virtual void SetTickValue(float tick);
00127 
00132     virtual float GetTickValue()
00133     {
00134         return tickValue;
00135     }
00136 
00137     virtual void Draw();
00138 
00139     virtual void SetHorizontal(bool value);
00140 
00144     virtual void SetReversed(bool reversed)
00145     {
00146         this->reversed = reversed;
00147     }
00148 
00149     // Scroll bars should not be focused.
00150     virtual bool OnGainFocus(bool /*notifyParent*/ = true)
00151     {
00152         return false;
00153     }
00154 
00155     virtual void OnResize();
00156 
00157     virtual bool OnMouseExit();
00158 
00159     virtual void OnUpdateData(const char* dataname,PAWSData &data);
00160 
00164     bool ScrollUp();
00168     bool ScrollDown();
00169 protected:
00171     void SetThumbLayout();
00172 
00174     void MoveThumbToMouse();
00175 
00177     void LimitCurrentValue();
00178 
00179     int GetScrollBarSize();
00180 
00181     int GetThumbScaleLength();
00182 
00184     void SetButtonLayout();
00185 
00186     void SetThumbVisibility();
00187 
00188     float currentValue;
00189     float maxValue;
00190     float minValue;
00191 
00193     float tickValue;
00194 
00195     csRef<iVirtualClock> clock;
00196 
00198     csTicks scrollTicks;
00199     bool mouseDown;
00200     bool reversed;
00201 
00202     int lastButton;
00203     int lastModifiers;
00204     pawsWidget* lastWidget;
00205 
00206     pawsButton* upButton, * downButton;
00207 
00208     pawsWidget* thumb;
00209     bool mouseIsDraggingThumb;  // is the user currently dragging the thumb with mouse ?
00210     int thumbDragPoint;         // coordinate of the point where mouse button was pressed down
00211     // when the user began drag'n'drop of thumb (relative to thumb position)
00212 
00213     csString upGrey;
00214     csString upUnpressed;
00215     csString upPressed;
00216     int      upOffsetx;
00217     int      upOffsety;
00218     int      upWidth;
00219     int      upHeight;
00220 
00221     csString downGrey;
00222     csString downUnpressed;
00223     csString downPressed;
00224     int      downOffsetx;
00225     int      downOffsety;
00226     int      downWidth;
00227     int      downHeight;
00228 
00229     csString thumbStopped;
00230     csString thumbMoving;
00231 
00232     bool horizontal;
00233     bool limited;
00234 };
00235 
00236 //--------------------------------------------------------------------------------
00237 CREATE_PAWS_FACTORY(pawsScrollBar);
00238 
00239 
00242 #endif