Replaced Fl::readqueue() in fl_color_chooser() by real callbacks.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7347 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
327c17bb71
commit
092b65139d
@ -516,7 +516,7 @@ void ColorChip::draw() {
|
||||
h()-Fl::box_dh(box()),r,g,b);
|
||||
}
|
||||
|
||||
static void chooser_cb(Fl_Object* o, void* vv) {
|
||||
static void chooser_cb(Fl_Widget* o, void* vv) {
|
||||
Fl_Color_Chooser* c = (Fl_Color_Chooser*)o;
|
||||
ColorChip* v = (ColorChip*)vv;
|
||||
v->r = uchar(255*c->r()+.5);
|
||||
@ -528,6 +528,27 @@ static void chooser_cb(Fl_Object* o, void* vv) {
|
||||
extern const char* fl_ok;
|
||||
extern const char* fl_cancel;
|
||||
|
||||
// fl_color_chooser's callback for ok_button (below)
|
||||
// [in] o is a pointer to okay_button (below)
|
||||
// [in] p is a pointer to an int to receive the return value (1)
|
||||
// closes the fl_color_chooser window
|
||||
static void cc_ok_cb (Fl_Widget *o, void *p) {
|
||||
*((int *)p) = 1; // set return value
|
||||
o->window()->hide();
|
||||
}
|
||||
|
||||
// fl_color_chooser's callback for cancel_button and window close
|
||||
// [in] o is a pointer to cancel_button (below) _or_ the dialog window
|
||||
// [in] p is a pointer to an int to receive the return value (0)
|
||||
// closes the fl_color_chooser window
|
||||
static void cc_cancel_cb (Fl_Widget *o, void *p) {
|
||||
*((int *)p) = 0; // set return value
|
||||
if (o->window()) // cancel button
|
||||
o->window()->hide();
|
||||
else // window close
|
||||
o->hide();
|
||||
}
|
||||
|
||||
/** \addtogroup group_comdlg
|
||||
@{ */
|
||||
/**
|
||||
@ -541,15 +562,19 @@ extern const char* fl_cancel;
|
||||
\relates Fl_Color_Chooser
|
||||
*/
|
||||
int fl_color_chooser(const char* name, double& r, double& g, double& b) {
|
||||
int ret = 0;
|
||||
Fl_Window window(215,200,name);
|
||||
window.callback(cc_cancel_cb,&ret);
|
||||
Fl_Color_Chooser chooser(10, 10, 195, 115);
|
||||
ColorChip ok_color(10, 130, 95, 25);
|
||||
Fl_Return_Button ok_button(10, 165, 95, 25, fl_ok);
|
||||
ok_button.callback(cc_ok_cb,&ret);
|
||||
ColorChip cancel_color(110, 130, 95, 25);
|
||||
cancel_color.r = uchar(255*r+.5); ok_color.r = cancel_color.r;
|
||||
ok_color.g = cancel_color.g = uchar(255*g+.5);
|
||||
ok_color.b = cancel_color.b = uchar(255*b+.5);
|
||||
Fl_Button cancel_button(110, 165, 95, 25, fl_cancel);
|
||||
cancel_button.callback(cc_cancel_cb,&ret);
|
||||
window.resizable(chooser);
|
||||
chooser.rgb(r,g,b);
|
||||
chooser.callback(chooser_cb, &ok_color);
|
||||
@ -557,21 +582,13 @@ int fl_color_chooser(const char* name, double& r, double& g, double& b) {
|
||||
window.set_modal();
|
||||
window.hotspot(window);
|
||||
window.show();
|
||||
while (window.shown()) {
|
||||
Fl::wait();
|
||||
for (;;) {
|
||||
Fl_Widget* o = Fl::readqueue();
|
||||
if (!o) break;
|
||||
if (o == &ok_button) {
|
||||
r = chooser.r();
|
||||
g = chooser.g();
|
||||
b = chooser.b();
|
||||
return 1;
|
||||
}
|
||||
if (o == &window || o == &cancel_button) return 0;
|
||||
}
|
||||
while (window.shown()) Fl::wait();
|
||||
if (ret) { // ok_button or Enter
|
||||
r = chooser.r();
|
||||
g = chooser.g();
|
||||
b = chooser.b();
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user