diff gui/ui/playbar.c @ 37053:84c93a60ead3

Add new item 'rpotmeter'. This is the missing counterpart to hpotmeter and vpotmeter allowing rotary control elements in a GUI skin now. Based on an idea and a realization by Hans-Dieter Kosch, hdkosch kabelbw de. Additionally, update (and revise) documentation.
author ib
date Sat, 12 Apr 2014 23:29:29 +0000
parents 2ef6693131f7
children
line wrap: on
line diff
--- a/gui/ui/playbar.c	Fri Apr 11 09:34:31 2014 +0000
+++ b/gui/ui/playbar.c	Sat Apr 12 23:29:29 2014 +0000
@@ -18,6 +18,7 @@
 
 /* playbar window */
 
+#include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -123,10 +124,13 @@
  static int     itemtype = 0;
         int     i;
         guiItem * item = NULL;
+ static double  prev_point;
+        double  point;
         float   value = 0.0f;
 
  static int     SelectedItem = -1;
         int     currentselected = -1;
+ static int     endstop;
 
  for ( i=0;i <= guiApp.IndexOfPlaybarItems;i++ )
    if ( ( guiApp.playbarItems[i].pressed != btnDisabled )&&
@@ -162,6 +166,12 @@
                  ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) )
                  { item->pressed=btnDisabled; }
                break;
+          case itRPotmeter:
+               prev_point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint;
+               if ( prev_point < 0.0 ) prev_point+=2*M_PI;
+               if ( prev_point <= item->arclength ) endstop=False;
+               else endstop=STOPPED_AT_0 + STOPPED_AT_100;   // block movement
+               break;
          }
 
         break;
@@ -183,6 +193,12 @@
           case itVPotmeter:
                value=100.0 - 100.0 * ( Y - item->y ) / item->height;
                break;
+          case itRPotmeter:
+               if ( endstop ) { itemtype=0; return; }
+               point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint;
+               if ( point < 0.0 ) point+=2*M_PI;
+               value=100.0 * point / item->arclength;
+               break;
          }
         uiEvent( item->message,value );
 
@@ -195,7 +211,7 @@
         if (currentselected != - 1)
          {
           item=&guiApp.playbarItems[currentselected];
-          if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter ) )
+          if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itRPotmeter ) )
            {
             item->value=constrain(item->value + value);
             uiEvent( item->message,item->value );
@@ -210,6 +226,45 @@
           case itPRMButton:
                if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 );
                break;
+          case itRPotmeter:
+               point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint;
+               if ( point < 0.0 ) point+=2*M_PI;
+               if ( item->arclength < 2 * M_PI )
+               /* a potmeter with separated 0% and 100% positions */
+                {
+                 value=item->value;
+                 if ( point - prev_point > M_PI )
+                 /* turned beyond the 0% position */
+                  {
+                   if ( !endstop )
+                    {
+                     endstop=STOPPED_AT_0;
+                     value=0.0f;
+                    }
+                  }
+                 else if ( prev_point - point > M_PI )
+                 /* turned back from beyond the 0% position */
+                  {
+                   if ( endstop == STOPPED_AT_0 ) endstop=False;
+                  }
+                 else if ( prev_point <= item->arclength && point > item->arclength )
+                 /* turned beyond the 100% position */
+                  {
+                   if ( !endstop )
+                    {
+                     endstop=STOPPED_AT_100;
+                     value=100.0f;
+                    }
+                  }
+                 else if ( prev_point > item->arclength && point <= item->arclength )
+                 /* turned back from beyond the 100% position */
+                  {
+                   if ( endstop == STOPPED_AT_100 ) endstop=False;
+                  }
+                }
+               if ( !endstop ) value=100.0 * point / item->arclength;
+               prev_point=point;
+               goto potihandled;
           case itVPotmeter:
                value=100.0 - 100.0 * ( Y - item->y ) / item->height;
                goto potihandled;