4 * by ]d : Original idea and basic initial code
5 * Pascal Hofstee : Code for wheeldrawing and calculating
7 * Primary coder of this Color Panel.
8 * Alban Hertroys : Optimizations for algorithms for color-
9 * wheel. Also custom ColorPalettes and
10 * magnifying glass. Secondary coder ;)
11 * Alfredo K. Kojima : For pointing out memory-allocation
12 * problems and similair code-issues
13 * Marco van Hylckama-Vlieg : For once again doing the artwork ;-)
19 * - Look at further optimization of colorWheel matrix calculation.
20 * It appears to be rather symmetric in angles of 60 degrees,
21 * while it is optimized in angles of 120 degrees.
22 * - Custom color-lists and custom colors in custom colo-lists.
27 #include "../src/config.h"
33 #include <sys/types.h>
38 /* BUG There's something fishy with shaped windows */
41 #define SHAPE_WAS_DEFINED
48 #include <X11/extensions/shape.h>
53 # define PATH_MAX 1024
57 char *WMColorPanelColorChangedNotification
= "WMColorPanelColorChangedNotification";
61 * Bitmaps for magnifying glass cursor
65 #define Cursor_x_hot 11
66 #define Cursor_y_hot 11
67 #define Cursor_width 32
68 #define Cursor_height 32
69 static unsigned char Cursor_bits
[] = {
70 0x00,0x7e,0x00,0x00,0xc0,0x81,0x03,0x00,0x20,0x00,0x04,0x00,0x10,0x00,0x08,
71 0x00,0x08,0x00,0x10,0x00,0x04,0x00,0x20,0x00,0x02,0x00,0x40,0x00,0x02,0x00,
72 0x40,0x00,0x02,0x00,0x40,0x00,0x01,0x42,0x80,0x00,0x01,0x24,0x80,0x00,0x01,
73 0x00,0x80,0x00,0x01,0x00,0x80,0x00,0x01,0x24,0x80,0x00,0x01,0x42,0x80,0x00,
74 0x02,0x00,0x40,0x00,0x02,0x00,0x40,0x00,0x02,0x00,0x40,0x00,0x04,0x00,0x20,
75 0x00,0x08,0x00,0x50,0x00,0x10,0x00,0x88,0x00,0x20,0x00,0x5c,0x01,0xc0,0x81,
76 0x3b,0x02,0x00,0x7e,0x70,0x05,0x00,0x00,0xe0,0x08,0x00,0x00,0xc0,0x15,0x00,
77 0x00,0x80,0x23,0x00,0x00,0x00,0x57,0x00,0x00,0x00,0x8e,0x00,0x00,0x00,0x5c,
78 0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x70};
80 /* Cursor shape-mask */
81 #define Cursor_shape_width 32
82 #define Cursor_shape_height 32
83 static unsigned char Cursor_shape_bits
[] = {
84 0x00,0x7e,0x00,0x00,0xc0,0x81,0x03,0x00,0x20,0x00,0x04,0x00,0x10,0x00,0x08,
85 0x00,0x08,0x00,0x10,0x00,0x04,0x00,0x20,0x00,0x02,0x00,0x40,0x00,0x02,0x00,
86 0x40,0x00,0x02,0x00,0x40,0x00,0x01,0x42,0x80,0x00,0x01,0x24,0x80,0x00,0x01,
87 0x00,0x80,0x00,0x01,0x00,0x80,0x00,0x01,0x24,0x80,0x00,0x01,0x42,0x80,0x00,
88 0x02,0x00,0x40,0x00,0x02,0x00,0x40,0x00,0x02,0x00,0x40,0x00,0x04,0x00,0x20,
89 0x00,0x08,0x00,0x70,0x00,0x10,0x00,0xf8,0x00,0x20,0x00,0xfc,0x01,0xc0,0x81,
90 0xfb,0x03,0x00,0x7e,0xf0,0x07,0x00,0x00,0xe0,0x0f,0x00,0x00,0xc0,0x1f,0x00,
91 0x00,0x80,0x3f,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xfc,
92 0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x70};
94 /* Clip-mask for magnified pixels */
95 #define Cursor_mask_width 24
96 #define Cursor_mask_height 24
97 static unsigned char Cursor_mask_bits
[] = {
98 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0xc0, 0xff, 0x03, 0xe0, 0xff, 0x07,
99 0xf0, 0xff, 0x0f, 0xf8, 0xff, 0x1f, 0xfc, 0xff, 0x3f, 0xfc, 0xff, 0x3f,
100 0xfc, 0xff, 0x3f, 0xfe, 0xff, 0x7f, 0xfe, 0xff, 0x7f, 0xfe, 0xff, 0x7f,
101 0xfe, 0xff, 0x7f, 0xfe, 0xff, 0x7f, 0xfe, 0xff, 0x7f, 0xfc, 0xff, 0x3f,
102 0xfc, 0xff, 0x3f, 0xfc, 0xff, 0x3f, 0xf8, 0xff, 0x1f, 0xf0, 0xff, 0x0f,
103 0xe0, 0xff, 0x07, 0xc0, 0xff, 0x03, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00};
106 typedef struct MovingView
{
107 WMView
*view
; /* The view this is all about */
108 XImage
*image
; /* What's under the view */
109 XImage
*dirtyRect
; /* Storage of overlapped image area */
110 Pixmap magPix
; /* Magnified part of pixmap */
111 RColor color
; /* Color of a pixel in the image */
114 typedef struct WheelMatrix
{
115 unsigned int width
, height
; /* Size of the colorwheel */
116 unsigned char *data
[3]; /* Wheel data (R,G,B) */
117 unsigned char values
[256]; /* Precalculated values R,G & B = 0-255 */
120 typedef struct W_ColorPanel
{
128 WMColorWell
*colorWell
;
129 WMButton
*magnifyBtn
;
131 WMButton
*slidersBtn
;
132 WMButton
*customPaletteBtn
;
133 WMButton
*colorListBtn
;
135 /* Magnifying Glass */
136 MovingView
*magnifyGlass
;
138 /* ColorWheel Panel */
140 WMSlider
*wheelBrightnessS
;
145 WMFrame
*seperatorFrm
;
150 /* Gray Scale Panel */
154 WMSlider
*grayBrightnessS
;
155 WMTextField
*grayBrightnessT
;
156 WMButton
*grayPresetBtn
[7];
165 WMTextField
*rgbRedT
;
166 WMTextField
*rgbGreenT
;
167 WMTextField
*rgbBlueT
;
174 WMSlider
*cmykMagentaS
;
175 WMSlider
*cmykYellowS
;
176 WMSlider
*cmykBlackS
;
177 WMTextField
*cmykCyanT
;
178 WMTextField
*cmykMagentaT
;
179 WMTextField
*cmykYellowT
;
180 WMTextField
*cmykBlackT
;
185 WMSlider
*hsbSaturationS
;
186 WMSlider
*hsbBrightnessS
;
187 WMTextField
*hsbHueT
;
188 WMTextField
*hsbSaturationT
;
189 WMTextField
*hsbBrightnessT
;
191 /* Custom Palette Panel*/
192 WMFrame
*customPaletteFrm
;
193 WMPopUpButton
*customPaletteHistoryBtn
;
194 WMFrame
*customPaletteContentFrm
;
195 WMPopUpButton
*customPaletteMenuBtn
;
196 WMView
*customPaletteContentView
;
198 /* Color List Panel */
199 WMFrame
*colorListFrm
;
200 WMPopUpButton
*colorListHistoryBtn
;
201 WMList
*colorListContentLst
;
202 WMPopUpButton
*colorListColorMenuBtn
;
203 WMPopUpButton
*colorListListMenuBtn
;
205 /* Look-Up Tables and Images */
206 wheelMatrix
*wheelMtrx
;
209 Pixmap selectionBackImg
;
210 RImage
*customPaletteImg
;
213 /* Common Data Fields */
214 RColor color
; /* Current color */
215 Bool colorSet
; /* Is color already set ? */
216 RHSVColor hsvcolor
; /* Backup HSV Color */
217 WMColorPanelMode mode
; /* Current color selection mode */
218 WMColorPanelMode slidersmode
;/* Current color sel. mode sliders panel */
219 WMColorPanelMode lastChanged
;/* Panel that last changed the color */
220 int colx
, coly
; /* (x,y) of sel.-marker in WheelMode */
221 int palx
, paly
; /* (x,y) of sel.-marker in
223 float palXRatio
, palYRatio
; /* Ratios in x & y between
227 char *configurationPath
;
230 unsigned int continuous
:1;
231 unsigned int dragging
:1;
240 CPmenuNewFromClipboard
241 } customPaletteMenuItem
;
252 #define colorWheelSize 150
253 #define customPaletteWidth 182
254 #define customPaletteHeight 106
255 #define knobThickness 8
257 #define SPECTRUM_WIDTH 511
258 #define SPECTRUM_HEIGHT 360
260 #define COLORWHEEL_PART 1
261 #define CUSTOMPALETTE_PART 2
267 #define RGBTXT "/usr/X11R6/lib/X11/rgb.txt"
270 #define MAX_LENGTH 1024
272 static int fetchFile(char* toPath
, char *imageSrcFile
, char *imageDestFileName
);
273 char *generateNewFilename(char *curName
);
274 RColor
ulongToRColor(WMScreen
*scr
, XImage
*image
, unsigned long value
);
276 static void modeButtonCallback(WMWidget
*w
, void *data
);
277 static int getPickerPart(W_ColorPanel
*panel
, int x
, int y
);
278 static void readConfiguration(W_ColorPanel
*panel
);
279 static void readXColors(W_ColorPanel
*panel
);
281 static void closeWindowCallback(WMWidget
*w
, void *data
);
283 static Cursor
magnifyGrabPointer(W_ColorPanel
*panel
);
284 static WMPoint
magnifyInitialize(W_ColorPanel
*panel
);
285 static void magnifyPutCursor(WMWidget
*w
, void *data
);
286 static Pixmap
magnifyCreatePixmap(WMColorPanel
*panel
);
287 static void magnifyGetImageStored(W_ColorPanel
*panel
, int x1
, int y1
,
289 static XImage
* magnifyGetImage(WMScreen
*scr
, XImage
*image
, int x
, int y
,
292 static wheelMatrix
* wheelCreateMatrix(unsigned int width
, unsigned int height
);
293 static void wheelDestroyMatrix(wheelMatrix
*matrix
);
294 static wheelMatrix
* wheelInitMatrix(W_ColorPanel
*panel
);
295 static void wheelRender(W_ColorPanel
*panel
);
296 static Bool
wheelInsideColorWheel(W_ColorPanel
*panel
, unsigned long ofs
);
297 static void wheelPaint(W_ColorPanel
*panel
);
299 static void wheelHandleEvents(XEvent
*event
, void *data
);
300 static void wheelHandleActionEvents(XEvent
*event
, void *data
);
301 static void wheelBrightnessSliderCallback(WMWidget
*w
, void *data
);
302 static void wheelUpdateSelection(W_ColorPanel
*panel
);
303 static void wheelUndrawSelection(W_ColorPanel
*panel
);
305 static void wheelPositionSelection(W_ColorPanel
*panel
, int x
, int y
);
306 static void wheelPositionSelectionOutBounds(W_ColorPanel
*panel
, int x
, int y
);
307 static void wheelUpdateBrightnessGradientFromHSV (W_ColorPanel
*panel
,
309 static void wheelUpdateBrightnessGradientFromLocation (W_ColorPanel
*panel
);
310 static void wheelUpdateBrightnessGradient(W_ColorPanel
*panel
, RColor topColor
);
312 static void grayBrightnessSliderCallback(WMWidget
*w
, void *data
);
313 static void grayPresetButtonCallback(WMWidget
*w
, void *data
);
314 static void grayBrightnessTextFieldCallback(void *observerData
,
315 WMNotification
*notification
);
317 static void rgbSliderCallback(WMWidget
*w
, void *data
);
318 static void rgbTextFieldCallback(void *observerData
,
319 WMNotification
*notification
);
321 static void cmykSliderCallback(WMWidget
*w
, void *data
);
322 static void cmykTextFieldCallback(void *observerData
,
323 WMNotification
*notification
);
325 static void hsbSliderCallback(WMWidget
*w
, void *data
);
326 static void hsbTextFieldCallback(void *observerData
,
327 WMNotification
*notification
);
328 static void hsbUpdateBrightnessGradient(W_ColorPanel
*panel
);
329 static void hsbUpdateSaturationGradient(W_ColorPanel
*panel
);
330 static void hsbUpdateHueGradient(W_ColorPanel
*panel
);
332 static void customRenderSpectrum(W_ColorPanel
*panel
);
333 static void customSetPalette(W_ColorPanel
*panel
);
334 static void customPaletteHandleEvents(XEvent
*event
, void *data
);
335 static void customPaletteHandleActionEvents(XEvent
*event
, void *data
);
336 static void customPalettePositionSelection(W_ColorPanel
*panel
, int x
, int y
);
337 static void customPalettePositionSelectionOutBounds(W_ColorPanel
*panel
,
339 static void customPaletteMenuCallback(WMWidget
*w
, void *data
);
340 static void customPaletteHistoryCallback(WMWidget
*w
, void *data
);
342 static void customPaletteMenuNewFromFile(W_ColorPanel
*panel
);
343 static void customPaletteMenuRename(W_ColorPanel
*panel
);
344 static void customPaletteMenuRemove(W_ColorPanel
*panel
);
346 static void colorListPaintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
,
347 int state
, WMRect
*rect
);
348 static void colorListSelect(WMWidget
*w
, void *data
);
349 static void colorListColorMenuCallback(WMWidget
*w
, void *data
);
350 static void colorListListMenuCallback(WMWidget
*w
, void *data
);
351 static void colorListListMenuNew(W_ColorPanel
*panel
);
353 static void wheelInit(W_ColorPanel
*panel
);
354 static void grayInit(W_ColorPanel
*panel
);
355 static void rgbInit(W_ColorPanel
*panel
);
356 static void cmykInit(W_ColorPanel
*panel
);
357 static void hsbInit(W_ColorPanel
*panel
);
362 WMSetColorPanelAction(WMColorPanel
*panel
, WMAction2
*action
, void *data
)
364 panel
->action
= action
;
365 panel
->clientData
= data
;
369 makeColorPanel(WMScreen
*scrPtr
, char *name
)
381 panel
= wmalloc(sizeof(WMColorPanel
));
382 memset(panel
, 0, sizeof(WMColorPanel
));
384 panel
->colorSet
= False
; /* Color has not been set yet */
386 panel
->font8
= WMSystemFontOfSize(scrPtr
, 8);
387 panel
->font12
= WMSystemFontOfSize(scrPtr
, 12);
389 panel
->win
= WMCreateWindowWithStyle(scrPtr
, name
,
390 WMTitledWindowMask
| WMClosableWindowMask
| WMResizableWindowMask
);
391 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
392 WMSetWindowTitle(panel
->win
, "Colors");
393 WMSetWindowCloseAction(panel
->win
, closeWindowCallback
, panel
);
396 /* Set Default ColorPanel Mode(s) */
397 panel
->mode
= WMWheelModeColorPanel
;
398 panel
->lastChanged
= WMWheelModeColorPanel
;
399 panel
->slidersmode
= WMRGBModeColorPanel
;
400 panel
->configurationPath
= wstrappend(wusergnusteppath(),
403 /* Some General Purpose Widgets */
404 panel
->colorWell
= WMCreateColorWell(panel
->win
);
405 WMResizeWidget(panel
->colorWell
, 134, 36);
406 WSetColorWellBordered(panel
->colorWell
, False
);
407 WMMoveWidget(panel
->colorWell
, 56, 4);
409 panel
->magnifyBtn
= WMCreateCustomButton(panel
->win
,
410 WBBStateLightMask
|WBBStateChangeMask
);
411 WMResizeWidget(panel
->magnifyBtn
, 46, 36);
412 WMMoveWidget(panel
->magnifyBtn
, 6,4);
413 WMSetButtonAction(panel
->magnifyBtn
, magnifyPutCursor
, panel
);
414 WMSetButtonImagePosition(panel
->magnifyBtn
, WIPImageOnly
);
415 WMSetButtonImage(panel
->magnifyBtn
, scrPtr
->magnifyIcon
);
417 panel
->wheelBtn
= WMCreateCustomButton(panel
->win
,
418 WBBStateLightMask
|WBBStateChangeMask
);
419 WMResizeWidget(panel
->wheelBtn
, 46, 32);
420 WMMoveWidget(panel
->wheelBtn
, 6, 44);
421 WMSetButtonAction(panel
->wheelBtn
, modeButtonCallback
, panel
);
422 WMSetButtonImagePosition(panel
->wheelBtn
, WIPImageOnly
);
423 WMSetButtonImage(panel
->wheelBtn
, scrPtr
->wheelIcon
);
425 panel
->slidersBtn
= WMCreateCustomButton(panel
->win
,
426 WBBStateLightMask
|WBBStateChangeMask
);
427 WMResizeWidget(panel
->slidersBtn
, 46, 32);
428 WMMoveWidget(panel
->slidersBtn
, 52, 44);
429 WMSetButtonAction(panel
->slidersBtn
, modeButtonCallback
, panel
);
430 WMSetButtonImagePosition(panel
->slidersBtn
, WIPImageOnly
);
431 WMSetButtonImage(panel
->slidersBtn
, scrPtr
->rgbIcon
);
433 panel
->customPaletteBtn
= WMCreateCustomButton(panel
->win
,
434 WBBStateLightMask
|WBBStateChangeMask
);
435 WMResizeWidget(panel
->customPaletteBtn
, 46, 32);
436 WMMoveWidget(panel
->customPaletteBtn
, 98, 44);
437 WMSetButtonAction(panel
->customPaletteBtn
, modeButtonCallback
, panel
);
438 WMSetButtonImagePosition(panel
->customPaletteBtn
, WIPImageOnly
);
439 WMSetButtonImage(panel
->customPaletteBtn
, scrPtr
->customPaletteIcon
);
441 panel
->colorListBtn
= WMCreateCustomButton(panel
->win
,
442 WBBStateLightMask
|WBBStateChangeMask
);
443 WMResizeWidget(panel
->colorListBtn
, 46, 32);
444 WMMoveWidget(panel
->colorListBtn
, 144, 44);
445 WMSetButtonAction(panel
->colorListBtn
, modeButtonCallback
, panel
);
446 WMSetButtonImagePosition(panel
->colorListBtn
, WIPImageOnly
);
447 WMSetButtonImage(panel
->colorListBtn
, scrPtr
->colorListIcon
);
449 /* Let's Group some of them together */
450 WMGroupButtons(panel
->wheelBtn
, panel
->slidersBtn
);
451 WMGroupButtons(panel
->wheelBtn
, panel
->customPaletteBtn
);
452 WMGroupButtons(panel
->wheelBtn
, panel
->colorListBtn
);
454 /* Widgets for the ColorWheel Panel */
455 panel
->wheelFrm
= WMCreateFrame(panel
->win
);
456 WMSetFrameRelief(panel
->wheelFrm
, WRFlat
);
457 WMResizeWidget(panel
->wheelFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26);
458 WMMoveWidget(panel
->wheelFrm
, 5, 80);
460 panel
->wheelView
= W_CreateView(W_VIEW(panel
->wheelFrm
));
461 /* XXX Can we create a view ? */
462 W_ResizeView(panel
->wheelView
, colorWheelSize
+4, colorWheelSize
+4);
463 W_MoveView(panel
->wheelView
, 0, 0);
465 /* Create an event handler to handle expose/click events in ColorWheel */
466 WMCreateEventHandler(panel
->wheelView
,
467 ButtonPressMask
|ButtonReleaseMask
|EnterWindowMask
|
468 LeaveWindowMask
|ButtonMotionMask
, wheelHandleActionEvents
, panel
);
470 WMCreateEventHandler(panel
->wheelView
, ExposureMask
, wheelHandleEvents
,
473 panel
->wheelBrightnessS
= WMCreateSlider(panel
->wheelFrm
);
474 WMResizeWidget(panel
->wheelBrightnessS
, 16, 153);
475 WMMoveWidget(panel
->wheelBrightnessS
, 5+colorWheelSize
+14, 1);
476 WMSetSliderMinValue(panel
->wheelBrightnessS
, 0);
477 WMSetSliderMaxValue(panel
->wheelBrightnessS
, 255);
478 WMSetSliderAction(panel
->wheelBrightnessS
, wheelBrightnessSliderCallback
,
480 WMSetSliderKnobThickness(panel
->wheelBrightnessS
, knobThickness
);
483 /* Widgets for the Slider Panels */
484 panel
->slidersFrm
= WMCreateFrame(panel
->win
);
485 WMSetFrameRelief(panel
->slidersFrm
, WRFlat
);
486 WMResizeWidget(panel
->slidersFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26);
487 WMMoveWidget(panel
->slidersFrm
, 4, 80);
489 panel
->seperatorFrm
= WMCreateFrame(panel
->slidersFrm
);
490 WMSetFrameRelief(panel
->seperatorFrm
, WRPushed
);
491 WMResizeWidget(panel
->seperatorFrm
, PWIDTH
- 8, 2);
492 WMMoveWidget(panel
->seperatorFrm
, 0, 1);
494 panel
->grayBtn
= WMCreateCustomButton(panel
->slidersFrm
,
495 WBBStateLightMask
|WBBStateChangeMask
);
496 WMResizeWidget(panel
->grayBtn
, 46, 24);
497 WMMoveWidget(panel
->grayBtn
, 1, 8);
498 WMSetButtonAction(panel
->grayBtn
, modeButtonCallback
, panel
);
499 WMSetButtonImagePosition(panel
->grayBtn
, WIPImageOnly
);
500 WMSetButtonImage(panel
->grayBtn
, scrPtr
->grayIcon
);
502 panel
->rgbBtn
= WMCreateCustomButton(panel
->slidersFrm
,
503 WBBStateLightMask
|WBBStateChangeMask
);
504 WMResizeWidget(panel
->rgbBtn
, 46, 24);
505 WMMoveWidget(panel
->rgbBtn
, 47, 8);
506 WMSetButtonAction(panel
->rgbBtn
, modeButtonCallback
, panel
);
507 WMSetButtonImagePosition(panel
->rgbBtn
, WIPImageOnly
);
508 WMSetButtonImage(panel
->rgbBtn
, scrPtr
->rgbIcon
);
510 panel
->cmykBtn
= WMCreateCustomButton(panel
->slidersFrm
,
511 WBBStateLightMask
|WBBStateChangeMask
);
512 WMResizeWidget(panel
->cmykBtn
, 46, 24);
513 WMMoveWidget(panel
->cmykBtn
, 93, 8);
514 WMSetButtonAction(panel
->cmykBtn
, modeButtonCallback
, panel
);
515 WMSetButtonImagePosition(panel
->cmykBtn
, WIPImageOnly
);
516 WMSetButtonImage(panel
->cmykBtn
, scrPtr
->cmykIcon
);
518 panel
->hsbBtn
= WMCreateCustomButton(panel
->slidersFrm
,
519 WBBStateLightMask
|WBBStateChangeMask
);
520 WMResizeWidget(panel
->hsbBtn
, 46, 24);
521 WMMoveWidget(panel
->hsbBtn
, 139, 8);
522 WMSetButtonAction(panel
->hsbBtn
, modeButtonCallback
, panel
);
523 WMSetButtonImagePosition(panel
->hsbBtn
, WIPImageOnly
);
524 WMSetButtonImage(panel
->hsbBtn
, scrPtr
->hsbIcon
);
526 /* Let's Group the Slider Panel Buttons Together */
527 WMGroupButtons(panel
->grayBtn
, panel
->rgbBtn
);
528 WMGroupButtons(panel
->grayBtn
, panel
->cmykBtn
);
529 WMGroupButtons(panel
->grayBtn
, panel
->hsbBtn
);
531 textcolor
= WMDarkGrayColor(scrPtr
);
533 /* Widgets for GrayScale Panel */
534 panel
->grayFrm
= WMCreateFrame(panel
->slidersFrm
);
535 WMSetFrameRelief(panel
->grayFrm
, WRFlat
);
536 WMResizeWidget(panel
->grayFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26 - 32);
537 WMMoveWidget(panel
->grayFrm
, 0, 34);
539 panel
->grayMinL
= WMCreateLabel(panel
->grayFrm
);
540 WMResizeWidget(panel
->grayMinL
, 20, 10);
541 WMMoveWidget(panel
->grayMinL
, 2, 2);
542 WMSetLabelText(panel
->grayMinL
, "0");
543 WMSetLabelTextAlignment(panel
->grayMinL
, WALeft
);
544 WMSetLabelTextColor(panel
->grayMinL
, textcolor
);
545 WMSetLabelFont(panel
->grayMinL
, panel
->font8
);
547 panel
->grayMaxL
= WMCreateLabel(panel
->grayFrm
);
548 WMResizeWidget(panel
->grayMaxL
, 40, 10);
549 WMMoveWidget(panel
->grayMaxL
, 104, 2);
550 WMSetLabelText(panel
->grayMaxL
, "100");
551 WMSetLabelTextAlignment(panel
->grayMaxL
, WARight
);
552 WMSetLabelTextColor(panel
->grayMaxL
, textcolor
);
553 WMSetLabelFont(panel
->grayMaxL
, panel
->font8
);
555 panel
->grayBrightnessS
= WMCreateSlider(panel
->grayFrm
);
556 WMResizeWidget(panel
->grayBrightnessS
, 141, 16);
557 WMMoveWidget(panel
->grayBrightnessS
, 2, 14);
558 WMSetSliderMinValue(panel
->grayBrightnessS
, 0);
559 WMSetSliderMaxValue(panel
->grayBrightnessS
, 100);
560 WMSetSliderKnobThickness(panel
->grayBrightnessS
, knobThickness
);
561 WMSetSliderAction(panel
->grayBrightnessS
, grayBrightnessSliderCallback
,
572 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
573 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
574 RDestroyImage(image
);
575 W_PaintText(W_VIEW(panel
->grayBrightnessS
), pixmap
->pixmap
,
576 panel
->font12
, 2, 0, 100, WALeft
, WMColorGC(scrPtr
->white
),
577 False
, "Brightness", strlen("Brightness"));
578 WMSetSliderImage(panel
->grayBrightnessS
, pixmap
);
579 WMReleasePixmap(pixmap
);
581 panel
->grayBrightnessT
= WMCreateTextField(panel
->grayFrm
);
582 WMResizeWidget(panel
->grayBrightnessT
, 40, 18);
583 WMMoveWidget(panel
->grayBrightnessT
, 146, 13);
584 WMSetTextFieldAlignment(panel
->grayBrightnessT
, WALeft
);
585 WMAddNotificationObserver(grayBrightnessTextFieldCallback
, panel
,
586 WMTextDidEndEditingNotification
, panel
->grayBrightnessT
);
588 image
= RCreateImage(13,13,False
);
589 for (i
=0; i
< 7; i
++) {
590 for (x
=0; x
< 13; x
++) {
591 for (y
=0; y
< 13; y
++) {
592 image
->data
[0][y
*13+x
] = 255/6*i
;
593 image
->data
[1][y
*13+x
] = 255/6*i
;
594 image
->data
[2][y
*13+x
] = 255/6*i
;
597 panel
->grayPresetBtn
[i
] = WMCreateCommandButton(panel
->grayFrm
);
598 WMResizeWidget(panel
->grayPresetBtn
[i
], 20, 24);
599 WMMoveWidget(panel
->grayPresetBtn
[i
], 2+(i
*20), 34);
600 WMSetButtonAction(panel
->grayPresetBtn
[i
],
601 grayPresetButtonCallback
, panel
);
602 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
603 WMSetButtonImage(panel
->grayPresetBtn
[i
], pixmap
);
604 WMSetButtonImagePosition(panel
->grayPresetBtn
[i
], WIPImageOnly
);
605 WMReleasePixmap(pixmap
);
607 RDestroyImage(image
);
608 /* End of GrayScale Panel */
610 /* Widgets for RGB Panel */
611 panel
->rgbFrm
= WMCreateFrame(panel
->slidersFrm
);
612 WMSetFrameRelief(panel
->rgbFrm
, WRFlat
);
613 WMResizeWidget(panel
->rgbFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26 - 32);
614 WMMoveWidget(panel
->rgbFrm
, 0, 34);
616 panel
->rgbMinL
= WMCreateLabel(panel
->rgbFrm
);
617 WMResizeWidget(panel
->rgbMinL
, 20, 10);
618 WMMoveWidget(panel
->rgbMinL
, 2, 2);
619 WMSetLabelText(panel
->rgbMinL
, "0");
620 WMSetLabelTextAlignment(panel
->rgbMinL
, WALeft
);
621 WMSetLabelTextColor(panel
->rgbMinL
, textcolor
);
622 WMSetLabelFont(panel
->rgbMinL
, panel
->font8
);
624 panel
->rgbMaxL
= WMCreateLabel(panel
->rgbFrm
);
625 WMResizeWidget(panel
->rgbMaxL
, 40, 10);
626 WMMoveWidget(panel
->rgbMaxL
, 104, 2);
627 WMSetLabelText(panel
->rgbMaxL
, "255");
628 WMSetLabelTextAlignment(panel
->rgbMaxL
, WARight
);
629 WMSetLabelTextColor(panel
->rgbMaxL
, textcolor
);
630 WMSetLabelFont(panel
->rgbMaxL
, panel
->font8
);
632 panel
->rgbRedS
= WMCreateSlider(panel
->rgbFrm
);
633 WMResizeWidget(panel
->rgbRedS
, 141, 16);
634 WMMoveWidget(panel
->rgbRedS
, 2, 14);
635 WMSetSliderMinValue(panel
->rgbRedS
, 0);
636 WMSetSliderMaxValue(panel
->rgbRedS
, 255);
637 WMSetSliderKnobThickness(panel
->rgbRedS
, knobThickness
);
638 WMSetSliderAction(panel
->rgbRedS
, rgbSliderCallback
, panel
);
644 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
645 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
646 W_PaintText(W_VIEW(panel
->rgbRedS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
647 100, WALeft
, WMColorGC(scrPtr
->white
), False
, "Red", strlen("Red"));
648 RDestroyImage(image
);
649 WMSetSliderImage(panel
->rgbRedS
, pixmap
);
650 WMReleasePixmap(pixmap
);
652 panel
->rgbRedT
= WMCreateTextField(panel
->rgbFrm
);
653 WMResizeWidget(panel
->rgbRedT
, 40, 18);
654 WMMoveWidget(panel
->rgbRedT
, 146, 13);
655 WMSetTextFieldAlignment(panel
->rgbRedT
, WALeft
);
656 WMAddNotificationObserver(rgbTextFieldCallback
, panel
,
657 WMTextDidEndEditingNotification
, panel
->rgbRedT
);
659 panel
->rgbGreenS
= WMCreateSlider(panel
->rgbFrm
);
660 WMResizeWidget(panel
->rgbGreenS
, 141, 16);
661 WMMoveWidget(panel
->rgbGreenS
, 2, 36);
662 WMSetSliderMinValue(panel
->rgbGreenS
, 0);
663 WMSetSliderMaxValue(panel
->rgbGreenS
, 255);
664 WMSetSliderKnobThickness(panel
->rgbGreenS
, knobThickness
);
665 WMSetSliderAction(panel
->rgbGreenS
, rgbSliderCallback
, panel
);
671 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
672 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
673 W_PaintText(W_VIEW(panel
->rgbGreenS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
674 100, WALeft
, WMColorGC(scrPtr
->white
), False
, "Green",
676 RDestroyImage(image
);
677 WMSetSliderImage(panel
->rgbGreenS
, pixmap
);
678 WMReleasePixmap(pixmap
);
680 panel
->rgbGreenT
= WMCreateTextField(panel
->rgbFrm
);
681 WMResizeWidget(panel
->rgbGreenT
, 40, 18);
682 WMMoveWidget(panel
->rgbGreenT
, 146, 35);
683 WMSetTextFieldAlignment(panel
->rgbGreenT
, WALeft
);
684 WMAddNotificationObserver(rgbTextFieldCallback
, panel
,
685 WMTextDidEndEditingNotification
, panel
->rgbGreenT
);
688 panel
->rgbBlueS
= WMCreateSlider(panel
->rgbFrm
);
689 WMResizeWidget(panel
->rgbBlueS
, 141, 16);
690 WMMoveWidget(panel
->rgbBlueS
, 2, 58);
691 WMSetSliderMinValue(panel
->rgbBlueS
, 0);
692 WMSetSliderMaxValue(panel
->rgbBlueS
, 255);
693 WMSetSliderKnobThickness(panel
->rgbBlueS
, knobThickness
);
694 WMSetSliderAction(panel
->rgbBlueS
, rgbSliderCallback
, panel
);
700 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
701 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
702 W_PaintText(W_VIEW(panel
->rgbBlueS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
703 100, WALeft
, WMColorGC(scrPtr
->white
), False
, "Blue",
705 RDestroyImage(image
);
706 WMSetSliderImage(panel
->rgbBlueS
, pixmap
);
707 WMReleasePixmap(pixmap
);
709 panel
->rgbBlueT
= WMCreateTextField(panel
->rgbFrm
);
710 WMResizeWidget(panel
->rgbBlueT
, 40, 18);
711 WMMoveWidget(panel
->rgbBlueT
, 146, 57);
712 WMSetTextFieldAlignment(panel
->rgbBlueT
, WALeft
);
713 WMAddNotificationObserver(rgbTextFieldCallback
, panel
,
714 WMTextDidEndEditingNotification
, panel
->rgbBlueT
);
715 /* End of RGB Panel */
717 /* Widgets for CMYK Panel */
718 panel
->cmykFrm
= WMCreateFrame(panel
->slidersFrm
);
719 WMSetFrameRelief(panel
->cmykFrm
, WRFlat
);
720 WMResizeWidget(panel
->cmykFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26 - 32);
721 WMMoveWidget(panel
->cmykFrm
, 0, 34);
723 panel
->cmykMinL
= WMCreateLabel(panel
->cmykFrm
);
724 WMResizeWidget(panel
->cmykMinL
, 20, 10);
725 WMMoveWidget(panel
->cmykMinL
, 2, 2);
726 WMSetLabelText(panel
->cmykMinL
, "0");
727 WMSetLabelTextAlignment(panel
->cmykMinL
, WALeft
);
728 WMSetLabelTextColor(panel
->cmykMinL
, textcolor
);
729 WMSetLabelFont(panel
->cmykMinL
, panel
->font8
);
731 panel
->cmykMaxL
= WMCreateLabel(panel
->cmykFrm
);
732 WMResizeWidget(panel
->cmykMaxL
, 40, 10);
733 WMMoveWidget(panel
->cmykMaxL
, 104, 2);
734 WMSetLabelText(panel
->cmykMaxL
, "100");
735 WMSetLabelTextAlignment(panel
->cmykMaxL
, WARight
);
736 WMSetLabelTextColor(panel
->cmykMaxL
, textcolor
);
737 WMSetLabelFont(panel
->cmykMaxL
, panel
->font8
);
739 panel
->cmykCyanS
= WMCreateSlider(panel
->cmykFrm
);
740 WMResizeWidget(panel
->cmykCyanS
, 141, 16);
741 WMMoveWidget(panel
->cmykCyanS
, 2, 14);
742 WMSetSliderMinValue(panel
->cmykCyanS
, 0);
743 WMSetSliderMaxValue(panel
->cmykCyanS
, 100);
744 WMSetSliderKnobThickness(panel
->cmykCyanS
, knobThickness
);
745 WMSetSliderAction(panel
->cmykCyanS
, cmykSliderCallback
, panel
);
755 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
756 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
757 W_PaintText(W_VIEW(panel
->cmykCyanS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
758 100, WALeft
, WMColorGC(scrPtr
->black
), False
, "Cyan",
760 RDestroyImage(image
);
761 WMSetSliderImage(panel
->cmykCyanS
, pixmap
);
762 WMReleasePixmap(pixmap
);
764 panel
->cmykCyanT
= WMCreateTextField(panel
->cmykFrm
);
765 WMResizeWidget(panel
->cmykCyanT
, 40, 18);
766 WMMoveWidget(panel
->cmykCyanT
, 146, 13);
767 WMSetTextFieldAlignment(panel
->cmykCyanT
, WALeft
);
768 WMAddNotificationObserver(cmykTextFieldCallback
, panel
,
769 WMTextDidEndEditingNotification
, panel
->cmykCyanT
);
772 panel
->cmykMagentaS
= WMCreateSlider(panel
->cmykFrm
);
773 WMResizeWidget(panel
->cmykMagentaS
, 141, 16);
774 WMMoveWidget(panel
->cmykMagentaS
, 2, 36);
775 WMSetSliderMinValue(panel
->cmykMagentaS
, 0);
776 WMSetSliderMaxValue(panel
->cmykMagentaS
, 100);
777 WMSetSliderKnobThickness(panel
->cmykMagentaS
, knobThickness
);
778 WMSetSliderAction(panel
->cmykMagentaS
, cmykSliderCallback
, panel
);
784 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
785 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
786 W_PaintText(W_VIEW(panel
->cmykMagentaS
), pixmap
->pixmap
, panel
->font12
, 2,
787 0, 100, WALeft
, WMColorGC(scrPtr
->black
), False
, "Magenta",
789 RDestroyImage(image
);
790 WMSetSliderImage(panel
->cmykMagentaS
, pixmap
);
791 WMReleasePixmap(pixmap
);
793 panel
->cmykMagentaT
= WMCreateTextField(panel
->cmykFrm
);
794 WMResizeWidget(panel
->cmykMagentaT
, 40, 18);
795 WMMoveWidget(panel
->cmykMagentaT
, 146, 35);
796 WMSetTextFieldAlignment(panel
->cmykMagentaT
, WALeft
);
797 WMAddNotificationObserver(cmykTextFieldCallback
, panel
,
798 WMTextDidEndEditingNotification
, panel
->cmykMagentaT
);
801 panel
->cmykYellowS
= WMCreateSlider(panel
->cmykFrm
);
802 WMResizeWidget(panel
->cmykYellowS
, 141, 16);
803 WMMoveWidget(panel
->cmykYellowS
, 2, 58);
804 WMSetSliderMinValue(panel
->cmykYellowS
, 0);
805 WMSetSliderMaxValue(panel
->cmykYellowS
, 100);
806 WMSetSliderKnobThickness(panel
->cmykYellowS
, knobThickness
);
807 WMSetSliderAction(panel
->cmykYellowS
, cmykSliderCallback
, panel
);
813 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
814 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
815 W_PaintText(W_VIEW(panel
->cmykYellowS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
816 100, WALeft
, WMColorGC(scrPtr
->black
), False
, "Yellow",
818 RDestroyImage(image
);
819 WMSetSliderImage(panel
->cmykYellowS
, pixmap
);
820 WMReleasePixmap(pixmap
);
822 panel
->cmykYellowT
= WMCreateTextField(panel
->cmykFrm
);
823 WMResizeWidget(panel
->cmykYellowT
, 40, 18);
824 WMMoveWidget(panel
->cmykYellowT
, 146, 57);
825 WMSetTextFieldAlignment(panel
->cmykYellowT
, WALeft
);
826 WMAddNotificationObserver(cmykTextFieldCallback
, panel
,
827 WMTextDidEndEditingNotification
, panel
->cmykYellowT
);
830 panel
->cmykBlackS
= WMCreateSlider(panel
->cmykFrm
);
831 WMResizeWidget(panel
->cmykBlackS
, 141, 16);
832 WMMoveWidget(panel
->cmykBlackS
, 2, 80);
833 WMSetSliderMinValue(panel
->cmykBlackS
, 0);
834 WMSetSliderMaxValue(panel
->cmykBlackS
, 100);
835 WMSetSliderValue(panel
->cmykBlackS
, 0);
836 WMSetSliderKnobThickness(panel
->cmykBlackS
, knobThickness
);
837 WMSetSliderAction(panel
->cmykBlackS
, cmykSliderCallback
, panel
);
843 image
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
844 pixmap
= WMCreatePixmapFromRImage(scrPtr
, image
, 0);
845 W_PaintText(W_VIEW(panel
->cmykBlackS
), pixmap
->pixmap
, panel
->font12
, 2, 0,
846 100, WALeft
, WMColorGC(scrPtr
->black
), False
, "Black",
848 RDestroyImage(image
);
849 WMSetSliderImage(panel
->cmykBlackS
, pixmap
);
850 WMReleasePixmap(pixmap
);
852 panel
->cmykBlackT
= WMCreateTextField(panel
->cmykFrm
);
853 WMResizeWidget(panel
->cmykBlackT
, 40, 18);
854 WMMoveWidget(panel
->cmykBlackT
, 146, 79);
855 WMSetTextFieldAlignment(panel
->cmykBlackT
, WALeft
);
856 WMAddNotificationObserver(cmykTextFieldCallback
, panel
,
857 WMTextDidEndEditingNotification
, panel
->cmykBlackT
);
858 /* End of CMYK Panel */
860 /* Widgets for HSB Panel */
861 panel
->hsbFrm
= WMCreateFrame(panel
->slidersFrm
);
862 WMSetFrameRelief(panel
->hsbFrm
, WRFlat
);
863 WMResizeWidget(panel
->hsbFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26 - 32);
864 WMMoveWidget(panel
->hsbFrm
, 0, 34);
866 panel
->hsbHueS
= WMCreateSlider(panel
->hsbFrm
);
867 WMResizeWidget(panel
->hsbHueS
, 141, 16);
868 WMMoveWidget(panel
->hsbHueS
, 2, 14);
869 WMSetSliderMinValue(panel
->hsbHueS
, 0);
870 WMSetSliderMaxValue(panel
->hsbHueS
, 359);
871 WMSetSliderKnobThickness(panel
->hsbHueS
, knobThickness
);
872 WMSetSliderAction(panel
->hsbHueS
, hsbSliderCallback
, panel
);
874 panel
->hsbHueT
= WMCreateTextField(panel
->hsbFrm
);
875 WMResizeWidget(panel
->hsbHueT
, 40, 18);
876 WMMoveWidget(panel
->hsbHueT
, 146, 13);
877 WMSetTextFieldAlignment(panel
->hsbHueT
, WALeft
);
878 WMAddNotificationObserver(hsbTextFieldCallback
, panel
,
879 WMTextDidEndEditingNotification
, panel
->hsbHueT
);
882 panel
->hsbSaturationS
= WMCreateSlider(panel
->hsbFrm
);
883 WMResizeWidget(panel
->hsbSaturationS
, 141, 16);
884 WMMoveWidget(panel
->hsbSaturationS
, 2, 36);
885 WMSetSliderMinValue(panel
->hsbSaturationS
, 0);
886 WMSetSliderMaxValue(panel
->hsbSaturationS
, 100);
887 WMSetSliderKnobThickness(panel
->hsbSaturationS
, knobThickness
);
888 WMSetSliderAction(panel
->hsbSaturationS
, hsbSliderCallback
, panel
);
890 panel
->hsbSaturationT
= WMCreateTextField(panel
->hsbFrm
);
891 WMResizeWidget(panel
->hsbSaturationT
, 40, 18);
892 WMMoveWidget(panel
->hsbSaturationT
, 146, 35);
893 WMSetTextFieldAlignment(panel
->hsbSaturationT
, WALeft
);
894 WMAddNotificationObserver(hsbTextFieldCallback
, panel
,
895 WMTextDidEndEditingNotification
, panel
->hsbSaturationT
);
898 panel
->hsbBrightnessS
= WMCreateSlider(panel
->hsbFrm
);
899 WMResizeWidget(panel
->hsbBrightnessS
, 141, 16);
900 WMMoveWidget(panel
->hsbBrightnessS
, 2, 58);
901 WMSetSliderMinValue(panel
->hsbBrightnessS
, 0);
902 WMSetSliderMaxValue(panel
->hsbBrightnessS
, 100);
903 WMSetSliderKnobThickness(panel
->hsbBrightnessS
, knobThickness
);
904 WMSetSliderAction(panel
->hsbBrightnessS
, hsbSliderCallback
, panel
);
906 panel
->hsbBrightnessT
= WMCreateTextField(panel
->hsbFrm
);
907 WMResizeWidget(panel
->hsbBrightnessT
, 40, 18);
908 WMMoveWidget(panel
->hsbBrightnessT
, 146, 57);
909 WMSetTextFieldAlignment(panel
->hsbBrightnessT
, WALeft
);
910 WMAddNotificationObserver(hsbTextFieldCallback
, panel
,
911 WMTextDidEndEditingNotification
, panel
->hsbBrightnessT
);
912 /* End of HSB Panel */
915 WMReleaseColor(textcolor
);
917 /* Widgets for the CustomPalette Panel */
918 panel
->customPaletteFrm
= WMCreateFrame(panel
->win
);
919 WMSetFrameRelief(panel
->customPaletteFrm
, WRFlat
);
920 WMResizeWidget(panel
->customPaletteFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26);
921 WMMoveWidget(panel
->customPaletteFrm
, 5, 80);
923 panel
->customPaletteHistoryBtn
= WMCreatePopUpButton(
924 panel
->customPaletteFrm
);
925 WMAddPopUpButtonItem(panel
->customPaletteHistoryBtn
, "Spectrum");
926 WMSetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
,
927 WMGetPopUpButtonNumberOfItems(panel
->customPaletteHistoryBtn
)-1);
928 WMSetPopUpButtonAction(panel
->customPaletteHistoryBtn
,
929 customPaletteHistoryCallback
, panel
);
930 WMResizeWidget(panel
->customPaletteHistoryBtn
, PWIDTH
- 8, 20);
931 WMMoveWidget(panel
->customPaletteHistoryBtn
, 0, 0);
933 panel
->customPaletteContentFrm
= WMCreateFrame(panel
->customPaletteFrm
);
934 WMSetFrameRelief(panel
->customPaletteContentFrm
, WRSunken
);
935 WMResizeWidget(panel
->customPaletteContentFrm
, PWIDTH
- 8, PHEIGHT
- 156);
936 WMMoveWidget(panel
->customPaletteContentFrm
, 0, 23);
938 panel
->customPaletteContentView
= W_CreateView(
939 W_VIEW(panel
->customPaletteContentFrm
));
940 /* XXX Test if we can create a view */
941 W_ResizeView(panel
->customPaletteContentView
, customPaletteWidth
,
942 customPaletteHeight
);
943 W_MoveView(panel
->customPaletteContentView
, 2, 2);
945 /* Create event handler to handle expose/click events in CustomPalette */
946 WMCreateEventHandler(panel
->customPaletteContentView
,
947 ButtonPressMask
|ButtonReleaseMask
|EnterWindowMask
| LeaveWindowMask
|
948 ButtonMotionMask
, customPaletteHandleActionEvents
, panel
);
950 WMCreateEventHandler(panel
->customPaletteContentView
, ExposureMask
,
951 customPaletteHandleEvents
, panel
);
953 panel
->customPaletteMenuBtn
= WMCreatePopUpButton(panel
->customPaletteFrm
);
954 WMSetPopUpButtonPullsDown(panel
->customPaletteMenuBtn
, 1);
955 WMSetPopUpButtonText(panel
->customPaletteMenuBtn
, "Palette");
956 WMSetPopUpButtonAction(panel
->customPaletteMenuBtn
,
957 customPaletteMenuCallback
, panel
);
958 WMResizeWidget(panel
->customPaletteMenuBtn
, PWIDTH
- 8, 20);
959 WMMoveWidget(panel
->customPaletteMenuBtn
, 0, PHEIGHT
- 130);
961 WMAddPopUpButtonItem(panel
->customPaletteMenuBtn
, "New from File...");
962 WMAddPopUpButtonItem(panel
->customPaletteMenuBtn
, "Rename...");
963 WMAddPopUpButtonItem(panel
->customPaletteMenuBtn
, "Remove");
964 WMAddPopUpButtonItem(panel
->customPaletteMenuBtn
, "Copy");
965 WMAddPopUpButtonItem(panel
->customPaletteMenuBtn
, "New from Clipboard");
967 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
, CPmenuRename
, 0);
968 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
, CPmenuRemove
, 0);
969 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
, CPmenuCopy
, 0);
970 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
,
971 CPmenuNewFromClipboard
, 0);
973 customRenderSpectrum(panel
);
974 panel
->currentPalette
= 0;
977 /* Widgets for the ColorList Panel */
978 panel
->colorListFrm
= WMCreateFrame(panel
->win
);
979 WMSetFrameRelief(panel
->colorListFrm
, WRFlat
);
980 WMResizeWidget(panel
->colorListFrm
, PWIDTH
- 8, PHEIGHT
- 80 - 26);
981 WMMoveWidget(panel
->colorListFrm
, 5, 80);
983 panel
->colorListHistoryBtn
= WMCreatePopUpButton(panel
->colorListFrm
);
984 WMAddPopUpButtonItem(panel
->colorListHistoryBtn
, "X11-Colors");
985 WMSetPopUpButtonSelectedItem(panel
->colorListHistoryBtn
,
986 WMGetPopUpButtonNumberOfItems(panel
->colorListHistoryBtn
)-1);
987 /* WMSetPopUpButtonAction(panel->colorListHistoryBtn,
988 * colorListHistoryCallback, panel); */
989 WMResizeWidget(panel
->colorListHistoryBtn
, PWIDTH
- 8, 20);
990 WMMoveWidget(panel
->colorListHistoryBtn
, 0, 0);
992 panel
->colorListContentLst
= WMCreateList(panel
->colorListFrm
);
993 WMSetListAction(panel
->colorListContentLst
, colorListSelect
, panel
);
994 WMSetListUserDrawProc(panel
->colorListContentLst
, colorListPaintItem
);
995 WMResizeWidget(panel
->colorListContentLst
, PWIDTH
- 8, PHEIGHT
- 156);
996 WMMoveWidget(panel
->colorListContentLst
, 0, 23);
997 WMHangData(panel
->colorListContentLst
, panel
);
999 panel
->colorListColorMenuBtn
= WMCreatePopUpButton(panel
->colorListFrm
);
1000 WMSetPopUpButtonPullsDown(panel
->colorListColorMenuBtn
, 1);
1001 WMSetPopUpButtonText(panel
->colorListColorMenuBtn
, "Color");
1002 WMSetPopUpButtonAction(panel
->colorListColorMenuBtn
,
1003 colorListColorMenuCallback
, panel
);
1004 WMResizeWidget(panel
->colorListColorMenuBtn
, (PWIDTH
- 16)/2, 20);
1005 WMMoveWidget(panel
->colorListColorMenuBtn
, 0, PHEIGHT
- 130);
1007 WMAddPopUpButtonItem(panel
->colorListColorMenuBtn
, "Add...");
1008 WMAddPopUpButtonItem(panel
->colorListColorMenuBtn
, "Rename...");
1009 WMAddPopUpButtonItem(panel
->colorListColorMenuBtn
, "Remove");
1011 WMSetPopUpButtonItemEnabled(panel
->colorListColorMenuBtn
, CLmenuAdd
, 0);
1012 WMSetPopUpButtonItemEnabled(panel
->colorListColorMenuBtn
, CLmenuRename
, 0);
1013 WMSetPopUpButtonItemEnabled(panel
->colorListColorMenuBtn
, CLmenuRemove
, 0);
1015 panel
->colorListListMenuBtn
= WMCreatePopUpButton(panel
->colorListFrm
);
1016 WMSetPopUpButtonPullsDown(panel
->colorListListMenuBtn
, 1);
1017 WMSetPopUpButtonText(panel
->colorListListMenuBtn
, "List");
1018 WMSetPopUpButtonAction(panel
->colorListListMenuBtn
,
1019 colorListListMenuCallback
, panel
);
1020 WMResizeWidget(panel
->colorListListMenuBtn
, (PWIDTH
- 16)/2, 20);
1021 WMMoveWidget(panel
->colorListListMenuBtn
, (PWIDTH
- 16)/2 + 8,
1024 WMAddPopUpButtonItem(panel
->colorListListMenuBtn
, "New...");
1025 WMAddPopUpButtonItem(panel
->colorListListMenuBtn
, "Rename...");
1026 WMAddPopUpButtonItem(panel
->colorListListMenuBtn
, "Remove");
1028 WMSetPopUpButtonItemEnabled(panel
->colorListListMenuBtn
, CLmenuRename
, 0);
1029 WMSetPopUpButtonItemEnabled(panel
->colorListListMenuBtn
, CLmenuRemove
, 0);
1031 WMRealizeWidget(panel
->win
);
1032 WMMapSubwidgets(panel
->win
);
1034 WMMapSubwidgets(panel
->wheelFrm
);
1035 WMMapSubwidgets(panel
->slidersFrm
);
1036 WMMapSubwidgets(panel
->grayFrm
);
1037 WMMapSubwidgets(panel
->rgbFrm
);
1038 WMMapSubwidgets(panel
->cmykFrm
);
1039 WMMapSubwidgets(panel
->hsbFrm
);
1040 WMMapSubwidgets(panel
->customPaletteFrm
);
1041 WMMapSubwidgets(panel
->customPaletteContentFrm
);
1042 WMMapSubwidgets(panel
->colorListFrm
);
1044 readConfiguration(panel
);
1052 WMGetColorPanel(WMScreen
*scrPtr
)
1054 WMColorPanel
*panel
;
1056 if (scrPtr
->sharedColorPanel
)
1057 return scrPtr
->sharedColorPanel
;
1059 panel
= makeColorPanel(scrPtr
, "colorPanel");
1061 scrPtr
->sharedColorPanel
= panel
;
1068 WMFreeColorPanel(WMColorPanel
*panel
)
1070 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1072 if (panel
== scr
->sharedColorPanel
) {
1073 scr
->sharedColorPanel
= NULL
;
1076 WMRemoveNotificationObserver(panel
);
1077 WMUnmapWidget(panel
->win
);
1081 WMReleaseFont(panel
->font8
);
1083 WMReleaseFont(panel
->font12
);
1086 if (panel
->wheelMtrx
)
1087 wheelDestroyMatrix(panel
->wheelMtrx
);
1088 if (panel
->wheelImg
)
1089 XFreePixmap(scr
->display
, panel
->wheelImg
);
1090 if (panel
->selectionImg
)
1091 XFreePixmap(scr
->display
, panel
->selectionImg
);
1092 if (panel
->selectionBackImg
)
1093 XFreePixmap(scr
->display
, panel
->selectionBackImg
);
1094 if (panel
->customPaletteImg
)
1095 RDestroyImage(panel
->customPaletteImg
);
1098 if (panel
->lastBrowseDir
)
1099 wfree(panel
->lastBrowseDir
);
1100 if (panel
->configurationPath
)
1101 wfree(panel
->configurationPath
);
1103 WMDestroyWidget(panel
->win
);
1110 WMCloseColorPanel(WMColorPanel
*panel
)
1112 WMFreeColorPanel(panel
);
1117 WMShowColorPanel(WMColorPanel
*panel
)
1119 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1120 WMColor
*white
= WMWhiteColor(scr
);
1122 if (!panel
->colorSet
)
1123 WMSetColorPanelColor(panel
, white
);
1124 WMReleaseColor(white
);
1126 WMSetColorPanelPickerMode(panel
, WMWheelModeColorPanel
);
1129 WMMapWidget(panel
->win
);
1134 closeWindowCallback(WMWidget
*w
, void *data
)
1136 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
1138 WMCloseColorPanel(panel
);
1143 readConfiguration(W_ColorPanel
*panel
)
1145 /* XXX Doesn't take care of "invalid" files */
1149 struct stat stat_buf
;
1152 if (stat(panel
->configurationPath
, &stat_buf
)!=0) {
1153 if (mkdir(panel
->configurationPath
,
1154 S_IRWXU
|S_IRGRP
|S_IROTH
|S_IXGRP
|S_IXOTH
)!=0) {
1155 wsyserror("ColorPanel could not create directory %s needed"
1156 " to store configurations", panel
->configurationPath
);
1157 WMSetPopUpButtonEnabled(panel
->customPaletteMenuBtn
, False
);
1158 WMSetPopUpButtonEnabled(panel
->colorListColorMenuBtn
, False
);
1159 WMSetPopUpButtonEnabled(panel
->colorListListMenuBtn
, False
);
1160 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1162 "Could not create ColorPanel configuration directory",
1168 dPtr
= opendir(panel
->configurationPath
);
1169 while ((dp
= readdir(dPtr
)) != NULL
) {
1170 if (dp
->d_name
[0] != '.')
1171 WMAddPopUpButtonItem(panel
->customPaletteHistoryBtn
, dp
->d_name
);
1173 (void)closedir(dPtr
);
1178 readXColors(W_ColorPanel
*panel
)
1180 struct stat stat_buf
;
1182 char line
[MAX_LENGTH
];
1183 int red
, green
, blue
;
1188 if (stat(RGBTXT
, &stat_buf
) != 0) {
1189 wwarning("Cannot find file %s", RGBTXT
);
1193 rgbtxt
= fopen(RGBTXT
, "r");
1195 while (fgets(line
, MAX_LENGTH
, rgbtxt
)) {
1196 if (sscanf(line
, "%d%d%d %[^\n]", &red
, &green
, &blue
, name
)) {
1197 color
= wmalloc(sizeof(RColor
));
1198 color
->red
= (unsigned char)red
;
1199 color
->green
= (unsigned char)green
;
1200 color
->blue
= (unsigned char)blue
;
1201 item
= WMAddListItem(panel
->colorListContentLst
, name
);
1202 item
->clientData
= (void *)color
;
1208 wsyserror("Unable to open file %s for reading", RGBTXT
);
1215 WMSetColorPanelPickerMode(WMColorPanel
*panel
, WMColorPanelMode mode
)
1217 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1219 if (mode
!= WMWheelModeColorPanel
) {
1220 WMUnmapWidget(panel
->wheelFrm
);
1221 if (panel
->selectionBackImg
) {
1222 XFreePixmap(WMWidgetScreen(panel
->win
)->display
,
1223 panel
->selectionBackImg
);
1224 panel
->selectionBackImg
= None
;
1227 if (mode
!= WMGrayModeColorPanel
)
1228 WMUnmapWidget(panel
->grayFrm
);
1229 if (mode
!= WMRGBModeColorPanel
)
1230 WMUnmapWidget(panel
->rgbFrm
);
1231 if (mode
!= WMCMYKModeColorPanel
)
1232 WMUnmapWidget(panel
->cmykFrm
);
1233 if (mode
!= WMHSBModeColorPanel
)
1234 WMUnmapWidget(panel
->hsbFrm
);
1235 if (mode
!= WMCustomPaletteModeColorPanel
) {
1236 WMUnmapWidget(panel
->customPaletteFrm
);
1237 if (panel
->selectionBackImg
) {
1238 XFreePixmap(WMWidgetScreen(panel
->win
)->display
,
1239 panel
->selectionBackImg
);
1240 panel
->selectionBackImg
= None
;
1243 if (mode
!= WMColorListModeColorPanel
)
1244 WMUnmapWidget(panel
->colorListFrm
);
1245 if ((mode
!= WMGrayModeColorPanel
) && (mode
!= WMRGBModeColorPanel
) &&
1246 (mode
!= WMCMYKModeColorPanel
) && (mode
!= WMHSBModeColorPanel
))
1247 WMUnmapWidget(panel
->slidersFrm
);
1249 panel
->slidersmode
= mode
;
1251 if (mode
== WMWheelModeColorPanel
) {
1252 WMMapWidget(panel
->wheelFrm
);
1253 WMSetButtonSelected(panel
->wheelBtn
, True
);
1254 if (panel
->lastChanged
!= WMWheelModeColorPanel
)
1258 } else if (mode
== WMGrayModeColorPanel
) {
1259 WMMapWidget(panel
->slidersFrm
);
1260 WMSetButtonSelected(panel
->slidersBtn
, True
);
1261 WMMapWidget(panel
->grayFrm
);
1262 WMSetButtonSelected(panel
->grayBtn
, True
);
1263 WMSetButtonImage(panel
->slidersBtn
, scr
->grayIcon
);
1264 if (panel
->lastChanged
!= WMGrayModeColorPanel
)
1266 } else if (mode
== WMRGBModeColorPanel
) {
1267 WMMapWidget(panel
->slidersFrm
);
1268 WMSetButtonSelected(panel
->slidersBtn
, True
);
1269 WMMapWidget(panel
->rgbFrm
);
1270 WMSetButtonSelected(panel
->rgbBtn
, True
);
1271 WMSetButtonImage(panel
->slidersBtn
, scr
->rgbIcon
);
1272 if (panel
->lastChanged
!= WMRGBModeColorPanel
)
1274 } else if (mode
== WMCMYKModeColorPanel
) {
1275 WMMapWidget(panel
->slidersFrm
);
1276 WMSetButtonSelected(panel
->slidersBtn
, True
);
1277 WMMapWidget(panel
->cmykFrm
);
1278 WMSetButtonSelected(panel
->cmykBtn
, True
);
1279 WMSetButtonImage(panel
->slidersBtn
, scr
->cmykIcon
);
1280 if (panel
->lastChanged
!= WMCMYKModeColorPanel
)
1282 } else if (mode
== WMHSBModeColorPanel
) {
1283 WMMapWidget(panel
->slidersFrm
);
1284 WMSetButtonSelected(panel
->slidersBtn
, True
);
1285 WMMapWidget(panel
->hsbFrm
);
1286 WMSetButtonSelected(panel
->hsbBtn
, True
);
1287 WMSetButtonImage(panel
->slidersBtn
, scr
->hsbIcon
);
1288 if (panel
->lastChanged
!= WMHSBModeColorPanel
)
1290 } else if (mode
== WMCustomPaletteModeColorPanel
) {
1291 WMMapWidget(panel
->customPaletteFrm
);
1292 WMSetButtonSelected(panel
->customPaletteBtn
, True
);
1293 customSetPalette(panel
);
1294 } else if (mode
== WMColorListModeColorPanel
) {
1295 WMMapWidget(panel
->colorListFrm
);
1296 WMSetButtonSelected(panel
->colorListBtn
, True
);
1304 WMGetColorPanelColor(WMColorPanel
*panel
)
1306 return WMGetColorWellColor(panel
->colorWell
);
1311 WMSetColorPanelColor(WMColorPanel
*panel
, WMColor
*color
)
1313 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1316 GC bgc
= WMColorGC(scr
->black
);
1317 GC wgc
= WMColorGC(scr
->white
);
1320 WMSetColorWellColor(panel
->colorWell
, color
);
1322 intcolor
.red
= color
->color
.red
>> 8;
1323 intcolor
.green
= color
->color
.green
>> 8;
1324 intcolor
.blue
= color
->color
.blue
>> 8;
1326 panel
->color
= intcolor
;
1327 panel
->colorSet
= True
;
1329 /* If color was set by HSB-Panel do not convert back to hsv */
1330 if (panel
->lastChanged
!= WMHSBModeColorPanel
) {
1332 /* if color is black, hue is undetermined, so it must be restored */
1333 if ((panel
->color
.red
== 0) &&
1334 (panel
->color
.green
== 0) &&
1335 (panel
->color
.blue
== 0) &&
1336 (panel
->hsvcolor
.hue
<= 359))
1338 originalHue
= panel
->hsvcolor
.hue
;
1339 RRGBtoHSV(&panel
->color
, &panel
->hsvcolor
);
1340 panel
->hsvcolor
.hue
= originalHue
;
1342 RRGBtoHSV(&panel
->color
, &panel
->hsvcolor
);
1346 panel
->wheelMtrx
= wheelInitMatrix(panel
); /* Needs to be done After Color is set */
1348 /* Maybe put this in a sub-function ... Initialising selected images */
1349 RRGBtoHSV(&intcolor
, &hsvcolor
);
1350 panel
->colx
= 2 + rint((colorWheelSize
/ 2.0) * (1 +
1351 (hsvcolor
.saturation
/255.0) * cos( hsvcolor
.hue
*M_PI
/180.0)));
1352 panel
->coly
= 2 + rint((colorWheelSize
/ 2.0) * (1 +
1353 (hsvcolor
.saturation
/255.0) * sin(-hsvcolor
.hue
*M_PI
/180.0)));
1354 wheelUpdateBrightnessGradientFromHSV(panel
, hsvcolor
);
1355 WMSetSliderValue(panel
->wheelBrightnessS
, 255 - hsvcolor
.value
);
1357 panel
->selectionImg
= XCreatePixmap(scr
->display
,
1358 W_VIEW(panel
->wheelFrm
)->window
, 4, 4, scr
->depth
);
1359 XFillRectangle(scr
->display
, panel
->selectionImg
, bgc
, 0, 0, 4, 4);
1360 XFillRectangle(scr
->display
, panel
->selectionImg
, wgc
, 1, 1, 2, 2);
1361 /* End of initialisation section */
1363 panel
->palx
= customPaletteWidth
/2;
1364 panel
->paly
= customPaletteHeight
/2;
1366 WMSetColorPanelPickerMode(panel
, panel
->mode
);
1371 updateSwatch(WMColorPanel
*panel
, RColor color
)
1373 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1377 wellcolor
= WMCreateRGBColor(scr
, color
.red
<< 8, color
.green
<< 8,
1378 color
.blue
<< 8, True
);
1380 WMSetColorWellColor(panel
->colorWell
, wellcolor
);
1381 WMReleaseColor(wellcolor
);
1383 panel
->color
= color
;
1385 /* If color was set by HSB-Panel do not convert back to hsv */
1386 if (panel
->lastChanged
!= WMHSBModeColorPanel
) {
1388 /* if color is black, hue is undetermined, so it must be restored */
1389 if ((panel
->color
.red
== 0) &&
1390 (panel
->color
.green
== 0) &&
1391 (panel
->color
.blue
== 0) &&
1392 (panel
->hsvcolor
.hue
<= 359))
1394 originalHue
= panel
->hsvcolor
.hue
;
1395 RRGBtoHSV(&panel
->color
, &panel
->hsvcolor
);
1396 panel
->hsvcolor
.hue
= originalHue
;
1398 RRGBtoHSV(&panel
->color
, &panel
->hsvcolor
);
1402 if (!panel
->flags
.dragging
|| panel
->flags
.continuous
) {
1404 (*panel
->action
)(panel
, panel
->clientData
);
1406 WMPostNotificationName(WMColorPanelColorChangedNotification
, panel
,
1412 modeButtonCallback(WMWidget
*w
, void *data
)
1414 W_ColorPanel
*panel
= (W_ColorPanel
*)(data
);
1416 if (w
== panel
->wheelBtn
)
1417 WMSetColorPanelPickerMode(panel
, WMWheelModeColorPanel
);
1418 else if (w
== panel
->slidersBtn
)
1419 WMSetColorPanelPickerMode(panel
, panel
->slidersmode
);
1420 else if (w
== panel
->customPaletteBtn
)
1421 WMSetColorPanelPickerMode(panel
, WMCustomPaletteModeColorPanel
);
1422 else if (w
== panel
->colorListBtn
)
1423 WMSetColorPanelPickerMode(panel
, WMColorListModeColorPanel
);
1424 else if (w
== panel
->grayBtn
)
1425 WMSetColorPanelPickerMode(panel
, WMGrayModeColorPanel
);
1426 else if (w
== panel
->rgbBtn
)
1427 WMSetColorPanelPickerMode(panel
, WMRGBModeColorPanel
);
1428 else if (w
== panel
->cmykBtn
)
1429 WMSetColorPanelPickerMode(panel
, WMCMYKModeColorPanel
);
1430 else if (w
== panel
->hsbBtn
)
1431 WMSetColorPanelPickerMode(panel
, WMHSBModeColorPanel
);
1435 /****************** Magnifying Cursor Functions *******************/
1438 magnifyGetImage(WMScreen
*scr
, XImage
*image
, int x
, int y
, int w
, int h
)
1440 int x0
= 0, y0
= 0, w0
= w
, h0
= h
;
1441 const int displayWidth
= DisplayWidth(scr
->display
, scr
->screen
),
1442 displayHeight
= DisplayHeight(scr
->display
, scr
->screen
);
1444 if (!(image
&& image
->data
)) {
1445 /* The image in panel->magnifyGlass->image does not exist yet.
1446 * Grab one from the screen (not beyond) and use it from now on.
1448 if (!(image
= XGetImage(scr
->display
, scr
->rootWin
,
1451 w
, h
, AllPlanes
, ZPixmap
)))
1452 wwarning("ColorPanel: X said I cannot grab an image from screen.");
1457 /* Coordinate correction for back pixmap
1458 * if magnifying glass is at screen-borders
1461 /* Figure 1: Shifting of rectangle-to-grab at top/left screen borders
1462 * Hatched area is beyond screen border.
1464 * |<-Cursor_x_hot->|
1465 * ________________|_____
1466 * |/ / / / / / /| | |
1467 * | / / / / / / |(x,y) |
1468 * |/_/_/_/_/_/_/|________|
1469 * |<----x0----->|<--w0-->|
1473 /* Figure 2: Shifting of rectangle-to-grab at bottom/right
1475 * Hatched area is beyond screen border
1477 * |<-Cursor_x_hot->|
1478 * ________________|_______________
1479 * | | | / / / / / /|
1480 * | (x,y)|/ / / / / / |
1481 * |___________________|_/_/_/_/_/_/|
1482 * |<-------w0-------->| |
1483 * |<---------------w--|----------->|
1488 if (x
< Cursor_x_hot
) { /* see fig. 1 */
1489 x0
= Cursor_x_hot
- x
;
1493 if (displayWidth
-1 < x
- Cursor_x_hot
+ w
) { /* see fig. 2 */
1494 w0
= (displayWidth
) - (x
- Cursor_x_hot
);
1497 if (y
< Cursor_y_hot
) { /* see fig. 1 */
1498 y0
= Cursor_y_hot
- y
;
1502 if (displayHeight
-1 < y
- Cursor_y_hot
+ h
) { /* see fig. 2 */
1503 h0
= (displayHeight
) - (y
- Cursor_y_hot
);
1505 /* end of coordinate correction */
1508 /* Grab an image from the screen, clipped if necessary,
1509 * and put it in the existing panel->magnifyGlass->image
1510 * with the corresponding clipping offset.
1512 if (!XGetSubImage(scr
->display
, scr
->rootWin
,
1513 x
- Cursor_x_hot
+ x0
,
1514 y
- Cursor_y_hot
+ y0
,
1515 w0
, h0
, AllPlanes
, ZPixmap
,
1517 wwarning("ColorPanel: X said I cannot grab a subimage from screen.");
1524 magnifyGetImageStored(WMColorPanel
*panel
, int x1
, int y1
, int x2
, int y2
)
1526 /* (x1, y1) = topleft corner of existing rectangle
1527 * (x2, y2) = topleft corner of new position
1530 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1531 int xa
= 0, ya
= 0, xb
= 0, yb
= 0;
1533 const int dx
= abs(x2
- x1
),
1536 const int x_min
= Cursor_x_hot
,
1537 y_min
= Cursor_y_hot
,
1538 x_max
= DisplayWidth(scr
->display
, scr
->screen
) -1 -
1539 (Cursor_mask_width
- Cursor_x_hot
),
1540 y_max
= DisplayHeight(scr
->display
, scr
->screen
) -1 -
1541 (Cursor_mask_height
- Cursor_y_hot
);
1543 if ((dx
== 0) && (dy
== 0) && panel
->magnifyGlass
->image
)
1544 return; /* Eh, Captain, we didn't move...
1545 * but... eh... how did we get here? */
1557 width
= Cursor_mask_width
- dx
;
1558 height
= Cursor_mask_height
- dy
;
1560 /* If the traversed distance is larger than the size of the magnifying
1561 * glass contents, there is no need to do dirty rectangles. A whole new
1562 * rectangle can be grabbed, unless that rectangle falls partially
1564 * Destroying the image and setting it to NULL will achieve that later on.
1566 * Of course, grabbing an XImage beyond the borders of the screen will
1567 * cause trouble, this is considdered a special case. Part of the screen
1568 * is grabbed, but there is no need for dirty rectangles.
1570 if ((width
<= 0) || (height
<= 0)) {
1571 if ((x2
>= x_min
) && (y2
>= y_min
) && (x2
<= x_max
) && (y2
<= y_max
)) {
1572 if (panel
->magnifyGlass
->image
)
1573 XDestroyImage(panel
->magnifyGlass
->image
);
1574 panel
->magnifyGlass
->image
= NULL
;
1577 if (panel
->magnifyGlass
->image
) {
1578 /* Get dirty rectangle from panel->magnifyGlass->image */
1579 panel
->magnifyGlass
->dirtyRect
=
1580 XSubImage(panel
->magnifyGlass
->image
, xa
, ya
, width
, height
);
1581 if (!panel
->magnifyGlass
->dirtyRect
) {
1582 wwarning("ColorPanel: X said I cannot get a dirty rectangle.");
1583 return; /* X returned a NULL from XSubImage */
1588 /* Get image from screen */
1589 image
= magnifyGetImage(scr
, panel
->magnifyGlass
->image
, x2
, y2
,
1590 Cursor_mask_width
, Cursor_mask_height
);
1591 if (image
) { /* Only reassign if a *new* image was grabbed */
1592 panel
->magnifyGlass
->image
= image
;
1596 /* Copy previously stored rectangle on covered part of image */
1597 if (panel
->magnifyGlass
->image
&& panel
->magnifyGlass
->dirtyRect
) {
1600 /* "width" and "height" are used as coordinates here,
1601 * and run from [0...width-1] and [0...height-1] respectively.
1605 old_height
= height
;
1607 for (; width
>= 0; width
--)
1608 for (height
= old_height
; height
>= 0; height
--)
1609 XPutPixel(panel
->magnifyGlass
->image
, xb
+ width
, yb
+ height
,
1610 XGetPixel(panel
->magnifyGlass
->dirtyRect
, width
, height
));
1611 XDestroyImage(panel
->magnifyGlass
->dirtyRect
);
1612 panel
->magnifyGlass
->dirtyRect
= NULL
;
1620 magnifyCreatePixmap(WMColorPanel
*panel
)
1622 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1625 unsigned long color
;
1627 if (!panel
->magnifyGlass
->image
)
1630 if (!panel
->magnifyGlass
->magPix
)
1634 * Copy an area of only 5x5 pixels from the center of the image.
1636 for (u
= 0; u
< 5; u
++) {
1637 for (v
= 0; v
< 5; v
++) {
1638 color
= XGetPixel(panel
->magnifyGlass
->image
, u
+ 9, v
+ 9);
1640 XSetForeground(scr
->display
, scr
->copyGC
, color
);
1642 if ((u
== 2) && (v
== 2)) /* (2,2) is center pixel (unmagn.) */
1643 panel
->magnifyGlass
->color
= ulongToRColor(scr
,
1644 panel
->magnifyGlass
->image
, color
);
1646 XFillRectangle(scr
->display
, panel
->magnifyGlass
->magPix
,
1647 scr
->copyGC
, u
* 5, v
* 5, 5, 5);
1651 pixmap
= XCreatePixmap(scr
->display
, W_DRAWABLE(scr
), Cursor_mask_width
,
1652 Cursor_mask_height
, scr
->depth
);
1657 XPutImage(scr
->display
, pixmap
, scr
->copyGC
, panel
->magnifyGlass
->image
,
1658 0, 0, 0, 0, Cursor_mask_width
, Cursor_mask_height
);
1661 /* Copy the magnified pixmap, with the clip mask, to background pixmap */
1662 XCopyArea(scr
->display
, panel
->magnifyGlass
->magPix
, pixmap
,
1663 scr
->clipGC
, 1, 1, Cursor_mask_width
, Cursor_mask_height
, 0, 0);
1664 /* (2,2) puts center pixel on center of glass */
1671 magnifyCreateView(W_ColorPanel
*panel
)
1673 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1676 magView
= W_CreateTopView(scr
);
1680 magView
->self
= panel
->win
;
1681 magView
->flags
.topLevel
= 1;
1682 magView
->attribFlags
|= CWOverrideRedirect
| CWSaveUnder
;
1683 magView
->attribs
.override_redirect
= True
;
1684 magView
->attribs
.save_under
= True
;
1686 W_ResizeView(magView
, Cursor_mask_width
, Cursor_mask_height
);
1688 W_RealizeView(magView
);
1695 magnifyGrabPointer(W_ColorPanel
*panel
)
1697 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1698 Pixmap magPixmap
, magPixmap2
;
1700 XColor fgColor
= {0, 0,0,0, DoRed
|DoGreen
|DoBlue
};
1701 XColor bgColor
= {0, 0xbf00, 0xa000, 0x5000, DoRed
|DoGreen
|DoBlue
};
1703 /* Cursor creation stuff */
1704 magPixmap
= XCreatePixmapFromBitmapData(scr
->display
, W_DRAWABLE(scr
),
1705 (char *)Cursor_bits
, Cursor_width
, Cursor_height
, 1, 0, 1);
1706 magPixmap2
= XCreatePixmapFromBitmapData(scr
->display
, W_DRAWABLE(scr
),
1707 (char *)Cursor_shape_bits
, Cursor_width
, Cursor_height
, 1, 0, 1);
1709 magCursor
= XCreatePixmapCursor(scr
->display
, magPixmap
, magPixmap2
,
1710 &fgColor
, &bgColor
, Cursor_x_hot
, Cursor_y_hot
);
1712 XFreePixmap(scr
->display
, magPixmap
);
1713 XFreePixmap(scr
->display
, magPixmap2
);
1715 XRecolorCursor(scr
->display
, magCursor
, &fgColor
, &bgColor
);
1717 /* Set up Pointer */
1718 XGrabPointer (scr
->display
, panel
->magnifyGlass
->view
->window
, True
,
1719 PointerMotionMask
| ButtonPressMask
,
1720 GrabModeAsync
, GrabModeAsync
,
1721 scr
->rootWin
, magCursor
, CurrentTime
);
1728 magnifyInitialize(W_ColorPanel
*panel
)
1730 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1731 unsigned int x
, y
, u
, v
;
1733 Pixmap pixmap
, clip_mask
;
1735 Window root_return
, child_return
;
1737 clip_mask
= XCreatePixmapFromBitmapData(scr
->display
, W_DRAWABLE(scr
),
1738 (char *)Cursor_mask_bits
, Cursor_mask_width
, Cursor_mask_height
,
1740 panel
->magnifyGlass
->magPix
= XCreatePixmap(scr
->display
, W_DRAWABLE(scr
),
1741 5*5, 5*5, scr
->depth
);
1743 XQueryPointer(scr
->display
, scr
->rootWin
, &root_return
, &child_return
,
1744 &x
, &y
, &u
, &v
, &mask
);
1746 panel
->magnifyGlass
->image
= NULL
;
1748 /* Clipmask to make magnified view-contents circular */
1751 XShapeCombineMask(scr
->display
, WMViewXID(panel
->magnifyGlass
->view
),
1752 ShapeBounding
, 0, 0, clip_mask
, ShapeSet
);
1754 /* Clip circle in glass cursor */
1755 XSetClipMask(scr
->display
, scr
->clipGC
, clip_mask
);
1756 XSetClipOrigin(scr
->display
, scr
->clipGC
, 0, 0);
1759 XFreePixmap(scr
->display
, clip_mask
);
1761 /* Draw initial magnifying glass contents */
1762 magnifyGetImageStored(panel
, x
, y
, x
, y
);
1764 pixmap
= magnifyCreatePixmap(panel
);
1765 XSetWindowBackgroundPixmap(scr
->display
,
1766 panel
->magnifyGlass
->view
->window
,
1768 XClearWindow(scr
->display
, panel
->magnifyGlass
->view
->window
);
1769 XFlush(scr
->display
);
1771 XFreePixmap(scr
->display
, pixmap
);
1781 magnifyPutCursor(WMWidget
*w
, void *data
)
1783 W_ColorPanel
*panel
= (W_ColorPanel
*)(data
);
1784 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
1789 WMPoint initialPosition
;
1791 /* Destroy wheelBackImg, so it'll update properly */
1792 if (panel
->selectionBackImg
) {
1793 XFreePixmap(WMWidgetScreen(panel
->win
)->display
,
1794 panel
->selectionBackImg
);
1795 panel
->selectionBackImg
= None
;
1798 /* Create magnifying glass */
1799 panel
->magnifyGlass
= wmalloc(sizeof(MovingView
));
1800 panel
->magnifyGlass
->view
= magnifyCreateView(panel
);
1801 if (!panel
->magnifyGlass
->view
)
1804 initialPosition
= magnifyInitialize(panel
);
1805 x
= initialPosition
.x
;
1806 y
= initialPosition
.y
;
1808 W_MoveView(panel
->magnifyGlass
->view
,
1811 W_MapView(panel
->magnifyGlass
->view
);
1813 magCursor
= magnifyGrabPointer(panel
);
1815 while (panel
->magnifyGlass
->image
)
1817 WMNextEvent(scr
->display
, &event
);
1819 /* Pack motion events */
1820 while (XCheckTypedEvent(scr
->display
, MotionNotify
, &event
)) {
1826 XDestroyImage(panel
->magnifyGlass
->image
);
1827 panel
->magnifyGlass
->image
= NULL
;
1829 if (event
.xbutton
.button
== Button1
) {
1830 updateSwatch(panel
, panel
->magnifyGlass
->color
);
1832 switch (panel
->mode
) {
1833 case WMWheelModeColorPanel
:
1838 case WMGrayModeColorPanel
:
1841 case WMRGBModeColorPanel
:
1844 case WMCMYKModeColorPanel
:
1847 case WMHSBModeColorPanel
:
1853 panel
->lastChanged
= panel
->mode
;
1855 WMSetButtonSelected(panel
->magnifyBtn
, False
);
1859 /* Get a "dirty rectangle" */
1860 magnifyGetImageStored( panel
, x
, y
,
1861 event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1863 /* Update coordinates */
1864 x
= event
.xmotion
.x_root
;
1865 y
= event
.xmotion
.y_root
;
1868 W_MoveView(panel
->magnifyGlass
->view
, x
- Cursor_x_hot
,
1871 /* Put new image (with magn.) in view */
1872 pixmap
= magnifyCreatePixmap(panel
);
1873 if (pixmap
!= None
) {
1874 XSetWindowBackgroundPixmap(scr
->display
,
1875 panel
->magnifyGlass
->view
->window
, pixmap
);
1876 XClearWindow(scr
->display
, panel
->magnifyGlass
->view
->window
);
1878 XFreePixmap(scr
->display
, pixmap
);
1882 /* Try XQueryPointer for this !!! It returns windows that the pointer
1883 * is over. Note: We found this solving the invisible donkey cap bug
1885 #if 0 /* As it is impossible to make this work in all cases,
1886 * we consider it confusing. Therefore we disabled it.
1888 case FocusOut
: /* fall through */
1891 * Color Panel window (panel->win) lost or received focus.
1892 * We need to update the pixmap in the magnifying glass.
1894 * BUG Doesn't work with focus switches between two windows
1895 * if none of them is the color panel.
1897 XUngrabPointer(scr
->display
, CurrentTime
);
1898 W_UnmapView(panel
->magnifyGlass
->view
);
1900 magnifyInitialize(panel
);
1902 W_MapView(panel
->magnifyGlass
->view
);
1903 XGrabPointer (scr
->display
, panel
->magnifyGlass
->view
->window
,
1904 True
, PointerMotionMask
| ButtonPressMask
,
1905 GrabModeAsync
, GrabModeAsync
,
1906 scr
->rootWin
, magCursor
, CurrentTime
);
1910 WMHandleEvent(&event
);
1915 XUngrabPointer(scr
->display
, CurrentTime
);
1916 XFreeCursor(scr
->display
, magCursor
);
1918 XFreePixmap(scr
->display
, panel
->magnifyGlass
->magPix
);
1919 panel
->magnifyGlass
->magPix
= None
;
1921 W_UnmapView(panel
->magnifyGlass
->view
);
1922 W_DestroyView(panel
->magnifyGlass
->view
);
1923 panel
->magnifyGlass
->view
= NULL
;
1925 wfree(panel
->magnifyGlass
);
1930 /****************** WheelMatrix Functions ************************/
1933 wheelCreateMatrix(unsigned int width
, unsigned int height
)
1935 wheelMatrix
*matrix
= NULL
;
1938 assert((width
> 0) && (height
> 0));
1940 matrix
= malloc(sizeof(wheelMatrix
));
1942 RErrorCode
= RERR_NOMEMORY
;
1946 memset(matrix
, 0, sizeof(wheelMatrix
));
1947 matrix
->width
= width
;
1948 matrix
->height
= height
;
1949 for (i
= 0; i
< 3; i
++) {
1950 matrix
->data
[i
] = malloc(width
*height
*sizeof(unsigned char));
1951 if (!matrix
->data
[i
])
1958 for (i
= 0; i
< 3; i
++) {
1959 if (matrix
->data
[i
])
1960 wfree(matrix
->data
[i
]);
1964 RErrorCode
= RERR_NOMEMORY
;
1970 wheelDestroyMatrix(wheelMatrix
*matrix
)
1974 assert (matrix
!=NULL
);
1976 for (i
= 0; i
< 3; i
++) {
1977 if (matrix
->data
[i
])
1978 wfree(matrix
->data
[i
]);
1985 wheelInitMatrix(W_ColorPanel
*panel
)
1989 wheelMatrix
*matrix
;
1990 unsigned char *rp
, *gp
, *bp
;
1999 matrix
= wheelCreateMatrix(colorWheelSize
+4, colorWheelSize
+4);
2003 RRGBtoHSV(&panel
->color
, &cur_hsv
);
2005 for (i
= 0; i
< 256; i
++)
2006 matrix
->values
[i
] = (unsigned char)(rint(i
*cur_hsv
.value
/255));
2008 cur_hsv
.value
= 255;
2011 ofs
[1] = -(colorWheelSize
+ 4);
2012 /* ofs[2] = 0; superfluous
2015 for (y
= 0; y
< (colorWheelSize
+4)/2; y
++) {
2016 for (x
= y
; x
< (colorWheelSize
+4-y
); x
++) {
2017 xcor
= ((float)(2.0*x
- 4.0) / colorWheelSize
) - 1;
2018 ycor
= ((float)(2.0*y
- 4.0) / colorWheelSize
) - 1;
2020 sat
= rint(255.0 * sqrt((xcor
*xcor
) + (ycor
*ycor
)));
2024 /* offsets are counterclockwise (in triangles) */
2027 if (y
< (colorWheelSize
+4)/2)
2031 ofs
[1] += colorWheelSize
+ 4;
2033 /* bottom quarter */
2034 ofs
[2] = (colorWheelSize
+ 4) * (colorWheelSize
+ 4) - 1 - ofs
[0];
2037 ofs
[3] = (colorWheelSize
+ 4) * (colorWheelSize
+ 4) - 1 - ofs
[1];
2040 cur_hsv
.saturation
= (unsigned char)sat
;
2043 hue
= atan(ycor
/xcor
);
2053 if ((xcor
> 0) && (ycor
< 0))
2056 hue
= -hue
; /* Reverse direction of ColorWheel */
2061 dhue
[0] = (hue
*360) / (M_PI
* 2.0);
2063 for (i
= 0; i
< 4; i
++) {
2066 dhue
[i
] = (dhue
[i
-1] + 90) % 360;
2068 if ((i
== 1) || (i
== 3))
2069 dhue
[i
] = 360 - dhue
[i
];
2072 dhue
[i
] = 360 - dhue
[i
] + 180;
2074 rp
= matrix
->data
[0] + (ofs
[i
] * sizeof(unsigned char));
2075 gp
= matrix
->data
[1] + (ofs
[i
] * sizeof(unsigned char));
2076 bp
= matrix
->data
[2] + (ofs
[i
] * sizeof(unsigned char));
2078 cur_hsv
.hue
= dhue
[i
];
2079 RHSVtoRGB(&cur_hsv
, &cur_rgb
);
2081 *rp
= (unsigned char)(cur_rgb
.red
);
2082 *gp
= (unsigned char)(cur_rgb
.green
);
2083 *bp
= (unsigned char)(cur_rgb
.blue
);
2087 for (i
= 0; i
< 4; i
++) {
2088 rp
= matrix
->data
[0] + (ofs
[i
] * sizeof(unsigned char));
2089 gp
= matrix
->data
[1] + (ofs
[i
] * sizeof(unsigned char));
2090 bp
= matrix
->data
[2] + (ofs
[i
] * sizeof(unsigned char));
2092 *rp
= (unsigned char)(0);
2093 *gp
= (unsigned char)(0);
2094 *bp
= (unsigned char)(0);
2098 if (y
< (colorWheelSize
+4)/2)
2101 ofs
[1] += 1 - (colorWheelSize
+ 4) * (colorWheelSize
+ 4 - 1 - 2*y
);
2107 /****************** ColorWheel Functions *******************/
2110 wheelRender(W_ColorPanel
*panel
)
2112 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2115 unsigned char *rp
, *gp
, *bp
;
2119 image
= RCreateImage(colorWheelSize
+4, colorWheelSize
+4, False
);
2123 gray
.red
= gray
.green
= gray
.blue
= 0xaa;
2125 for (x
= 0; x
< colorWheelSize
+4; x
++) {
2126 for (y
= 0; y
< colorWheelSize
+4; y
++) {
2128 ofs
= (y
* image
->width
) + x
;
2129 rp
= image
->data
[0] + ofs
;
2130 gp
= image
->data
[1] + ofs
;
2131 bp
= image
->data
[2] + ofs
;
2133 if (wheelInsideColorWheel(panel
, ofs
)) {
2134 *rp
= (unsigned int)(panel
->wheelMtrx
->values
[
2135 panel
->wheelMtrx
->data
[0][ofs
] ]);
2136 *gp
= (unsigned int)(panel
->wheelMtrx
->values
[
2137 panel
->wheelMtrx
->data
[1][ofs
] ]);
2138 *bp
= (unsigned int)(panel
->wheelMtrx
->values
[
2139 panel
->wheelMtrx
->data
[2][ofs
] ]);
2142 *rp
= (unsigned char)(gray
.red
);
2143 *gp
= (unsigned char)(gray
.green
);
2144 *bp
= (unsigned char)(gray
.blue
);
2149 if (panel
->wheelImg
)
2150 XFreePixmap(scr
->display
, panel
->wheelImg
);
2152 panel
->wheelImg
= XCreatePixmap(scr
->display
, W_DRAWABLE(scr
),
2153 colorWheelSize
+4, colorWheelSize
+4, scr
->depth
);
2154 RConvertImage(scr
->rcontext
, image
, &panel
->wheelImg
);
2156 /* Check if backimage exists. If it doesn't, allocate and fill it */
2157 if (!panel
->selectionBackImg
) {
2158 panel
->selectionBackImg
= XCreatePixmap(scr
->display
,
2159 W_VIEW(panel
->wheelFrm
)->window
, 4, 4, scr
->depth
);
2160 XCopyArea(scr
->display
, panel
->wheelImg
, panel
->selectionBackImg
,
2161 scr
->copyGC
, panel
->colx
-2, panel
->coly
-2, 4, 4, 0, 0);
2162 /* -2 is hot spot correction */
2165 RDestroyImage(image
);
2169 wheelInsideColorWheel(W_ColorPanel
*panel
, unsigned long ofs
)
2171 return ((panel
->wheelMtrx
->data
[0][ofs
] != 0) &&
2172 (panel
->wheelMtrx
->data
[1][ofs
] != 0) &&
2173 (panel
->wheelMtrx
->data
[2][ofs
] != 0));
2177 wheelPaint (W_ColorPanel
*panel
)
2179 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2181 XCopyArea(scr
->display
, panel
->wheelImg
, panel
->wheelView
->window
,
2182 scr
->copyGC
, 0, 0, colorWheelSize
+4, colorWheelSize
+4, 0, 0);
2184 /* Draw selection image */
2185 XCopyArea(scr
->display
, panel
->selectionImg
, panel
->wheelView
->window
,
2186 scr
->copyGC
, 0, 0, 4, 4, panel
->colx
-2, panel
->coly
-2);
2190 wheelHandleEvents(XEvent
*event
, void *data
)
2192 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2194 switch (event
->type
) {
2196 if (event
->xexpose
.count
!= 0)
2204 wheelHandleActionEvents(XEvent
*event
, void *data
)
2206 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2208 switch (event
->type
) {
2210 if (getPickerPart(panel
, event
->xbutton
.x
, event
->xbutton
.y
) ==
2212 panel
->flags
.dragging
= 1;
2213 wheelPositionSelection(panel
, event
->xbutton
.x
, event
->xbutton
.y
);
2218 panel
->flags
.dragging
= 0;
2219 if (!panel
->flags
.continuous
) {
2221 (*panel
->action
)(panel
, panel
->clientData
);
2226 if (panel
->flags
.dragging
) {
2227 if (getPickerPart(panel
, event
->xmotion
.x
, event
->xmotion
.y
) ==
2229 wheelPositionSelection(panel
, event
->xmotion
.x
,
2233 wheelPositionSelectionOutBounds(panel
, event
->xmotion
.x
,
2242 getPickerPart(W_ColorPanel
*panel
, int x
, int y
)
2250 if (panel
->mode
== WMWheelModeColorPanel
) {
2251 if ((lx
>= 2) && (lx
<= 2+colorWheelSize
) && (ly
>= 2) &&
2252 (ly
<= 2+colorWheelSize
)) {
2254 ofs
= ly
*panel
->wheelMtrx
->width
+lx
;
2256 if (wheelInsideColorWheel(panel
, ofs
))
2257 return COLORWHEEL_PART
;
2261 if (panel
->mode
== WMCustomPaletteModeColorPanel
) {
2262 if ((lx
>= 2) && (lx
< customPaletteWidth
-2) && (ly
>= 2) &&
2263 (ly
< customPaletteHeight
-2)) {
2264 return CUSTOMPALETTE_PART
;
2273 wheelBrightnessSliderCallback(WMWidget
*w
, void *data
)
2281 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2283 value
= 255-WMGetSliderValue(panel
->wheelBrightnessS
);
2285 for (i
= 0; i
< 256; i
++) {
2286 /* We divide by 128 in advance, and check whether that number divides
2287 * by 2 properly. If not, we add one to round the number correctly
2291 panel
->wheelMtrx
->values
[i
] = (unsigned char)((v
>> 1) + v
);
2293 panel
->wheelMtrx
->values
[i
] = (unsigned char)((v
>> 1) +(v
& 0x01));
2297 ofs
= (panel
->coly
* panel
->wheelMtrx
->width
) + panel
->colx
;
2299 if (!wheelInsideColorWheel(panel
, ofs
)) {
2300 panel
->hsvcolor
.saturation
= 255;
2301 panel
->hsvcolor
.value
= value
;
2302 RHSVtoRGB(&panel
->hsvcolor
, &cur_rgb
);
2304 panel
->color
= cur_rgb
;
2307 panel
->color
.red
= panel
->wheelMtrx
->values
[
2308 panel
->wheelMtrx
->data
[0][ofs
] ];
2309 panel
->color
.green
= panel
->wheelMtrx
->values
[
2310 panel
->wheelMtrx
->data
[1][ofs
] ];
2311 panel
->color
.blue
= panel
->wheelMtrx
->values
[
2312 panel
->wheelMtrx
->data
[2][ofs
] ];
2317 wheelUpdateSelection(panel
);
2322 wheelUpdateSelection(W_ColorPanel
*panel
)
2324 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2326 updateSwatch(panel
, panel
->color
);
2327 panel
->lastChanged
= WMWheelModeColorPanel
;
2329 /* Redraw color selector (and make a backup of the part it will cover) */
2330 XCopyArea(scr
->display
, panel
->wheelImg
, panel
->selectionBackImg
,
2331 scr
->copyGC
, panel
->colx
-2, panel
->coly
-2, 4, 4, 0, 0);
2332 /* "-2" is correction for hotspot location */
2333 XCopyArea(scr
->display
, panel
->selectionImg
, panel
->wheelView
->window
,
2334 scr
->copyGC
, 0, 0, 4, 4, panel
->colx
-2, panel
->coly
-2);
2339 wheelUndrawSelection(W_ColorPanel
*panel
)
2341 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2343 XCopyArea(scr
->display
, panel
->selectionBackImg
, panel
->wheelView
->window
,
2344 scr
->copyGC
, 0, 0, 4, 4, panel
->colx
-2, panel
->coly
-2);
2349 wheelPositionSelection(W_ColorPanel
*panel
, int x
, int y
)
2351 unsigned long ofs
= (y
* panel
->wheelMtrx
->width
)+ x
;
2353 panel
->color
.red
= panel
->wheelMtrx
->values
[
2354 panel
->wheelMtrx
->data
[0][ofs
] ];
2356 panel
->color
.green
= panel
->wheelMtrx
->values
[
2357 panel
->wheelMtrx
->data
[1][ofs
] ];
2359 panel
->color
.blue
= panel
->wheelMtrx
->values
[
2360 panel
->wheelMtrx
->data
[2][ofs
] ];
2362 wheelUndrawSelection(panel
);
2367 wheelUpdateSelection(panel
);
2368 wheelUpdateBrightnessGradientFromLocation(panel
);
2372 wheelPositionSelectionOutBounds(W_ColorPanel
*panel
, int x
, int y
)
2378 xcor
= ((x
*2.0) / (colorWheelSize
+4)) - 1.0;
2379 ycor
= ((y
*2.0) / (colorWheelSize
+4)) - 1.0;
2381 cur_hsv
.saturation
= 255;
2382 cur_hsv
.value
= 255 - WMGetSliderValue(panel
->wheelBrightnessS
);
2385 hue
= atan(ycor
/xcor
);
2395 if ((xcor
> 0) && (ycor
< 0))
2403 cur_hsv
.hue
= (hue
*180.0)/(M_PI
);
2404 RHSVtoRGB(&cur_hsv
, &panel
->color
);
2406 wheelUndrawSelection(panel
);
2408 panel
->colx
= 2 + rint((colorWheelSize
* (1.0 +
2409 cos( cur_hsv
.hue
*M_PI
/180))) /2.0);
2410 /* "+2" because of "colorWheelSize + 4" */
2411 panel
->coly
= 2 + rint((colorWheelSize
* (1.0 +
2412 sin(-cur_hsv
.hue
*M_PI
/180))) /2.0);
2414 wheelUpdateSelection(panel
);
2415 wheelUpdateBrightnessGradientFromHSV(panel
, cur_hsv
);
2419 wheelUpdateBrightnessGradientFromHSV(W_ColorPanel
*panel
, RHSVColor topColor
)
2423 /* Update Brightness-Slider */
2424 topColor
.value
= 255;
2425 RHSVtoRGB(&topColor
, &from
);
2427 wheelUpdateBrightnessGradient(panel
, from
);
2431 wheelUpdateBrightnessGradientFromLocation(W_ColorPanel
*panel
)
2436 ofs
= panel
->coly
* panel
->wheelMtrx
->width
+ panel
->colx
;
2438 from
.red
= panel
->wheelMtrx
->data
[0][ofs
];
2439 from
.green
= panel
->wheelMtrx
->data
[1][ofs
];
2440 from
.blue
= panel
->wheelMtrx
->data
[2][ofs
];
2442 wheelUpdateBrightnessGradient(panel
, from
);
2446 wheelUpdateBrightnessGradient(W_ColorPanel
*panel
, RColor topColor
)
2450 WMPixmap
*sliderPxmp
;
2452 to
.red
= to
.green
= to
.blue
= 0;
2454 sliderImg
= RRenderGradient(16, 153, &topColor
, &to
, RGRD_VERTICAL
);
2455 sliderPxmp
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->win
),
2457 RDestroyImage(sliderImg
);
2458 WMSetSliderImage(panel
->wheelBrightnessS
, sliderPxmp
);
2459 WMReleasePixmap(sliderPxmp
);
2462 /****************** Grayscale Panel Functions ***************/
2465 grayBrightnessSliderCallback(WMWidget
*w
, void *data
)
2470 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2472 value
= WMGetSliderValue(panel
->grayBrightnessS
);
2474 sprintf(tmp
, "%d", value
);
2476 WMSetTextFieldText(panel
->grayBrightnessT
, tmp
);
2477 color
.red
= color
.green
= color
.blue
= rint(2.55*value
);
2479 updateSwatch(panel
, color
);
2480 panel
->lastChanged
= WMGrayModeColorPanel
;
2484 grayPresetButtonCallback(WMWidget
*w
, void *data
)
2490 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2493 if (w
== panel
->grayPresetBtn
[i
])
2498 value
= rint(100.0/6.0*i
);
2499 sprintf(tmp
, "%d", value
);
2501 WMSetTextFieldText(panel
->grayBrightnessT
, tmp
);
2502 color
.red
= color
.green
= color
.blue
= rint(255.0*i
/6.0);
2504 WMSetSliderValue(panel
->grayBrightnessS
, rint(100.0*i
/6.0));
2506 updateSwatch(panel
, color
);
2507 panel
->lastChanged
= WMGrayModeColorPanel
;
2511 grayBrightnessTextFieldCallback(void *observerData
,
2512 WMNotification
*notification
)
2517 W_ColorPanel
*panel
= (W_ColorPanel
*)observerData
;
2519 value
= atoi(WMGetTextFieldText(panel
->grayBrightnessT
));
2525 sprintf(tmp
, "%d", value
);
2526 WMSetTextFieldText(panel
->grayBrightnessT
, tmp
);
2527 WMSetSliderValue(panel
->grayBrightnessS
, value
);
2529 color
.red
= color
.green
= color
.blue
= rint(255.0*value
/100.0);
2530 updateSwatch(panel
, color
);
2531 panel
->lastChanged
= WMGrayModeColorPanel
;
2534 /******************* RGB Panel Functions *****************/
2537 rgbSliderCallback(WMWidget
*w
, void *data
)
2542 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2544 value
[0] = WMGetSliderValue(panel
->rgbRedS
);
2545 value
[1] = WMGetSliderValue(panel
->rgbGreenS
);
2546 value
[2] = WMGetSliderValue(panel
->rgbBlueS
);
2548 sprintf(tmp
, "%d", value
[0]);
2549 WMSetTextFieldText(panel
->rgbRedT
, tmp
);
2550 sprintf(tmp
, "%d", value
[1]);
2551 WMSetTextFieldText(panel
->rgbGreenT
, tmp
);
2552 sprintf(tmp
, "%d", value
[2]);
2553 WMSetTextFieldText(panel
->rgbBlueT
, tmp
);
2555 color
.red
= value
[0];
2556 color
.green
= value
[1];
2557 color
.blue
= value
[2];
2559 updateSwatch(panel
, color
);
2560 panel
->lastChanged
= WMRGBModeColorPanel
;
2564 rgbTextFieldCallback(void *observerData
, WMNotification
*notification
)
2570 W_ColorPanel
*panel
= (W_ColorPanel
*)observerData
;
2572 value
[0] = atoi(WMGetTextFieldText(panel
->rgbRedT
));
2573 value
[1] = atoi(WMGetTextFieldText(panel
->rgbGreenT
));
2574 value
[2] = atoi(WMGetTextFieldText(panel
->rgbBlueT
));
2576 for (n
=0; n
< 3; n
++) {
2583 sprintf(tmp
, "%d", value
[0]);
2584 WMSetTextFieldText(panel
->rgbRedT
, tmp
);
2585 sprintf(tmp
, "%d", value
[1]);
2586 WMSetTextFieldText(panel
->rgbGreenT
, tmp
);
2587 sprintf(tmp
, "%d", value
[2]);
2588 WMSetTextFieldText(panel
->rgbBlueT
, tmp
);
2590 WMSetSliderValue(panel
->rgbRedS
, value
[0]);
2591 WMSetSliderValue(panel
->rgbGreenS
, value
[1]);
2592 WMSetSliderValue(panel
->rgbBlueS
, value
[2]);
2594 color
.red
= value
[0];
2595 color
.green
= value
[1];
2596 color
.blue
= value
[2];
2598 updateSwatch(panel
, color
);
2599 panel
->lastChanged
= WMRGBModeColorPanel
;
2603 /******************* CMYK Panel Functions *****************/
2606 cmykSliderCallback(WMWidget
*w
, void *data
)
2611 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2613 value
[0] = WMGetSliderValue(panel
->cmykCyanS
);
2614 value
[1] = WMGetSliderValue(panel
->cmykMagentaS
);
2615 value
[2] = WMGetSliderValue(panel
->cmykYellowS
);
2616 value
[3] = WMGetSliderValue(panel
->cmykBlackS
);
2618 sprintf(tmp
, "%d", value
[0]);
2619 WMSetTextFieldText(panel
->cmykCyanT
, tmp
);
2620 sprintf(tmp
, "%d", value
[1]);
2621 WMSetTextFieldText(panel
->cmykMagentaT
, tmp
);
2622 sprintf(tmp
, "%d", value
[2]);
2623 WMSetTextFieldText(panel
->cmykYellowT
, tmp
);
2624 sprintf(tmp
, "%d", value
[3]);
2625 WMSetTextFieldText(panel
->cmykBlackT
, tmp
);
2627 color
.red
= rint((255.0 - (value
[0] * 2.55)) * (1.0 - (value
[3] / 100.0)));
2628 color
.green
= rint((255.0 - (value
[1] * 2.55)) * (1.0 - (value
[3]/100.0)));
2629 color
.blue
= rint((255.0 - (value
[2] * 2.55)) * (1.0 - (value
[3] /100.0)));
2631 updateSwatch(panel
, color
);
2632 panel
->lastChanged
= WMCMYKModeColorPanel
;
2636 cmykTextFieldCallback(void *observerData
, WMNotification
*notification
)
2642 W_ColorPanel
*panel
= (W_ColorPanel
*)observerData
;
2644 value
[0] = atoi(WMGetTextFieldText(panel
->cmykCyanT
));
2645 value
[1] = atoi(WMGetTextFieldText(panel
->cmykMagentaT
));
2646 value
[2] = atoi(WMGetTextFieldText(panel
->cmykYellowT
));
2647 value
[3] = atoi(WMGetTextFieldText(panel
->cmykBlackT
));
2649 for (n
=0; n
< 4; n
++) {
2656 sprintf(tmp
, "%d", value
[0]);
2657 WMSetTextFieldText(panel
->cmykCyanT
, tmp
);
2659 sprintf(tmp
, "%d", value
[1]);
2660 WMSetTextFieldText(panel
->cmykMagentaT
, tmp
);
2662 sprintf(tmp
, "%d", value
[2]);
2663 WMSetTextFieldText(panel
->cmykYellowT
, tmp
);
2665 sprintf(tmp
, "%d", value
[3]);
2666 WMSetTextFieldText(panel
->cmykBlackT
, tmp
);
2668 WMSetSliderValue(panel
->cmykCyanS
, value
[0]);
2669 WMSetSliderValue(panel
->cmykMagentaS
, value
[1]);
2670 WMSetSliderValue(panel
->cmykYellowS
, value
[2]);
2671 WMSetSliderValue(panel
->cmykBlackS
, value
[3]);
2673 color
.red
= rint((255.0 - (value
[0] * 2.55)) * (1.0 - (value
[3] / 100.0)));
2674 color
.green
= rint((255.0 - (value
[1] * 2.55)) * (1.0 - (value
[3]/100.0)));
2675 color
.blue
= rint((255.0 - (value
[2] * 2.55)) * (1.0 - (value
[3] /100.0)));
2677 updateSwatch(panel
, color
);
2678 panel
->lastChanged
= WMCMYKModeColorPanel
;
2681 /********************** HSB Panel Functions ***********************/
2684 hsbSliderCallback(WMWidget
*w
, void *data
)
2689 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
2691 value
[0] = WMGetSliderValue(panel
->hsbHueS
);
2692 value
[1] = WMGetSliderValue(panel
->hsbSaturationS
);
2693 value
[2] = WMGetSliderValue(panel
->hsbBrightnessS
);
2695 sprintf(tmp
, "%d", value
[0]);
2696 WMSetTextFieldText(panel
->hsbHueT
, tmp
);
2697 sprintf(tmp
, "%d", value
[1]);
2698 WMSetTextFieldText(panel
->hsbSaturationT
, tmp
);
2699 sprintf(tmp
, "%d", value
[2]);
2700 WMSetTextFieldText(panel
->hsbBrightnessT
, tmp
);
2702 panel
->hsvcolor
.hue
= value
[0];
2703 panel
->hsvcolor
.saturation
= value
[1]*2.55;
2704 panel
->hsvcolor
.value
= value
[2]*2.55;
2706 RHSVtoRGB(&panel
->hsvcolor
, &color
);
2708 panel
->lastChanged
= WMHSBModeColorPanel
;
2709 updateSwatch(panel
, color
);
2711 if (w
!= panel
->hsbBrightnessS
)
2712 hsbUpdateBrightnessGradient(panel
);
2713 if (w
!= panel
->hsbSaturationS
)
2714 hsbUpdateSaturationGradient(panel
);
2715 if (w
!= panel
->hsbHueS
)
2716 hsbUpdateHueGradient(panel
);
2720 hsbTextFieldCallback(void *observerData
, WMNotification
*notification
)
2726 W_ColorPanel
*panel
= (W_ColorPanel
*)observerData
;
2728 value
[0] = atoi(WMGetTextFieldText(panel
->hsbHueT
));
2729 value
[1] = atoi(WMGetTextFieldText(panel
->hsbSaturationT
));
2730 value
[2] = atoi(WMGetTextFieldText(panel
->hsbBrightnessT
));
2737 for (n
=1; n
< 3; n
++) {
2744 sprintf(tmp
, "%d", value
[0]);
2745 WMSetTextFieldText(panel
->hsbHueT
, tmp
);
2746 sprintf(tmp
, "%d", value
[1]);
2747 WMSetTextFieldText(panel
->hsbSaturationT
, tmp
);
2748 sprintf(tmp
, "%d", value
[2]);
2749 WMSetTextFieldText(panel
->hsbBrightnessT
, tmp
);
2751 WMSetSliderValue(panel
->hsbHueS
, value
[0]);
2752 WMSetSliderValue(panel
->hsbSaturationS
, value
[1]);
2753 WMSetSliderValue(panel
->hsbBrightnessS
, value
[2]);
2755 panel
->hsvcolor
.hue
= value
[0];
2756 panel
->hsvcolor
.saturation
= value
[1]*2.55;
2757 panel
->hsvcolor
.value
= value
[2]*2.55;
2759 RHSVtoRGB(&panel
->hsvcolor
, &color
);
2761 panel
->lastChanged
= WMHSBModeColorPanel
;
2762 updateSwatch(panel
, color
);
2764 hsbUpdateBrightnessGradient(panel
);
2765 hsbUpdateSaturationGradient(panel
);
2766 hsbUpdateHueGradient(panel
);
2770 hsbUpdateBrightnessGradient(W_ColorPanel
*panel
)
2772 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2777 WMPixmap
*sliderPxmp
;
2779 from
.red
= from
.green
= from
.blue
= 0;
2780 hsvcolor
= panel
->hsvcolor
;
2781 hsvcolor
.value
= 255;
2783 RHSVtoRGB(&hsvcolor
, &to
);
2785 sliderImg
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
2786 sliderPxmp
= WMCreatePixmapFromRImage(scr
, sliderImg
, 0);
2787 RDestroyImage(sliderImg
);
2788 W_PaintText(W_VIEW(panel
->hsbBrightnessS
), sliderPxmp
->pixmap
,
2789 panel
->font12
, 2, 0, 100, WALeft
, WMColorGC(scr
->white
), False
,
2790 "Brightness", strlen("Brightness"));
2791 WMSetSliderImage(panel
->hsbBrightnessS
, sliderPxmp
);
2792 WMReleasePixmap(sliderPxmp
);
2796 hsbUpdateSaturationGradient(W_ColorPanel
*panel
)
2798 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2803 WMPixmap
*sliderPxmp
;
2805 hsvcolor
= panel
->hsvcolor
;
2806 hsvcolor
.saturation
= 0;
2807 RHSVtoRGB(&hsvcolor
, &from
);
2809 hsvcolor
.saturation
= 255;
2810 RHSVtoRGB(&hsvcolor
, &to
);
2812 sliderImg
= RRenderGradient(141, 16, &from
, &to
, RGRD_HORIZONTAL
);
2813 sliderPxmp
= WMCreatePixmapFromRImage(scr
, sliderImg
, 0);
2814 RDestroyImage(sliderImg
);
2815 W_PaintText(W_VIEW(panel
->hsbSaturationS
), sliderPxmp
->pixmap
,
2816 panel
->font12
, 2, 0, 100, WALeft
,
2817 WMColorGC(hsvcolor
.value
< 128 ? scr
->white
: scr
->black
), False
,
2818 "Saturation", strlen("Saturation"));
2820 WMSetSliderImage(panel
->hsbSaturationS
, sliderPxmp
);
2821 WMReleasePixmap(sliderPxmp
);
2825 hsbUpdateHueGradient(W_ColorPanel
*panel
)
2827 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2828 RColor
**colors
= NULL
;
2831 WMPixmap
*sliderPxmp
;
2834 hsvcolor
= panel
->hsvcolor
;
2836 colors
= malloc(sizeof(RColor
*)*(8));
2837 for (i
=0; i
<7; i
++) {
2838 hsvcolor
.hue
= (360*i
)/6;
2839 colors
[i
] = malloc(sizeof(RColor
));
2840 RHSVtoRGB(&hsvcolor
, colors
[i
]);
2844 sliderImg
= RRenderMultiGradient(141, 16, colors
, RGRD_HORIZONTAL
);
2845 sliderPxmp
= WMCreatePixmapFromRImage(scr
, sliderImg
, 0);
2846 RDestroyImage(sliderImg
);
2847 W_PaintText(W_VIEW(panel
->hsbHueS
), sliderPxmp
->pixmap
,
2848 panel
->font12
, 2, 0, 100, WALeft
,
2849 WMColorGC(hsvcolor
.value
< 128 ? scr
->white
: scr
->black
), False
,
2850 "Hue", strlen("Hue"));
2852 WMSetSliderImage(panel
->hsbHueS
, sliderPxmp
);
2853 WMReleasePixmap(sliderPxmp
);
2855 for (i
=0; i
<7; i
++) {
2863 /*************** Custom Palette Functions ****************/
2866 customRenderSpectrum(W_ColorPanel
*panel
)
2872 unsigned char *rp
, *gp
, *bp
;
2876 spectrum
= RCreateImage(SPECTRUM_WIDTH
, SPECTRUM_HEIGHT
, 0);
2878 for (y
=0; y
<360; y
++) {
2882 for (x
=0; x
<511; x
++) {
2883 ofs
= (y
* 511) + x
;
2886 cur_hsv
.saturation
= sat
;
2887 cur_hsv
.value
= val
;
2889 RHSVtoRGB (&cur_hsv
, &color
);
2891 rp
= spectrum
->data
[0] + ofs
;
2892 gp
= spectrum
->data
[1] + ofs
;
2893 bp
= spectrum
->data
[2] + ofs
;
2895 *rp
= (unsigned char)color
.red
;
2896 *gp
= (unsigned char)color
.green
;
2897 *bp
= (unsigned char)color
.blue
;
2906 if (panel
->customPaletteImg
) {
2907 RDestroyImage(panel
->customPaletteImg
);
2908 panel
->customPaletteImg
= NULL
;
2910 panel
->customPaletteImg
= spectrum
;
2916 customSetPalette(W_ColorPanel
*panel
)
2918 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2923 image
= XCreatePixmap(scr
->display
, W_DRAWABLE(scr
), customPaletteWidth
,
2924 customPaletteHeight
, scr
->depth
);
2926 scaledImg
= RScaleImage(panel
->customPaletteImg
, customPaletteWidth
,
2927 customPaletteHeight
);
2928 RConvertImage(scr
->rcontext
, scaledImg
, &image
);
2929 RDestroyImage(scaledImg
);
2931 XCopyArea(scr
->display
, image
, panel
->customPaletteContentView
->window
,
2932 scr
->copyGC
, 0, 0, customPaletteWidth
, customPaletteHeight
, 0, 0);
2934 /* Check backimage exists. If it doesn't, allocate and fill it */
2935 if (!panel
->selectionBackImg
) {
2936 panel
->selectionBackImg
= XCreatePixmap(scr
->display
,
2937 panel
->customPaletteContentView
->window
, 4, 4, scr
->depth
);
2940 XCopyArea(scr
->display
, image
, panel
->selectionBackImg
, scr
->copyGC
,
2941 panel
->palx
-2, panel
->paly
-2, 4, 4, 0, 0);
2942 XCopyArea(scr
->display
, panel
->selectionImg
,
2943 panel
->customPaletteContentView
->window
, scr
->copyGC
, 0 , 0, 4, 4,
2944 panel
->palx
-2, panel
->paly
-2);
2945 XFreePixmap(scr
->display
, image
);
2947 panel
->palXRatio
= (float)(panel
->customPaletteImg
->width
) /
2948 (float)(customPaletteWidth
);
2949 panel
->palYRatio
= (float)(panel
->customPaletteImg
->height
) /
2950 (float)(customPaletteHeight
);
2952 item
= WMGetPopUpButtonSelectedItem (panel
->customPaletteHistoryBtn
);
2954 /* if palette != "Spectrum", we are allowed to rename and remove it */
2955 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
, CPmenuRename
,
2957 WMSetPopUpButtonItemEnabled(panel
->customPaletteMenuBtn
, CPmenuRemove
,
2963 customPalettePositionSelection(W_ColorPanel
*panel
, int x
, int y
)
2965 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
2969 /* undraw selection */
2970 XCopyArea(scr
->display
, panel
->selectionBackImg
,
2971 panel
->customPaletteContentView
->window
, scr
->copyGC
, 0, 0, 4, 4,
2972 panel
->palx
-2, panel
->paly
-2);
2977 ofs
= rint(x
* panel
->palXRatio
) + rint(y
* panel
->palYRatio
) *
2978 panel
->customPaletteImg
->width
;
2980 panel
->color
.red
= panel
->customPaletteImg
->data
[0][ofs
];
2981 panel
->color
.green
= panel
->customPaletteImg
->data
[1][ofs
];
2982 panel
->color
.blue
= panel
->customPaletteImg
->data
[2][ofs
];
2984 updateSwatch(panel
, panel
->color
);
2985 panel
->lastChanged
= WMCustomPaletteModeColorPanel
;
2987 /* Redraw color selector (and make a backup of the part it will cover) */
2988 XCopyArea(scr
->display
, panel
->customPaletteContentView
->window
,
2989 panel
->selectionBackImg
, scr
->copyGC
, panel
->palx
-2, panel
->paly
-2,
2990 4, 4, 0, 0); /* "-2" is correction for hotspot location */
2991 XCopyArea(scr
->display
, panel
->selectionImg
,
2992 panel
->customPaletteContentView
->window
, scr
->copyGC
, 0, 0, 4, 4,
2993 panel
->palx
-2, panel
->paly
-2); /* see above */
2998 customPalettePositionSelectionOutBounds(W_ColorPanel
*panel
, int x
, int y
)
3004 if (x
>= customPaletteWidth
)
3005 x
= customPaletteWidth
-2;
3006 if (y
>= customPaletteHeight
)
3007 y
= customPaletteHeight
-2;
3009 customPalettePositionSelection(panel
, x
, y
);
3014 customPaletteHandleEvents(XEvent
*event
, void *data
)
3016 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3018 switch (event
->type
) {
3020 if (event
->xexpose
.count
!= 0)
3022 customSetPalette(panel
);
3028 customPaletteHandleActionEvents(XEvent
*event
, void *data
)
3030 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3033 switch (event
->type
) {
3035 x
= event
->xbutton
.x
;
3036 y
= event
->xbutton
.y
;
3038 if (getPickerPart(panel
, x
, y
) == CUSTOMPALETTE_PART
) {
3039 panel
->flags
.dragging
= 1;
3040 customPalettePositionSelection(panel
, x
, y
);
3045 panel
->flags
.dragging
= 0;
3046 if (!panel
->flags
.continuous
) {
3048 (*panel
->action
)(panel
, panel
->clientData
);
3053 x
= event
->xmotion
.x
;
3054 y
= event
->xmotion
.y
;
3056 if (panel
->flags
.dragging
) {
3057 if (getPickerPart(panel
, x
, y
) == CUSTOMPALETTE_PART
) {
3058 customPalettePositionSelection(panel
, x
, y
);
3061 customPalettePositionSelectionOutBounds(panel
, x
, y
);
3069 customPaletteMenuCallback(WMWidget
*w
, void *data
)
3071 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3072 int item
= WMGetPopUpButtonSelectedItem(panel
->customPaletteMenuBtn
);
3075 case CPmenuNewFromFile
:
3076 customPaletteMenuNewFromFile(panel
);
3079 customPaletteMenuRename(panel
);
3082 customPaletteMenuRemove(panel
);
3086 case CPmenuNewFromClipboard
:
3093 customPaletteMenuNewFromFile(W_ColorPanel
*panel
)
3095 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
3096 WMOpenPanel
*browseP
;
3098 char *filename
= NULL
;
3102 RImage
*tmpImg
= NULL
;
3104 if ((!panel
->lastBrowseDir
) || (strcmp(panel
->lastBrowseDir
,"\0") == 0))
3105 spath
= wexpandpath(wgethomedir());
3107 spath
= wexpandpath(panel
->lastBrowseDir
);
3109 browseP
= WMGetOpenPanel(scr
);
3110 WMSetFilePanelCanChooseDirectories(browseP
, 0);
3111 WMSetFilePanelCanChooseFiles(browseP
, 1);
3113 /* Get a filename */
3114 if (WMRunModalFilePanelForDirectory(browseP
, panel
->win
, spath
,
3115 "Open Palette", RSupportedFileFormats()) ) {
3116 filepath
= WMGetFilePanelFileName(browseP
);
3118 /* Get seperation position between path and filename */
3119 i
= strrchr(filepath
, '/') - filepath
+ 1;
3120 if (i
> strlen(filepath
))
3121 i
= strlen(filepath
);
3123 /* Store last browsed path */
3124 if (panel
->lastBrowseDir
)
3125 wfree(panel
->lastBrowseDir
);
3126 panel
->lastBrowseDir
= wmalloc((i
+1)*sizeof(char));
3127 strncpy(panel
->lastBrowseDir
, filepath
, i
);
3128 panel
->lastBrowseDir
[i
] = '\0';
3130 /* Get filename from path */
3131 filename
= wstrdup(filepath
+ i
);
3133 /* Check for duplicate files, and rename it if there are any */
3134 tmp
= wstrappend(panel
->configurationPath
, filename
);
3135 while (access (tmp
, F_OK
) == 0) {
3140 newName
= generateNewFilename(filename
);
3144 tmp
= wstrappend(panel
->configurationPath
, filename
);
3148 /* Copy image to $(gnustepdir)/Library/Colors/ &
3149 * Add filename to history menu */
3150 if (fetchFile (panel
->configurationPath
, filepath
, filename
) == 0) {
3152 /* filepath is a "local" path now the file has been copied */
3154 filepath
= wstrappend(panel
->configurationPath
, filename
);
3156 /* load the image & add menu entries */
3157 tmpImg
= RLoadImage(scr
->rcontext
, filepath
, 0);
3159 if (panel
->customPaletteImg
)
3160 RDestroyImage(panel
->customPaletteImg
);
3161 panel
->customPaletteImg
= tmpImg
;
3163 customSetPalette(panel
);
3164 WMAddPopUpButtonItem(panel
->customPaletteHistoryBtn
, filename
);
3166 panel
->currentPalette
= WMGetPopUpButtonNumberOfItems(
3167 panel
->customPaletteHistoryBtn
)-1;
3169 WMSetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
,
3170 panel
->currentPalette
);
3175 tmp
= wstrappend(panel
->configurationPath
, filename
);
3177 i
= remove(tmp
); /* Delete the file, it doesn't belong here */
3178 WMRunAlertPanel(scr
, panel
->win
, "File Error",
3179 "Invalid file format !", "OK", NULL
, NULL
);
3181 wsyserror("can't remove file %s", tmp
);
3182 WMRunAlertPanel(scr
, panel
->win
, "File Error",
3183 "Couldn't remove file from Configuration Directory !",
3191 WMFreeFilePanel(browseP
);
3198 customPaletteMenuRename(W_ColorPanel
*panel
)
3200 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
3201 char *toName
= NULL
;
3203 char *toPath
, *fromPath
;
3207 item
= WMGetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
);
3208 fromName
= WMGetPopUpButtonItem(panel
->customPaletteHistoryBtn
, item
);
3210 toName
= WMRunInputPanel(scr
, panel
->win
, "Rename", "Rename palette to:",
3211 fromName
, "OK", "Cancel");
3215 /* As some people do certain stupid things... */
3216 if (strcmp(toName
, fromName
) == 0) {
3221 /* For normal people */
3222 fromPath
= wstrappend(panel
->configurationPath
, fromName
);
3223 toPath
= wstrappend(panel
->configurationPath
, toName
);
3225 if (access (toPath
, F_OK
) == 0) {
3226 /* Careful, this palette exists already */
3227 if (WMRunAlertPanel(scr
, panel
->win
, "Warning",
3228 "Palette already exists !\n\nOverwrite ?", "No", "Yes",
3230 /* "No" = 0, "Yes" = 1 */
3231 int items
= WMGetPopUpButtonNumberOfItems(
3232 panel
->customPaletteHistoryBtn
);
3236 /* Remove from History list too */
3238 while ((index
< items
) && (strcmp(WMGetPopUpButtonItem(
3239 panel
->customPaletteHistoryBtn
, index
),
3243 if (index
< items
) {
3244 WMRemovePopUpButtonItem(panel
->customPaletteHistoryBtn
,
3259 if ( rename(fromPath
, toPath
) != 0)
3260 wsyserror("Couldn't rename palette %s to %s\n", fromName
, toName
);
3262 WMRemovePopUpButtonItem(panel
->customPaletteHistoryBtn
, item
);
3263 WMInsertPopUpButtonItem(panel
->customPaletteHistoryBtn
, item
,
3266 WMSetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
, item
);
3276 customPaletteMenuRemove(W_ColorPanel
*panel
)
3278 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
3284 item
= WMGetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
);
3286 tmp
= wstrappend( "This will permanently remove the palette ",
3287 WMGetPopUpButtonItem(panel
->customPaletteHistoryBtn
, item
));
3288 text
= wstrappend( tmp
,
3289 ".\n\nAre you sure you want to remove this palette ?");
3292 choice
= WMRunAlertPanel(scr
, panel
->win
, NULL
, text
, "Yes", "No", NULL
);
3293 /* returns 0 (= "Yes") or 1 (="No") */
3298 tmp
= wstrappend(panel
->configurationPath
,
3299 WMGetPopUpButtonItem(panel
->customPaletteHistoryBtn
, item
));
3301 if ( remove(tmp
) != 0)
3302 wsyserror("Couldn't remove palette %s\n", tmp
);
3305 /* item -1 always exists */
3306 WMSetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
, item
-1);
3308 customPaletteHistoryCallback(panel
->customPaletteHistoryBtn
, panel
);
3309 customSetPalette(panel
);
3311 WMRemovePopUpButtonItem(panel
->customPaletteHistoryBtn
, item
);
3317 customPaletteHistoryCallback(WMWidget
*w
, void *data
)
3319 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3320 W_Screen
*scr
= WMWidgetScreen(panel
->win
);
3325 item
= WMGetPopUpButtonSelectedItem(panel
->customPaletteHistoryBtn
);
3326 if (item
== panel
->currentPalette
)
3330 customRenderSpectrum(panel
);
3332 /* Load file from configpath */
3333 filename
= wstrappend( panel
->configurationPath
,
3334 WMGetPopUpButtonItem(panel
->customPaletteHistoryBtn
, item
) );
3336 /* XXX To do: Check existence of file and remove it from the history
3337 * if it doesn't exist */
3339 tmp
= RLoadImage(scr
->rcontext
, filename
, 0);
3341 if (panel
->customPaletteImg
) {
3342 RDestroyImage(panel
->customPaletteImg
);
3343 panel
->customPaletteImg
= NULL
;
3345 panel
->customPaletteImg
= tmp
;
3349 customSetPalette(panel
);
3351 panel
->currentPalette
= item
;
3355 /*************** Panel Initialisation Functions *****************/
3358 wheelInit(W_ColorPanel
*panel
)
3364 RRGBtoHSV(&panel
->color
, &cur_hsv
);
3366 WMSetSliderValue(panel
->wheelBrightnessS
, 255-cur_hsv
.value
);
3367 wheelUpdateBrightnessGradientFromHSV(panel
, cur_hsv
);
3369 panel
->colx
= 2 + rint((colorWheelSize
/ 2.0) * (1 + (
3370 cur_hsv
.saturation
/255.0) * cos( cur_hsv
.hue
*M_PI
/180.0)));
3371 panel
->coly
= 2 + rint((colorWheelSize
/ 2.0) * (1 + (
3372 cur_hsv
.saturation
/255.0) * sin(-cur_hsv
.hue
*M_PI
/180.0)));
3374 for (i
= 0; i
< 256; i
++) {
3375 /* We divide by 128 in advance, and check whether that number divides
3376 * by 2 properly. If not, we add one to round the number correctly
3378 v
= (i
*cur_hsv
.value
) >> 7;
3379 panel
->wheelMtrx
->values
[i
] = (unsigned char)((v
>> 1) + (v
& 1));
3384 grayInit(W_ColorPanel
*panel
)
3390 RRGBtoHSV(&panel
->color
, &cur_hsv
);
3392 value
= rint(cur_hsv
.value
/2.55);
3393 WMSetSliderValue(panel
->grayBrightnessS
, value
);
3395 sprintf(tmp
, "%d", value
);
3396 WMSetTextFieldText(panel
->grayBrightnessT
, tmp
);
3400 rgbInit(W_ColorPanel
*panel
)
3404 WMSetSliderValue(panel
->rgbRedS
,panel
->color
.red
);
3405 WMSetSliderValue(panel
->rgbGreenS
,panel
->color
.green
);
3406 WMSetSliderValue(panel
->rgbBlueS
,panel
->color
.blue
);
3408 sprintf(tmp
, "%d", panel
->color
.red
);
3409 WMSetTextFieldText(panel
->rgbRedT
, tmp
);
3410 sprintf(tmp
, "%d", panel
->color
.green
);
3411 WMSetTextFieldText(panel
->rgbGreenT
, tmp
);
3412 sprintf(tmp
, "%d", panel
->color
.blue
);
3413 WMSetTextFieldText(panel
->rgbBlueT
, tmp
);
3417 cmykInit(W_ColorPanel
*panel
)
3422 value
[0] = rint((255-panel
->color
.red
)/2.55);
3423 value
[1] = rint((255-panel
->color
.green
)/2.55);
3424 value
[2] = rint((255-panel
->color
.blue
)/2.55);
3426 WMSetSliderValue(panel
->cmykCyanS
, value
[0]);
3427 WMSetSliderValue(panel
->cmykMagentaS
, value
[1]);
3428 WMSetSliderValue(panel
->cmykYellowS
, value
[2]);
3429 WMSetSliderValue(panel
->cmykBlackS
, 0);
3431 sprintf(tmp
, "%d", value
[0]);
3432 WMSetTextFieldText(panel
->cmykCyanT
, tmp
);
3433 sprintf(tmp
, "%d", value
[1]);
3434 WMSetTextFieldText(panel
->cmykMagentaT
, tmp
);
3435 sprintf(tmp
, "%d", value
[2]);
3436 WMSetTextFieldText(panel
->cmykYellowT
, tmp
);
3437 WMSetTextFieldText(panel
->cmykBlackT
, "0");
3441 hsbInit(W_ColorPanel
*panel
)
3446 value
[0] = panel
->hsvcolor
.hue
;
3447 value
[1] = rint(panel
->hsvcolor
.saturation
/2.55);
3448 value
[2] = rint(panel
->hsvcolor
.value
/2.55);
3450 WMSetSliderValue(panel
->hsbHueS
,value
[0]);
3451 WMSetSliderValue(panel
->hsbSaturationS
,value
[1]);
3452 WMSetSliderValue(panel
->hsbBrightnessS
,value
[2]);
3454 sprintf(tmp
, "%d", value
[0]);
3455 WMSetTextFieldText(panel
->hsbHueT
, tmp
);
3456 sprintf(tmp
, "%d", value
[1]);
3457 WMSetTextFieldText(panel
->hsbSaturationT
, tmp
);
3458 sprintf(tmp
, "%d", value
[2]);
3459 WMSetTextFieldText(panel
->hsbBrightnessT
, tmp
);
3461 hsbUpdateBrightnessGradient(panel
);
3462 hsbUpdateSaturationGradient(panel
);
3463 hsbUpdateHueGradient(panel
);
3469 /************************* ColorList Panel Functions **********************/
3472 colorListPaintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
,
3473 int state
, WMRect
*rect
)
3475 int width
, height
, x
, y
;
3476 RColor color
= *((RColor
*)WMGetListItem(lPtr
, index
)->clientData
);
3477 WMScreen
*scr
= WMWidgetScreen(lPtr
);
3478 Display
*dpy
= WMScreenDisplay(scr
);
3479 W_ColorPanel
*panel
= WMGetHangedData(lPtr
);
3480 WMColor
*white
= WMWhiteColor(scr
);
3481 WMColor
*black
= WMBlackColor(scr
);
3484 width
= rect
->size
.width
;
3485 height
= rect
->size
.height
;
3489 if (state
& WLDSSelected
)
3490 WMPaintColorSwatch(white
, d
, x
+15, y
, width
-15, height
);
3492 XClearArea(dpy
, d
, x
+15, y
, width
-15, height
, False
);
3494 fillColor
= WMCreateRGBColor(scr
, color
.red
*256, color
.green
*256,
3495 color
.blue
*256, False
);
3497 WMSetColorInGC(fillColor
, WMColorGC(fillColor
));
3498 WMPaintColorSwatch(fillColor
, d
, x
, y
, 15, 15);
3499 WMReleaseColor(fillColor
);
3501 WMDrawString(scr
, d
, WMColorGC(black
), panel
->font12
, x
+18, y
, text
,
3504 WMReleaseColor(white
);
3505 WMReleaseColor(black
);
3510 colorListSelect(WMWidget
*w
, void *data
)
3512 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3513 RColor color
= *((RColor
*)WMGetListSelectedItem(w
)->clientData
);
3515 panel
->lastChanged
= WMColorListModeColorPanel
;
3516 updateSwatch(panel
, color
);
3521 colorListColorMenuCallback(WMWidget
*w
, void *data
)
3523 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3524 int item
= WMGetPopUpButtonSelectedItem(panel
->colorListColorMenuBtn
);
3538 colorListListMenuCallback(WMWidget
*w
, void *data
)
3540 W_ColorPanel
*panel
= (W_ColorPanel
*)data
;
3541 int item
= WMGetPopUpButtonSelectedItem(panel
->colorListListMenuBtn
);
3545 /* New Color List */
3546 colorListListMenuNew(panel
);
3557 colorListListMenuNew(W_ColorPanel
*panel
)
3563 /************************** Common utility functions ************************/
3566 fetchFile(char *toPath
, char *srcFile
, char *destFile
)
3573 if ((src
= open(srcFile
, O_RDONLY
)) == 0) {
3574 wsyserror("Could not open %s", srcFile
);
3578 tmp
= wstrappend(toPath
, destFile
);
3579 if ((dest
= open( tmp
, O_RDWR
|O_CREAT
, S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
))
3581 wsyserror("Could not create %s", tmp
);
3589 while ((n
= read(src
, buf
, BUFSIZE
)) > 0)
3591 if (write (dest
, buf
, n
) != n
) {
3592 wsyserror("Write error on file %s", destFile
);
3602 generateNewFilename(char *curName
)
3616 ((ptr
= strrchr(ptr
, '{')) == 0) ||
3617 sscanf(ptr
, "{%i}%c", &n
, &c
) != 1
3619 return wstrappend(curName
, " {1}");
3621 baseLen
= ptr
- curName
-1;
3623 newName
= wmalloc(baseLen
+ 16);
3624 strncpy(newName
, curName
, baseLen
);
3625 newName
[baseLen
] = 0;
3627 sprintf(&newName
[baseLen
], " {%i}", n
+1);
3634 get_shifts(unsigned long mask
)
3647 ulongToRColor(WMScreen
*scr
, XImage
*image
, unsigned long value
)
3650 int rmask
, gmask
, bmask
;
3651 int rshift
, gshift
, bshift
;
3653 if (scr
->rcontext
->depth
== image
->depth
) {
3654 rmask
= scr
->rcontext
->visual
->red_mask
;
3655 gmask
= scr
->rcontext
->visual
->green_mask
;
3656 bmask
= scr
->rcontext
->visual
->blue_mask
;
3658 rmask
= image
->red_mask
;
3659 gmask
= image
->green_mask
;
3660 bmask
= image
->blue_mask
;
3663 rshift
= get_shifts(rmask
) -8; /* -8 because otherwise the byte */
3664 gshift
= get_shifts(gmask
) -8; /* containing the color would be */
3665 bshift
= get_shifts(bmask
) -8; /* shifted over the edge. */
3667 color
.red
= (rshift
> 0) ? (value
& rmask
) >> rshift
:
3668 (value
& rmask
) << -rshift
;
3669 color
.green
= (gshift
> 0) ? (value
& gmask
) >> gshift
:
3670 (value
& gmask
) << -gshift
;
3671 color
.blue
= (bshift
> 0) ? (value
& bmask
) >> bshift
:
3672 (value
& bmask
) << -bshift
;
3677 #ifdef SHAPE_WAS_DEFINED
3678 #undef SHAPE_WAS_DEFINED