From a196caf47b556c0171f5a6ba2f497d50f200b9ec Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 07:13:48 +0000 Subject: [PATCH] MCDE dtpaint: image attributes and colour editor (D4) Image > Attributes... (Ctrl+E) asks width and height (1..4096), builds a new pixmap filled with the background, copies the overlap and discards the selection; the resize is a document operation, so undo starts fresh after it. Colors > Edit Colors... opens three RGB scales initialised from the current foreground; OK allocates the colour and updates the fg square. Both dialogs are FormDialogs with OK/Cancel from the catalog; the form size is set after popup so the shell does not shrink to its children. Measured under Xvfb: 640x480 -> 300x300 canvas; Red 255 + OK draws a red line and turns the fg indicator red. --- programs/dtpaint/dtpaint.c | 244 +++++++++++++++++- programs/dtpaint/dtpaint.msg | 11 + .../localized/de_DE.UTF-8/msg/dtpaint.msg | 11 + 3 files changed, 263 insertions(+), 3 deletions(-) diff --git a/programs/dtpaint/dtpaint.c b/programs/dtpaint/dtpaint.c index dfba4baa..20fd0078 100644 --- a/programs/dtpaint/dtpaint.c +++ b/programs/dtpaint/dtpaint.c @@ -46,10 +46,12 @@ #include #include #include +#include #include #include #include #include +#include #include /* dtpaint's message catalog (programs/dtpaint/dtpaint.msg, the locale's copy @@ -143,6 +145,7 @@ static Pixmap selMaskPix, selFloat; static int selPts; static int selPX[SELPT_MAX], selPY[SELPT_MAX]; static Widget clearSelItem; +static Widget attrW, attrH, colRS, colGS, colBS; static int toolsShown = 1, colorsShown = 1, statusShown = 1; static char curPath[512]; static int dirty; @@ -1692,7 +1695,8 @@ SwatchActivate(Widget w, XtPointer data, XtPointer call) enum { C_NEW, C_OPEN, C_SAVE, C_SAVEAS, C_EXIT, C_UNDO, C_CLEAR, C_CLEARSEL, C_SELALL, C_INVERT, C_FLIP, - C_TOOLS, C_COLORS, C_STATUS, C_HELP, C_ABOUT, C_ZNORMAL, C_ZLARGE + C_TOOLS, C_COLORS, C_STATUS, C_HELP, C_ABOUT, C_ZNORMAL, C_ZLARGE, + C_ATTR, C_EDITCOLORS }; enum { A_NEW, A_OPEN, A_EXIT }; @@ -1748,6 +1752,233 @@ ShowInfo(int bodyId, const char *bodyFb, int titleId, const char *titleFb) XtManageChild(d); } +/* ------------------------------------------------- image size and colours */ + +static void +ResizeImage(int nw, int nh) +{ + Pixmap np, ns; + + if (nw < 1 || nh < 1 || nw > 4096 || nh > 4096) + return; + np = XCreatePixmap(dpy, RootWindowOfScreen(scr), (unsigned) nw, + (unsigned) nh, depth); + ns = XCreatePixmap(dpy, RootWindowOfScreen(scr), (unsigned) nw, + (unsigned) nh, depth); + if (np == None || ns == None) { + if (np != None) + XFreePixmap(dpy, np); + if (ns != None) + XFreePixmap(dpy, ns); + return; + } + Deselect(); + XSetForeground(dpy, gc, bgPix); + XFillRectangle(dpy, np, gc, 0, 0, (unsigned) nw, (unsigned) nh); + XCopyArea(dpy, pix, np, gc, 0, 0, + (unsigned) (imgW < nw ? imgW : nw), + (unsigned) (imgH < nh ? imgH : nh), 0, 0); + XFreePixmap(dpy, pix); + XFreePixmap(dpy, snap); + pix = np; + snap = ns; + imgW = nw; + imgH = nh; + XCopyArea(dpy, pix, snap, gc, 0, 0, imgW, imgH, 0, 0); + dirty = 1; + SetCanvasSize(); + Redraw(); +} + +static void +AttrOk(Widget w, XtPointer cd, XtPointer call) +{ + char *sw = XmTextFieldGetString(attrW); + char *sh = XmTextFieldGetString(attrH); + long nw = (sw != NULL) ? strtol(sw, NULL, 10) : 0; + long nh = (sh != NULL) ? strtol(sh, NULL, 10) : 0; + + (void) cd; (void) call; + if (sw != NULL) + XtFree(sw); + if (sh != NULL) + XtFree(sh); + if (nw < 1 || nw > 4096 || nh < 1 || nh > 4096) { + ShowInfo(42, "Width and height must be between 1 and 4096.", + 43, "Attributes"); + return; + } + ResizeImage((int) nw, (int) nh); + DestroyDialog(w, NULL, NULL); +} + +static void +AttrDialog(void) +{ + Widget form = XmCreateFormDialog(top, "attributes", NULL, 0); + Widget shell, lw, lh, buttons, ok, cancel; + XmString s; + char buf[32]; + + if (form == NULL) + return; + shell = XtParent(form); + XtVaSetValues(shell, + XmNtitle, (String) PaintMsg(43, "Attributes"), + XmNwidth, 280, XmNheight, 190, + XmNdeleteResponse, XmDESTROY, + XmNdialogStyle, XmDIALOG_APPLICATION_MODAL, NULL); + + lw = XmCreateLabel(form, "widthLabel", NULL, 0); + s = Msg(40, "Width:"); + XtVaSetValues(lw, XmNlabelString, s, + XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, + XmNtopOffset, 12, XmNleftOffset, 10, NULL); + XmStringFree(s); + XtManageChild(lw); + + attrW = XmCreateTextField(form, "width", NULL, 0); + snprintf(buf, sizeof buf, "%d", imgW); + XmTextFieldSetString(attrW, buf); + XtVaSetValues(attrW, + XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, lw, XmNrightAttachment, XmATTACH_FORM, + XmNtopOffset, 8, XmNleftOffset, 8, XmNrightOffset, 10, NULL); + XtManageChild(attrW); + + lh = XmCreateLabel(form, "heightLabel", NULL, 0); + s = Msg(41, "Height:"); + XtVaSetValues(lh, XmNlabelString, s, + XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, attrW, + XmNleftAttachment, XmATTACH_FORM, + XmNtopOffset, 10, XmNleftOffset, 10, NULL); + XmStringFree(s); + XtManageChild(lh); + + attrH = XmCreateTextField(form, "height", NULL, 0); + snprintf(buf, sizeof buf, "%d", imgH); + XmTextFieldSetString(attrH, buf); + XtVaSetValues(attrH, + XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, attrW, + XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, lh, + XmNrightAttachment, XmATTACH_FORM, + XmNtopOffset, 6, XmNleftOffset, 8, XmNrightOffset, 10, NULL); + XtManageChild(attrH); + + buttons = XmCreateRowColumn(form, "buttons", NULL, 0); + XtVaSetValues(buttons, XmNorientation, XmHORIZONTAL, + XmNpacking, XmPACK_TIGHT, XmNspacing, 8, + XmNbottomAttachment, XmATTACH_FORM, + XmNrightAttachment, XmATTACH_FORM, + XmNbottomOffset, 10, XmNrightOffset, 10, NULL); + ok = XmCreatePushButton(buttons, "ok", NULL, 0); + XtAddCallback(ok, XmNactivateCallback, AttrOk, NULL); + s = Msg(48, "OK"); + XtVaSetValues(ok, XmNlabelString, s, NULL); + XmStringFree(s); + XtManageChild(ok); + cancel = XmCreatePushButton(buttons, "cancel", NULL, 0); + XtAddCallback(cancel, XmNactivateCallback, DestroyDialog, NULL); + s = Msg(49, "Cancel"); + XtVaSetValues(cancel, XmNlabelString, s, NULL); + XmStringFree(s); + XtManageChild(cancel); + XtManageChild(buttons); + XtVaSetValues(form, XmNwidth, 280, XmNheight, 190, + XmNresizePolicy, XmRESIZE_NONE, NULL); + XtManageChild(form); + XtPopup(shell, XtGrabNone); + XtVaSetValues(shell, XmNwidth, 280, XmNheight, 190, NULL); +} + +static void +ColorOk(Widget w, XtPointer cd, XtPointer call) +{ + int r, g, b; + + (void) cd; (void) call; + XmScaleGetValue(colRS, &r); + XmScaleGetValue(colGS, &g); + XmScaleGetValue(colBS, &b); + fgPix = RGBToPixel((unsigned) r, (unsigned) g, (unsigned) b); + ShowColors(); + DestroyDialog(w, NULL, NULL); +} + +static Widget +ColorRow(Widget parent, const char *name, const char *label, int value) +{ + Widget row = XmCreateRowColumn(parent, (char *) name, NULL, 0); + Widget lab, sc; + XmString s = XmStringCreateLocalized((String) label); + + XtVaSetValues(row, XmNorientation, XmHORIZONTAL, XmNspacing, 6, + XmNpacking, XmPACK_TIGHT, NULL); + lab = XmCreateLabel(row, "label", NULL, 0); + XtVaSetValues(lab, XmNlabelString, s, XmNwidth, 55, + XmNrecomputeSize, False, NULL); + XmStringFree(s); + XtManageChild(lab); + sc = XmCreateScale(row, "scale", NULL, 0); + XtVaSetValues(sc, XmNminimum, 0, XmNmaximum, 255, XmNvalue, value, + XmNorientation, XmHORIZONTAL, XmNshowValue, True, + XmNwidth, 220, NULL); + XtManageChild(sc); + XtManageChild(row); + return sc; +} + +static void +ColorDialog(void) +{ + Widget form = XmCreateFormDialog(top, "editcolors", NULL, 0); + Widget shell, rc, buttons, ok, cancel; + XmString s; + unsigned r, g, b; + + if (form == NULL) + return; + shell = XtParent(form); + XtVaSetValues(shell, + XmNtitle, (String) PaintMsg(44, "Edit Colors"), + XmNwidth, 330, XmNheight, 230, + XmNdeleteResponse, XmDESTROY, + XmNdialogStyle, XmDIALOG_APPLICATION_MODAL, NULL); + PixelToRGB(fgPix, &r, &g, &b); + + rc = XmCreateRowColumn(form, "rc", NULL, 0); + XtVaSetValues(rc, XmNorientation, XmVERTICAL, XmNspacing, 8, + XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, + XmNrightAttachment, XmATTACH_FORM, + XmNtopOffset, 12, XmNleftOffset, 12, XmNrightOffset, 12, NULL); + colRS = ColorRow(rc, "red", PaintMsg(45, "Red:"), (int) r); + colGS = ColorRow(rc, "green", PaintMsg(46, "Green:"), (int) g); + colBS = ColorRow(rc, "blue", PaintMsg(47, "Blue:"), (int) b); + + buttons = XmCreateRowColumn(rc, "buttons", NULL, 0); + XtVaSetValues(buttons, XmNorientation, XmHORIZONTAL, + XmNpacking, XmPACK_TIGHT, XmNspacing, 8, NULL); + ok = XmCreatePushButton(buttons, "ok", NULL, 0); + XtAddCallback(ok, XmNactivateCallback, ColorOk, NULL); + s = Msg(48, "OK"); + XtVaSetValues(ok, XmNlabelString, s, NULL); + XmStringFree(s); + XtManageChild(ok); + cancel = XmCreatePushButton(buttons, "cancel", NULL, 0); + XtAddCallback(cancel, XmNactivateCallback, DestroyDialog, NULL); + s = Msg(49, "Cancel"); + XtVaSetValues(cancel, XmNlabelString, s, NULL); + XmStringFree(s); + XtManageChild(cancel); + XtManageChild(buttons); + XtManageChild(rc); + XtVaSetValues(form, XmNwidth, 330, XmNheight, 230, + XmNresizePolicy, XmRESIZE_NONE, NULL); + XtManageChild(form); + XtPopup(shell, XtGrabNone); + XtVaSetValues(shell, XmNwidth, 330, XmNheight, 230, NULL); +} + /* Ask before throwing away unsaved work (New / Open / Exit). */ static void DiscardAnswer(Widget w, XtPointer data, XtPointer call) @@ -1898,6 +2129,12 @@ Command(Widget w, XtPointer data, XtPointer call) case C_ZLARGE: SetZoom(4); break; + case C_ATTR: + AttrDialog(); + break; + case C_EDITCOLORS: + ColorDialog(); + break; case C_HELP: ShowInfo(34, "Pick a tool on the left and a colour below it, then draw on " @@ -2213,9 +2450,10 @@ main(int argc, char **argv) AddItem(m, PaintMsg(17, "Flip Horizontal"), NULL, NULL, C_FLIP, 0, True); AddItem(m, PaintMsg(18, "Invert Colors"), "CtrlI", "Ctrl+I", C_INVERT, 0, True); AddItem(m, PaintMsg(19, "Clear Image"), "Ctrl ShiftN", "Ctrl+Shift+N", C_CLEAR, 0, True); + AddItem(m, NULL, NULL, NULL, 0, 1, True); + AddItem(m, PaintMsg(39, "Attributes..."), "CtrlE", "Ctrl+E", C_ATTR, 0, True); m = AddMenu(menubarW, PaintMsg(5, "Colors")); - /* needs the colour editor (D4); insensitive until it exists */ - AddItem(m, PaintMsg(20, "Edit Colors..."), NULL, NULL, C_ABOUT, 0, False); + AddItem(m, PaintMsg(20, "Edit Colors..."), NULL, NULL, C_EDITCOLORS, 0, True); m = AddMenu(menubarW, PaintMsg(6, "Help")); AddItem(m, PaintMsg(33, "Help Topics"), "CtrlF1", "Ctrl+F1", C_HELP, 0, True); AddItem(m, NULL, NULL, NULL, 0, 1, True); diff --git a/programs/dtpaint/dtpaint.msg b/programs/dtpaint/dtpaint.msg index d566364b..8872bb6b 100644 --- a/programs/dtpaint/dtpaint.msg +++ b/programs/dtpaint/dtpaint.msg @@ -40,3 +40,14 @@ $set 1 36 Large Size 37 Text: 38 Select All +39 Attributes... +40 Width: +41 Height: +42 Width and height must be between 1 and 4096. +43 Attributes +44 Edit Colors +45 Red: +46 Green: +47 Blue: +48 OK +49 Cancel diff --git a/programs/localized/de_DE.UTF-8/msg/dtpaint.msg b/programs/localized/de_DE.UTF-8/msg/dtpaint.msg index 158ef773..8aff9038 100644 --- a/programs/localized/de_DE.UTF-8/msg/dtpaint.msg +++ b/programs/localized/de_DE.UTF-8/msg/dtpaint.msg @@ -41,3 +41,14 @@ $set 1 36 Grosse Darstellung 37 Text: 38 Alles auswaehlen +39 Attribute... +40 Breite: +41 Hoehe: +42 Breite und Hoehe muessen zwischen 1 und 4096 liegen. +43 Attribute +44 Farben bearbeiten +45 Rot: +46 Gruen: +47 Blau: +48 OK +49 Abbrechen