diff gui/ui/main.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 ae4f30c4ef02
line wrap: on
line diff
--- a/gui/ui/main.c	Fri Apr 11 09:34:31 2014 +0000
+++ b/gui/ui/main.c	Sat Apr 12 23:29:29 2014 +0000
@@ -18,6 +18,7 @@
 
 /* main window */
 
+#include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -95,10 +96,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.IndexOfMainItems;i++ )
   if ( ( guiApp.mainItems[i].pressed != btnDisabled )&&
@@ -135,6 +139,13 @@
                   { item->pressed=btnDisabled; }
                  break;
            }*/
+          if ( itemtype == 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;
    case wsRLMouseButton:
           boxMoved=False;
@@ -154,6 +165,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 );
           itemtype=0;
@@ -170,7 +187,7 @@
           if (currentselected != - 1)
            {
             item=&guiApp.mainItems[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 );
@@ -189,6 +206,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;