[SNIPPET] DrawGradientBar

With this function you can draw gradient bars, as the title says. You must be careful to the "value", which musn't be higher than 100.0, or it will fail.

Just a little example of how it works:
0AB1: call_scm_func @drawGradientBar 11 position 320.0 224.0 size 56.0 6.0 value 100.0 RR 0.0 0.0 GG 100.0 155.0 BB 155.0 255.0
This will draw a full bar (100.0/100.0) from 320.0 to 376.0 ( size 56.0). The initial green value (for value == 0.0) is 100.0 and the final one (for value == 100.0) is 155.0. Same from blue, just from 155.0 to 255.0.

Code:
:drawGradientBar
//0AB1: call_scm_func @drawGradientBar 11 position 320.0 224.0 size 56.0 6.0 value 100.0 RR 0.0 0.0 GG 100.0 155.0 BB 155.0 255.0 
0087: 12@ = 2@
0017: 12@ /= 100.0

0087: 13@ = 6@
0063: 13@ -= 5@
0073: 13@ /= 4@
0092: 5@ = float 5@ to_integer
0092: 13@ = float 13@ to_integer

0087: 14@ = 8@
0063: 14@ -= 7@
0073: 14@ /= 4@
0092: 7@ = float 7@ to_integer
0092: 14@ = float 14@ to_integer

0087: 15@ = 10@
0063: 15@ -= 9@
0073: 15@ /= 4@
0092: 9@ = float 9@ to_integer
0092: 15@ = float 15@ to_integer

    for 11@ = 0.0 to 4@ step 1.0
    038E: draw_box_position 0@ 1@ size 12@ 3@ RGBA 5@ 7@ 9@ 255
    005B: 0@ += 12@
    005A: 5@ += 13@
    005A: 7@ += 14@
    005A: 9@ += 15@
    end
0AB2: ret 0

Image:
6IxBUoQ.jpg

Requests:
*03F0: enable_text_draw 1 at the beggining of your script.
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,495
Reaction score
237
Location
( ͡° ͜ʖ ͡°)
Re: DrawGradientBar

It's OK. But don't forget that the textdraw limit is not really high. You will probably crash after drawing 2 of these bars  :imoverit:
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: DrawGradientBar

1 bar = works
2 bars = crash.

Any solution to avoid crash ?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Re: DrawGradientBar

The problem about it is that it draws multiple little lines for each bar. Theoretically you could edit the function by decreasing number of textdraws it uses and increase the width of each line (the resolution would decrease so you'd get more "pixelish" bars).


Code:
:drawGradientBar
//0AB1: call_scm_func @drawGradientBar 12 position 320.0 224.0 size 56.0 6.0 value 100.0 RR 0.0 0.0 GG 100.0 155.0 BB 155.0 255.0  resolution 0.1
0087: 12@ = 2@
0017: 12@ /= 100.0
0073: 12@ /= 11@ // this will increase the width of each line
006B: 4@ *= 11@ // this will decrease the number or lines needed to draw one bar (before it was drawing 100 lines per each bars)



0087: 13@ = 6@
0063: 13@ -= 5@
0073: 13@ /= 4@
0092: 5@ = float 5@ to_integer
0092: 13@ = float 13@ to_integer

0087: 14@ = 8@
0063: 14@ -= 7@
0073: 14@ /= 4@
0092: 7@ = float 7@ to_integer
0092: 14@ = float 14@ to_integer

0087: 15@ = 10@
0063: 15@ -= 9@
0073: 15@ /= 4@
0092: 9@ = float 9@ to_integer
0092: 15@ = float 15@ to_integer

    for 31@ = 0.0 to 4@ step 1.0//changed 11@ into 31@ so it doesn't mix with the "resolution" variable which is 11@(useless here but a good habit overall)
    038E: draw_box_position 0@ 1@ size 12@ 3@ RGBA 5@ 7@ 9@ 255
    005B: 0@ += 12@
    005A: 5@ += 13@
    005A: 7@ += 14@
    005A: 9@ += 15@
    end
0AB2: ret 0

The value of "resolution" variable should be between 0.1 - 1.0. Setting it to 0.1 = 10 times less lines per each bar = 10 times more bars can be drawn. I didn't test it but I hope it will work
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: DrawGradientBar

Works perfectly thanks Monday !!

2 bars = res 0.5
3 bars = res 0.3

Even with res 0.3 it looks great.

Leo638U.jpg
 
Top