[MPlayer-cvslog] r37122 - in trunk/gui: app/app.c ui/main.c ui/playbar.c util/misc.c util/misc.h

ib subversion at mplayerhq.hu
Thu Apr 3 13:30:53 CEST 2014


Author: ib
Date: Thu Apr  3 13:30:53 2014
New Revision: 37122

Log:
Constrain an item's value to be in the range of 0 to 100.

Add function contrain() and replace checking the bounds by it.

Add it for mouse wheeling, too, where it has been missing so far.

Modified:
   trunk/gui/app/app.c
   trunk/gui/ui/main.c
   trunk/gui/ui/playbar.c
   trunk/gui/util/misc.c
   trunk/gui/util/misc.h

Modified: trunk/gui/app/app.c
==============================================================================
--- trunk/gui/app/app.c	Thu Apr  3 12:16:01 2014	(r37121)
+++ trunk/gui/app/app.c	Thu Apr  3 13:30:53 2014	(r37122)
@@ -24,6 +24,7 @@
 #include "app.h"
 #include "gui.h"
 #include "gui/skin/font.h"
+#include "gui/util/misc.h"
 
 #include "libavutil/common.h"
 
@@ -190,25 +191,13 @@ void btnModify(int event, float value)
 
     for (i = 0; i <= guiApp.IndexOfMainItems; i++)
         if (guiApp.mainItems[i].message == event)
-            if (hasValue(guiApp.mainItems[i])) {
-                if (value < 0.0f)
-                    value = 0.0f;
-                if (value > 100.0f)
-                    value = 100.0f;
-
-                guiApp.mainItems[i].value = value;
-            }
+            if (hasValue(guiApp.mainItems[i]))
+                guiApp.mainItems[i].value = constrain(value);
 
     for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++)
         if (guiApp.playbarItems[i].message == event)
-            if (hasValue(guiApp.playbarItems[i])) {
-                if (value < 0.0f)
-                    value = 0.0f;
-                if (value > 100.0f)
-                    value = 100.0f;
-
-                guiApp.playbarItems[i].value = value;
-            }
+            if (hasValue(guiApp.playbarItems[i]))
+                guiApp.playbarItems[i].value = constrain(value);
 }
 
 /**

Modified: trunk/gui/ui/main.c
==============================================================================
--- trunk/gui/ui/main.c	Thu Apr  3 12:16:01 2014	(r37121)
+++ trunk/gui/ui/main.c	Thu Apr  3 13:30:53 2014	(r37122)
@@ -32,6 +32,7 @@
 #include "gui/skin/skin.h"
 #include "gui/util/list.h"
 #include "gui/util/mem.h"
+#include "gui/util/misc.h"
 #include "gui/util/string.h"
 #include "gui/wm/ws.h"
 #include "gui/wm/wsxdnd.h"
@@ -171,7 +172,7 @@ rollerhandled:
             item=&guiApp.mainItems[currentselected];
             if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter ) )
              {
-              item->value+=value;
+              item->value=constrain(item->value + value);
               uiEvent( item->message,item->value );
              }
            }
@@ -189,13 +190,12 @@ rollerhandled:
                  if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 );
                  break;
             case itVPotmeter:
-                 item->value=100.0 - 100.0 * ( Y - item->y ) / item->height;
+                 value=100.0 - 100.0 * ( Y - item->y ) / item->height;
                  goto potihandled;
             case itHPotmeter:
-                 item->value=100.0 * ( X - item->x ) / item->width;
+                 value=100.0 * ( X - item->x ) / item->width;
 potihandled:
-                 if ( item->value > 100.0f ) item->value=100.0f;
-                 if ( item->value < 0.0f ) item->value=0.0f;
+                 item->value=constrain(value);
                  uiEvent( item->message,item->value );
                  break;
            }

Modified: trunk/gui/ui/playbar.c
==============================================================================
--- trunk/gui/ui/playbar.c	Thu Apr  3 12:16:01 2014	(r37121)
+++ trunk/gui/ui/playbar.c	Thu Apr  3 13:30:53 2014	(r37122)
@@ -30,6 +30,7 @@
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
 #include "gui/util/mem.h"
+#include "gui/util/misc.h"
 #include "gui/wm/ws.h"
 
 #include "help_mp.h"
@@ -196,7 +197,7 @@ rollerhandled:
           item=&guiApp.playbarItems[currentselected];
           if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter ) )
            {
-            item->value+=value;
+            item->value=constrain(item->value + value);
             uiEvent( item->message,item->value );
            }
          }
@@ -210,13 +211,12 @@ rollerhandled:
                if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 );
                break;
           case itVPotmeter:
-               item->value=100.0 - 100.0 * ( Y - item->y ) / item->height;
+               value=100.0 - 100.0 * ( Y - item->y ) / item->height;
                goto potihandled;
           case itHPotmeter:
-               item->value=100.0 * ( X - item->x ) / item->width;
+               value=100.0 * ( X - item->x ) / item->width;
 potihandled:
-               if ( item->value > 100.0f ) item->value=100.0f;
-               if ( item->value < 0.0f ) item->value=0.0f;
+               item->value=constrain(value);
                uiEvent( item->message,item->value );
                break;
          }

Modified: trunk/gui/util/misc.c
==============================================================================
--- trunk/gui/util/misc.c	Thu Apr  3 12:16:01 2014	(r37121)
+++ trunk/gui/util/misc.c	Thu Apr  3 13:30:53 2014	(r37122)
@@ -47,3 +47,20 @@ char *fgetstr(char *str, int size, FILE 
 
     return s;
 }
+
+/**
+ * @brief Constrain a @a value to be in the range of 0 to 100.
+ *
+ * @param value value to be checked
+ *
+ * @return a value in the range of 0 to 100
+ */
+float constrain(float value)
+{
+    if (value < 0.0f)
+        return 0.0f;
+    if (value > 100.0f)
+        return 100.0f;
+
+    return value;
+}

Modified: trunk/gui/util/misc.h
==============================================================================
--- trunk/gui/util/misc.h	Thu Apr  3 12:16:01 2014	(r37121)
+++ trunk/gui/util/misc.h	Thu Apr  3 13:30:53 2014	(r37122)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+float constrain(float value);
 char *fgetstr(char *str, int size, FILE *file);
 
 #endif /* MPLAYER_GUI_MISC_H */


More information about the MPlayer-cvslog mailing list