commit 5a6c93269636558e5ac824a2b9897df3158a9d26
parent b8ec173466593611f68bd7da8ab074ffe265169d
Author: glenda <glenda@kobeni>
Date: Mon, 8 Jan 2024 19:23:25 +0000
src/noise: add menu, blank mode
Diffstat:
5 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/src/noise/blank.c b/src/noise/blank.c
@@ -0,0 +1,39 @@
+/* solid color fill scene */
+
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+#include "noise.h"
+
+#include "blank.h"
+
+struct Blank_State {
+ Image *fill;
+} bls;
+
+void blank_init(void *)
+{
+ lockdisplay(display);
+ bls.fill = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DGreen);
+ unlockdisplay(display);
+}
+
+void blank_draw(void *)
+{
+ draw(screen, screen->r, bls.fill, nil, ZP);
+}
+
+void blank_stop(void *)
+{
+ lockdisplay(display);
+ freeimage(bls.fill);
+ unlockdisplay(display);
+}
+
+Scene BlankScene = {
+ "solid filler",
+ blank_init,
+ blank_draw,
+ blank_stop,
+ nil};
diff --git a/src/noise/blank.h b/src/noise/blank.h
@@ -0,0 +1 @@
+extern Scene BlankScene;
diff --git a/src/noise/config.h b/src/noise/config.h
@@ -1,6 +1,8 @@
#include "dnoise.h"
+#include "blank.h"
Scene *plist[] = {
+ &BlankScene,
&DNoiseScene,
nil,
};
diff --git a/src/noise/main.c b/src/noise/main.c
@@ -9,6 +9,10 @@
#include "config.h"
+enum {
+ PlSize = sizeof(plist) / sizeof(Scene *),
+};
+
Scene *cs;
struct FPSWidget {
@@ -46,6 +50,13 @@ procdraw(void *v)
}
}
+char *
+getmenulabel(int n)
+{
+ if (plist[n] == nil) return nil;
+ return plist[n]->name;
+}
+
void
threadmain(int, char **)
{
@@ -59,6 +70,12 @@ threadmain(int, char **)
display->locking = 1;
mctl = initmouse(nil, screen);
+ Menu menu = {
+ nil,
+ getmenulabel,
+ 0
+ };
+
fps.img = allocimage(display, Rect(0, 0, 512, font->height), RGB24, 0, DBlack);
fps.fg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DYellow);
fps.r = fps.img->r;
@@ -79,6 +96,16 @@ threadmain(int, char **)
for (;;) {
switch(alt(alts)) {
case 0: // mouse
+ if (mouse.buttons == 1) {
+ threadkill(dtid);
+ lockdisplay(display);
+ int hit = menuhit(1, mctl, &menu, nil);
+ unlockdisplay(display);
+ if (cs->stop != nil) cs->stop(cs->aux);
+ cs = plist[hit];
+ if (cs->init != nil) cs->init(cs->aux);
+ dtid = proccreate(procdraw, cs, 8 * 1024);
+ }
break;
case 1: // resize
threadkill(dtid);
diff --git a/src/noise/mkfile b/src/noise/mkfile
@@ -2,9 +2,12 @@
TARG=noise
BIN=.
-OFILES=\
- main.$O\
- dnoise.$O\
+# OFILES=\
+# main.$O\
+# dnoise.$O\
+
+CFILES=`{echo *.c}
+OFILES=${CFILES:%.c=%.$O}
HFILES=\
noise.h\