Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgslider.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library 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 GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:04 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgslider.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pgslider.h"
00030 #include "pgapplication.h"
00031 #include "pgtheme.h"
00032 
00033 PG_Slider::PG_Slider(PG_Widget* parent, const PG_Rect& r, ScrollDirection direction, int id, const std::string& style) : PG_ScrollBar(parent, r, direction, id) {
00034         delete scrollbutton[0];
00035         scrollbutton[0] = NULL;
00036 
00037         delete scrollbutton[1];
00038         scrollbutton[1] = NULL;
00039 
00040         // connect signals
00041         sigScrollPos.connect(sigSlideEnd.slot());
00042         sigScrollTrack.connect(sigSlide.slot());
00043 
00044         LoadThemeStyle(style);
00045         SetPosition(scroll_min);
00046 }
00047 
00048 PG_Slider::~PG_Slider() {}
00049 
00050 void PG_Slider::LoadThemeStyle(const std::string& widgettype) {
00051         PG_Theme* t = PG_Application::GetTheme();
00052 
00053         dragbutton->LoadThemeStyle(widgettype, "SliderDrag");
00054 
00055         if(sb_direction == VERTICAL) {
00056                 Uint16 h = dragbutton->h;
00057                 t->GetProperty(widgettype, "SliderDragV", "height", h);
00058                 dragbutton->LoadThemeStyle(widgettype, "SliderDragV");
00059                 dragbutton->SizeWidget(dragbutton->w, h);
00060                 PG_ThemeWidget::LoadThemeStyle(widgettype, "SliderV");
00061         } else {
00062                 Uint16 w = dragbutton->w;
00063                 t->GetProperty(widgettype, "SliderDragH", "width", w);
00064                 dragbutton->LoadThemeStyle(widgettype, "SliderDragH");
00065                 dragbutton->SizeWidget(w, dragbutton->h);
00066                 PG_ThemeWidget::LoadThemeStyle(widgettype, "SliderH");
00067         }
00068 
00069         RecalcPositions();
00070 }
00071 
00072 void PG_Slider::RecalcPositions() {
00073         position[0] = PG_Rect::null;
00074         position[1] = PG_Rect::null;
00075 
00076         position[2].x = 0;
00077         position[2].y = 0;
00078         position[2].w = w;
00079         position[2].h = h;
00080 
00081         if(sb_direction == VERTICAL) {
00082                 position[3].x = 0;
00083                 position[3].w = w;
00084                 position[3].h = dragbutton->h;
00085 
00086                 if((scroll_max - scroll_min) == 0) {
00087                         position[3].y = position[2].y;
00088                 } else {
00089                         position[3].y = ((position[2].h - position[3].h) / (scroll_max - scroll_min)) * scroll_current;
00090                 }
00091         } else {
00092                 position[3].y = 0;
00093                 position[3].w = dragbutton->w;
00094                 position[3].h = h;
00095 
00096                 if((scroll_max - scroll_min) == 0) {
00097                         position[3].x = position[2].x;
00098                 } else {
00099                         position[3].x = ((position[2].w - position[3].w) / (scroll_max - scroll_min)) * scroll_current;
00100                 }
00101         }
00102 
00103         int pos =       scroll_current - scroll_min;
00104 
00105         if(sb_direction == VERTICAL) {
00106                 position[3].x = 0;
00107                 position[3].h = (Uint16)((double)position[2].h / ((double)position[2].h / (double)position[3].h));
00108                 position[3].y = (Uint16)(position[0].h + (((double)position[2].h - (double)position[3].h) / (double)(scroll_max - scroll_min)) * (double)pos);
00109         } else {
00110                 position[3].y = 0;
00111                 position[3].w = (Uint16)((double)position[2].w / ((double)position[2].w / (double)position[3].w) );
00112                 position[3].x = (Uint16)(position[0].w + (((double)position[2].w - (double)position[3].w) / (double)(scroll_max - scroll_min)) * (double)pos);
00113         }
00114 
00115         // bordersize
00116         for(int i=2; i<4; i++) {
00117                 if(i == 3 || i == 2) {
00118                         if(sb_direction == VERTICAL) {
00119                                 position[i].x += my_bordersize;
00120                                 if(position[i].w > 2*my_bordersize) {
00121                                         position[i].w -= 2*my_bordersize;
00122                                 }
00123                         } else {
00124                                 position[i].y += my_bordersize;
00125                                 if(position[i].h > 2*my_bordersize) {
00126                                         position[i].h -= 2*my_bordersize;
00127                                 }
00128                         }
00129                         continue;
00130                 }
00131                 position[i].x += my_bordersize;
00132                 position[i].y += my_bordersize;
00133                 if(position[i].w > 2*my_bordersize) {
00134                         position[i].w -= 2*my_bordersize;
00135                 }
00136                 if(position[i].h > 2*my_bordersize) {
00137                         position[i].h -= 2*my_bordersize;
00138                 }
00139         }
00140         if(scrollbutton[0] != NULL) {
00141                 scrollbutton[0]->MoveWidget(position[0]);
00142         }
00143         if(scrollbutton[1] != NULL) {
00144                 scrollbutton[1]->MoveWidget(position[1]);
00145         }
00146         dragbutton->MoveWidget(position[3]);
00147 }
00148 
00149 bool PG_Slider::eventMouseButtonUp(const SDL_MouseButtonEvent* button) {
00150 
00151         switch(button->button) {
00152                 case 4:
00153                         if(scroll_current <= scroll_min + my_linesize) {
00154                                 SetPosition(scroll_min);
00155                         } else {
00156                                 SetPosition(scroll_current - my_linesize);
00157                         }
00158                         break;
00159 
00160                 case 5:
00161                         SetPosition(scroll_current + my_linesize);
00162                         break;
00163         }
00164 
00165         sigSlideEnd(this, scroll_current);
00166 
00167         return true;
00168 }

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2