/* Copyright (C) 2011, Stephane Bisaro, aka iri License : you can do what you want with this source code This code is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ /* Creation of a gauge bar with the 2d graphic api See http://www.scolring.org/files/doc_html/compslidebar_.html Here, we create a gauge. Its value changes to each top of a timer. Instead of a timer, this may be the progress of a batch, the progress of a download, etc */ var value = 0;; // current value of the gauge /* When the value of the slider changes (the user moves the cursor, by example), this reflex is called. The new value is displayed in a text field. Prototype : fun [CompSlideBar [ObjContainer CompText] I] I */ fun CBsliderChanged (objslider, user_parameter, newValue)= let user_parameter -> [container cValue] in ( _SETcompText cValue itoa newValue nil nil CT_END; _PAINTcontainer container; 0 );; /* At each top of the timer, the gauge increases to 5 units At 100, the timer is destroyed Prototype : fun [Timer [ObjContainer CompSlideBar]] I */ fun CBtop (objtimer, user_parameter)= let user_parameter -> [container cSlider] in ( set value = value + 5; _SETcompSlideBarValue cSlider value; _PAINTcontainer container; ); if value > 100 then _deltimer objtimer else nil; 0;; /* Before to close the VM, all components and resources are destroyed. Prototype : fun [ObjWin [ObjContainer CompSlideBar CompText AlphaBitmap ObjFont]] I */ fun end (win, user_parameter)= let user_parameter -> [container cSlider cValue alphabitmap font] in ( _DScompSlideBar cSlider; _DScompText cValue; _DScontainer container; _DSalphaBitmap alphabitmap; _DSfont font; _closemachine );; /* Main function called by the launcher Prototype : fun [] I */ fun main ()= _showconsole; // load the png file let _LDalphaBitmap _channel _checkpack "tutorials/slidebar/gauge.png" -> alphabitmap in // create a font reference let _CRfont _channel 14 0 0 "Arial" -> font in // create a timer. Its period is 1 second (1000 ms) let _starttimer _channel 1000 -> timer in // create a window and a container let _CRwindow _channel nil 50 50 250 450 WN_MENU " Example : Sliderbar" -> window in let _CRcontainerFromObjWin _channel window 0 0 250 450 CO_CHILDINSIDE 0x888888 "" -> container in // create a gauge. To do this, the flag must be defined at SLB_GAUGE let _CRcompSlideBar _channel container nil [10 20] OBJ_ENABLE|OBJ_VISIBLE|SLB_GAUGE 0 alphabitmap [13 373 386] SLB_VERTICAL 0 100 1 -> cSlider in // create a text field where the value of the gauge will be displayed let _CRcompText _channel container nil [50 20] OBJ_ENABLE|OBJ_VISIBLE|CT_LABEL 0 40 20 "0" font [0 0 0 0] nil nil nil -> cValue in ( _CBwinDestroy window @end [container cSlider cValue alphabitmap font]; // initial value of the gauge _SETcompSlideBarValue cSlider value; // callback when this value changes _CBcompSlideBarValue cSlider @CBsliderChanged [container cValue]; // callback for each top of the timer _rfltimer timer @CBtop [container cSlider]; _PAINTcontainer container; 0 );;