Murga-Projects Forums

Full Version: Different redraw behaviors with different box types
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Take this (the clock test code provided by Mikshaw)

Code:
-- Demonstration of clock widget
-- Code by mikshaw (http://damnsmalllinux.org/cgi-bin/forums/ikonboard.cgi)

ww=180 --window width
wh=200 --window height

w=fltk:Fl_Window(ww,wh,"murgaLua Clock Demo")

clock=fltk:Fl_Clock(5,5,ww-10,ww-10,"a clock")
clock:box(fltk.FL_DOWN_BOX)

w:show()
Fl:run()


Works as expected.

Now change the box type to one that has no colored background, for instance, NO_BOX

Code:
clock:box(fltk.FL_NO_BOX)


The clock is updated, but the traces of the prior rendering remains visible on the screen. Normal behavior?

Interesting. It looks like it might be an FLTK bug, but I don't know enough about it to say more than that guess.

You could emulate no box by using FL_FLAT_BOX and set its color according to what its parent is.

mikshaw Wrote:
You could emulate no box by using FL_FLAT_BOX and set its color according to what its parent is.


Thanks for the tip. Unfortunately, what I was trying to achieve was to display a nice png picture to make up the frame of the clock (an oval clock frame).

PHP Code:
ww=180 --window width
wh
=200
gw
=ww-20 -- group
gh
=wh-50
fltk
.fl_register_images()
img_back Fl_Shared_Image.get("clock.png")

w=fltk:Fl_Window(ww,wh,"murgaLua Group Demo")
w:color(55)

group fltk:Fl_Group(10,10,gw,gh)
group:box(fltk.FL_BORDER_BOX)
group:color(79)

  clock_back fltk:Fl_Box(3020gw-40,gw-40);
  clock_back:box(fltk.FL_FLAT_BOX);
  clock_back:image(img_back);
  clock_back:color(79);

  clock=fltk:Fl_Clock(30,20,gw-40,gw-40,"a clock")
  clock:box(fltk.FL_FLAT_BOX)
 
fltk:Fl_End()

w:show()
Fl:run() 


If I try "  clock:image(img_back);" then the image gets displayed below the clock rather than behind it.

Any tip on how to achieve this?

widged Wrote:
Any tip on how to achieve this?


Well, you could use wait rather than run, so to get some control on your redraw.

Great suggestion!

Code:
ww=180 --window dims
wh=200
gw=ww-20 -- group dims
gh=wh-50
fltk.fl_register_images()
img_back = Fl_Shared_Image.get("clock.png")

function clock_callback()
  local tCount = 1
  repeat
    Fl:wait(1)
    out:value(Fl:event()) -- displays the events as they happen on screen
    if (Fl:event() == 7) then tCount = 99999999 end
    w:redraw()
    tCount = tCount + 1
  until tCount >= 500 -- avoided infinity during testing.
end

w=fltk:Fl_Window(ww,wh,"murgaLua Group Demo")
w:color(55)

group = fltk:Fl_Group(10,10,gw,gh)
group:box(fltk.FL_NO_BOX)

  clock_back = fltk:Fl_Box(30, 20, gw-40,gw-40);
  clock_back:box(fltk.FL_FLAT_BOX);
  clock_back:image(img_back);
  clock_back:color(55);

  clock=fltk:Fl_Clock(31,17,gw-40,gw-40,"a clock")
  clock:box(fltk.FL_NO_BOX);

  out=fltk:Fl_Output(5,wh-30,ww/2-10,25)

fltk:Fl_End()

w:show()
loop=clock_callback()
Fl:wait(0)


And the result is:

I borrowed the picture for the back of the clock from this Industrial Skin at skinbase.org

wow!
Skinning murgaLua apps is something that had never occured to me.
I assume the clock is a unique situation, and you wouldn't need to force redraw on most interactive widgets?

Nice work, doc!

mikshaw Wrote:
I assume the clock is a unique situation, and you wouldn't need to force redraw on most interactive widgets?


Anytime you use a "NO_BOX" or "FRAME" type (boxes with no background), the window:redraw() doesn't flush the previous tracing (I had had the same problem with the bezier animation).

With widgets other than the clock, a redraw is needed only when the widget has been changed. This can be detected via:

Code:
widget:when(1); -- 1 : something changed
widget:callback(function()
out:value("changed")
end)


or better, triggered by any code that does some drawing.

-- Typed from memory, not guaranteed to work as described. Second thought, when is related to on screen events like mouseclick which cause the state of the object to change (checkbox checked, etc.)... best is to trigger a window refresh in the code that causes the screen content to change --

On skinning, what would be really cool would be to be able to have a transparent window. Something that would allow to write widget types of apps.

See konfabulator gallery for examples of what I mean. Then murgalua could become a widget engine for Linux Wink.
Reference URL's