码迷,mamicode.com
首页 > 其他好文 > 详细

Sliders

时间:2014-12-18 16:32:43      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   io   color   os   sp   for   on   

  1 //Sliders.cpp
  2 
  3 /*
  4 Copyright 2000-2004 The VCF Project.
  5 Please see License.txt in the top level directory
  6 where you installed the VCF.
  7 */
  8 
  9 
 10 #include "vcf/ApplicationKit/ApplicationKit.h"
 11 #include "vcf/ApplicationKit/ControlsKit.h"
 12 
 13 using namespace VCF;
 14 
 15 /**
 16 This example show how to add slider controls
 17 */
 18 class SlidersWindow : public Window {
 19 public:
 20     SlidersWindow() {
 21         setCaption( "Sliders" );
 22         setWidth( 500 );
 23         setHeight( 500 );
 24 
 25         Rect r = getClientBounds();
 26 
 27         double y = 20;
 28 
 29         Label* label = new Label();
 30 
 31         label->setBounds( 20, y, r.getWidth()-40, label->getPreferredHeight() );
 32         label->setAnchor( AnchorLeft|AnchorRight);
 33         label->setCaption( "Slider 1 position: " );
 34         label->setName( "Label1" );
 35         add( label );
 36 
 37 
 38         y = label->getBottom() + 20;
 39 
 40 
 41 
 42         SliderControl* slider = new SliderControl();
 43         slider->setBounds( 20, y, r.getWidth()-40, slider->getPreferredHeight() );
 44 
 45         slider->setAnchor( AnchorLeft|AnchorRight);
 46 
 47         slider->setTickMarkStyle( SliderControl::tmsTopLeft );
 48 
 49         add( slider );
 50         slider->setPosition( slider->getMaxValue() );
 51 
 52         slider->PositionChanged +=
 53             new ClassProcedure1<Event*,SlidersWindow>( this, &SlidersWindow::onSliderPositionChanged, "SlidersWindow::onSliderPositionChanged" );
 54 
 55 
 56 
 57         y = slider->getBottom() + 20;
 58 
 59 
 60         slider = new SliderControl();
 61         slider->setBounds( 20, y, r.getWidth()-40, slider->getPreferredHeight() );
 62 
 63         slider->setAnchor( AnchorLeft|AnchorRight);
 64 
 65         slider->setTickMarkStyle( SliderControl::tmsBottomRight );
 66 
 67         add( slider );
 68 
 69 
 70         y = slider->getBottom() + 20;
 71 
 72 
 73         slider = new SliderControl();
 74         slider->setBounds( 20, y, r.getWidth()-40, slider->getPreferredHeight() );
 75 
 76         slider->setAnchor( AnchorLeft|AnchorRight);
 77 
 78         slider->setTickFrequency( 5 );
 79 
 80         slider->setMaxValue( 60 );
 81         slider->setMinValue( 10 );
 82 
 83         slider->setTickMarkStyle( SliderControl::tmsBottomRight | SliderControl::tmsTopLeft );
 84 
 85         add( slider );
 86 
 87 
 88         y = slider->getBottom() + 20;
 89         double x = 20;
 90 
 91 
 92         slider = new SliderControl();
 93         slider->setDisplayOrientation( SliderControl::doVertical );
 94         slider->setBounds( x, y, slider->getPreferredWidth(), 200 );
 95 
 96         slider->setAnchor( AnchorTop|AnchorBottom);
 97         slider->setTickMarkStyle( SliderControl::tmsBottomRight );
 98 
 99         add( slider );
100 
101         x = slider->getRight() + 20;
102 
103 
104         slider = new SliderControl();
105         slider->setDisplayOrientation( SliderControl::doVertical );
106         slider->setBounds( x, y, slider->getPreferredWidth(), 200 );
107 
108         slider->setAnchor( AnchorTop|AnchorBottom);
109         slider->setTickMarkStyle( SliderControl::tmsTopLeft );
110 
111         add( slider );
112 
113         x = slider->getRight() + 20;
114 
115 
116 
117         slider = new SliderControl();
118         slider->setDisplayOrientation( SliderControl::doVertical );
119         slider->setBounds( x, y, slider->getPreferredWidth(), 200 );
120 
121         slider->setAnchor( AnchorTop|AnchorBottom);
122         slider->setTickMarkStyle( SliderControl::tmsBottomRight | SliderControl::tmsTopLeft );
123 
124         slider->setTickFrequency( 25 );
125 
126         add( slider );
127 
128         x = slider->getRight() + 20;
129 
130 
131         //slider->setEnabled( false );
132     }
133 
134     virtual ~SlidersWindow(){};
135 
136     void onSliderPositionChanged( Event* e ) {
137         Label* label = (Label*)findComponent( "Label1" );
138         SliderControl* slider = (SliderControl*)e->getSource();
139         label->setCaption( Format( "Slider1 position: %0.3f" ) % slider->getPosition() );
140     }
141 };
142 
143 
144 
145 
146 class SlidersApplication : public Application {
147 public:
148 
149     SlidersApplication( int argc, char** argv ) : Application(argc, argv) {
150 
151     }
152 
153     virtual bool initRunningApplication(){
154         bool result = Application::initRunningApplication();
155 
156         Window* mainWindow = new SlidersWindow();
157         setMainWindow(mainWindow);
158         mainWindow->show();
159 
160 
161         return result;
162     }
163 
164 };
165 
166 
167 int main(int argc, char *argv[])
168 {
169     Application* app = new SlidersApplication( argc, argv );
170 
171 
172     Application::main();
173 
174     return 0;
175 }
176 
177 
178 /**
179 $Id: Sliders.cpp 3184 2007-09-17 02:26:00Z ddiego $
180 */

 

Sliders

标签:style   blog   ar   io   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/elitiwin/p/4171789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!