Gadgets & accessing parameters

I’m working on an update for some gadgets.
One problem I found it to set/change parameters of these gadgets and how to get informations from.

There are 3 different approaches:

  1. using OOP language features;
  2. using existent function;
  3. using ad-hoc function;
  4. creating a new approach;

1, OOP language features

It is quite easy: you can use OOP syntax to access and manipulate gadgets’ fields.

TIconGadget(ic4).frame_start=2

In this example I have a gadget (ic4) that is a ‘proxygadget’; to access to its own field frame_start I must ‘cast’ to the proxygadget class.
It works of course, not good to see. And in this way you can read or write everything (of course you need to check the source code to know fields and parameters).

2. Using existing functions

This means we need to use the ‘standard’ MaxGUI functions, like SetGadgetItem, GadgetItem, ModifyGadgetItem and so on to set, read and change parameters.
This way is implemented in many gadgets and many proxygadgets, but it has a limit: if the gadget has MANY parameters you have problems!
An example using my latest IconGadget

local ic1:Tgadget=CreateIconGadget(10,10,32,32,window,pix1)
rem I want to stop the animation, set start frame to 3 and finish frame to 5
ModifyGadgetItem ic1,INDEX,text,FLAGS,ICON,tips,Extra

ModifyGadgetItem was written for other gadgets. I can use INDEX,FLAGS and ICON to pass 3 parameters, but I would have to change FRAME_START, FRAME_END, FRAME_SPEED, ANIM_DIRECTION and ANIM_STATUS(on or off): too many!

A possible solution could be to set a ‘code’

ModifyGadgetItem ic1,””,0,,0
ModifyGadgetItem ic1,””,1,,3
ModifyGadgetItem ic1,””,2,,5

Index allows to access to different parametes: 0 means ANIM_STATUS, while FLAGS is the value (0 or 1); 1 means FRAME_START and FLAGS is ‘3’ and so on.

Not very handy to read and to write: if you want to change many parameters you need to use many ‘calls’ to the same function.

 3. Using ad-hoc function

The solution used even in MaxGUI standard gadget is to create new functions, specifically for a gadget.
For example we have SetSliderValue, SetSliderRange and SliderValue: these functions are SPECIFIC for the gadget SLIDER. A most logic way is to create a GENERIC function like SetValue, SetRange and GadgetValue, GadgetRange to set and to read back the parameters: it will be the gadget to interpret the functions depending on the gadget’s behavior.

So for my IconGadget I should implement these 2 different functions: SetIconGadgetFrame(status,start,finish,speed,direction) and IconGadgetFrame() to read the parameters.

The ‘cost’ of this approach is to expand the MaxGUI commands to every new gadget (and time to find what are the commands supported or the new ones).

4 Creating a new approach

When I created my proxygadgets I tried to ‘recycle’ all the standard MaxGUI function if possible. So in IconGadget you can still use SetGadgetPixmap and SetGadgetIconStrip to set fixed image or animation on my gadget without using new commands/functions.
And SelectGadgetItem can change the current frame.

I tried to use ModifyGadgetItem (the first implementation allows only to start or to stop animation). Now I want the user can access to anim direction, play, stop and frames. So I need new way.
One solution is to create SetGadgetIconFrame() as above mentioned.

But during my ‘experiments’ I’ve implemented a different approach, teorically more ‘generic’ (for the user).
I’ve used ModifyGadgetItem as ‘interface’ between program and maxgui source code. But everything stop here:

ModifyGadgetItem ic1,0,"START=0;END=15;SPEED=200;REVERSE"

I decided to send a ‘message’ to the gadget and it’s what it contains:

Set frame start as 0
Set frame end as 15
Set frame speed (duration) as 200ms
Animation is reversed

One function, one string, more commands, human ‘readable’.
Other commands are PLAY, STOP.

The idea is to have something like SetGadgetMessage gadget,message as generic interface.

SetGadgetMessage gadget,"VALUE=10;RANGE=0,20"

means (for a Slider) SetValue=10, SetRange from 0 to 20, but could means also (for a listbox/combobox) select item 10, and show from 0 to 20

SetGadgetMessage gadget,"SELECT=1;DISABLE"

means (for a listbox or a combobox) Select item with ID=1 and disable the gadget.

In general a function like that should:

              1. know the class of the gadget
              2. reads the commands
              3. apply the commands if possible to the gadget

Of course this means a deep change in MaxGUI structure. But a more elengant and light (for the user, not in code) approach.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close