April 18, 2024, 07:45:14 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Gradient coloured Boxes

Started by GWS, September 10, 2013, 08:00:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Here's a subroutine that draws boxes and colours them with any colour gradients you specify.

Just position and size them, and specify the colours you want at the top left, top right, bottom left and bottom right of the box. :)

Not amazingly fast - but then there's a lot of pixels to colour in  ::)

Best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Just thought I'd mention .. standard top to bottom, left to right, and diagonal shading is obtained by choosing the corner colours to give the desired effect ..  :)

One snag .. if another window opens on top (like wordpad), the boxes are erased  :o .. and I've forgotten how to stop that happening. Good grief! - can anyone remember how to fix that?

Best wishes, :)

Graham
Tomorrow may be too late ..

LarryMc

make your window @noautodraw
then put your drawing code inside the @IDPAINT/WM_PAINT message handler
like this example
def w:window
declare "user32", InvalidateRect(hwnd:window, lpRect:int, bErase:int),int
window w, 0, 0, 500, 500, @CAPTION|@SYSMENU|@NOAUTODRAW|@SIZE, 0, "Grid sample", Handler
control w, "C, Toggle grid, 5, 450, 100, 20, 0, 1"
run = 1
waituntil run = 0
closewindow w
end
sub Handler
   select @CLASS
   case @IDCONTROL
      InvalidateRect(w, 0, 1)
   case @IDPAINT :' WM_PAINT
      def hdc:int
      hdc = gethdc(w)
      DrawPicture()
      if (getstate(w, 1) = 1) then DrawGrid()
      releasehdc(w, hdc)
   case @IDCLOSEWINDOW
      run = 0
   endselect
return
sub DrawGrid()
   for i = 0 to 500 step 10
      line(w, i, 0, i, 440, 0)
   next i
   for i = 0 to 440 step 10
      line(w, 0, i, 500, i, 0)
   next i
return
sub DrawPicture()
   rect(w, 40, 40, 200, 200, rgb(255, 0, 0), rgb(255, 0, 0))
   circle(w, 240, 240, 50, rgb(0, 255, 0), rgb(0, 255, 0))
return
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Thanks Larry - I'll try that ..  :)

I got as far as @noautodraw .. but of course that did nothing by itself - it was the other bits I'd forgotten  ::)

Getting a bit old for this tricky stuff ..  :)

Graham
Tomorrow may be too late ..

GWS

No luck .. the noautodraw test program crashes ..  ::)

I suspect it's because of multiple @IDPAINT re-paints occuring, calling the Box subroutine to fire too many times - and the stack running out of space.

I'm not hopeful with this one .. there's such a lot of drawing going on.

It would be nice if the completely drawn screen could be cached - and the whole thing blitted as required.
No idea how to do this though.

Best wishes, :)

Graham
Tomorrow may be too late ..