~ft/picker

72a65f4596a41a569ef02852c9ab638d6329a481 — Sigrid Haflínudóttir a month ago ffb97ab
add "revert" and "revert all" to menu
1 files changed, 39 insertions(+), 15 deletions(-)

M picker.c
M picker.c => picker.c +39 -15
@@ 33,6 33,7 @@ struct Color {
	Image *i;
	double v[4];
	double rgba[4];
	double rgba0[4]; /* that's for reverting back to the original */
	Rectangle r;
	u32int u;
	int nchan;


@@ 115,7 116,7 @@ static Space spaces[] = {
	},
};

static char *menu2i[nelem(spaces)+4];
static char *menu2i[nelem(spaces)+6];
static Menu menu2 = { .item = menu2i };

static Color *colors, *color, *last;


@@ 409,6 410,7 @@ readcolors(void *x)
				free(c->id);
				new->prev = c->prev;
				new->next = c->next;
				memmove(new->rgba0, c->rgba0, sizeof(new->rgba0));
				memmove(c, new, sizeof(*c));
				break;
			}


@@ 416,6 418,7 @@ readcolors(void *x)

		if (c == nil) {
			c = new;
			memmove(c->rgba0, c->rgba, sizeof(c->rgba));
			if (last != nil)
				last->next = new;
			new->prev = last;


@@ 487,7 490,7 @@ threadmain(int argc, char **argv)
		[Cloaded] = { nil, nil, CHANRCV },
		{ nil, nil, CHANEND },
	};
	int i, oldbuttons, slider;
	int i, oldbuttons, slider, menusnarf, menusnarfall, menurevert, menurevertall, menuexit;
	ulong u;
	char buf[16];



@@ 523,9 526,11 @@ threadmain(int argc, char **argv)

	for (i = 0; i < nelem(spaces); i++)
		menu2i[i] = spaces[i].name;
	menu2i[i++] = "snarf";
	menu2i[i++] = "snarf all";
	menu2i[i] = "exit";
	menu2i[menusnarf = i++] = "snarf";
	menu2i[menusnarfall = i++] = "snarf all";
	menu2i[menurevert = i++] = "revert";
	menu2i[menurevertall = i++] = "revert all";
	menu2i[menuexit = i] = "exit";

	if (initdraw(nil, nil, "picker") < 0)
		sysfatal("initdraw: %r");


@@ 610,7 615,7 @@ changed:
					}
				}
			} else if (m.buttons == 4 && (i = menuhit(3, mctl, &menu2, nil)) >= 0) {
				if (i == nelem(spaces)+2)
				if (i == menuexit)
					goto end;
				if (i < nelem(spaces)) {
					space = &spaces[i];


@@ 618,15 623,34 @@ changed:
					for (i = 0; i < 3; i++)
						c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
					goto changed;
				}

				int f;
				if ((f = open("/dev/snarf", OWRITE)) >= 0) {
					if (i == nelem(spaces))
						write(f, hex, strlen(hex));
					else
						dump(f);
					close(f);
				} else if (i == menusnarf || i == menusnarfall) {
					int f;
					if ((f = open("/dev/snarf", OWRITE)) >= 0) {
						if (i == menusnarf)
							write(f, hex, strlen(hex));
						else
							dump(f);
						close(f);
					}
				} else if (i == menurevert) {
					space->fromrgb(c->rgba0, c->v);
					goto changed;
				} else if (i == menurevertall) {
					for (c = colors; c != nil; c = c->next) {
						memmove(c->rgba, c->rgba0, sizeof(c->rgba));
						space->fromrgb(c->rgba, c->v);
						space->torgb(c->v, c->rgba);
						u = rgba2u(c->rgba);
						if (c->u != u) {
							c->u = u;
							if (!once)
								printcolor(1, c);
							freeimage(c->i);
							c->i = nil;
						}
					}
					redraw();
					break;
				}
			} else if (m.buttons == 2) {
				strcpy(buf, hex);