Thread: setBackColor not working
-
July 11th, 2019, 07:14 #1
setBackColor not working
Given a field in a CT window defined like this:
Code:... <number_ct_crosslink name="hps"> <anchored to="rightanchor" width="40" height="20"> <top /> <right anchor="left" relation="relative" offset="-10" /> </anchored> <tabtarget prev="name" /> <script> function update() window.onHealthChanged(); end </script> </number_ct_crosslink> ...
Code:hps.setColor(sColor); hps.setBackColor(sBackColor); Debug.console("Color:", sColor); Debug.console("Back:", sBackColor);
Am I doing something wrong, or are number_ct_crosslink fields unable to change their background color?
-
July 11th, 2019, 07:18 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
If your control has a frame, it will be drawn on top of the background color. The background color is an option to draw a solid color box, not a tint of a frame. Frame tinting is done with multiple frame definitions. See the "required" frame definition which shows a red field as an example that the existing rulesets use. Otherwise, you'd need to use a frame with transparency, and let the background color show through.
Regards,
JPG
-
July 11th, 2019, 14:36 #3
number_ct_crosslink is a template from CoreRPG (ct/template_ct.xml), which is built up from these templates:
Code:<template name="number"> <numberfield> <noreset /> <script file="common/scripts/number.lua" /> </numberfield> </template> <template name="simplenumber"> <number> <droptypes> <type>number</type> </droptypes> <font>sheetnumber</font> </number> </template> <template name="number_ct_static"> <simplenumber> <frame name="fieldlight" offset="7,5,7,5" /> <readonly /> <nodrag /> <hideonvalue value="0" /> </simplenumber> </template>
Given that, can I somehow access the "fieldlight" frame from the "hps" variable, and then change it's backcolor?
EDIT: I found that I could access something using "hps.frame":
Debug.console("Hps:", hps.frame);
which shows:
Runtime Notice: s'Hps:' | { #1 = bTRUE }
I am still very new to Lua, so "{ #1 = bTRUE }" is a table? With one entry (the number 1) that holds a boolean (true). Unfortunately, this doesn't seem to be enough information to get to the frame.
Funny, you can "setFrame()", to switch to a new frame, but you can't find the old frame ;-)Last edited by Nose66; July 11th, 2019 at 16:13.
-
July 11th, 2019, 22:29 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
You can't query the frame values in a control, just set it to what you want it to be as the control is initialized or the value is changed.
All tags in the XML are represented within the control as a variable, but attributes are not accessible, only values. The { #1 = bTRUE } means that there is a single tag named "frame" with no value in between the tags. If there was more than one tag, then you would have #2, #3, etc.
Regards,
JPG
-
July 12th, 2019, 21:55 #5
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
So if you want to access it, ensure you define the frame using a tag and not an attribute. Then you can use lua table syntax to get to the value.
-
July 15th, 2019, 06:03 #6
Sorry, still not quite following, however, I did understand the difference between a tag and an attribute.
So I changed the template from this:
Code:<simplenumber> <frame mergerule="replace" name="fielddark" offset="7,5,7,5" /> <stateframe> <keyedit name="fieldfocus" offset="7,5,7,5" /> <hover name="fieldfocus" offset="7,5,7,5" hidereadonly="true" /> <drophilight name="fieldfocus" offset="7,5,7,5" hidereadonly="true" /> </stateframe> </simplenumber>
Code:<simplenumber> <frame mergerule="replace" offset="7,5,7,5"> <name>fielddark</name> </frame> <stateframe> <keyedit name="fieldfocus" offset="7,5,7,5" /> <hover name="fieldfocus" offset="7,5,7,5" hidereadonly="true" /> <drophilight name="fieldfocus" offset="7,5,7,5" hidereadonly="true" /> </stateframe> </simplenumber>
Code:Debug.console(hps); Debug.console(hps.frame); Debug.console(hps.frame.name);
Runtime Notice: Reloading ruleset
Ruleset Warning: Could not load icon resource (desktopdecal_sw)
Runtime Notice: numbercontrol = { value = #14, x,y,w,h = 0,0,0,0 }
Runtime Notice: { #1 = { s'name' = { #1 = s'fielddark' } } }
Runtime Notice: nil
But it seems that the frame is already a tag (not an attribute) of the simplenumber ("hps"), which is why I can print it out.
So I am still a bit lost, is it possible to define the template slightly differently so that from inside the current <simplenumber> widget (called "hps"), I can get access to the frame such that I can send it the "setBackColor" message?
-
July 15th, 2019, 06:15 #7
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
Here's some additional information:
* Every window control can have a frame and a background color. The background color gets drawn first, then the frame gets drawn, then the text gets drawn. The background and the frame were meant to be used independently, not together.
* In most of the included rulesets, the frame is not transparent, so the background color won't be seen, since the frame gets drawn on top of it.
* You can not query the current value of a window control frame. The mechanism you are pursuing with the XML tags will only tell you what is defined initially in the XML, not what the current frame is. There is no mechanism to query the current frame.
* If you need to change the frame based on the value of the field, then add an onValueChanged function to the control, query the value of the field using getValue(), then use setFrame() to specify the frame you want to show based on the value. There's no need to know what the frame is currently, just specify the correct one based on the value.
* As an example, in CoreRPG, there is a "required" frame asset. You can swap the frame value between "fielddark" and "required" using the setFrame() function, based on the value of the field.
Regards,
JPG
-
July 16th, 2019, 05:11 #8
Thank you all, I was able to swap out the frame. I just had to determine the correct offsets.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks