summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstanley lieber <stanley.lieber@gmail.com>2012-02-27 20:15:37 -0600
committerstanley lieber <stanley.lieber@gmail.com>2012-02-27 20:15:37 -0600
commitcb3fdfb70fef1a06e902e1993e9f09774acc4238 (patch)
treed3f64ae677fa4819fe0d402fd514370aa206e99b
parentcbb83c4fcee19d89d7b4927dcad734af02d24f24 (diff)
paint: open existing files for editing
-rw-r--r--sys/man/1/paint5
-rw-r--r--sys/src/cmd/paint.c40
2 files changed, 43 insertions, 2 deletions
diff --git a/sys/man/1/paint b/sys/man/1/paint
index 54959cb53..27bc0bc7e 100644
--- 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
@@ -25,6 +25,9 @@ in the pop-up box and hit enter.
.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
suggesting a default filename of
diff --git a/sys/src/cmd/paint.c b/sys/src/cmd/paint.c
index f09a597c0..46c89608f 100644
--- a/sys/src/cmd/paint.c
+++ b/sys/src/cmd/paint.c
@@ -10,6 +10,22 @@ eresized(int)
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 @@ screendump(char *name, int full)
}
void
-main()
+main(int argc, char *argv[])
{
Event e;
Point last;
@@ -52,6 +68,23 @@ main()
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 @@ main()
}
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'){