Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| My first comment is that the problem is vaguely described. Five "pretty small" rectangles could be anything. And the difference between GDI drawing and manually setting bytes is likely to change from insignificant for small rectangles to quite noticeable for large ones.
However, doing my best to reproduce, I made this (for the Immediate window):
<aliases>
<alias
match="gradient"
enabled="y"
group="miniwindows"
send_to="12"
sequence="100"
>
<send>
-- replacement for WindowRectOp action 5, which allows for a 3D look while maintaining color theme
-- Requires global theme.HIGHLIGHT, theme.FACE, theme.INNERSHADOW, and theme.OUTERSHADOW rgb colors to be set.
function DrawThemed3DRect(Window, left, top, right, bottom)
WindowRectOp(Window, 2, left, top, right, bottom, theme.FACE)
--WindowGradient ( Window , left, top, right, bottom, ColourNameToRGB "red", ColourNameToRGB "yellow" , 1)
WindowLine(Window, left, top, right, top, theme.HIGHLIGHT, 0 + 0x0200, 1)
WindowLine(Window, left, top, left, bottom, theme.HIGHLIGHT, 0 + 0x0200, 1)
WindowLine(Window, left, bottom-2, right, bottom-2, theme.INNERSHADOW, 0 + 0x0200, 1)
WindowLine(Window, right-2, top, right-2, bottom-2, theme.INNERSHADOW, 0 + 0x0200, 1)
WindowLine(Window, left, bottom-1, right, bottom-1, theme.OUTERSHADOW, 0 + 0x0200, 1)
WindowLine(Window, right-1, top, right-1, bottom-1, theme.OUTERSHADOW, 0 + 0x0200, 1)
end
Window = "test"
theme = {
FACE = ColourNameToRGB ("cyan"),
HIGHLIGHT = ColourNameToRGB ( "red"),
INNERSHADOW = ColourNameToRGB ( "lightgray"),
OUTERSHADOW = ColourNameToRGB ( "darkgray"),
}
WindowCreate (Window ,
0, -- left
0, -- top
500, -- width
500, -- height
6, -- mode
0, -- flags
ColourNameToRGB ("navajowhite"))
start = utils.timer ( )
DrawThemed3DRect(Window, 5, 5, 250, 250)
DrawThemed3DRect(Window, 100, 100, 350, 350)
DrawThemed3DRect(Window, 200, 200, 450, 450)
DrawThemed3DRect(Window, 250, 250, 500, 500)
DrawThemed3DRect(Window, 350, 10, 600, 250)
print (string.format ("time take = %%0.6f", utils.timer () - start))
WindowShow (Window , true)
</send>
</alias>
</aliases>
I am guessing here quite large rectangles (around 250 x 250) which is hardly "pretty small".
Anyway, with the timing I get this for the WindowGradient line uncommented (and hitting Ctrl+R to repeat the alias):
time take = 0.001843
time take = 0.001861
time take = 0.001781
time take = 0.001763
time take = 0.001949
time take = 0.001775
time take = 0.001759
time take = 0.001813
And with that commented out and the WindowRectOp instead, I get:
time take = 0.000406
time take = 0.000388
time take = 0.000410
time take = 0.000410
time take = 0.000385
time take = 0.000418
Certainly it is quicker doing one GDI call than mucking around setting bytes, but not by an order of magnitude. Four times slower I would say, roughly.
I'll look into making the function more efficient, but more detail about the rectangle sizes and comparative timing would help to know if the problem is acceptably solved.
The other question is, do you write on top of these rectangles, or are they decoration? In any case, it could be quicker to pre-render them (if their size doesn't change) into another window and just blit them onto the visible one.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|