Discussion:
Smooth blinking
m***@public.gmane.org
2013-03-18 14:59:52 UTC
Permalink
Hi all,
forgive me but here is another question, not-so-evident for me.

You have to realize a blinking message, or an object which periodically swaps two images :
think of an alarm icon.
The alarm is sounding, and the icon keeps alternating red/yellow horn images until the user pushes the ack button.

Use a timer to blink... but things are not always "smooth blinking".
Not a big problem, anyway... just would like to know if there is a clever way to assure a smooth blinking
(usually we are speaking of small objects).

Thanks,
regards

Lucio
Greg Ercolano
2013-03-18 17:43:41 UTC
Permalink
Post by m***@public.gmane.org
Hi all,
forgive me but here is another question, not-so-evident for me.
think of an alarm icon.
The alarm is sounding, and the icon keeps alternating red/yellow horn images until the user pushes the ack button.
Use a timer to blink... but things are not always "smooth blinking".
Not a big problem, anyway... just would like to know if there is a clever way to assure a smooth blinking
(usually we are speaking of small objects).
Make sure the window is an Fl_Double_Window, so that it uses double-buffering.

Beyond that, just have the timer callback:

1) Change the the thing being blinked to "on" or "off" (hide()/show() can work)

2) Call redraw() on the widget that handles the background of the widget in question.

If the widget draws its own background, then tell /it/ to redraw. If the widget
is 'see through' (eg. text label with FL_NO_BOX), then tell the closest parent
that handles the background to redraw()
or call redraw() on the parent that draws the background under the widget

3) Call Fl::repeat_timeout() to reset the timer for the next trigger
MacArthur, Ian (Selex ES, UK)
2013-03-19 13:35:28 UTC
Permalink
Post by m***@public.gmane.org
Post by m***@public.gmane.org
You have to realize a blinking message, or an object which
think of an alarm icon.
The alarm is sounding, and the icon keeps alternating red/yellow horn
images until the user pushes the ack button.
Post by m***@public.gmane.org
Use a timer to blink... but things are not always "smooth blinking".
Not a big problem, anyway... just would like to know if there is a
clever way to assure a smooth blinking
Post by m***@public.gmane.org
(usually we are speaking of small objects).
Not really sure this is what was being asked, but here's a simple demo of "blinking" widgets.

Maybe this is what was wanted?

----------------------

//
// Flashing Boxes
//

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>

static Fl_Double_Window *main_win = 0;
static Fl_Button *quit_bt = 0;

static Fl_Box *box1 = 0;
static Fl_Box *box2 = 0;

static void cb_quit(Fl_Widget *, void *) {
main_win->hide();
} // cb_quit

void update_box1(void *) {
static int state = 0;
if(state) {
state = 0;
box1->color(FL_GREEN);
}
else {
state = -1;
box1->color(FL_RED);
}

Fl::repeat_timeout(0.7, update_box1);
box1->redraw();
} // update_box1

void update_box2(void *) {
static int state = 0;
static int step = 1;
const int thd = 15;
state += step;
if(state >= thd) {
step = -1;
}
else if (state <= 0) {
step = 1;
}
float alpha = (float)state / (float)thd;

Fl_Color col = fl_color_average(FL_RED, FL_BACKGROUND_COLOR, alpha);
box2->color(col);

Fl::repeat_timeout(0.05, update_box2);
box2->redraw();
} // update_box2

int main(int argc, char ** argv) {
main_win = new Fl_Double_Window(370, 230, "Flashing Widgets");
main_win->begin();

box1 = new Fl_Box(10, 10, 60, 30, "ALERT!");
box1->box(FL_FLAT_BOX);
box1->color(FL_GREEN);

box2 = new Fl_Box(80, 10, 60, 30, "ALERT!");
box2->box(FL_FLAT_BOX);
box2->color(FL_BACKGROUND_COLOR);

quit_bt = new Fl_Button(300, 190, 60, 30, "Quit");
quit_bt->box(FL_THIN_UP_BOX);
quit_bt->callback(cb_quit);

main_win->end();
main_win->show(argc,argv);

Fl::add_timeout(0.3, update_box1);
Fl::add_timeout(0.05, update_box2);

return Fl::run();
} // main

// end of file //





Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
m***@public.gmane.org
2013-03-19 15:31:37 UTC
Permalink
Hi Greg and Ian,
Post by m***@public.gmane.org
Post by m***@public.gmane.org
Use a timer to blink... but things are not always "smooth blinking".
Not a big problem, anyway... just would like to know if there is a
clever way to assure a smooth blinking
Post by m***@public.gmane.org
(usually we are speaking of small objects).
Not really sure this is what was being asked, but here's a simple demo of "blinking" widgets.
Maybe this is what was wanted?
Yes.
The problem was that, under particular conditions (many redraw of images), my blinking could become irregular,
as timers, if I understand well, are all at the same "priority level".

The technique you and Greg told me is clear ; will "clean up" something in my (growing!) app and try
to avoid unnecessary redraws.

Again,
thank you a lot for your precious help.

Best regards,
Lucio
Albrecht Schlosser
2013-03-20 10:58:47 UTC
Permalink
Post by m***@public.gmane.org
The problem was that, under particular conditions (many redraw of images), my blinking could become irregular,
as timers, if I understand well, are all at the same "priority level".
Hint Fl::repeat_timeout() is designed to compensate for small timer
delays, so that the next timer interval will be shorted if the
actual timer callback is serviced later than it should. However,
this does obviously work only if the overall CPU usage is small
enough so that there is room to *wait* for the next timer. If the
CPU is utilized so heavily that there is no time left, then ...

Also note that this timer delay compensation works well (i.e. as
designed) on Linux, but probably not on Windows :-( I did some
tests a while back, but lost track of it. I can't say anything
about Mac OS WRT this.
Post by m***@public.gmane.org
The technique you and Greg told me is clear ; will "clean up" something in my (growing!) app and try
to avoid unnecessary redraws.
That's always a good idea.

Albrecht
m***@public.gmane.org
2013-03-20 13:34:40 UTC
Permalink
Hi Albrecht,
Post by Albrecht Schlosser
Also note that this timer delay compensation works well (i.e. as
designed) on Linux, but probably not on Windows :-( I did some
tests a while back, but lost track of it. I can't say anything
about Mac OS WRT this.
No Windows here, m8 :
just pure Linux &amp; microwindows on a 400 MHz PowerPC embedded platform ;-)

Thanks,
regards

Lucio
MacArthur, Ian (Selex ES, UK)
2013-03-20 14:51:48 UTC
Permalink
Post by m***@public.gmane.org
just pure Linux &amp; microwindows on a 400 MHz PowerPC embedded platform ;-)
If you have a 400 MHz PPC, is microwindows the best choice? That
should be easily able to run a "real" X11 server, (I'm thinking
of the TinxX / K-drive stuff, for example.)

I only ask because (admittedly a *long* time ago now) I had a
project using microwindows and it was just a world of hurt -
it was really awful.
So we switched to a "real" X-server and then things Just Worked.

That said, I am led to believe the microwidows got a lot better
since then, but I was too badly burned to consider going back...





Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
m***@public.gmane.org
2013-03-20 15:31:04 UTC
Permalink
Hi Ian,
microwindows is a piece coming from the past.
I have already realized several machines running with AMD Alchemy (MIPS), more or less same horsepower as the actual one.
It was the usual work of putting together pieces (microwindows + nano-X, truetype fonts and so on),
but it works.
Microwindows + nano-X actually is not a project with as much as activity as fltk, but it's working.

Maybe another solution could be better now, but I already had to switch hardware platform as Alchemy is end of life product :
new schematics, new bios, new kernel (Alchemy=2.4.x, PPC=2.6.x), new kernel drivers... and note that MIPS=little endian, PPC = big endian.
I just had sufficient new things, to think of throwing away microwindows + nanox.

I was surely tempted of trying X11 server, but now I cannot do this for time constraints.
Don't know kdrive, but I'm curious and sooner or later will try it.


Regards
Lucio

Continue reading on narkive:
Loading...