|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Jun 17, 2004 12:17 am
Refreshing controls/windows |
Hey Zugg, does Zeus expose some method to force a control (specifically a button) or a window to repaint itself?
I'm almost finished with a demo game for Zeus, but since controls won't refresh themselves until my script finishes executing, it doesn't work correctly. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jun 17, 2004 6:53 pm |
The scripting system still needs some work in that regards. Right now, you can access any published *property* of a control. The controls inherit from Delphi controls that any Delphi programmer would probably recognize, so even properties that I don't necessarily document are available.
Unfortunately, when it comes to "methods", Delphi has them as "Public" rather than "Published". That means the type information needed to access them is not available. What the scripting system does is provide a mechanism for me to add support for various methods to each control, but I have to specifically list each and ever method that I want to access and built that method into a "helper class". Yeah, that's a bit technical, but what it means is that in general, methods are not yet accessible.
In Delphi, each control has an "Update" method that is used to force an immediate refresh of the control. I'll add this method to the list that I need to publish for each control. Thanks for bringing this issue to my attention.
Now, that covers the "painting" aspect of refreshing a control. There is another issue involved in linked controls (which you probably aren't using because I haven't documented it yet). Basically, linked controls involve something like this:
<label name="Label" caption="=Edit.Text"/>
<edit name="Edit"/>
See how the Caption field of the "Label" control is linked to the Text property of the "Edit" control? So, when you change the Edit field, the label gets automatically updated. This works fine interactively. But if you do the following in a script:
Edit.Text = "new text"
then the Label control will only be updated at the end of the script, regardless of whether you use the Update method to repaint it. This is done to minimize recursive recalculations of linked fields during a script execution. To deal with situations where you really want the update to occur, there is a method called Recalc that can be used in your script:
core.Recalc("Label")
would force the Label to recalculate it's value *now* rather than waiting till the end of the script. Unfortunately, Recalc only works with linked fields, so I don't think you can use it as a "trick" to cause the control to update otherwise.
Then again, you could use a linked field in the following way:
<label name="Label" caption="=x"/>
So in this case, we have linked the caption of the label to the scripting variable "x" rather than directly to a control. When linking a control in this way, Zeus has no way to ever recalculate the label because there is no way for Zeus to detect when the "x" variable has been changed in your script. So, in this case you *must* use the Recalc method when you want to update the label. So, in your script you'd do something like:
x = "New Text"
core.Recalc("Label")
and "New Text" should now appear in the label.
So, even though I haven't handled the "Update" method for a control yet, using the concept of Linked fields and the Recalc method might be a way around it for now. Certainly something to play with. Field linking can be *very* powerful. There are many aspects of it that still need a lot of documentation, and none of the demo apps really use it.
Glad to hear someone is playing with this |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Jun 17, 2004 7:24 pm |
Cool [8D]
I'll play a bit with that for a work-around for now. Thanks. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jun 18, 2004 5:17 pm |
Hmm, this doesn't appear to work though. Here is my test ZML file:
<?xml version='1.0' encoding='ISO-8859-1' ?>
<zeus>
<head>
<splash>
</splash>
</head>
<window name='main' caption='Test 2' width="240" height="240">
<label name="Label" autoleft="true" caption="=x" />
<script>
x = "New Text"
core.Recalc("Label")
</script>
</window>
</zeus>
The one with the edit box works fine, but not the one where the value is changed in code. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jun 18, 2004 9:01 pm |
Hmm, thanks for reporting that. I'll take a look at the code.
I added the Update method (and also an Invalidate method which tells Windows to repaint the control next time it has a chance). I'll probably be posting a new version later next week when I have the email viewer demo ready. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jun 18, 2004 9:22 pm |
Oh, I there is another undocumented trick that might help. Zeus has "variables" that can be used for links. Here is what you would do:
<?xml version='1.0' encoding='ISO-8859-1' ?>
<zeus>
<head>
<splash>
</splash>
</head>
<window name='main' caption='Test 2' width="240" height="240">
<label name="Label" autoleft="true" caption="=x.value" />
<var name="x"/>
<script>
x.value = "New Text"
core.Recalc("Label")
</script>
</window>
</zeus>
As with zMUD, I'm trying to make sure there are always several ways to do things. Anyway, the <var> tag creates a variable that can hold anything (string, integer, COM object, whatever). The "value" field is the value of the variable and is what you link other objects to. This will cause an automatic recalc when the script is over, but the forced Recalc should force the update just as in the case with an <edit> control.
Looks like the link and recalc code currently requires an object and not just a script variable which is why the previous test didn't work.
Good luck! |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Jun 19, 2004 1:19 am |
That one doesn't seem to work either. I also tried putting the var tag before the label and some other stuff, but apparently Recalc is not repainting the control.
Anyway, I'll think about some other workaround later. Otherwise, it'll just have to wait until the next version of Zeus. No big deal, just wanted to give something for everyone to play with and get a little bit more interested in Zeus. |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|