2 registered members (Quad, vicknick),
692
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Suggestions for improving some lite-c standard functions
#286301
08/24/09 14:21
08/24/09 14:21
|
Joined: Oct 2007
Posts: 306 Austria
Alan
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2007
Posts: 306
Austria
|
Hi there, I've been working with panels during the past few weeks a lot. As we all know, a panel is defined like this:
PANEL* mypan =
{
pos_x = 160;
pos_y = 120;
[...]
}
Okay. In a screen resolution of 320x240px that would be the center of the screen. Now let's say we switch the screen resolution to 1024x768px. The absolute position of the panel on the screen would change and be somewhere on the upper left. So, I tried to improve the code and did something like this:
PANEL* mypan =
{
pos_x = screen_size.x / 2;
pos_y = screen_size.y / 2;
[...]
}
In theory, this makes sure that the panel is always at the center of the screen. However, it cannot be compiled since lite-c NEEDS a numeric value in the "pos_x" parameter. A var parameter is NOT accepted, which would be very useful. You might say that a var parameter there would cost a lot of CPU power because whenever the var changes, the position of the panel has to change as well - I claim that it would be enough if the panel reads its position out of the variable at the time of its creation and then maintains that position, no matter what the var's content might be later on, until the "pos_x" or "pos_y" parameter is changed manually. Another example of where a var parameter is impossible: the WINDOW command for panels.
window(x, y, dx, dy, bmap, varx, vary);
bmap, varx and vary can be given a variable or pointer. dx and dy, however, expect a numeric value. However, it would be so *VERY* useful if dx and dy could be given variables as parameters. Why? Let us assume we have an energy bar. Its bitmap displays a color gradient from red (on the left side) to green (on the right end). Currently, we can only "move" the window within the bitmap. If we do so, the red and green end and all the colors in between would change their position, making the entire color gradient senseless. However, if we were able to manipulate the actual SIZE of the window on the bitmap, the colors always maintain their position (if the player has high HitPoints, the right end of the bar is green, the lower they get the more red the right end of the bar gets as the size of the window is decreasing as well). Do you know what I mean? Basically what I would suggest is: free the parameters! Expect the user to enter numeric values OR variables for EVERY parameter a function/struct has. I don't know whether this is possible or not, but after all, this is just a suggestion ^^' Greets, Alan
|
|
|
Re: Suggestions for improving some lite-c standard functions
[Re: Alan]
#286316
08/24/09 16:26
08/24/09 16:26
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
A var parameter is NOT accepted, which would be very useful. Is already in the forecast. Edit: It seems like they removed it, but I'm sure that this is a planned feature, event if it's not high priority.
Last edited by Dark_samurai; 08/24/09 16:28.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Suggestions for improving some lite-c standard functions
[Re: Alan]
#286322
08/24/09 17:00
08/24/09 17:00
|
Joined: Aug 2008
Posts: 133 Sweden, Stockholm
Enduriel
Member
|
Member
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
|
why don't you write inside your "change resolution" function to use pan_setpos function? that function takes a vector, the Z component can be 0.
and also you can always access the panels pos_x with panel.pos_x = 50; as an example. You could always write that inside your "change resolution" function aswell.
Last edited by Enduriel; 08/24/09 17:03.
|
|
|
Re: Suggestions for improving some lite-c standard functions
[Re: jcl]
#286335
08/24/09 19:10
08/24/09 19:10
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hey Alan, you could always do it my way. NEVER define a panel...
Just create a "panel_action" function that creates the panel with pan_create, and arranges its position, size and all its buttons etc. Then this panel_action STAYS RUNNING, watching for a resolution change, and then re-arranges itself if there was a resolution change.
Works for me...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Suggestions for improving some lite-c standard functions
[Re: EvilSOB]
#286458
08/25/09 11:50
08/25/09 11:50
|
Joined: Oct 2007
Posts: 306 Austria
Alan
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2007
Posts: 306
Austria
|
@EvilSOB: Hm, sounds good... I did it the way Enduriel explained, but your solution for this problem sounds good, too! @JCL: Defining the pos_x and pos_y coordinates in a panel definition has nothing to do with movement. If the variable given changes after the panel was defined, the panel does not have to change its position as well. The only purpose for a variable to be in a definition is flexibility - the flexibility to define screen-relative (and therefore resolution-independent) panel-positions. Of course this can be done in a function after the definition, but it would be cool if one could define things like
var my_screen_size_x = 1024;
var my_screen_size_y = 768;
PANEL* my_test_pan =
{
pos_x = my_screen_size_x / 2 + 30;
pos_y = my_screen_size_y / 2 + 50;
[...]
}
void main()
{
screen_size.x = my_screen_size_x;
screen_size.y = my_screen_size_y;
[...]
my_screen_size_x *= 2; //the panel maintains its absolute position here,
my_screen_size_y *= 2; //although the resolution is changed!
screen_size.x = my_screen_size_x;
screen_size.y = my_screen_size_y;
}
No matter what I enter for "my_screen_size_x" and "my_screen_size_y", the panel would maintain its relative position on the screen. Of course, as mentioned, it can be done afterwards by a function. But a definition like the one I did above would make that function unneccessary.
Last edited by Alan; 08/25/09 11:53.
|
|
|
Re: Suggestions for improving some lite-c standard functions
[Re: Alan]
#286465
08/25/09 12:39
08/25/09 12:39
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Why not use a #define? Since the panels get defined right at the very beginning, the only variables that would be relevant are global variables' default values, so instead of doing that you could just use a #define (since they just get replaced at compile time anyway).
Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|