Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src


Modified Files:
        ewl_spinner.c ewl_spinner.h 


Log Message:
Spinner now continues to change while the arrows are held down. The change is
exponential over time like the scrollbars.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_spinner.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -3 -r1.49 -r1.50
--- ewl_spinner.c       10 Apr 2004 18:12:05 -0000      1.49
+++ ewl_spinner.c       16 May 2004 05:48:17 -0000      1.50
@@ -1,6 +1,7 @@
 #include <Ewl.h>
 
 static void ewl_spinner_calc_value(Ewl_Spinner *s, double val);
+static int ewl_spinner_timer(void *data);
 
 /**
  * @return Returns a new spinner widget on success, NULL on failure.
@@ -49,6 +50,8 @@
                            NULL);
        ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, ewl_spinner_configure_cb,
                            NULL);
+       ewl_callback_append(w, EWL_CALLBACK_DESTROY, ewl_spinner_destroy_cb,
+                           NULL);
 
        s->entry = ewl_entry_new("0");
        ewl_container_append_child(EWL_CONTAINER(s), s->entry);
@@ -80,12 +83,16 @@
                            ewl_spinner_key_down_cb, NULL);
        ewl_callback_append(s->entry, EWL_CALLBACK_DESELECT,
                            ewl_spinner_deselect_cb, NULL);
-       ewl_callback_append(s->button_increase, EWL_CALLBACK_CLICKED,
+       ewl_callback_append(s->button_increase, EWL_CALLBACK_MOUSE_DOWN,
                            ewl_spinner_increase_value_cb, w);
+       ewl_callback_append(s->button_increase, EWL_CALLBACK_MOUSE_UP,
+                           ewl_spinner_value_stop_cb, w);
        ewl_callback_append(s->button_increase, EWL_CALLBACK_KEY_DOWN,
                            ewl_spinner_key_down_cb, NULL);
-       ewl_callback_append(s->button_decrease, EWL_CALLBACK_CLICKED,
+       ewl_callback_append(s->button_decrease, EWL_CALLBACK_MOUSE_DOWN,
                            ewl_spinner_decrease_value_cb, w);
+       ewl_callback_append(s->button_decrease, EWL_CALLBACK_MOUSE_UP,
+                           ewl_spinner_value_stop_cb, w);
        ewl_callback_append(s->button_decrease, EWL_CALLBACK_KEY_DOWN,
                            ewl_spinner_key_down_cb, NULL);
 
@@ -143,6 +150,19 @@
 }
 
 /**
+ * @param s: the spinner to retrieve minimum value
+ * @brief Retrieves the minimum value for the spinner.
+ * @return Returns the currently set minimum value for the specified spinner.
+ */
+double ewl_spinner_get_min_val(Ewl_Spinner *s)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("s", s, 0.0);
+
+       DRETURN_FLOAT(s->min_val, DLEVEL_STABLE);
+}
+
+/**
  * @param s: the spinner to change the minimum possible value
  * @param val: the new minimum possible value for @a s
  * @return Returns no value.
@@ -162,6 +182,19 @@
 }
 
 /**
+ * @param s: the spinner to retrieve maximum value
+ * @brief Retrieves the maximum value for the spinner.
+ * @return Returns the currently set maximum value for the specified spinner.
+ */
+double ewl_spinner_get_max_val(Ewl_Spinner *s)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("s", s, 100.0);
+
+       DRETURN_FLOAT(s->max_val, DLEVEL_STABLE);
+}
+
+/**
  * @param s: the spinner to change the maximum possible value
  * @param val: the new maximum possible value for @a s
  * @return Returns no value.
@@ -457,6 +490,30 @@
 
        ewl_spinner_calc_value(s, s->value + s->step);
 
+       if (ev_data) {
+               s->direction = 1;
+               s->start_time = ecore_time_get();
+               s->timer = ecore_timer_add(0.02, ewl_spinner_timer, s);
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+void
+ewl_spinner_value_stop_cb(Ewl_Widget * w, void *ev_data, void *user_data)
+{
+       Ewl_Spinner *s = user_data;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       if (s->timer) {
+               ecore_timer_del(s->timer);
+
+               s->timer = NULL;
+               s->direction = 0;
+               s->start_time = 0;
+       }
+
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
@@ -474,5 +531,62 @@
 
        ewl_spinner_calc_value(s, s->value - s->step);
 
+       if (ev_data) {
+               s->direction = -1;
+               s->start_time = ecore_time_get();
+               s->timer = ecore_timer_add(0.02, ewl_spinner_timer, s);
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+void ewl_spinner_destroy_cb(Ewl_Widget *w, void *ev_data, void *user_data)
+{
+       Ewl_Spinner *s;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       s = EWL_SPINNER(w);
+
+       if (s->timer) {
+               ecore_timer_del(s->timer);
+               s->timer = NULL;
+       }
+
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
+
+static int ewl_spinner_timer(void *data)
+{
+       Ewl_Spinner    *s;
+       double          dt;
+       double          value, range;
+       int             velocity;
+
+       s = EWL_SPINNER(data);
+
+       dt = ecore_time_get() - s->start_time;
+       value = ewl_spinner_get_value(s);
+       range = s->max_val - s->min_val;
+
+       /*
+        * Check the theme for a velocity setting and bring it within normal
+        * useable bounds.
+        */
+       velocity = ewl_theme_data_get_int(EWL_WIDGET(s), "velocity");
+       if (velocity < 1)
+               velocity = 1;
+       else if (velocity > 10)
+               velocity = 10;
+
+       /*
+        * Move the value of the spinner based on the direction of it's motion
+        * and the velocity setting.
+        */
+       value += ((double)(s->direction) * (1 - exp(-dt)) * 
+                ((double)(velocity) / 100.0)) * range;
+
+       ewl_spinner_set_value(s, value);
+
+       return 1;
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_spinner.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- ewl_spinner.h       18 Mar 2004 06:16:31 -0000      1.22
+++ ewl_spinner.h       16 May 2004 05:48:17 -0000      1.23
@@ -41,6 +41,9 @@
        Ewl_Widget     *entry; /**< The Ewl_Entry displaying value */
        Ewl_Widget     *button_increase; /**< Ewl_Button to add value */
        Ewl_Widget     *button_decrease; /**< Ewl_Button to subtract value */
+       double          start_time; /**< Time the spinner was pressed */
+       int             direction; /**< Indicate increasing/decreasing value */
+       Ecore_Timer    *timer; /**< Timer for tracking mouse button held down */
 };
 
 Ewl_Widget     *ewl_spinner_new(void);
@@ -48,7 +51,9 @@
 void            ewl_spinner_set_value(Ewl_Spinner * s, double value);
 double          ewl_spinner_get_value(Ewl_Spinner * s);
 void            ewl_spinner_set_digits(Ewl_Spinner * s, int digits);
+double          ewl_spinner_get_min_val(Ewl_Spinner * s);
 void            ewl_spinner_set_min_val(Ewl_Spinner * s, double val);
+double          ewl_spinner_get_max_val(Ewl_Spinner * s);
 void            ewl_spinner_set_max_val(Ewl_Spinner * s, double val);
 void            ewl_spinner_set_step(Ewl_Spinner * s, double step);
 
@@ -71,6 +76,8 @@
                                   void *user_data);
 void ewl_spinner_decrease_value_cb(Ewl_Widget * widget, void *ev_data,
                                   void *user_data);
+void ewl_spinner_value_stop_cb(Ewl_Widget * w, void *ev_data, void *user_data);
+void ewl_spinner_destroy_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 
 /**
  * @}




-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to