shithub: dormer

Download patch

ref: 4ae4cb2ec7d3fecf526b29d98eeb55d374a99dda
parent: 1f1a8bbd7ce97df5e6798b907de931105387a67a
author: glenda <glenda@9front.local>
date: Wed Jan 6 10:44:44 EST 2021

fixing last commit

--- a/canvas.c
+++ b/canvas.c
@@ -21,6 +21,16 @@
 	return c;
 }
 
+static void
+tilesprite(Sprite *s)
+{
+	Image *im = s->image;
+	int x = im->r.max.x / s->tnum;
+	int y = im->r.max.y;
+	int n = s->tile;
+	replclipr(im, 1, Rect((n-1)*x,0,n*x,y));
+}
+
 void
 present(void)
 {
@@ -30,8 +40,12 @@
 
 	int i;
 	for(i=0;i<vs.canvas->si;++i){
+		tilesprite(&vs.canvas->spritev[i]);
 		Point p = {vs.canvas->spritev[i].x, vs.canvas->spritev[i].y};
-		draw(screen, rectaddpt(screen->r, p), vs.canvas->spritev[i].image, 0, ZP);
+		Rectangle r = Rect(0,0,800,600);
+		/* This is to be fixed. */
+		r = rectaddpt(r, screen->r.min);
+		draw(screen, rectaddpt(r, p), vs.canvas->spritev[i].image, 0, ZP);
 	}
 	for(i=0;i<vs.canvas->ti;++i){
 		Point p = {vs.canvas->textv[i].x, vs.canvas->textv[i].y};
--- a/dormer.h
+++ b/dormer.h
@@ -29,6 +29,8 @@
 {
 	void *image;
 	int x, y;
+	int tnum;
+	int tile;
 };
 
 struct Text
@@ -52,8 +54,8 @@
 
 extern void present(void);
 extern Canvas *canvas(int sn, int tn, long fgcol);
-extern Sprite *mksprite(Canvas *c, char *path);
-extern void mvsprite(Sprite *s, int x, int y);
+extern Sprite *mksprite(Canvas *c, char *path, int tnum);
+extern void mvsprite(Sprite *s, int x, int y, int tile);
 extern Text *mktext(Canvas *c, char *str, char *ft, int x, int y, long bgcol);
 
 
--- a/sprite.c
+++ b/sprite.c
@@ -5,16 +5,19 @@
 #include "dormer.h"
 
 Sprite*
-mksprite(Canvas *c, char *path)
+mksprite(Canvas *c, char *path, int tnum)
 {
 	c->spritev[c->si].image = readimage(display, open(path, OREAD), 0);
+	c->spritev[c->si].tnum = tnum;
 	Sprite *s = &c->spritev[c->si++];
 	return s;
 }
 
 void
-mvsprite(Sprite *s, int x, int y)
+mvsprite(Sprite *s, int x, int y, int tile)
 {
-	s->x = x;
+	Image *im = s->image;
+	s->tile = tile;
+	s->x = x - (s->tile-1)*(im->r.max.x / s->tnum);
 	s->y = y;
 }
--- a/test.c
+++ b/test.c
@@ -3,33 +3,50 @@
 #include <draw.h>
 #include <event.h>
 #include <keyboard.h>
+#include <cursor.h>
 #include "dormer.h"
 
-/* TODO: resize and rotate sprites,
- *		 handle rgba,
+/* TODO: transform sprites,
  *		 play audio,
  *		 timer (?),
  *		 animate sprites
+ *		 set cursor
+ *		 change text
  */
 
+Cursor reading = {
+	{-1, -1},
+	{0x0, 0x80, 0xff, 0x80, 0xff, 0x00, 0xfe, 0x00, 
+	 0xff, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xef, 0xe0, 
+	 0xc7, 0xf0, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0xc0, 
+	 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, },
+	{0x00, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x7c, 0x00, 
+	 0x7e, 0x00, 0x7f, 0x00, 0x6f, 0x80, 0x74, 0xc0, 
+	 0x03, 0xe0, 0x01, 0xf0, 0x00, 0xe0, 0x00, 0x40, 
+	 0x00, 0x00, 0x01, 0xb6, 0x01, 0xb6, 0x90, 0x00, }
+};
+
+int tile = 1;
+
 void
 main()
 {
-	int y = 300;
-
 	winit();
 
 	Canvas *c = canvas(3, 2, DBlue);
-	Sprite *black = mksprite(c, "res/glenda4.im");
-	Sprite *white = mksprite(c, "res/glenda.im");
-	Sprite *space = mksprite(c, "res/glenda3.im");
-	mvsprite(black, 100, 100);
-	mvsprite(white, 200, y--);
-	mvsprite(space, 400, 100);
+	Sprite *black = mksprite(c, "res/anim.im", 9);
+	Sprite *white = mksprite(c, "res/glenda4.im", 3);
+	Sprite *space = mksprite(c, "res/flower.im", 1);
+	mvsprite(black, 100, 100, tile);
+	mvsprite(white, 500, 500, 2);
+	mvsprite(space, 400, 100, 1);
 
 	mktext(c, "helo rofik", "/lib/font/bit/lucidasans/unicode.7.font", 100, 100, DRed);
 	mktext(c, "second", "/lib/font/bit/lucidasans/unicode.7.font", 0, 0, DTransparent);
 
+
+	esetcursor(&reading);
+
 	present();
 
 	for(;;){
@@ -45,7 +62,9 @@
 				exits(0);
 			}
 			if(dm.key == 'w'){
-				mvsprite(white, 200, y--);
+				if(tile >= 9) tile = 1;
+				mvsprite(black, 100, 100, ++tile);
+				print("screen->r.min: (%d,%d)\n", screen->r.min.x, screen->r.min.y);
 				present();
 			}
 			break;