Fixes from Bill:

- Fl_Clock now uses the Fl_Clock_Output base class to get the
      system time.
    - Fl_Window::iconize() and Fl_Window::icon() now coexist
      peacefully with all X window managers.
    - Minor fixes to mandelbrot and shape demos.
    - Menu code cleanup.


git-svn-id: file:///fltk/svn/fltk/trunk@209 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
1999-01-13 15:45:50 +00:00
parent a64292cc5f
commit ab5771b62f
9 changed files with 90 additions and 78 deletions

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Clock.H,v 1.4 1999/01/07 19:16:52 mike Exp $"
// "$Id: Fl_Clock.H,v 1.5 1999/01/13 15:45:48 mike Exp $"
//
// Clock header file for the Fast Light Tool Kit (FLTK).
//
@@ -36,19 +36,17 @@
#define FL_ANALOG_CLOCK FL_SQUARE_CLOCK
#define FL_DIGITAL_CLOCK FL_SQUARE_CLOCK // nyi
class Fl_Clock : public Fl_Widget {
// a Fl_Clock_Output can be used to display a program-supplied time:
class Fl_Clock_Output : public Fl_Widget {
int hour_, minute_, second_;
ulong value_;
void drawhands(Fl_Color,Fl_Color); // part of draw
protected:
void draw(int, int, int, int);
void draw();
void _Fl_Clock();
int handle(int);
public:
Fl_Clock(int x,int y,int w,int h, const char *l = 0);
Fl_Clock(uchar t,int x,int y,int w,int h, const char *l);
~Fl_Clock();
Fl_Clock_Output(int x,int y,int w,int h, const char *l = 0);
void value(ulong v); // set to this Unix time
void value(int,int,int); // set hour, minute, second
ulong value() const {return value_;}
@@ -57,8 +55,19 @@ public:
int second() const {return second_;}
};
// a Fl_Clock displays the current time always by using a timeout:
class Fl_Clock : public Fl_Clock_Output {
int handle(int);
public:
void update();
Fl_Clock(int x,int y,int w,int h, const char *l = 0);
Fl_Clock(uchar t,int x,int y,int w,int h, const char *l);
~Fl_Clock();
};
#endif
//
// End of "$Id: Fl_Clock.H,v 1.4 1999/01/07 19:16:52 mike Exp $".
// End of "$Id: Fl_Clock.H,v 1.5 1999/01/13 15:45:48 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Function_Type.cxx,v 1.11 1999/01/07 21:21:20 mike Exp $"
// "$Id: Fl_Function_Type.cxx,v 1.12 1999/01/13 15:45:48 mike Exp $"
//
// C function type code for the Fast Light Tool Kit (FLTK).
//
@@ -211,14 +211,14 @@ void Fl_Function_Type::write_code1() {
if (name()[0] == '~')
constructor = 1;
else {
size_t n = strlen(k);
if (!strncmp(name(), k, n) && name()[n] == '(') constructor = 1;
size_t n = strlen(k);
if (!strncmp(name(), k, n) && name()[n] == '(') constructor = 1;
}
write_h(" ");
if (!constructor) {
if (is_static) write_h("static ");
write_h("%s ", t);
write_c("%s ", t);
if (is_static) write_h("static ");
write_h("%s ", t);
write_c("%s ", t);
}
write_h("%s;\n", name());
write_c("%s::%s {\n", k, name());
@@ -697,5 +697,5 @@ void Fl_Class_Type::write_code2() {
}
//
// End of "$Id: Fl_Function_Type.cxx,v 1.11 1999/01/07 21:21:20 mike Exp $".
// End of "$Id: Fl_Function_Type.cxx,v 1.12 1999/01/13 15:45:48 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Clock.cxx,v 1.4 1999/01/07 19:17:18 mike Exp $"
// "$Id: Fl_Clock.cxx,v 1.5 1999/01/13 15:45:49 mike Exp $"
//
// Clock widget for the Fast Light Tool Kit (FLTK).
//
@@ -29,9 +29,6 @@
#include <math.h>
#include <time.h>
// There really should be a way to make this display something other
// than the current time...
// Original clock display written by Paul Haeberli at SGI.
// Modifications by Mark Overmars for Forms
// Further changes by Bill Spitzak for fltk
@@ -51,7 +48,7 @@ static void drawhand(double ang,const float v[][2],Fl_Color fill,Fl_Color line)
fl_pop_matrix();
}
void Fl_Clock::drawhands(Fl_Color fill, Fl_Color line) {
void Fl_Clock_Output::drawhands(Fl_Color fill, Fl_Color line) {
drawhand(-360*(hour()+minute()/60.0)/12, hourhand, fill, line);
drawhand(-360*(minute()+second()/60.0)/60, minhand, fill, line);
drawhand(-360*(second()/60.0), sechand, fill, line);
@@ -68,7 +65,7 @@ static void rect(double x, double y, double w, double h) {
fl_end_polygon();
}
void Fl_Clock::draw(int x, int y, int w, int h) {
void Fl_Clock_Output::draw(int x, int y, int w, int h) {
draw_box(box(), x, y, w, h, type()==FL_ROUND_CLOCK ? FL_GRAY : color());
fl_push_matrix();
fl_translate(x+w/2.0-.5, y+h/2.0-.5);
@@ -99,65 +96,75 @@ void Fl_Clock::draw(int x, int y, int w, int h) {
fl_pop_matrix();
}
void Fl_Clock::draw() {
void Fl_Clock_Output::draw() {
draw(x(), y(), w(), h());
draw_label();
}
void Fl_Clock::value(int h, int m, int s) {
void Fl_Clock_Output::value(int h, int m, int s) {
if (h!=hour_ || m!=minute_ || s!=second_) {
hour_ = h; minute_ = m; second_ = s;
redraw();
damage(FL_DAMAGE_CHILD);
}
}
void Fl_Clock::value(ulong v) {
void Fl_Clock_Output::value(ulong v) {
struct tm *timeofday;
timeofday = localtime((const time_t *)&v);
value(timeofday->tm_hour, timeofday->tm_min, timeofday->tm_sec);
}
static void tick(void *v) {
((Fl_Clock*)v)->value(time(0));
Fl::add_timeout(1, tick, v);
}
void Fl_Clock::_Fl_Clock() {
selection_color(fl_gray_ramp(5));
align(FL_ALIGN_BOTTOM);
value(time(0));
//Fl::add_timeout(1, tick, this);
}
Fl_Clock::Fl_Clock(int x, int y, int w, int h, const char *l)
Fl_Clock_Output::Fl_Clock_Output(int x, int y, int w, int h, const char *l)
: Fl_Widget(x, y, w, h, l) {
box(FL_UP_BOX);
_Fl_Clock();
selection_color(fl_gray_ramp(5));
align(FL_ALIGN_BOTTOM);
hour_ = 0;
minute_ = 0;
second_ = 0;
value_ = 0;
}
////////////////////////////////////////////////////////////////
Fl_Clock::Fl_Clock(int x, int y, int w, int h, const char *l)
: Fl_Clock_Output(x, y, w, h, l) {}
Fl_Clock::Fl_Clock(uchar t, int x, int y, int w, int h, const char *l)
: Fl_Widget(x, y, w, h, l) {
: Fl_Clock_Output(x, y, w, h, l) {
type(t);
box(t==FL_ROUND_CLOCK ? FL_NO_BOX : FL_UP_BOX);
_Fl_Clock();
}
Fl_Clock::~Fl_Clock() {
Fl::remove_timeout(tick, this);
#ifndef WIN32
#include <sys/time.h>
#endif
static void tick(void *v) {
struct timeval t;
gettimeofday(&t, NULL);
((Fl_Clock*)v)->value(t.tv_sec);
double delay = 1.0-t.tv_usec*.000001;
if (delay < .1 || delay > .9) delay = 1.0;
Fl::add_timeout(delay, tick, v);
}
int Fl_Clock::handle(int event) {
switch (event) {
case FL_SHOW:
tick(this);
break;
case FL_HIDE:
Fl::remove_timeout(tick, this);
break;
case FL_SHOW:
Fl::remove_timeout(tick, this);
tick(this);
}
return 0;
return Fl_Clock_Output::handle(event);
}
Fl_Clock::~Fl_Clock() {
Fl::remove_timeout(tick, this);
}
//
// End of "$Id: Fl_Clock.cxx,v 1.4 1999/01/07 19:17:18 mike Exp $".
// End of "$Id: Fl_Clock.cxx,v 1.5 1999/01/13 15:45:49 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu.cxx,v 1.11 1999/01/07 19:17:22 mike Exp $"
// "$Id: Fl_Menu.cxx,v 1.12 1999/01/13 15:45:49 mike Exp $"
//
// Menu code for the Fast Light Tool Kit (FLTK).
//
@@ -138,7 +138,7 @@ void Fl_Menu_Item::draw(int x, int y, int w, int h, const Fl_Menu_* m,
b = m ? m->box() : FL_UP_BOX;
} else {
r = (Fl_Color)(FL_COLOR_CUBE-1); // white
l.color = contrast((Fl_Color)labelcolor_, r);
l.color = contrast((Fl_Color)labelcolor_, r);
}
} else {
l.color = contrast((Fl_Color)labelcolor_, r);
@@ -703,5 +703,5 @@ const Fl_Menu_Item* Fl_Menu_Item::test_shortcut() const {
}
//
// End of "$Id: Fl_Menu.cxx,v 1.11 1999/01/07 19:17:22 mike Exp $".
// End of "$Id: Fl_Menu.cxx,v 1.12 1999/01/13 15:45:49 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu_Bar.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $"
// "$Id: Fl_Menu_Bar.cxx,v 1.6 1999/01/13 15:45:49 mike Exp $"
//
// Menu bar widget for the Fast Light Tool Kit (FLTK).
//
@@ -40,6 +40,9 @@ void Fl_Menu_Bar::draw() {
int Fl_Menu_Bar::handle(int event) {
const Fl_Menu_Item* v;
if (menu() && menu()->text) switch (event) {
case FL_ENTER:
case FL_LEAVE:
return 1;
case FL_PUSH:
v = 0;
J1:
@@ -57,5 +60,5 @@ int Fl_Menu_Bar::handle(int event) {
}
//
// End of "$Id: Fl_Menu_Bar.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $".
// End of "$Id: Fl_Menu_Bar.cxx,v 1.6 1999/01/13 15:45:49 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_Window.cxx,v 1.5 1999/01/07 19:17:29 mike Exp $"
// "$Id: Fl_Window.cxx,v 1.6 1999/01/13 15:45:49 mike Exp $"
//
// Window widget class for the Fast Light Tool Kit (FLTK).
//
@@ -59,7 +59,7 @@ Fl_Window::Fl_Window(int W, int H, const char *l)
Fl_Window *Fl_Widget::window() const {
for (Fl_Widget *o = parent(); o; o = o->parent())
if (o->type()>=FL_WINDOW) return (Fl_Window*)o;
if (o->type() >= FL_WINDOW) return (Fl_Window*)o;
return 0;
}
@@ -102,5 +102,5 @@ void Fl_Window::default_callback(Fl_Window* window, void* v) {
}
//
// End of "$Id: Fl_Window.cxx,v 1.5 1999/01/07 19:17:29 mike Exp $".
// End of "$Id: Fl_Window.cxx,v 1.6 1999/01/13 15:45:49 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_x.cxx,v 1.20 1999/01/07 19:17:33 mike Exp $"
// "$Id: Fl_x.cxx,v 1.21 1999/01/13 15:45:50 mike Exp $"
//
// X specific code for the Fast Light Tool Kit (FLTK).
//
@@ -652,15 +652,6 @@ void Fl_X::make_xid(Fl_Window* w, XVisualInfo *visual, Colormap colormap)
(unsigned char *)buffer, p-buffer-1);
}
// Set the icon pixmap as needed:
if (w->icon()) {
XWMHints hints;
hints.icon_pixmap = (Pixmap)w->icon();
hints.flags = IconPixmapHint;
XSetWMHints(fl_display, x->xid, &hints);
}
if (w->non_modal() && x->next && !fl_disable_transient_for) {
// find some other window to be "transient for":
Fl_Window* w = x->next->w;
@@ -668,13 +659,18 @@ void Fl_X::make_xid(Fl_Window* w, XVisualInfo *visual, Colormap colormap)
XSetTransientForHint(fl_display, x->xid, fl_xid(w));
}
XWMHints hints;
hints.flags = 0;
if (fl_show_iconic) {
XWMHints hints;
hints.flags = StateHint;
hints.initial_state = 3;
XSetWMHints(fl_display, x->xid, &hints);
hints.initial_state = IconicState;
fl_show_iconic = 0;
}
if (w->icon()) {
hints.icon_pixmap = (Pixmap)w->icon();
hints.flags |= IconPixmapHint;
}
if (hints.flags) XSetWMHints(fl_display, x->xid, &hints);
}
XMapWindow(fl_display, x->xid);
@@ -823,5 +819,5 @@ void Fl_Window::make_current() {
#endif
//
// End of "$Id: Fl_x.cxx,v 1.20 1999/01/07 19:17:33 mike Exp $".
// End of "$Id: Fl_x.cxx,v 1.21 1999/01/13 15:45:50 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: mandelbrot.cxx,v 1.7 1999/01/07 19:17:57 mike Exp $"
// "$Id: mandelbrot.cxx,v 1.8 1999/01/13 15:45:50 mike Exp $"
//
// Mandelbrot set demo for the Fast Light Tool Kit (FLTK).
//
@@ -69,7 +69,7 @@ void Drawing_Area::draw() {
}
int Drawing_Area::idle() {
if (!window()->shown() || !window()->visible()) return 0;
if (!window()->visible()) return 0;
if (drawn < nextline) {
window()->make_current();
int yy = drawn+y()+4;
@@ -197,5 +197,5 @@ void Drawing_Area::resize(int X,int Y,int W,int H) {
}
//
// End of "$Id: mandelbrot.cxx,v 1.7 1999/01/07 19:17:57 mike Exp $".
// End of "$Id: mandelbrot.cxx,v 1.8 1999/01/13 15:45:50 mike Exp $".
//

View File

@@ -1,5 +1,5 @@
//
// "$Id: shape.cxx,v 1.4 1999/01/07 19:18:00 mike Exp $"
// "$Id: shape.cxx,v 1.5 1999/01/13 15:45:50 mike Exp $"
//
// Tiny OpenGL demo program for the Fast Light Tool Kit (FLTK).
//
@@ -106,13 +106,10 @@ int main(int argc, char **argv) {
window.end();
window.show(argc,argv);
// in the X version you must show() all Fl_Window's in top/down order
// other systems may not require this, but it will be harmless:
//sw.show();
return Fl::run();
}
//
// End of "$Id: shape.cxx,v 1.4 1999/01/07 19:18:00 mike Exp $".
// End of "$Id: shape.cxx,v 1.5 1999/01/13 15:45:50 mike Exp $".
//