|
|
#1 |
|
Junior Member
Join Date: Nov 2002
Posts: 4
|
Hi there,
I used switchLayout to switch between a normal window and a minimized one. Therefore I defined two groups, one for the titlebar and another for the the rest of the window. Afterwards I defined two layouts, one consisting only of the titlebar group and another which holds the titlebar group and the group for the rest of the window. After loading the script I showed the first layout - lets say normal - and took a reference to a button in the titlebar for minimizing. My question: what happens to that reference when the layout is switched? Is it stil valid? |
|
|
|
|
|
#2 |
|
Major Dude
(Reviewer) Join Date: Aug 2002
Location: South Florida
Posts: 1,387
|
You can access buttons and groups in any layout whether or not it is the active one. Even after switching layouts, the object is still valid and accessable.
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Nov 2002
Posts: 4
|
what I still don't get is the syntax of defining Object in MAKI script:
There seems to be no distinction between classes and object? to define the behaviour of an object, which is normally done by clases MAKI defines the structure of an instance of a class e.g. //define Slider MySlider; MySlider.onSetPosition(int newpos) { ... } In this example I can change the reference by doing: MySlider = getCOntainer("main").getLayout("normal").getObject("slider"); TO come back to my problem I paste some code of a script I wrote (maybe not too fine, but its my first one and I built it yesterday): ------------XML file <container id="pause" name="Pause plugin" default_x="0" default_y="0" w="200" h="100" default_visible="1"> <groupdef id="group.titlebar" name="Title Bar"> <text id="text.titlebar.info" default="Pause between tracks" x="3" y="2" w="120" h="20" font="wasabi.font.default" fontsize="12" ghost="1"/> <button id="button.titlebar.minimize" action="SWITCH" x="105" y="7" image="button.minimize.off" downImage="button.minimize.on" tooltip="Minimize/Maximize window" activeAlpha="255"/> <button id="button.titlebar.close" action="SWITCH" x="121" y="7" image="button.close" downImage="button.close" tooltip="Close window" activeAlpha="255"/> </groupdef> <groupdef id="group.control" name="Control Panel"> <layer id="layer.control.sliderBar" x="28" y="18" image="slider.bar"/> <Slider id="slider.control.delay" x="28" y="14" w="77" h="13" inactiveAlpha="200" thumb="slider.thumb" downThumb="slider.thumb" tooltip="set delay"/> <text id="text.control.currentvalue" default="Delay deactivated" x="12" y="30" w="120" h="20" font="wasabi.font.default" fontsize="16" ghost="1"/> </groupdef> <layout id="layout.normal" background="pause.background.full" drawbackground="1" desktopalpha="1"> <group id="group.titlebar" x="0" y="0"/> <group id="group.control" x="0" y="20"/> </layout> <layout id="layout.minimized" background="pause.background.min" drawbackground="1" desktopalpha="1"> <group id="group.titlebar" x="0" y="0"/> </layout> </container> --------end XML And the code: -----Script include "../../../lib/std.mi" Global Timer DelayTimer; Global Slider MySlider; Global Text CurrentValue; Global int IntValue; Global Button MinButton; Global Button CloseButton; Global boolean minimized; Global Layout currLayout; Global COntainer PauseContainer; System.onTitleChange(STring newTitle) { if (intValue >= 1000) { pause(); DelayTimer.start(); } else DelayTimer.stop(); } System.onScriptLoaded() { Group gtmp; PauseContainer = getContainer("pause"); //initialize objects for normal layout currLayout = PauseContainer.getLayout("layout.normal"); gtmp = currLayout.getObject("group.control"); MySlider = gtmp.getObject("slider.control.delay"); CurrentValue = gtmp.getObject("text.control.currentvalue"); //use minized layout as default currLayout = PauseContainer.getLayout("layout.minimized"); gtmp = currLayout.getObject("group.titlebar"); MinButton = gtmp.getObject("button.titlebar.minimize"); CloseButton = gtmp.getObject("button.titlebar.close"); minimized = true; currLayout.show(); //configure timer DelayTimer = new Timer; intValue = 0; DelayTimer.setDelay(0); } DelayTimer.onTimer() { DelayTimer.stop(); play(); } MySlider.onSetPosition(int pos) { intValue = pos * 1000 *20 / 255; if (intValue >= 1000) CurrentValue.setText("Current delay " + integerToString(intValue / 1000) + " secs"); else CurrentValue.setText("Delay deactivated"); DelayTimer.setDelay(intValue); } //there was an error in the header file "../../../lib/std.mi" //switchToLayout takes a String as parameter, trying to give a layout //ends up in an exception, so I just adapted the std.mi file to: //extern Container.switchToLayout(String layout_id); //instead of: //extern Container.switchToLayout(Layout layout_id); MinButton.onleftClick() { MinButton = NULL; CloseButton = NULL; if (currLayout.getID() == "layout.minimized") { getContainer("pause").switchToLayout("layout.normal"); currLayout = PauseContainer.getLayout("layout.normal"); } else { getContainer("pause").switchToLayout("layout.minimized"); currLayout = PauseContainer.getLayout("layout.minimized"); } //Adjust reference to button Group gtmp; gtmp = currLayout.getObject("group.titlebar"); MinButton = gtmp.getObject("button.titlebar.minimize"); CloseButton = gtmp.getObject("button.titlebar.close"); } CloseButton.onLeftClick() { getContainer("pause").hide(); intValue = 0; } ---------------end script so what happens if I change the Layout? which reference is hold by MinButton? |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|