9front - general discussion about 9front
 help / color / mirror / Atom feed
* [PATCH] games/blit: render screen from top to bottom rather than around center
@ 2017-04-14 14:08 Tony Kaku
  0 siblings, 0 replies; only message in thread
From: Tony Kaku @ 2017-04-14 14:08 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

It makes more sense to favor showing the top of the screen than the
middle when the enclosing window's dimensions are smaller than
800x1024.

The cursors' alignment is still kinda wonky, but you can make them
align by moving the host cursor outside the window and moving it back
in through the top left corner.

Also added -m flag for easier keeping track of cursor alignment.

tkk


[-- Attachment #2: blit.patch --]
[-- Type: text/x-patch, Size: 2165 bytes --]

diff -r f1b3bbf7c96b sys/src/games/blit/blit.c
--- a/sys/src/games/blit/blit.c	Tue Apr 11 02:26:39 2017 +0200
+++ b/sys/src/games/blit/blit.c	Fri Apr 14 15:57:12 2017 +0200
@@ -10,7 +10,6 @@
 
 int baud = 40000;
 int scale = 1;
-Rectangle picr;
 Image *tmp, *bg;
 Channel *keych, *uartrxch, *uarttxch;
 Mousectl *mc;
@@ -26,10 +25,6 @@
 static void
 screeninit(void)
 {
-	Point p;
-
-	p = divpt(addpt(screen->r.min, screen->r.max), 2);
-	picr = (Rectangle){subpt(p, Pt(scale * SX/2, scale * SY/2)), addpt(p, Pt(scale * SX/2, scale * SY/2))};
 	if(tmp != nil) freeimage(tmp);
 	tmp = allocimage(display, Rect(0, 0, scale * SX, scale > 1 ? 1 : scale * SY), CHAN1(CMap, 1), scale > 1, 0);
 	if(bg != nil) freeimage(bg);
@@ -56,9 +51,9 @@
 		screeninit();
 	}
 	while(nbrecv(mc->c, &m) > 0){
-		if(ptinrect(m.xy, picr)){
-			mousex = picr.max.x - m.xy.x - 1;
-			mousey = picr.max.y - m.xy.y - 1;
+		if(ptinrect(m.xy, screen->r)){
+			mousex = screen->r.max.x - m.xy.x - 1;
+			mousey = screen->r.max.y - m.xy.y - 1;
 		}
 		n = m.buttons >> 2 & 1 | m.buttons & 2 | m.buttons << 2 & 4;
 		if(n != mousebut){
@@ -88,10 +83,10 @@
 
 	loadimage(tmp, r, pic+o, Dy(r)*(SX/8));
 	if(realcolors){
-		draw(screen, rectaddpt(r, picr.min), colfg, nil, r.min);
-		draw(screen, rectaddpt(r, picr.min), colbg, tmp, r.min);
+		draw(screen, rectaddpt(r, screen->r.min), colfg, nil, r.min);
+		draw(screen, rectaddpt(r, screen->r.min), colbg, tmp, r.min);
 	}else
-		draw(screen, rectaddpt(r, picr.min), tmp, nil, r.min);
+		draw(screen, rectaddpt(r, screen->r.min), tmp, nil, r.min);
 	updated = Rect(SX, SY, 0, 0);
 	flushimage(display, 1);
 }
@@ -157,12 +152,13 @@
 void
 threadmain(int argc, char **argv)
 {
-	int n;
+	int n, ms;
 	static Cursor blank;
 	char *telnet;
 	char *p;
 	extern int diag;
 	
+	ms = 0;
 	telnet = nil;
 	ARGBEGIN{
 	case 'b':
@@ -184,6 +180,9 @@
 	case 'd':
 		diag++;
 		break;
+	case 'm':
+		ms++;
+		break;
 	default: usage();
 	}ARGEND;
 	if(argc != 0) usage();
@@ -201,7 +200,8 @@
 	mc = initmouse(nil, screen);
 	if(mc == nil)
 		sysfatal("initmouse: %r");
-	setcursor(mc, &blank);
+	if(ms == 0)
+		setcursor(mc, &blank);
 
 	cpureset();
 	for(;;){

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-14 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-14 14:08 [PATCH] games/blit: render screen from top to bottom rather than around center Tony Kaku

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).