summaryrefslogtreecommitdiff
path: root/menuitems.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2009-05-03 14:15:21 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2009-05-03 14:15:21 +0200
commitf161d1b2fe69d4fcfac37581fa60b5d9ce5ded11 (patch)
treeff65b9bcb3041e0733ebb1c59bac1203002c5903 /menuitems.c
parent34b3d467849d0e8192c9cfbd65a630973f602863 (diff)
downloadvdr-f161d1b2fe69d4fcfac37581fa60b5d9ce5ded11.tar.gz
vdr-f161d1b2fe69d4fcfac37581fa60b5d9ce5ded11.tar.bz2
OSD sizes in percent; automatic update of OSD size
Diffstat (limited to 'menuitems.c')
-rw-r--r--menuitems.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/menuitems.c b/menuitems.c
index 6702384c..df14b10d 100644
--- a/menuitems.c
+++ b/menuitems.c
@@ -4,11 +4,12 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: menuitems.c 2.3 2009/04/05 10:15:12 kls Exp $
+ * $Id: menuitems.c 2.4 2009/05/03 13:37:55 kls Exp $
*/
#include "menuitems.h"
#include <ctype.h>
+#include <math.h>
#include <wctype.h>
#include "i18n.h"
#include "plugin.h"
@@ -200,6 +201,71 @@ eOSState cMenuEditNumItem::ProcessKey(eKeys Key)
return state;
}
+// --- cMenuEditPrcItem ------------------------------------------------------
+
+cMenuEditPrcItem::cMenuEditPrcItem(const char *Name, double *Value, double Min, double Max, int Decimals)
+:cMenuEditItem(Name)
+{
+ value = Value;
+ min = Min;
+ max = Max;
+ decimals = Decimals;
+ factor = 100;
+ while (Decimals-- > 0)
+ factor *= 10;
+ if (*value < min)
+ *value = min;
+ else if (*value > max)
+ *value = max;
+ Set();
+}
+
+void cMenuEditPrcItem::Set(void)
+{
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%.*f", decimals, *value * 100);
+ SetValue(buf);
+}
+
+eOSState cMenuEditPrcItem::ProcessKey(eKeys Key)
+{
+ eOSState state = cMenuEditItem::ProcessKey(Key);
+
+ if (state == osUnknown) {
+ double newValue = round(*value * factor); // avoids precision problems
+ Key = NORMALKEY(Key);
+ switch (Key) {
+ case kNone: break;
+ case k0 ... k9:
+ if (fresh) {
+ newValue = 0;
+ fresh = false;
+ }
+ newValue = newValue * 10 + (Key - k0);
+ break;
+ case kLeft: // TODO might want to increase the delta if repeated quickly?
+ newValue--;
+ fresh = true;
+ break;
+ case kRight:
+ newValue++;
+ fresh = true;
+ break;
+ default:
+ if (*value < min) { *value = min; Set(); }
+ if (*value > max) { *value = max; Set(); }
+ return state;
+ }
+ newValue /= factor;
+ if (newValue != *value && (!fresh || min <= newValue) && newValue <= max) {
+ *value = newValue;
+ Set();
+ }
+ state = osContinue;
+ }
+ return state;
+}
+
// --- cMenuEditChrItem ------------------------------------------------------
cMenuEditChrItem::cMenuEditChrItem(const char *Name, char *Value, const char *Allowed)