1 /*
2  * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3  *
4  * Copyright (C) 2005, 2008 Jens Wilhelm Wulf (original author)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 
23 #include "crrc_slider.h"
24 #include <stdio.h>
25 
26 // UL_RTTI_DEF1(crrcSlider,puGroup)
27 
handle_slider(puObject * obj)28 void crrcSlider::handle_slider ( puObject *obj )
29 {
30   crrcSlider *sl = (crrcSlider *)obj->getUserData () ;
31   sl->setValue ( obj->getFloatValue () ) ;
32   sl->__setInputBox ( obj->getFloatValue () ) ;
33 
34   sl->invokeCallback () ;
35 }
36 
handle_input(puObject * obj)37 void crrcSlider::handle_input ( puObject *obj  )
38 {
39   float val;
40   float m;
41 
42   crrcSlider *sl = (crrcSlider *)obj->getUserData () ;
43 
44   val = obj->getFloatValue();
45 
46   m = sl->getMaxValue();
47   if (val > m)
48     val = m;
49   m = sl->getMinValue();
50   if (val < m)
51     val = m;
52 
53   sl->setValue ( val ) ;
54   sl->invokeCallback () ;
55 }
56 
crrcSlider(int minx,int miny,int maxx,int maxy,int inputw)57 crrcSlider::crrcSlider ( int minx, int miny, int maxx, int maxy, int inputw ) : puGroup ( minx, miny )
58 {
59   type |= PUCLASS_SLIDER ;
60   slider = new puSlider (inputw, 0, maxx-minx-inputw, false, maxy-miny) ;
61   input_box = new puInput (0, 0, inputw, maxy-miny) ;
62   input_box->setValue ( 0 ) ;
63   slider->setUserData ( this ) ;
64   slider->setCallback ( handle_slider ) ;
65   input_box->setUserData ( this ) ;
66   input_box->setCallback ( handle_input ) ;
67   close () ;
68 }
69 
70 
setSize(int w,int h)71 void crrcSlider::setSize ( int w, int h )
72 {
73   slider->setSize ( 20, h-40 ) ;
74   slider->setPosition ( w/2-10, 0 ) ;
75 
76   input_box->setSize ( w, 20 ) ;
77   input_box->setPosition ( 0, 0 ) ;
78 }
79 
80 
draw(int dx,int dy)81 void crrcSlider::draw ( int dx, int dy )
82 {
83   if ( !visible || ( window != puGetWindow () ) ) return ;
84 
85   draw_label ( dx, dy ) ;
86 
87   puGroup::draw ( dx, dy ) ;
88 }
89 
90 
checkKey(int key,int updown)91 int crrcSlider::checkKey ( int key, int updown )
92 {
93   if ( ! isVisible () || ! isActive () || ( window != puGetWindow () ) )
94     return FALSE ;
95 
96   return ( input_box->checkKey ( key, updown ) ) ;
97 }
98 
99