shithub: cursedfs

Download patch

ref: b0e0ff38a15e54a4763831d94543dffa1341f417
parent: ba9a4254b691e9cdd6b06dcb33fd2f36eb4703cb
author: henesy <[email protected]>
date: Fri Mar 11 02:22:13 EST 2022

blank screen

--- a/screen.c
+++ b/screen.c
@@ -1,12 +1,3 @@
-/*
- * Ball - a first attempt at Plan 9 graphics programming
- * Author:	nspool
- * Date:	2013-02-19
- * Licence: MIT
- * /
-
-/* Build with '8c -FTVw ball.c && 8l -o ball ball.8' */
-
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
@@ -20,6 +11,9 @@
 Image *ball;
 
 Point p;
+Font *ourfont;
+Image *brush;
+Rune *s = L"☺☹σπß";
 
 /* Menus */
 char *buttons[] = {"exit", 0};
@@ -39,18 +33,27 @@
 void
 moveball()
 {
-	static Point bp={6, 6}; /* Ball Position */
+	/*
+	static Point bp={6, 6}; // Ball Position 
 	static double Δi=4, Δj=4;
 
-	/* Collision detection */
+	// Collision detection 
 	if(bp.x > p.x - (r*3) || bp.x < -r) Δi = Δi*-1;
 	if(bp.y > p.y - (r*3) || bp.y < -r) Δj = Δj*-1;
 	
-	/* Increment ball position */
+	// Increment ball position 
 	bp.x = bp.x + Δi;
 	bp.y = bp.y + Δj;
 
 	draw(screen, rectaddpt(screen->r, bp), ball, nil, ZP);
+	*/
+
+
+	Point out = runestring(
+			screen, p, display->black, ZP,
+		    ourfont, s
+	);
+	flushimage(display, 1);
 }
 
 
@@ -73,6 +76,33 @@
 }
 
 
+// Center font rendering at a point?
+// from faces(1)
+/*
+void
+center(Font *f, Point p, char *s, Image *color)
+{
+	int i, n, dx;
+	Rune rbuf[32];
+	char sbuf[32*UTFmax+1];
+
+	dx = stringwidth(f, s);
+	if(dx > Facesize){
+		n = torune(rbuf, s, nelem(rbuf));
+		for(i=0; i<n; i++){
+			dx = runestringnwidth(f, rbuf, i+1);
+			if(dx > Facesize)
+				break;
+		}
+		sprint(sbuf, "%.*S", i, rbuf);
+		s = sbuf;
+		dx = stringwidth(f, s);
+	}
+	p.x += (Facesize-dx)/2;
+	string(screen, p, color, ZP, f, s);
+}
+*/
+
 /* Draw red ball inside a square of white background
  * When ball is drawn at new position, background will
  * blot out the previous image */
@@ -80,11 +110,24 @@
 void
 initball()
 {
-	Image *brush;
-	brush=allocimage(display, Rect(0,0,1,1), CMAP8, 1, DRed);
+	Point out;
+	ourfont = openfont(display, "/lib/font/bit/vga/unicode.font");
+
+	p = runestringsize(ourfont, s);
+
+	//brush = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlack);
+	out = runestring(
+			screen, p, display->black, ZP,
+		    ourfont, s
+	);
+	flushimage(display, 1);
+	//sysfatal("%d %d\n", p.x, p.y);
+
+	/*
 	ball=allocimage(display, (Rectangle){(Point){0,0},(Point){r*4,r*4}},
 			screen->chan, 0, DWhite);
 	fillellipse(ball, (Point){r*2,r*2}, r, r, brush, ZP);
+	*/
 }
 
 
@@ -124,7 +167,7 @@
 
 		if( (e == Emouse) &&
 			(ev.mouse.buttons & 4) && 
-			(emenuhit(3, &ev.mouse, &menu) == 0)) exits(nil);
+			(emenuhit(3, &ev.mouse, &menu) == 0)) threadexitsall(nil);
 		else 
 			if(e == timer)
 				moveball();