paint: change colors in the palette with button 3

This commit is contained in:
Sigrid 2020-05-23 20:41:20 +02:00
parent ec737b6a2e
commit a8e4b50cb2
2 changed files with 20 additions and 1 deletions

View file

@ -13,6 +13,8 @@ displays a canvas upon which can be drawn lines using the mouse holding
down buttons 1 or 2 for foreground or background color. The canvas
may be moved with button 3. Colors and brush sizes may be selected by
clicking on the palette at the bottom of the screen with buttons 1 or 2.
Clicking button 3 on the palette allows changing a color by entering its
hex value.
.PP
If the optional
.I file

View file

@ -515,6 +515,10 @@ drawpal(void)
int
hitpal(Mouse m)
{
int i;
u32int c;
char buf[16], *e;
if(ptinrect(m.xy, penr)){
if(m.buttons & 7){
brush = ((m.xy.x - penr.min.x) * NBRUSH) / Dx(penr);
@ -525,7 +529,8 @@ hitpal(Mouse m)
if(ptinrect(m.xy, palr)){
Image *col;
col = pal[(m.xy.x - palr.min.x) * nelem(pal) / Dx(palr)];
i = (m.xy.x - palr.min.x) * nelem(pal) / Dx(palr);
col = pal[i];
switch(m.buttons & 7){
case 1:
ink = col;
@ -536,6 +541,18 @@ hitpal(Mouse m)
drawpal();
update(nil);
break;
case 4:
snprint(buf, sizeof(buf), "%06x", c64[i]);
if(eenter("Hex", buf, sizeof(buf), &m) == 6){
c = strtoll(buf, &e, 16);
if(*e == 0){
c64[i] = c;
freeimage(pal[i]);
pal[i] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, c<<8|0xff);
drawpal();
}
}
break;
}
return 1;
}