shithub: riscv

Download patch

ref: cb3fdfb70fef1a06e902e1993e9f09774acc4238
parent: cbb83c4fcee19d89d7b4927dcad734af02d24f24
author: stanley lieber <[email protected]>
date: Mon Feb 27 15:15:37 EST 2012

paint: open existing files for editing

--- a/sys/man/1/paint
+++ b/sys/man/1/paint
@@ -3,7 +3,7 @@
 .SH NAME
 paint \- create image files by drawing with a mouse or other pointing device
 .SH SYNOPSIS
-.B paint
+.B paint [file]
 .SH DESCRIPTION
 .I Paint
 provides a window upon which can be drawn lines by moving the cursor while
@@ -24,6 +24,9 @@
 .TP
 .B c
 Clear the screen. Any unsaved work will be lost.
+.TP
+.B o
+Open a bitmap image file for editing.
 .TP
 .B s
 Save the current screen as a bitmap image. A pop-up box appears
--- a/sys/src/cmd/paint.c
+++ b/sys/src/cmd/paint.c
@@ -10,6 +10,22 @@
 		sysfatal("resize failed");
 }
 
+void
+loadimg(char *name)
+{
+	Image *b;
+	int fd;
+
+	fd=open(name, OREAD);
+	if(fd==-1)
+		sysfatal("can't open file");
+	if((b=readimage(display, fd, 0)) == nil)
+		sysfatal("can't read image");
+	draw(screen, screen->r, b, 0, b->r.min);
+	flushimage(display, 1);
+	close(fd);
+}
+
 /* stolen from mothra */
 void
 screendump(char *name, int full)
@@ -35,7 +51,7 @@
 }
 
 void
-main()
+main(int argc, char *argv[])
 {
 	Event e;
 	Point last;
@@ -52,6 +68,23 @@
 	einit(Emouse | Ekeyboard);
 	draw(screen, screen->r, display->white, 0, ZP);
 	flushimage(display, 1);
+
+	ARGBEGIN{
+	default:
+		goto Usage;
+	}ARGEND
+	switch(argc){
+	default:
+	Usage:
+		fprint(2, "Usage: [file]\n");
+		exits("usage");
+	case 0:
+		break;
+	case 1:
+		loadimg(argv[0]);
+		break;
+	}
+
 	while(1){
 		switch(event(&e)){
 		case Emouse:
@@ -79,6 +112,11 @@
 			}
 			if(e.kbdc == 'c')
 				draw(screen, screen->r, display->white, 0, ZP);
+			if(e.kbdc == 'o'){
+				if(eenter("Open file", file, sizeof(file), &e.mouse) <= 0)
+					break;
+				loadimg(file);
+			}
 			if(e.kbdc == 'q')
 				exits(nil);
 			if(e.kbdc == 's'){