[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[XForms] Fdesign mbuttons fix, radio button handling fix, enhanced color
From: |
SBP |
Subject: |
[XForms] Fdesign mbuttons fix, radio button handling fix, enhanced color chooser |
Date: |
Sat, 04 Feb 2017 20:47:49 -0600 |
Hi there!
I'd like to share with you three patches based on 1.2.4.
First one: make fdesign emit the right value for the mouse buttons a
button is set to respond to ('mbuttons'). Comes with default
scrollbutton object as well (from previous patch). Seems like something
changed and instead of storing 1/2/4/8/16 in sp->react_to, now is 1/0,
thus the proposed fix.
<< PATCH
--- sp_button.c~ 2017-02-04 20:15:51.662115499 -0600
+++ sp_button.c 2017-02-04 20:15:21.192390143 -0600
@@ -231,11 +231,11 @@
if ( memcmp( sp->react_to, defsp->react_to, sizeof sp->react_to ) )
{
- unsigned int rt = ( sp->react_to[ 0 ] & 1 )
- | ( sp->react_to[ 1 ] & 2 )
- | ( sp->react_to[ 2 ] & 4 )
- | ( sp->react_to[ 3 ] & 8 )
- | ( sp->react_to[ 4 ] & 16 );
+ unsigned int rt = ( sp->react_to[ 0 ] << 0 )
+ | ( sp->react_to[ 1 ] << 1 )
+ | ( sp->react_to[ 2 ] << 2 )
+ | ( sp->react_to[ 3 ] << 3 )
+ | ( sp->react_to[ 4 ] << 4 );
fprintf( fp, " mbuttons: %u\n", rt );
}
@@ -307,11 +307,11 @@
if ( memcmp( sp->react_to, defsp->react_to, sizeof sp->react_to ) )
{
- unsigned int rt = ( sp->react_to[ 0 ] & 1 )
- | ( sp->react_to[ 1 ] & 2 )
- | ( sp->react_to[ 2 ] & 4 )
- | ( sp->react_to[ 3 ] & 8 )
- | ( sp->react_to[ 4 ] & 16 );
+ unsigned int rt = ( sp->react_to[ 0 ] << 0 )
+ | ( sp->react_to[ 1 ] << 1 )
+ | ( sp->react_to[ 2 ] << 2 )
+ | ( sp->react_to[ 3 ] << 3 )
+ | ( sp->react_to[ 4 ] << 4 );
fprintf( fp, " fl_set_button_mouse_buttons( obj, %u );\n",
rt );
}
@@ -606,6 +606,8 @@
defobj = fl_create_checkbutton( ob->type, 0, 0, 0, 0, "" );
else if ( ob->objclass == FL_ROUND3DBUTTON )
defobj = fl_create_round3dbutton( ob->type, 0, 0, 0, 0, "" );
+ else if ( ob->objclass == FL_SCROLLBUTTON )
+ defobj = fl_create_scrollbutton( ob->type, 0, 0, 0, 0, "" );
else
fprintf( stderr, "Unknown Button Class: %d\n", ob->objclass );
PATCH
Second one: fixes a bug wherein pushing any radio button in a group,
with any mouse button, released the radio button currently set, without
honoring the 'mbuttons' setting. As this is about a button affecting
other buttons, it can't be implemented in the button handler, but
rather at the point where the radio button affects other radio buttons
(when fli_do_radio_push is called). I think this is the simplest
solution, but maybe there's a better one...
<< PATCH
--- handling.c~ 2017-02-04 20:07:09.993459973 -0600
+++ handling.c 2017-02-04 20:07:55.323055872 -0600
@@ -416,6 +416,7 @@
FL_OBJECT *obj = NULL;
FL_Coord x,
y;
+ unsigned int mbuttons;
if ( ! form || form->visible != FL_VISIBLE )
return;
@@ -511,8 +512,11 @@
fli_int.pushobj = obj;
fli_handle_object( obj, FL_PUSH, x, y, key, xev, 1 );
}
- else if ( obj->radio )
- fli_do_radio_push( obj, x, y, key, xev, 0 );
+ else if ( obj->radio ) {
+ fl_get_button_mouse_buttons( obj, &mbuttons );
+ if( mbuttons & (1 << (key - 1) ) )
+ fli_do_radio_push( obj, x, y, key, xev, 0 );
+ }
break;
case FL_RELEASE : /* mouse button was released inside
the form */
PATCH
Third one: enhances the color chooser goodie by replacing input fields
with spinners, making the OK button into a RETURN_BUTTON and adding
<Escape> shortcut to Cancel button. Includes value clamp fix (from
previous patch).
<< PATCH
--- goodie_colchooser.c~ 2017-02-04 19:33:56.101297001 -0600
+++ goodie_colchooser.c 2017-02-04 19:33:30.771522851 -0600
@@ -31,8 +31,8 @@
FL_OBJECT * pm; /* pixmap with colorwheel */
FL_OBJECT * pos; /* positioner to select hue and
saturation */
FL_OBJECT * sl; /* slider for HSV value */
- FL_OBJECT * hsv_inp[ 3 ]; /* HSV input fields */
- FL_OBJECT * rgb_inp[ 3 ]; /* RGB input fields */
+ FL_OBJECT * hsv_spin[ 3 ]; /* HSV spinners */
+ FL_OBJECT * rgb_spin[ 3 ]; /* RGB spinners */
FL_OBJECT * area; /* area for showing selected color */
FL_OBJECT * hex; /* label showing selected RGB color in
hex */
FL_OBJECT * ok; /* "OK" button */
@@ -233,7 +233,7 @@
/***************************************
- * Sets the colorfor the box sowing the currently selected color
+ * Sets the color for the box showing the currently selected color
* and the label with its hexadecimal value.
***************************************/
@@ -250,30 +250,30 @@
/***************************************
- * Sets all HSV input field values at once
+ * Sets all HSV spinner values at once
***************************************/
static void
-set_hsv_inputs( COLOR_CHOOSER * cc )
+set_hsv_spinners( COLOR_CHOOSER * cc )
{
int i;
for ( i = HUE; i <= VALUE; i++ )
- fl_set_input_f( cc->hsv_inp[ i ], "%d", cc->hsv[ i ] );
+ fl_set_spinner_value( cc->hsv_spin[ i ], (double) cc->hsv[ i ]
);
}
/***************************************
- * Sets all RGB input field values at once
+ * Sets all RGB spinner values at once
***************************************/
static void
-set_rgb_inputs( COLOR_CHOOSER * cc )
+set_rgb_spinners( COLOR_CHOOSER * cc )
{
int i;
for ( i = RED; i <= BLUE; ++i )
- fl_set_input_f( cc->rgb_inp[ i ], "%d", cc->rgb[ i ] );
+ fl_set_spinner_value( cc->rgb_spin[ i ], (double) cc->rgb[ i ]
);
}
@@ -334,9 +334,9 @@
if ( cc->hsv[ HUE ] < 0 )
cc->hsv[ HUE ] += 360;
- set_hsv_inputs( cc );
+ set_hsv_spinners( cc );
hsv2rgb( cc->hsv, cc->rgb );
- set_rgb_inputs( cc );
+ set_rgb_spinners( cc );
update_color_area( cc );
}
@@ -353,23 +353,23 @@
cc->hsv[ VALUE ] = fl_get_slider_value( obj );
- fl_set_input_f( cc->hsv_inp[ VALUE ], "%d", cc->hsv[ VALUE ] );
+ fl_set_spinner_value( cc->hsv_spin[ VALUE ], (double)
cc->hsv[ VALUE ] );
hsv2rgb( cc->hsv, cc->rgb );
- set_rgb_inputs( cc );
+ set_rgb_spinners( cc );
update_color_area( cc );
}
/***************************************
- * Callback for the HSV input fields
+ * Callback for the HSV spinners
***************************************/
static void
-hsv_input_cb( FL_OBJECT * obj,
+hsv_spinner_cb( FL_OBJECT * obj,
long data )
{
COLOR_CHOOSER *cc = obj->u_vdata;
- int value = strtol( fl_get_input( obj ), NULL, 10 );
+ int value = (int) fl_get_spinner_value( obj );
if ( data == HUE )
{
@@ -381,10 +381,10 @@
value = FL_clamp( value, 0, 100 );
cc->hsv[ data ] = value;
- fl_set_input_f( obj, "%d", value );
+ fl_set_spinner_value( obj, (double) value );
hsv2rgb( cc->hsv, cc->rgb );
- set_rgb_inputs( cc );
+ set_rgb_spinners( cc );
if ( data == VALUE )
set_hsv_slider( cc );
@@ -396,21 +396,21 @@
/***************************************
- * Callback for the RGB input fields
+ * Callback for the RGB spinners
***************************************/
static void
-rgb_input_cb( FL_OBJECT * obj,
+rgb_spinner_cb( FL_OBJECT * obj,
long data )
{
COLOR_CHOOSER *cc = obj->u_vdata;
- int value = strtol( fl_get_input( obj ), NULL, 10 );
+ int value = (int) fl_get_spinner_value( obj );
- cc->rgb[ data ] = FL_clamp( value, 0, 100 );
- fl_set_input_f( obj, "%d", cc->rgb[ data ] );
+ cc->rgb[ data ] = FL_clamp( value, 0, 255 );
+ fl_set_spinner_value( obj, (double) cc->rgb[ data ] );
rgb2hsv( cc->rgb, cc->hsv );
- set_hsv_inputs( cc );
+ set_hsv_spinners( cc );
set_hsv_elements( cc );
update_color_area( cc );
@@ -430,6 +430,7 @@
int i;
const char *hsv_txts[ ] = { "Hue:", "Saturation:", "Value:" };
const char *rgb_txts[ ] = { "Red:", "Green:", "Blue:" };
+ const int hsv_bnds[3] = { 359, 100, 100 };
/* Start the form */
@@ -472,27 +473,29 @@
fl_set_object_callback( cc->sl, slider_cb, 0 );
cc->sl->u_vdata = cc;
- /* Add input fields (and labels) for the HSV and RGB values. We do
that
- in sepearte loops to jump within the input fields with <Tab>
first
- through the HSV and then through the RGB input fileds. */
+ /* Add spinners with labels for the HSV and RGB values. We do that
+ in sepearte loops to jump within the spinners with <Tab> first
+ through the HSV and then through the RGB spinners. */
for ( i = HUE; i <= VALUE; i++ )
{
- fl_add_text( FL_NORMAL_TEXT, 290, 20 + i * 55, 80, 30,
hsv_txts[ i ] );
- cc->hsv_inp[ i ] = fl_add_input( FL_INT_INPUT, 370, 20 + i *
55,
- 80, 30, "" );
+ cc->hsv_spin[ i ] = fl_add_spinner( FL_INT_SPINNER, 370, 20 +
i * 55,
+ 80, 30, hsv_txts[ i ] );
+ fl_set_object_lsize( cc->hsv_spin[ i ], FL_DEFAULT_SIZE );
+ fl_set_spinner_bounds( cc->hsv_spin[ i ], 0.0, (double)
hsv_bnds[ i ] );
}
for ( i = RED; i <= BLUE; i++ )
{
- fl_set_object_callback( cc->hsv_inp[ i ], hsv_input_cb, i );
- cc->hsv_inp[ i ]->u_vdata = cc;
+ fl_set_object_callback( cc->hsv_spin[ i ], hsv_spinner_cb, i );
+ cc->hsv_spin[ i ]->u_vdata = cc;
- fl_add_text( FL_NORMAL_TEXT, 460, 20 + i * 55, 55, 30,
rgb_txts[ i ] );
- cc->rgb_inp[ i ] = fl_add_input( FL_INT_INPUT, 515, 20 + i *
55,
- 80, 30, "" );
- fl_set_object_callback( cc->rgb_inp[ i ], rgb_input_cb, i );
- cc->rgb_inp[ i ]->u_vdata = cc;
+ cc->rgb_spin[ i ] = fl_add_spinner( FL_INT_SPINNER, 515, 20 +
i * 55,
+ 80, 30, rgb_txts[ i ] );
+ fl_set_object_lsize( cc->rgb_spin[ i ], FL_DEFAULT_SIZE );
+ fl_set_spinner_bounds( cc->rgb_spin[ i ], 0.0, 255.0 );
+ fl_set_object_callback( cc->rgb_spin[ i ], rgb_spinner_cb, i );
+ cc->rgb_spin[ i ]->u_vdata = cc;
}
/* Get a color slot for the area showing the selected color. Then
@@ -508,8 +511,9 @@
/* Finally add the "Ok" and "Cancel" buttons. */
- cc->ok = fl_add_button( FL_NORMAL_BUTTON, 455, 213, 60, 30, "Ok" );
+ cc->ok = fl_add_button( FL_RETURN_BUTTON, 455, 213, 60, 30, "Ok" );
cc->quit = fl_add_button( FL_NORMAL_BUTTON, 535, 213, 60, 30,
"Cancel" );
+ fl_set_button_shortcut( cc->quit, "^[", 0 );
fl_end_form( );
}
@@ -520,7 +524,7 @@
* The first argument is a (const) array of RGB values to the used at
* the start and can be a NULL pointer (in which case white is used
* as the initial color). The second is an array of three ints used for
- * returning RFB values of the selected color. The function returns 1
+ * returning RGB values of the selected color. The function returns 1
* on success and 0 when the user aborts selecting a color.
***************************************/
@@ -557,9 +561,9 @@
else
memcpy( cc.rgb, irgb, 3 * sizeof *irgb );
- set_rgb_inputs( &cc );
+ set_rgb_spinners( &cc );
rgb2hsv( cc.rgb, cc.hsv );
- set_hsv_inputs( &cc );
+ set_hsv_spinners( &cc );
set_hsv_elements( &cc );
update_color_area( &cc );
PATCH
Hope you find them useful as do I!
Cheers!
Sirius.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [XForms] Fdesign mbuttons fix, radio button handling fix, enhanced color chooser,
SBP <=