shithub: neindaw

Download patch

ref: d52d4aa3ed87c0b94a953a3b65246a6774c80ae7
parent: b67a151aecb558eeee40f34a6838ebce68b618bf
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Dec 31 23:24:36 EST 2019

split out ui types to use for gui

--- a/aux.h
+++ b/aux.h
@@ -12,19 +12,6 @@
 	Xuimeta,
 }Auxtype;
 
-typedef enum {
-	UITGroup,
-	UIHGroup,
-	UIVGroup,
-	UIButton,
-	UICheckBox,
-	UIVSlider,
-	UIHSlider,
-	UINEntry,
-	UIHBarGraph,
-	UIVBarGraph,
-}UItype;
-
 typedef struct Aux Aux;
 typedef struct Auxdsp Auxdsp;
 typedef struct Meta Meta;
--- /dev/null
+++ b/common.c
@@ -1,0 +1,14 @@
+#include "common.h"
+
+char *uitypenames[UInum] = {
+	[UITGroup] = "tgroup",
+	[UIHGroup] = "hgroup",
+	[UIVGroup] = "vgroup",
+	[UIButton] = "button",
+	[UICheckBox] = "checkbox",
+	[UIVSlider] = "vslider",
+	[UIHSlider] = "hslider",
+	[UINEntry] = "nentry",
+	[UIHBarGraph] = "hbargraph",
+	[UIVBarGraph] = "vbargraph",
+};
--- /dev/null
+++ b/common.h
@@ -1,0 +1,15 @@
+typedef enum {
+	UITGroup,
+	UIHGroup,
+	UIVGroup,
+	UIButton,
+	UICheckBox,
+	UIVSlider,
+	UIHSlider,
+	UINEntry,
+	UIHBarGraph,
+	UIVBarGraph,
+	UInum,
+}UItype;
+
+extern char *uitypenames[UInum];
--- a/fs.c
+++ b/fs.c
@@ -6,6 +6,7 @@
 #include "uiglue.h"
 typedef struct DSP DSP;
 #include "dspf.h"
+#include "common.h"
 #include "aux.h"
 
 enum {
--- a/mkfile
+++ b/mkfile
@@ -5,6 +5,7 @@
 
 BIN=/$objtype/bin/daw
 OFILES=\
+	common.$O\
 	fs.$O\
 	uiglue.$O\
 
--- a/uiglue.c
+++ b/uiglue.c
@@ -4,6 +4,7 @@
 #include <thread.h>
 #include <9p.h>
 #include "uiglue.h"
+#include "common.h"
 #include "aux.h"
 
 static struct {
@@ -15,22 +16,34 @@
 static char *
 ui_readstr(UI *ui, int type, char *s, int sz)
 {
-	char *x;
+	char *x, *t;
 	int i;
 
 	if (type == Xuictl) {
+		if (ui->type < 0 || ui->type >= UInum)
+			sysfatal("unknown ui type %d", ui->type);
+		t = uitypenames[ui->type];
 		switch (ui->type) {
-		case UITGroup: snprint(s, sz, "tgroup\n"); return s;
-		case UIHGroup: snprint(s, sz, "hgroup\n"); return s;
-		case UIVGroup: snprint(s, sz, "vgroup\n"); return s;
-		case UIButton: snprint(s, sz, "button\t%d\n", !!*ui->zone); return s;
-		case UICheckBox: snprint(s, sz, "checkbox\t%d\n", !!*ui->zone); return s;
-		case UIVSlider: snprint(s, sz, "vslider\t%g\t%g\t%g\t%g\t%g\n", *ui->zone, ui->init, ui->min, ui->max, ui->step); return s;
-		case UIHSlider: snprint(s, sz, "hslider\t%g\t%g\t%g\t%g\t%g\n", *ui->zone, ui->init, ui->min, ui->max, ui->step); return s;
-		case UINEntry: snprint(s, sz, "nentry\t%g\t%g\t%g\t%g\t%g\n", *ui->zone, ui->init, ui->min, ui->max, ui->step); return s;
-		case UIHBarGraph: snprint(s, sz, "hbargraph\t%g\t%g\t%g\n", *ui->zone, ui->min, ui->max); return s;
-		case UIVBarGraph: snprint(s, sz, "vbargraph\t%g\t%g\t%g\n", *ui->zone, ui->min, ui->max); return s;
-		default: sysfatal("unknown ui type %d", ui->type);
+		case UITGroup:
+		case UIHGroup:
+		case UIVGroup:
+			snprint(s, sz, "%s\n", t);
+			return s;
+		case UIButton:
+		case UICheckBox:
+			snprint(s, sz, "%s\t%d\n", t, !!*ui->zone);
+			return s;
+		case UIVSlider:
+		case UIHSlider:
+		case UINEntry:
+			snprint(s, sz, "%s\t%g\t%g\t%g\t%g\t%g\n", t, *ui->zone, ui->init, ui->min, ui->max, ui->step);
+			return s;
+		case UIHBarGraph:
+		case UIVBarGraph:
+			snprint(s, sz, "%s\t%g\t%g\t%g\n", t, *ui->zone, ui->min, ui->max);
+			return s;
+		default:
+			sysfatal("readstr not implemented for ui type %d", ui->type);
 		}
 	} else if (type == Xuimeta) {
 		x = s;