ref: 37d050563f02063f183566ee75c767da1e4e70be
parent: 2334bbcfe1b0137c8e271bc9d14f18f5d29132ae
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Aug 9 12:55:27 EDT 2024
p9image: adds first tool UI
--- a/blie.c
+++ b/blie.c
@@ -299,17 +299,12 @@
m->xy = subpt(m->xy, panels.tools->r.min);
if (estate.ed->toolinput)
n = estate.ed->toolinput(estate.l, Emouse, ev);
- switch (n) {
- case Rdrawing:
+ if (n & Rdrawing) {
setdrawingdirty(Dcontent);
redrawdrawing();
- break;
- case Rtools:
+ }
+ if (n & Rtools) {
redrawtools();
- break;
- case 3:
- redraw(0);
- break;
}
return;
}
@@ -317,17 +312,12 @@
m->xy = subpt(m->xy, panels.drawing->r.min);
if (estate.ed->drawinput)
n = estate.ed->drawinput(estate.l, Emouse, ev);
- switch (n) {
- case Rdrawing:
+ if (n & Rdrawing) {
setdrawingdirty(Dcontent);
redrawdrawing();
- break;
- case Rtools:
+ }
+ if (n & Rtools) {
redrawtools();
- break;
- case 3:
- redraw(0);
- break;
}
esetcursor(dstate.cursor);
drawcursor(xy, 0);
@@ -441,6 +431,7 @@
if (!headless)
if (initdraw(nil, nil, "blie") < 0)
sysfatal("initdraw: %r");
+ initvdata();
loadeditors();
if (!loadfile())
@@ -453,7 +444,6 @@
einit(Emouse|Ekeyboard);
- initvdata();
estate.ed = nil;
estate.l = nil;
screeninit();
--- a/p9image.c
+++ b/p9image.c
@@ -18,6 +18,8 @@
0x40, 0x02, 0x40, 0x02, 0x7f, 0xfe, 0x00, 0x00}
};
+Point toolcell;
+
typedef struct Data Data;
struct Data {
Memimage *img;
@@ -102,6 +104,8 @@
tstate.mode = Composite;
tstate.drawtarget = DTimg;
+ toolcell = Pt(15, vdata.fontheight + 4);
+
if (headless)
return;
@@ -238,9 +242,31 @@
}
static void
+drcells(Image *i, Point p, char *s, int hl)
+{
+ Rectangle r;
+ r.min = p;
+ r.max = addpt(p, toolcell);
+ border(i, r, 1, vdata.gray, ZP);
+ if (hl) {
+ r = insetrect(r, 2);
+ draw(i, r, vdata.gray, nil, ZP);
+ }
+ string(i, addpt(p, Pt(2, 2)), display->black, ZP, font, s);
+}
+
+static void
p9drawtools(Layer *l, Image *i)
{
- draw(i, insetrect(i->r, 5), display->white, nil, ZP);
+ Point p;
+ p = i->r.min;
+ draw(i, i->r, display->white, nil, ZP);
+
+ drcells(i, p, "C", tstate.mode == Composite);
+ p.x += toolcell.x;
+ drcells(i, p, "S", tstate.mode == Img);
+ p.x += toolcell.x;
+ drcells(i, p, "M", tstate.mode == Mask);
}
static int
@@ -316,23 +342,23 @@
if (!ev.mouse.buttons)
return Rnil;
- switch (ev.mouse.xy.x / 50) {
- case 0:
- tstate.mode = Composite;
- tstate.drawtarget = DTimg;
- break;
- case 1:
- tstate.mode = Img;
- tstate.drawtarget = DTimg;
- break;
- case 2:
- tstate.mode = Mask;
- tstate.drawtarget = DTmask;
- break;
- default:
- return Rnil;
+ if (ev.mouse.xy.y / toolcell.y == 0) {
+ switch (ev.mouse.xy.x / toolcell.x) {
+ case 0:
+ tstate.mode = Composite;
+ tstate.drawtarget = DTimg;
+ return Rdrawing|Rtools;
+ case 1:
+ tstate.mode = Img;
+ tstate.drawtarget = DTimg;
+ return Rdrawing|Rtools;
+ case 2:
+ tstate.mode = Mask;
+ tstate.drawtarget = DTmask;
+ return Rdrawing|Rtools;
+ }
}
- return Rdrawing;
+ return Rnil;
}
Editor p9image = {