mirror of
https://github.com/gryf/wmaker.git
synced 2026-04-20 15:21:27 +02:00
Updated/fixed version of colorpanel
This commit is contained in:
+1
-1
@@ -955,7 +955,7 @@ void WMShowColorPanel(WMColorPanel *panel);
|
||||
|
||||
void WMCloseColorPanel(WMColorPanel *panel);
|
||||
|
||||
void WMSetColorPanelColor(WMColorPanel *panel, RColor color);
|
||||
void WMSetColorPanelColor(WMColorPanel *panel, WMColor *color);
|
||||
|
||||
RColor WMGetColorPanelColor(WMColorPanel *panel);
|
||||
|
||||
|
||||
+138
-74
@@ -11,7 +11,7 @@
|
||||
* and similair code-issues
|
||||
* Marco van Hylckama-Vlieg : For once again doing the artwork ;-)
|
||||
*
|
||||
* small note: Tabstop size = 8
|
||||
* small note: Tabstop size = 4
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -324,8 +324,6 @@ WMSetColorPanelAction(WMColorPanel *panel, WMAction *action, void *data)
|
||||
panel->clientData = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static WMColorPanel*
|
||||
makeColorPanel(WMScreen *scrPtr, char *name)
|
||||
{
|
||||
@@ -350,6 +348,7 @@ makeColorPanel(WMScreen *scrPtr, char *name)
|
||||
WMSetWindowTitle(panel->win, "Colors");
|
||||
WMSetWindowCloseAction(panel->win, closeWindowCallback, panel);
|
||||
|
||||
|
||||
/* Set Default ColorPanel Mode(s) */
|
||||
panel->mode = WMWheelModeColorPanel;
|
||||
panel->lastChanged = WMWheelModeColorPanel;
|
||||
@@ -524,7 +523,7 @@ makeColorPanel(WMScreen *scrPtr, char *name)
|
||||
WMMoveWidget(panel->grayBrightnessT, 146, 13);
|
||||
WMSetTextFieldAlignment(panel->grayBrightnessT, WALeft);
|
||||
WMAddNotificationObserver(grayBrightnessTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
|
||||
image = RCreateImage(13,13,False);
|
||||
for (i=0; i < 7; i++) {
|
||||
@@ -592,9 +591,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->rgbRedT, 40, 18);
|
||||
WMMoveWidget(panel->rgbRedT, 146, 13);
|
||||
WMSetTextFieldAlignment(panel->rgbRedT, WALeft);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->rgbRedT);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->rgbRedT);
|
||||
|
||||
|
||||
panel->rgbGreenS = WMCreateSlider(panel->rgbFrm);
|
||||
@@ -620,9 +618,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->rgbGreenT, 40, 18);
|
||||
WMMoveWidget(panel->rgbGreenT, 146, 35);
|
||||
WMSetTextFieldAlignment(panel->rgbGreenT, WALeft);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->rgbGreenT);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->rgbGreenT);
|
||||
|
||||
|
||||
panel->rgbBlueS = WMCreateSlider(panel->rgbFrm);
|
||||
@@ -648,9 +645,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->rgbBlueT, 40, 18);
|
||||
WMMoveWidget(panel->rgbBlueT, 146, 57);
|
||||
WMSetTextFieldAlignment(panel->rgbBlueT, WALeft);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->rgbBlueT);
|
||||
WMAddNotificationObserver(rgbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->rgbBlueT);
|
||||
/* End of RGB Panel */
|
||||
|
||||
/* Widgets for CMYK Panel */
|
||||
@@ -702,9 +698,9 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->cmykCyanT, 40, 18);
|
||||
WMMoveWidget(panel->cmykCyanT, 146, 13);
|
||||
WMSetTextFieldAlignment(panel->cmykCyanT, WALeft);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->cmykCyanT);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->cmykCyanT);
|
||||
|
||||
|
||||
panel->cmykMagentaS = WMCreateSlider(panel->cmykFrm);
|
||||
WMResizeWidget(panel->cmykMagentaS, 141, 16);
|
||||
@@ -729,9 +725,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->cmykMagentaT, 40, 18);
|
||||
WMMoveWidget(panel->cmykMagentaT, 146, 35);
|
||||
WMSetTextFieldAlignment(panel->cmykMagentaT, WALeft);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->cmykMagentaT);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->cmykMagentaT);
|
||||
|
||||
|
||||
panel->cmykYellowS = WMCreateSlider(panel->cmykFrm);
|
||||
@@ -757,9 +752,9 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->cmykYellowT, 40, 18);
|
||||
WMMoveWidget(panel->cmykYellowT, 146, 57);
|
||||
WMSetTextFieldAlignment(panel->cmykYellowT, WALeft);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->cmykYellowT);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->cmykYellowT);
|
||||
|
||||
|
||||
panel->cmykBlackS = WMCreateSlider(panel->cmykFrm);
|
||||
WMResizeWidget(panel->cmykBlackS, 141, 16);
|
||||
@@ -785,9 +780,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->cmykBlackT, 40, 18);
|
||||
WMMoveWidget(panel->cmykBlackT, 146, 79);
|
||||
WMSetTextFieldAlignment(panel->cmykBlackT, WALeft);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->cmykBlackT);
|
||||
WMAddNotificationObserver(cmykTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->cmykBlackT);
|
||||
/* End of CMYK Panel */
|
||||
|
||||
/* Widgets for HSB Panel */
|
||||
@@ -808,9 +802,9 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->hsbHueT, 40, 18);
|
||||
WMMoveWidget(panel->hsbHueT, 146, 13);
|
||||
WMSetTextFieldAlignment(panel->hsbHueT, WALeft);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->hsbHueT);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->hsbHueT);
|
||||
|
||||
|
||||
panel->hsbSaturationS = WMCreateSlider(panel->hsbFrm);
|
||||
WMResizeWidget(panel->hsbSaturationS, 141, 16);
|
||||
@@ -824,9 +818,9 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->hsbSaturationT, 40, 18);
|
||||
WMMoveWidget(panel->hsbSaturationT, 146, 35);
|
||||
WMSetTextFieldAlignment(panel->hsbSaturationT, WALeft);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->hsbSaturationT);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->hsbSaturationT);
|
||||
|
||||
|
||||
panel->hsbBrightnessS = WMCreateSlider(panel->hsbFrm);
|
||||
WMResizeWidget(panel->hsbBrightnessS, 141, 16);
|
||||
@@ -840,9 +834,8 @@ WMTextDidEndEditingNotification, panel->grayBrightnessT);
|
||||
WMResizeWidget(panel->hsbBrightnessT, 40, 18);
|
||||
WMMoveWidget(panel->hsbBrightnessT, 146, 57);
|
||||
WMSetTextFieldAlignment(panel->hsbBrightnessT, WALeft);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel,
|
||||
WMTextDidEndEditingNotification,
|
||||
panel->hsbBrightnessT);
|
||||
WMAddNotificationObserver(hsbTextFieldCallback, panel, \
|
||||
WMTextDidEndEditingNotification, panel->hsbBrightnessT);
|
||||
/* End of HSB Panel */
|
||||
|
||||
|
||||
@@ -1031,32 +1024,9 @@ void
|
||||
WMShowColorPanel(WMColorPanel *panel)
|
||||
{
|
||||
WMScreen *scr = WMWidgetScreen(panel->win);
|
||||
XEvent event;
|
||||
RHSVColor hsvcolor;
|
||||
GC bgc = WMColorGC(scr->black);
|
||||
GC wgc = WMColorGC(scr->white);
|
||||
RColor color;
|
||||
|
||||
panel->wheelMtrx = wheelInitMatrix(panel); /* Needs to be done After Color is set */
|
||||
|
||||
|
||||
|
||||
/* Maybe put this in sub-function ... Initialising selection images */
|
||||
RRGBtoHSV(&color, &hsvcolor);
|
||||
panel->colx = 2 + rint((colorWheelSize / 2.0) * (1 + (hsvcolor.saturation/255.0) * cos( hsvcolor.hue*M_PI/180.0)));
|
||||
panel->coly = 2 + rint((colorWheelSize / 2.0) * (1 + (hsvcolor.saturation/255.0) * sin(-hsvcolor.hue*M_PI/180.0)));
|
||||
wheelUpdateBrightnessGradientFromHSV(panel, hsvcolor);
|
||||
WMSetSliderValue(panel->wheelBrightnessS, 255 - hsvcolor.value);
|
||||
|
||||
panel->selectionImg = XCreatePixmap(scr->display, W_VIEW(panel->wheelFrm)->window, 4, 4, scr->depth);
|
||||
XFillRectangle(scr->display, panel->selectionImg, bgc, 0, 0, 4, 4);
|
||||
XFillRectangle(scr->display, panel->selectionImg, wgc, 1, 1, 2, 2);
|
||||
/* End of initialisation section */
|
||||
|
||||
panel->palx = customPaletteWidth/2;
|
||||
panel->paly = customPaletteHeight/2;
|
||||
|
||||
WMSetColorPanelPickerMode(panel, WMWheelModeColorPanel);
|
||||
wheelInit(panel);
|
||||
|
||||
WMMapWidget(panel->win);
|
||||
}
|
||||
@@ -1168,7 +1138,7 @@ WMSetColorPanelPickerMode(WMColorPanel *panel, WMColorPanelMode mode)
|
||||
if (mode != WMColorListModeColorPanel)
|
||||
WMUnmapWidget(panel->colorListFrm);
|
||||
if ((mode != WMGrayModeColorPanel) && (mode != WMRGBModeColorPanel) && \
|
||||
(mode != WMCMYKModeColorPanel) && (mode != WMHSBModeColorPanel))
|
||||
(mode != WMCMYKModeColorPanel) && (mode != WMHSBModeColorPanel))
|
||||
WMUnmapWidget(panel->slidersFrm);
|
||||
else
|
||||
panel->slidersmode = mode;
|
||||
@@ -1225,24 +1195,97 @@ WMSetColorPanelPickerMode(WMColorPanel *panel, WMColorPanelMode mode)
|
||||
panel->mode = mode;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMSetColorPanelColor(WMColorPanel *panel, RColor color)
|
||||
WMSetColorPanelColor(WMColorPanel *panel, WMColor *color)
|
||||
{
|
||||
return;
|
||||
WMScreen *scr = WMWidgetScreen(panel->win);
|
||||
RHSVColor hsvcolor;
|
||||
RColor intcolor;
|
||||
GC bgc = WMColorGC(scr->black);
|
||||
GC wgc = WMColorGC(scr->white);
|
||||
int originalHue;
|
||||
|
||||
WMSetColorWellColor(panel->colorWell, color);
|
||||
|
||||
intcolor.red = color->color.red >> 8;
|
||||
intcolor.green = color->color.green >> 8;
|
||||
intcolor.blue = color->color.blue >> 8;
|
||||
|
||||
panel->color = intcolor;
|
||||
|
||||
/* If color was set by HSB-Panel do not convert back to hsv */
|
||||
if (panel->lastChanged != WMHSBModeColorPanel) {
|
||||
|
||||
/* if color is black, hue is undetermined, so it must be restored */
|
||||
if ((panel->color.red == 0) &&
|
||||
(panel->color.green == 0) &&
|
||||
(panel->color.blue == 0) &&
|
||||
(panel->hsvcolor.hue <= 359))
|
||||
{
|
||||
originalHue = panel->hsvcolor.hue;
|
||||
RRGBtoHSV(&panel->color, &panel->hsvcolor);
|
||||
panel->hsvcolor.hue = originalHue;
|
||||
} else {
|
||||
RRGBtoHSV(&panel->color, &panel->hsvcolor);
|
||||
}
|
||||
}
|
||||
|
||||
panel->wheelMtrx = wheelInitMatrix(panel); /* Needs to be done After Color is set */
|
||||
|
||||
/* Maybe put this in a sub-function ... Initialising selected images */
|
||||
RRGBtoHSV(&intcolor, &hsvcolor);
|
||||
panel->colx = 2 + rint((colorWheelSize / 2.0) * (1 + (hsvcolor.saturation/255.0) * cos( hsvcolor.hue*M_PI/180.0)));
|
||||
panel->coly = 2 + rint((colorWheelSize / 2.0) * (1 + (hsvcolor.saturation/255.0) * sin(-hsvcolor.hue*M_PI/180.0)));
|
||||
wheelUpdateBrightnessGradientFromHSV(panel, hsvcolor);
|
||||
WMSetSliderValue(panel->wheelBrightnessS, 255 - hsvcolor.value);
|
||||
|
||||
panel->selectionImg = XCreatePixmap(scr->display, W_VIEW(panel->wheelFrm)->window, 4, 4, scr->depth);
|
||||
XFillRectangle(scr->display, panel->selectionImg, bgc, 0, 0, 4, 4);
|
||||
XFillRectangle(scr->display, panel->selectionImg, wgc, 1, 1, 2, 2);
|
||||
/* End of initialisation section */
|
||||
|
||||
panel->palx = customPaletteWidth/2;
|
||||
panel->paly = customPaletteHeight/2;
|
||||
|
||||
WMSetColorPanelPickerMode(panel, panel->mode);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
updateSwatch(WMColorPanel *panel, RColor color)
|
||||
{
|
||||
WMSetColorPanelColor(panel, color);
|
||||
WMScreen *scr = WMWidgetScreen(panel->win);
|
||||
WMColor *wellcolor;
|
||||
int originalHue;
|
||||
|
||||
wellcolor = WMCreateRGBColor(scr, color.red << 8, color.green << 8, color.blue << 8, True);
|
||||
|
||||
WMSetColorWellColor(panel->colorWell, wellcolor);
|
||||
WMReleaseColor(wellcolor);
|
||||
|
||||
panel->color = color;
|
||||
|
||||
/* If color was set by HSB-Panel do not convert back to hsv */
|
||||
if (panel->lastChanged != WMHSBModeColorPanel) {
|
||||
|
||||
/* if color is black, hue is undetermined, so it must be restored */
|
||||
if ((panel->color.red == 0) &&
|
||||
(panel->color.green == 0) &&
|
||||
(panel->color.blue == 0) &&
|
||||
(panel->hsvcolor.hue <= 359))
|
||||
{
|
||||
originalHue = panel->hsvcolor.hue;
|
||||
RRGBtoHSV(&panel->color, &panel->hsvcolor);
|
||||
panel->hsvcolor.hue = originalHue;
|
||||
} else {
|
||||
RRGBtoHSV(&panel->color, &panel->hsvcolor);
|
||||
}
|
||||
}
|
||||
|
||||
if (panel->action && (!panel->flags.dragging || panel->flags.continuous)) {
|
||||
(*panel->action)(panel, panel->clientData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
modeButtonCallback(WMWidget *w, void *data)
|
||||
{
|
||||
@@ -1438,7 +1481,6 @@ magnifyCreateView(W_ColorPanel *panel)
|
||||
magView->attribs.save_under = True;
|
||||
|
||||
W_RealizeView(magView);
|
||||
W_MapView(magView);
|
||||
|
||||
return magView;
|
||||
}
|
||||
@@ -1502,7 +1544,6 @@ magnifyInitialize(W_ColorPanel *panel)
|
||||
panel->magnifyGlass->valid = True;
|
||||
|
||||
pixmap = magnifyCreatePixmap(panel);
|
||||
W_MoveView(panel->magnifyGlass->view, x - Cursor_x_hot +1, y - Cursor_y_hot +1);
|
||||
|
||||
XSetWindowBackgroundPixmap(scr->display, panel->magnifyGlass->view->window, pixmap);
|
||||
XClearWindow(scr->display, panel->magnifyGlass->view->window);
|
||||
@@ -1536,14 +1577,16 @@ magnifyPutCursor(WMWidget *w, void *data)
|
||||
|
||||
/* Create magnifying glass */
|
||||
panel->magnifyGlass = wmalloc(sizeof(MovingView));
|
||||
|
||||
panel->magnifyGlass->view = magnifyCreateView(panel);
|
||||
magCursor = magnifyGrabPointer(panel);
|
||||
|
||||
initialPosition = magnifyInitialize(panel);
|
||||
x = initialPosition.x;
|
||||
y = initialPosition.y;
|
||||
|
||||
W_MoveView(panel->magnifyGlass->view, x - Cursor_x_hot +1, y - Cursor_y_hot +1);
|
||||
W_MapView(panel->magnifyGlass->view);
|
||||
|
||||
magCursor = magnifyGrabPointer(panel);
|
||||
|
||||
while(panel->magnifyGlass->valid)
|
||||
{
|
||||
@@ -1603,6 +1646,24 @@ magnifyPutCursor(WMWidget *w, void *data)
|
||||
XFreePixmap(scr->display, pixmap);
|
||||
break;
|
||||
|
||||
case FocusOut: /* fall through */
|
||||
case FocusIn:
|
||||
/*
|
||||
* Color Panel window (panel->win) lost or received focus.
|
||||
* We need to update the pixmap in the magnifying glass.
|
||||
*/
|
||||
XUngrabPointer(scr->display, CurrentTime);
|
||||
W_UnmapView(panel->magnifyGlass->view);
|
||||
|
||||
magnifyInitialize(panel);
|
||||
|
||||
W_MapView(panel->magnifyGlass->view);
|
||||
XGrabPointer (scr->display, panel->magnifyGlass->view->window, True,
|
||||
PointerMotionMask | ButtonPressMask,
|
||||
GrabModeAsync, GrabModeAsync,
|
||||
scr->rootWin, magCursor, CurrentTime);
|
||||
break;
|
||||
|
||||
default:
|
||||
WMHandleEvent(&event);
|
||||
break;
|
||||
@@ -1648,7 +1709,7 @@ wheelCreateMatrix(unsigned int width, unsigned int height)
|
||||
|
||||
return matrix;
|
||||
|
||||
error:
|
||||
error:
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (matrix->data[i])
|
||||
free(matrix->data[i]);
|
||||
@@ -3229,12 +3290,15 @@ generateNewFilename(char *curName)
|
||||
char *ptr;
|
||||
char *newName;
|
||||
|
||||
|
||||
assert(curName);
|
||||
|
||||
ptr = curName;
|
||||
|
||||
while ((ptr = strrchr(ptr, '{')) && !(sscanf(ptr, "{%i}%c", &n, &c)==1)) {
|
||||
ptr++;
|
||||
}
|
||||
if (!ptr)
|
||||
if (
|
||||
((ptr = strrchr(ptr, '{')) == 0) ||
|
||||
sscanf(ptr, "{%i}%c", &n, &c) != 1
|
||||
)
|
||||
return wstrappend(curName, " {1}");
|
||||
|
||||
baseLen = ptr - curName -1;
|
||||
|
||||
+2
-3
@@ -424,13 +424,11 @@ handleActionEvents(XEvent *event, void *data)
|
||||
if (cPtr->flags.active) {
|
||||
WMPostNotificationName(_ColorWellActivatedNotification, cPtr, NULL);
|
||||
}
|
||||
/*
|
||||
cpanel = WMGetColorPanel(scr);
|
||||
if (cPtr->color)
|
||||
WMSetColorPanelColor(cpanel, cPtr->color);
|
||||
WMShowColorPanel(cpanel);
|
||||
*
|
||||
*/
|
||||
/*
|
||||
{
|
||||
char *t;
|
||||
WMColor *color;
|
||||
@@ -451,6 +449,7 @@ handleActionEvents(XEvent *event, void *data)
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user