Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
1 /* TexturePanel.c- texture editting panel
2 *
3 * WPrefs - WindowMaker Preferences Program
4 *
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * Copyright (c) 1998 James Thompson
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
22 *
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <ctype.h>
30
31 #include <X11/Xlib.h>
32
33 #include <WINGs/WINGs.h>
34
35 #include "WPrefs.h"
36
37 #include "TexturePanel.h"
38
39 #define MAX_SECTION_PARTS 5
40
41 typedef struct _TexturePanel {
42 WMWindow *win;
43
44 /* texture name */
45 WMFrame *nameF;
46 WMTextField *nameT;
47
48 /* texture type */
49 WMPopUpButton *typeP;
50
51 /* default color */
52 WMFrame *defcF;
53 WMColorWell *defcW;
54
55 WMFont *listFont;
56
57 /*-- Gradient --*/
58
59 Pixmap gimage;
60
61 /* colors */
62 WMFrame *gcolF;
63 WMList *gcolL;
64 WMButton *gcolaB;
65 WMButton *gcoldB;
66 WMSlider *ghueS;
67 WMSlider *gsatS;
68 WMSlider *gvalS;
69
70 WMSlider *gbriS;
71 WMSlider *gconS;
72
73 /* direction (common) */
74 WMFrame *dirF;
75 WMButton *dirhB;
76 WMButton *dirvB;
77 WMButton *dirdB;
78
79 /*-- Simple Gradient --*/
80
81 /*-- Textured Gradient --*/
82
83 WMFrame *tcolF;
84 WMColorWell *tcol1W;
85 WMColorWell *tcol2W;
86
87 WMFrame *topaF;
88 WMSlider *topaS;
89
90 /*-- Image --*/
91 WMFrame *imageF;
92 WMScrollView *imageV;
93 WMTextField *imageT;
94 WMLabel *imageL;
95 WMButton *browB;
96 WMButton *dispB;
97 WMPopUpButton *arrP;
98
99 RImage *image;
100 char *imageFile;
101
102 /*****/
103
104 WMButton *okB;
105 WMButton *cancelB;
106
107 WMCallback *okAction;
108 void *okData;
109
110 WMCallback *cancelAction;
111 void *cancelData;
112
113 /****/
114 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
115
116 int currentType;
117
118 WMPropList *pathList;
119
120 } _TexturePanel;
121
122 #define TYPE_SOLID 0
123 #define TYPE_GRADIENT 1
124 #define TYPE_SGRADIENT 2
125 #define TYPE_TGRADIENT 3
126 #define TYPE_PIXMAP 4
127
128 #define PTYPE_TILE 0
129 #define PTYPE_SCALE 1
130 #define PTYPE_CENTER 2
131 #define PTYPE_MAXIMIZE 3
132
133 /*
134 *--------------------------------------------------------------------------
135 * Private Functions
136 *--------------------------------------------------------------------------
137 */
138
139 /************/
140
141 static void updateGradButtons(TexturePanel * panel)
142 {
143 RImage *image;
144 WMPixmap *pixmap;
145 int colorn;
146 RColor **colors;
147
148 colorn = WMGetListNumberOfRows(panel->gcolL);
149 if (colorn < 1) {
150 pixmap = NULL;
151 } else {
152 int i;
153 WMListItem *item;
154
155 colors = wmalloc(sizeof(RColor *) * (colorn + 1));
156
157 for (i = 0; i < colorn; i++) {
158 item = WMGetListItem(panel->gcolL, i);
159 colors[i] = (RColor *) item->clientData;
160 }
161 colors[i] = NULL;
162
163 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
164 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
165 RReleaseImage(image);
166 WMSetButtonImage(panel->dirhB, pixmap);
167 WMReleasePixmap(pixmap);
168
169 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
170 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
171 RReleaseImage(image);
172 WMSetButtonImage(panel->dirvB, pixmap);
173 WMReleasePixmap(pixmap);
174
175 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
176 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
177 RReleaseImage(image);
178 WMSetButtonImage(panel->dirdB, pixmap);
179 WMReleasePixmap(pixmap);
180
181 wfree(colors);
182 }
183 }
184
185 static void updateTGradImage(TexturePanel * panel)
186 {
187 RImage *image, *gradient;
188 WMPixmap *pixmap;
189 RColor from;
190 RColor to;
191 WMColor *color;
192
193 if (!panel->image)
194 return;
195
196 color = WMGetColorWellColor(panel->tcol1W);
197 from.red = WMRedComponentOfColor(color) >> 8;
198 from.green = WMGreenComponentOfColor(color) >> 8;
199 from.blue = WMBlueComponentOfColor(color) >> 8;
200
201 color = WMGetColorWellColor(panel->tcol2W);
202 to.red = WMRedComponentOfColor(color) >> 8;
203 to.green = WMGreenComponentOfColor(color) >> 8;
204 to.blue = WMBlueComponentOfColor(color) >> 8;
205
206 if (panel->image->width < 141 || panel->image->height < 91) {
207 image = RMakeTiledImage(panel->image, 141, 91);
208 } else {
209 image = RCloneImage(panel->image);
210 }
211
212 if (WMGetButtonSelected(panel->dirhB)) {
213 gradient = RRenderGradient(image->width, image->height, &from, &to, RHorizontalGradient);
214 } else if (WMGetButtonSelected(panel->dirvB)) {
215 gradient = RRenderGradient(image->width, image->height, &from, &to, RVerticalGradient);
216 } else {
217 gradient = RRenderGradient(image->width, image->height, &from, &to, RDiagonalGradient);
218 }
219
220 RCombineImagesWithOpaqueness(image, gradient, WMGetSliderValue(panel->topaS));
221 RReleaseImage(gradient);
222 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win), image, 128);
223
224 WMSetLabelImage(panel->imageL, pixmap);
225 WMReleasePixmap(pixmap);
226 WMResizeWidget(panel->imageL, image->width, image->height);
227 RReleaseImage(image);
228 }
229
230 static void updateSGradButtons(TexturePanel * panel)
231 {
232 RImage *image;
233 WMPixmap *pixmap;
234 RColor from;
235 RColor to;
236 WMColor *color;
237
238 color = WMGetColorWellColor(panel->tcol1W);
239 from.red = WMRedComponentOfColor(color) >> 8;
240 from.green = WMGreenComponentOfColor(color) >> 8;
241 from.blue = WMBlueComponentOfColor(color) >> 8;
242
243 color = WMGetColorWellColor(panel->tcol2W);
244 to.red = WMRedComponentOfColor(color) >> 8;
245 to.green = WMGreenComponentOfColor(color) >> 8;
246 to.blue = WMBlueComponentOfColor(color) >> 8;
247
248 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
249 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
250 RReleaseImage(image);
251 WMSetButtonImage(panel->dirhB, pixmap);
252 WMReleasePixmap(pixmap);
253
254 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
255 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
256 RReleaseImage(image);
257 WMSetButtonImage(panel->dirvB, pixmap);
258 WMReleasePixmap(pixmap);
259
260 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
261 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
262 RReleaseImage(image);
263 WMSetButtonImage(panel->dirdB, pixmap);
264 WMReleasePixmap(pixmap);
265 }
266
267 /*********** Gradient ************/
268
269 static void updateSVSlider(WMSlider * sPtr, Bool saturation, WMFont * font, RHSVColor * hsv)
270 {
271 RImage *image;
272 WMPixmap *pixmap;
273 WMScreen *scr = WMWidgetScreen(sPtr);
274 RColor from, to;
275 RHSVColor tmp;
276 char *buffer;
277
278 tmp = *hsv;
279 if (saturation) {
280 tmp.saturation = 0;
281 RHSVtoRGB(&tmp, &from);
282 tmp.saturation = 255;
283 RHSVtoRGB(&tmp, &to);
284 } else {
285 tmp.value = 0;
286 RHSVtoRGB(&tmp, &from);
287 tmp.value = 255;
288 RHSVtoRGB(&tmp, &to);
289 }
290 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
291 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
292 RReleaseImage(image);
293
294 if (saturation)
295 buffer = wstrdup(_("Saturation"));
296 else
297 buffer = wstrdup(_("Brightness"));
298
299 if (hsv->value < 128 || !saturation) {
300 WMColor *col = WMWhiteColor(scr);
301
302 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
303 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
304 WMReleaseColor(col);
305 } else {
306 WMColor *col = WMBlackColor(scr);
307
308 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
309 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
310 WMReleaseColor(col);
311 }
312 wfree(buffer);
313 WMSetSliderImage(sPtr, pixmap);
314 WMReleasePixmap(pixmap);
315 }
316
317 static void updateHueSlider(WMSlider * sPtr, WMFont * font, RHSVColor * hsv)
318 {
319 RColor *colors[8];
320 RImage *image;
321 WMPixmap *pixmap;
322 WMScreen *scr = WMWidgetScreen(sPtr);
323 RHSVColor thsv;
324 int i;
325
326 thsv = *hsv;
327 for (i = 0; i <= 6; i++) {
328 thsv.hue = (360 * i) / 6;
329 colors[i] = wmalloc(sizeof(RColor));
330 RHSVtoRGB(&thsv, colors[i]);
331 }
332 colors[i] = NULL;
333
334 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
335 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
336 RReleaseImage(image);
337
338 if (hsv->value < 128) {
339 WMColor *col = WMWhiteColor(scr);
340
341 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
342 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
343 WMReleaseColor(col);
344 } else {
345 WMColor *col = WMBlackColor(scr);
346
347 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
348 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
349 WMReleaseColor(col);
350 }
351 WMSetSliderImage(sPtr, pixmap);
352 WMReleasePixmap(pixmap);
353
354 for (i = 0; i <= 6; i++)
355 wfree(colors[i]);
356 }
357
358 static void sliderChangeCallback(WMWidget * w, void *data)
359 {
360 TexturePanel *panel = (TexturePanel *) data;
361 RHSVColor hsv;
362 int row, rows;
363 WMListItem *item;
364 RColor **colors;
365 int i;
366 RImage *image;
367 WMScreen *scr = WMWidgetScreen(w);
368
369 hsv.hue = WMGetSliderValue(panel->ghueS);
370 hsv.saturation = WMGetSliderValue(panel->gsatS);
371 hsv.value = WMGetSliderValue(panel->gvalS);
372
373 row = WMGetListSelectedItemRow(panel->gcolL);
374 if (row >= 0) {
375 RColor *rgb;
376
377 item = WMGetListItem(panel->gcolL, row);
378
379 rgb = (RColor *) item->clientData;
380
381 RHSVtoRGB(&hsv, rgb);
382
383 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
384 }
385
386 if (w == panel->ghueS) {
387 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
388 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
389 } else if (w == panel->gsatS) {
390 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
391 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
392 } else {
393 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
394 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
395 }
396
397 rows = WMGetListNumberOfRows(panel->gcolL);
398 if (rows == 0)
399 return;
400
401 colors = wmalloc(sizeof(RColor *) * (rows + 1));
402
403 for (i = 0; i < rows; i++) {
404 item = WMGetListItem(panel->gcolL, i);
405
406 colors[i] = (RColor *) item->clientData;
407 }
408 colors[i] = NULL;
409
410 if (panel->gimage != None) {
411 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
412 }
413
414 image = RRenderMultiGradient(30, i * WMGetListItemHeight(panel->gcolL), colors, RVerticalGradient);
415 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
416 RReleaseImage(image);
417
418 wfree(colors);
419
420 WMRedisplayWidget(panel->gcolL);
421
422 updateGradButtons(panel);
423 }
424
425 static void paintGradListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
426 {
427 TexturePanel *panel = (TexturePanel *) WMGetHangedData(lPtr);
428 WMScreen *scr = WMWidgetScreen(lPtr);
429 WMColor *white = WMWhiteColor(scr);
430 WMColor *black = WMBlackColor(scr);
431 WMColor *gray = WMGrayColor(scr);
432 WMListItem *item;
433 int width, height, x, y;
434 Display *dpy;
435
436 dpy = WMScreenDisplay(scr);
437
438 width = rect->size.width;
439 height = rect->size.height;
440 x = rect->pos.x;
441 y = rect->pos.y;
442
443 if (state & WLDSSelected)
444 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
445 else
446 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
447
448 item = WMGetListItem(lPtr, index);
449
450 if (panel->gimage) {
451 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
452 0, height * index, 30, height, x + 5, y);
453 }
454 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
455
456 WMReleaseColor(white);
457 WMReleaseColor(black);
458 WMReleaseColor(gray);
459 }
460
461 static void gradAddCallback(WMWidget * w, void *data)
462 {
463 TexturePanel *panel = (TexturePanel *) data;
464 WMListItem *item;
465 int row;
466 RColor *rgb;
467
468 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
469 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
470 rgb = wmalloc(sizeof(RColor));
471 memset(rgb, 0, sizeof(RColor));
472 item->clientData = rgb;
473
474 WMSelectListItem(panel->gcolL, row);
475
476 updateGradButtons(panel);
477
478 sliderChangeCallback(panel->ghueS, panel);
479
480 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
481 }
482
483 static void gradClickCallback(WMWidget * w, void *data)
484 {
485 TexturePanel *panel = (TexturePanel *) data;
486 WMListItem *item;
487 int row;
488 RHSVColor hsv;
489
490 row = WMGetListSelectedItemRow(w);
491 if (row < 0)
492 return;
493
494 item = WMGetListItem(panel->gcolL, row);
495 RRGBtoHSV((RColor *) item->clientData, &hsv);
496
497 WMSetSliderValue(panel->ghueS, hsv.hue);
498 WMSetSliderValue(panel->gsatS, hsv.saturation);
499 WMSetSliderValue(panel->gvalS, hsv.value);
500
501 sliderChangeCallback(panel->ghueS, panel);
502 sliderChangeCallback(panel->gsatS, panel);
503 }
504
505 static void gradDeleteCallback(WMWidget * w, void *data)
506 {
507 TexturePanel *panel = (TexturePanel *) data;
508 WMListItem *item;
509 int row;
510
511 row = WMGetListSelectedItemRow(panel->gcolL);
512 if (row < 0)
513 return;
514
515 item = WMGetListItem(panel->gcolL, row);
516 wfree(item->clientData);
517
518 WMRemoveListItem(panel->gcolL, row);
519
520 WMSelectListItem(panel->gcolL, row - 1);
521
522 updateGradButtons(panel);
523
524 gradClickCallback(panel->gcolL, panel);
525
526 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
527 }
528
529 /*************** Simple Gradient ***************/
530
531 static void colorWellObserver(void *self, WMNotification * n)
532 {
533 updateSGradButtons(self);
534 }
535
536 static void opaqChangeCallback(WMWidget * w, void *data)
537 {
538 TexturePanel *panel = (TexturePanel *) data;
539
540 updateTGradImage(panel);
541 }
542
543 /****************** Image ******************/
544
545 static void updateImage(TexturePanel * panel, char *path)
546 {
547 WMScreen *scr = WMWidgetScreen(panel->win);
548 RImage *image;
549 WMPixmap *pixmap;
550 WMSize size;
551
552 if (path) {
553 image = RLoadImage(WMScreenRContext(scr), path, 0);
554 if (!image) {
555 char *message;
556
557 message = wstrconcat(_("Could not load the selected file: "),
558 (char *)RMessageForError(RErrorCode));
559
560 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
561
562 if (!panel->image)
563 WMSetButtonEnabled(panel->okB, False);
564
565 wfree(message);
566 return;
567 }
568
569 WMSetButtonEnabled(panel->okB, True);
570
571 if (panel->image)
572 RReleaseImage(panel->image);
573 panel->image = image;
574 } else {
575 image = panel->image;
576 }
577
578 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
579 if (image) {
580 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
581
582 size = WMGetPixmapSize(pixmap);
583 WMSetLabelImage(panel->imageL, pixmap);
584 WMResizeWidget(panel->imageL, size.width, size.height);
585
586 WMReleasePixmap(pixmap);
587 }
588 } else {
589 updateTGradImage(panel);
590 }
591 }
592
593 static void browseImageCallback(WMWidget * w, void *data)
594 {
595 TexturePanel *panel = (TexturePanel *) data;
596 WMOpenPanel *opanel;
597 WMScreen *scr = WMWidgetScreen(w);
598 static char *ipath = NULL;
599
600 opanel = WMGetOpenPanel(scr);
601 WMSetFilePanelCanChooseDirectories(opanel, False);
602 WMSetFilePanelCanChooseFiles(opanel, True);
603
604 if (!ipath)
605 ipath = wstrdup(wgethomedir());
606
607 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
608 char *path, *fullpath;
609 char *tmp, *tmp2;
610
611 tmp = WMGetFilePanelFileName(opanel);
612 if (!tmp)
613 return;
614 fullpath = tmp;
615
616 wfree(ipath);
617 ipath = fullpath;
618
619 path = wstrdup(fullpath);
620
621 tmp2 = strrchr(fullpath, '/');
622 if (tmp2)
623 tmp2++;
624
625 tmp = wfindfileinarray(panel->pathList, tmp2);
626
627 if (tmp) {
628 if (strcmp(fullpath, tmp) == 0) {
629 wfree(path);
630 path = tmp2;
631 }
632 wfree(tmp);
633 }
634
635 if (!RGetImageFileFormat(fullpath)) {
636 WMRunAlertPanel(scr, panel->win, _("Error"),
637 _("The selected file does not contain a supported image."),
638 _("OK"), NULL, NULL);
639 wfree(path);
640 } else {
641 updateImage(panel, fullpath);
642 wfree(panel->imageFile);
643 panel->imageFile = path;
644
645 WMSetTextFieldText(panel->imageT, path);
646 }
647 }
648 }
649
650 static void buttonCallback(WMWidget * w, void *data)
651 {
652 TexturePanel *panel = (TexturePanel *) data;
653
654 if (w == panel->okB) {
655 (*panel->okAction) (panel->okData);
656 } else {
657 (*panel->cancelAction) (panel->cancelData);
658 }
659 }
660
661 static void changeTypeCallback(WMWidget * w, void *data)
662 {
663 TexturePanel *panel = (TexturePanel *) data;
664 int newType;
665 int i;
666
667 newType = WMGetPopUpButtonSelectedItem(w);
668 if (newType == panel->currentType)
669 return;
670
671 if (panel->currentType >= 0) {
672 for (i = 0; i < MAX_SECTION_PARTS; i++) {
673 if (panel->sectionParts[panel->currentType][i] == NULL)
674 break;
675 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
676 }
677 }
678
679 for (i = 0; i < MAX_SECTION_PARTS; i++) {
680 if (panel->sectionParts[newType][i] == NULL)
681 break;
682 WMMapWidget(panel->sectionParts[newType][i]);
683 }
684 panel->currentType = newType;
685
686 switch (newType) {
687 case TYPE_SGRADIENT:
688 updateSGradButtons(panel);
689 WMSetButtonEnabled(panel->okB, True);
690 break;
691 case TYPE_GRADIENT:
692 updateGradButtons(panel);
693 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
694 break;
695 case TYPE_TGRADIENT:
696 case TYPE_PIXMAP:
697 updateImage(panel, NULL);
698 WMSetButtonEnabled(panel->okB, panel->image != NULL);
699 break;
700 default:
701 WMSetButtonEnabled(panel->okB, True);
702 break;
703 }
704 }
705
706 /*
707 *--------------------------------------------------------------------------
708 * Public functions
709 *--------------------------------------------------------------------------
710 */
711 void DestroyTexturePanel(TexturePanel * panel)
712 {
713
714 }
715
716 void ShowTexturePanel(TexturePanel * panel)
717 {
718 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
719 Screen *scr = DefaultScreenOfDisplay(dpy);
720
721 WMSetWindowInitialPosition(panel->win,
722 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
723 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
724 WMMapWidget(panel->win);
725 }
726
727 void HideTexturePanel(TexturePanel * panel)
728 {
729 WMUnmapWidget(panel->win);
730 }
731
732 void SetTexturePanelOkAction(TexturePanel * panel, WMCallback * action, void *clientData)
733 {
734 panel->okAction = action;
735 panel->okData = clientData;
736 }
737
738 void SetTexturePanelCancelAction(TexturePanel * panel, WMCallback * action, void *clientData)
739 {
740 panel->cancelAction = action;
741 panel->cancelData = clientData;
742 }
743
744 void SetTexturePanelTexture(TexturePanel * panel, char *name, WMPropList * texture)
745 {
746 WMScreen *scr = WMWidgetScreen(panel->win);
747 char *str, *type;
748 WMPropList *p;
749 WMColor *color;
750 int i;
751 char buffer[64];
752 int gradient = 0;
753
754 WMSetTextFieldText(panel->nameT, name);
755
756 if (!texture)
757 return;
758
759 p = WMGetFromPLArray(texture, 0);
760 if (!p) {
761 goto bad_texture;
762 }
763 type = WMGetFromPLString(p);
764
765 /*............................................... */
766 if (strcasecmp(type, "solid") == 0) {
767
768 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
769
770 p = WMGetFromPLArray(texture, 1);
771 if (!p) {
772 str = "black";
773 } else {
774 str = WMGetFromPLString(p);
775 }
776 color = WMCreateNamedColor(scr, str, False);
777
778 WMSetColorWellColor(panel->defcW, color);
779
780 WMReleaseColor(color);
781 /*............................................... */
782 } else if (strcasecmp(type, "hgradient") == 0
783 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
784
785 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
786
787 p = WMGetFromPLArray(texture, 1);
788 if (!p) {
789 str = "black";
790 } else {
791 str = WMGetFromPLString(p);
792 }
793 color = WMCreateNamedColor(scr, str, False);
794
795 WMSetColorWellColor(panel->tcol1W, color);
796
797 WMReleaseColor(color);
798
799 p = WMGetFromPLArray(texture, 2);
800 if (!p) {
801 str = "black";
802 } else {
803 str = WMGetFromPLString(p);
804 }
805 color = WMCreateNamedColor(scr, str, False);
806
807 WMSetColorWellColor(panel->tcol2W, color);
808
809 WMReleaseColor(color);
810
811 gradient = type[0];
812 /*............................................... */
813 } else if (strcasecmp(type, "thgradient") == 0
814 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
815 int i;
816
817 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
818
819 gradient = type[1];
820
821 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
822 if (panel->imageFile)
823 wfree(panel->imageFile);
824 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
825
826 i = 180;
827 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
828 WMSetSliderValue(panel->topaS, i);
829
830 p = WMGetFromPLArray(texture, 3);
831 if (!p) {
832 str = "black";
833 } else {
834 str = WMGetFromPLString(p);
835 }
836 color = WMCreateNamedColor(scr, str, False);
837
838 WMSetColorWellColor(panel->tcol1W, color);
839
840 WMReleaseColor(color);
841
842 p = WMGetFromPLArray(texture, 4);
843 if (!p) {
844 str = "black";
845 } else {
846 str = WMGetFromPLString(p);
847 }
848 color = WMCreateNamedColor(scr, str, False);
849
850 WMSetColorWellColor(panel->tcol2W, color);
851
852 WMReleaseColor(color);
853
854 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
855
856 if (panel->imageFile)
857 wfree(panel->imageFile);
858 if ((panel->imageFile = wfindfileinarray(panel->pathList,
859 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) !=
860 NULL) {
861
862 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
863 updateTGradImage(panel);
864
865 updateSGradButtons(panel);
866 } else
867 wwarning(_("could not load file '%s': %s"), panel->imageFile,
868 RMessageForError(RErrorCode));
869
870 /*............................................... */
871 } else if (strcasecmp(type, "mhgradient") == 0
872 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
873 WMListItem *item;
874
875 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
876 item = WMGetListItem(panel->gcolL, i);
877 wfree(item->clientData);
878 }
879 WMClearList(panel->gcolL);
880
881 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
882
883 p = WMGetFromPLArray(texture, 1);
884 if (!p) {
885 str = "black";
886 } else {
887 str = WMGetFromPLString(p);
888 }
889 color = WMCreateNamedColor(scr, str, False);
890
891 WMSetColorWellColor(panel->defcW, color);
892
893 WMReleaseColor(color);
894
895 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
896 RColor *rgb;
897 XColor xcolor;
898
899 p = WMGetFromPLArray(texture, i);
900 if (!p) {
901 str = "black";
902 } else {
903 str = WMGetFromPLString(p);
904 }
905
906 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
907
908 rgb = wmalloc(sizeof(RColor));
909 rgb->red = xcolor.red >> 8;
910 rgb->green = xcolor.green >> 8;
911 rgb->blue = xcolor.blue >> 8;
912 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
913
914 item = WMAddListItem(panel->gcolL, buffer);
915 item->clientData = rgb;
916 }
917
918 sliderChangeCallback(panel->ghueS, panel);
919
920 gradient = type[1];
921 /*............................................... */
922 } else if (strcasecmp(type, "cpixmap") == 0
923 || strcasecmp(type, "spixmap") == 0
924 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
925
926 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
927
928 switch (toupper(type[0])) {
929 case 'C':
930 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
931 break;
932 case 'S':
933 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
934 break;
935 case 'M':
936 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
937 break;
938 default:
939 case 'T':
940 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
941 break;
942 }
943
944 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
945
946 if (panel->imageFile)
947 wfree(panel->imageFile);
948 panel->imageFile = wfindfileinarray(panel->pathList,
949 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
950
951 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
952 WMSetColorWellColor(panel->defcW, color);
953 WMReleaseColor(color);
954
955 updateImage(panel, panel->imageFile);
956 }
957
958 changeTypeCallback(panel->typeP, panel);
959
960 if (gradient > 0) {
961 updateGradButtons(panel);
962
963 switch (toupper(gradient)) {
964 case 'H':
965 WMPerformButtonClick(panel->dirhB);
966 break;
967 case 'V':
968 WMPerformButtonClick(panel->dirvB);
969 break;
970 default:
971 case 'D':
972 WMPerformButtonClick(panel->dirdB);
973 break;
974 }
975 }
976
977 return;
978
979 bad_texture:
980 str = WMGetPropListDescription(texture, False);
981 wwarning(_("error creating texture %s"), str);
982 wfree(str);
983
984 }
985
986 char *GetTexturePanelTextureName(TexturePanel * panel)
987 {
988 return WMGetTextFieldText(panel->nameT);
989
990 }
991
992 WMPropList *GetTexturePanelTexture(TexturePanel * panel)
993 {
994 WMPropList *prop = NULL;
995 WMColor *color;
996 char *str, *str2;
997 char buff[32];
998 int i;
999
1000 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1001
1002 case TYPE_SOLID:
1003 color = WMGetColorWellColor(panel->defcW);
1004 str = WMGetColorRGBDescription(color);
1005 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1006 wfree(str);
1007
1008 break;
1009
1010 case TYPE_PIXMAP:
1011 color = WMGetColorWellColor(panel->defcW);
1012 str = WMGetColorRGBDescription(color);
1013
1014 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1015 case PTYPE_SCALE:
1016 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1017 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1018 break;
1019 case PTYPE_MAXIMIZE:
1020 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1021 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1022 break;
1023 case PTYPE_CENTER:
1024 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1025 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1026 break;
1027 case PTYPE_TILE:
1028 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1029 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1030 break;
1031 }
1032 wfree(str);
1033 break;
1034
1035 case TYPE_TGRADIENT:
1036 color = WMGetColorWellColor(panel->tcol1W);
1037 str = WMGetColorRGBDescription(color);
1038
1039 color = WMGetColorWellColor(panel->tcol2W);
1040 str2 = WMGetColorRGBDescription(color);
1041
1042 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1043
1044 if (WMGetButtonSelected(panel->dirdB)) {
1045 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1046 WMCreatePLString(panel->imageFile),
1047 WMCreatePLString(buff),
1048 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1049 } else if (WMGetButtonSelected(panel->dirvB)) {
1050 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1051 WMCreatePLString(panel->imageFile),
1052 WMCreatePLString(buff),
1053 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1054 } else {
1055 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1056 WMCreatePLString(panel->imageFile),
1057 WMCreatePLString(buff),
1058 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1059 }
1060 wfree(str);
1061 wfree(str2);
1062 break;
1063
1064 case TYPE_SGRADIENT:
1065 color = WMGetColorWellColor(panel->tcol1W);
1066 str = WMGetColorRGBDescription(color);
1067
1068 color = WMGetColorWellColor(panel->tcol2W);
1069 str2 = WMGetColorRGBDescription(color);
1070
1071 if (WMGetButtonSelected(panel->dirdB)) {
1072 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1073 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1074 } else if (WMGetButtonSelected(panel->dirvB)) {
1075 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1076 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1077 } else {
1078 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1079 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1080 }
1081 wfree(str);
1082 wfree(str2);
1083 break;
1084
1085 case TYPE_GRADIENT:
1086 color = WMGetColorWellColor(panel->defcW);
1087 str = WMGetColorRGBDescription(color);
1088
1089 if (WMGetButtonSelected(panel->dirdB)) {
1090 prop = WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str), NULL);
1091 } else if (WMGetButtonSelected(panel->dirvB)) {
1092 prop = WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str), NULL);
1093 } else {
1094 prop = WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str), NULL);
1095 }
1096 wfree(str);
1097
1098 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1099 RColor *rgb;
1100 WMListItem *item;
1101
1102 item = WMGetListItem(panel->gcolL, i);
1103
1104 rgb = (RColor *) item->clientData;
1105
1106 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1107
1108 WMAddToPLArray(prop, WMCreatePLString(buff));
1109 }
1110 break;
1111 }
1112
1113 return prop;
1114 }
1115
1116 void SetTexturePanelPixmapPath(TexturePanel * panel, WMPropList * array)
1117 {
1118 panel->pathList = array;
1119 }
1120
1121 TexturePanel *CreateTexturePanel(WMWindow * keyWindow)
1122 /*CreateTexturePanel(WMScreen *scr)*/
1123 {
1124 TexturePanel *panel;
1125 WMScreen *scr = WMWidgetScreen(keyWindow);
1126
1127 panel = wmalloc(sizeof(TexturePanel));
1128 memset(panel, 0, sizeof(TexturePanel));
1129
1130 panel->listFont = WMSystemFontOfSize(scr, 12);
1131
1132 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1133 WMTitledWindowMask | WMClosableWindowMask);
1134 /*
1135 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1136 WMTitledWindowMask
1137 |WMClosableWindowMask);
1138 */
1139
1140 WMResizeWidget(panel->win, 325, 423);
1141 WMSetWindowTitle(panel->win, _("Texture Panel"));
1142 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1143
1144 /* texture name */
1145 panel->nameF = WMCreateFrame(panel->win);
1146 WMResizeWidget(panel->nameF, 185, 50);
1147 WMMoveWidget(panel->nameF, 15, 10);
1148 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1149
1150 panel->nameT = WMCreateTextField(panel->nameF);
1151 WMResizeWidget(panel->nameT, 160, 20);
1152 WMMoveWidget(panel->nameT, 12, 18);
1153
1154 WMMapSubwidgets(panel->nameF);
1155
1156 /* texture types */
1157 panel->typeP = WMCreatePopUpButton(panel->win);
1158 WMResizeWidget(panel->typeP, 185, 20);
1159 WMMoveWidget(panel->typeP, 15, 65);
1160 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1161 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1162 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1163 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1164 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1165 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1166 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1167
1168 /* color */
1169 panel->defcF = WMCreateFrame(panel->win);
1170 WMResizeWidget(panel->defcF, 100, 75);
1171 WMMoveWidget(panel->defcF, 210, 10);
1172 WMSetFrameTitle(panel->defcF, _("Default Color"));
1173
1174 panel->defcW = WMCreateColorWell(panel->defcF);
1175 WMResizeWidget(panel->defcW, 60, 45);
1176 WMMoveWidget(panel->defcW, 20, 20);
1177
1178 WMMapSubwidgets(panel->defcF);
1179
1180 /****** Gradient ******/
1181 panel->gcolF = WMCreateFrame(panel->win);
1182 WMResizeWidget(panel->gcolF, 295, 205);
1183 WMMoveWidget(panel->gcolF, 15, 95);
1184 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1185
1186 panel->gcolL = WMCreateList(panel->gcolF);
1187 WMResizeWidget(panel->gcolL, 130, 140);
1188 WMMoveWidget(panel->gcolL, 10, 25);
1189 WMHangData(panel->gcolL, panel);
1190 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1191 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1192
1193 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1194 WMResizeWidget(panel->gcolaB, 64, 24);
1195 WMMoveWidget(panel->gcolaB, 10, 170);
1196 WMSetButtonText(panel->gcolaB, _("Add"));
1197 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1198
1199 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1200 WMResizeWidget(panel->gcoldB, 64, 24);
1201 WMMoveWidget(panel->gcoldB, 75, 170);
1202 WMSetButtonText(panel->gcoldB, _("Delete"));
1203 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1204
1205 #if 0
1206 panel->gbriS = WMCreateSlider(panel->gcolF);
1207 WMResizeWidget(panel->gbriS, 130, 16);
1208 WMMoveWidget(panel->gbriS, 150, 25);
1209 WMSetSliderKnobThickness(panel->gbriS, 8);
1210 WMSetSliderMaxValue(panel->gbriS, 100);
1211 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1212 {
1213 WMPixmap *pixmap;
1214 WMColor *color;
1215
1216 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1217 color = WMDarkGrayColor(scr);
1218 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1219 WMReleaseColor(color);
1220 color = WMWhiteColor(color);
1221 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1222 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1223 WMSetSliderImage(panel->gbriS, pixmap);
1224 WMReleasePixmap(pixmap);
1225 }
1226
1227 panel->gconS = WMCreateSlider(panel->gcolF);
1228 WMResizeWidget(panel->gconS, 130, 16);
1229 WMMoveWidget(panel->gconS, 150, 50);
1230 WMSetSliderKnobThickness(panel->gconS, 8);
1231 WMSetSliderMaxValue(panel->gconS, 100);
1232 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1233 {
1234 WMPixmap *pixmap;
1235 WMColor *color;
1236
1237 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1238 color = WMDarkGrayColor(scr);
1239 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1240 WMReleaseColor(color);
1241 color = WMWhiteColor(scr);
1242 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1243 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1244 WMSetSliderImage(panel->gconS, pixmap);
1245 WMReleasePixmap(pixmap);
1246 }
1247 #endif
1248 panel->ghueS = WMCreateSlider(panel->gcolF);
1249 WMResizeWidget(panel->ghueS, 130, 16);
1250 WMMoveWidget(panel->ghueS, 150, 100);
1251 WMSetSliderKnobThickness(panel->ghueS, 8);
1252 WMSetSliderMaxValue(panel->ghueS, 359);
1253 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1254
1255 panel->gsatS = WMCreateSlider(panel->gcolF);
1256 WMResizeWidget(panel->gsatS, 130, 16);
1257 WMMoveWidget(panel->gsatS, 150, 125);
1258 WMSetSliderKnobThickness(panel->gsatS, 8);
1259 WMSetSliderMaxValue(panel->gsatS, 255);
1260 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1261
1262 panel->gvalS = WMCreateSlider(panel->gcolF);
1263 WMResizeWidget(panel->gvalS, 130, 16);
1264 WMMoveWidget(panel->gvalS, 150, 150);
1265 WMSetSliderKnobThickness(panel->gvalS, 8);
1266 WMSetSliderMaxValue(panel->gvalS, 255);
1267 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1268
1269 WMMapSubwidgets(panel->gcolF);
1270
1271 /** Direction **/
1272 panel->dirF = WMCreateFrame(panel->win);
1273 WMSetFrameTitle(panel->dirF, _("Direction"));
1274 WMResizeWidget(panel->dirF, 295, 75);
1275 WMMoveWidget(panel->dirF, 15, 305);
1276
1277 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1278 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1279 WMResizeWidget(panel->dirvB, 90, 40);
1280 WMMoveWidget(panel->dirvB, 10, 20);
1281
1282 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1283 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1284 WMResizeWidget(panel->dirhB, 90, 40);
1285 WMMoveWidget(panel->dirhB, 102, 20);
1286
1287 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1288 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1289 WMResizeWidget(panel->dirdB, 90, 40);
1290 WMMoveWidget(panel->dirdB, 194, 20);
1291
1292 WMGroupButtons(panel->dirvB, panel->dirhB);
1293 WMGroupButtons(panel->dirvB, panel->dirdB);
1294
1295 WMMapSubwidgets(panel->dirF);
1296
1297 /****************** Textured Gradient ******************/
1298 panel->tcolF = WMCreateFrame(panel->win);
1299 WMResizeWidget(panel->tcolF, 100, 135);
1300 WMMoveWidget(panel->tcolF, 210, 10);
1301 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1302
1303 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1304 WMResizeWidget(panel->tcol1W, 60, 45);
1305 WMMoveWidget(panel->tcol1W, 20, 25);
1306 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1307
1308 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1309 WMResizeWidget(panel->tcol2W, 60, 45);
1310 WMMoveWidget(panel->tcol2W, 20, 75);
1311 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1312
1313 /** Opacity */
1314 panel->topaF = WMCreateFrame(panel->win);
1315 WMResizeWidget(panel->topaF, 185, 50);
1316 WMMoveWidget(panel->topaF, 15, 95);
1317 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1318
1319 panel->topaS = WMCreateSlider(panel->topaF);
1320 WMResizeWidget(panel->topaS, 155, 18);
1321 WMMoveWidget(panel->topaS, 15, 20);
1322 WMSetSliderMaxValue(panel->topaS, 255);
1323 WMSetSliderValue(panel->topaS, 200);
1324 WMSetSliderContinuous(panel->topaS, False);
1325 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1326
1327 WMMapSubwidgets(panel->topaF);
1328
1329 {
1330 WMPixmap *pixmap;
1331 Pixmap p;
1332 WMColor *color;
1333
1334 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1335 p = WMGetPixmapXID(pixmap);
1336
1337 color = WMDarkGrayColor(scr);
1338 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1339 WMReleaseColor(color);
1340
1341 color = WMWhiteColor(scr);
1342 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1343 WMDrawString(scr, p, color, panel->listFont,
1344 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1345 WMReleaseColor(color);
1346
1347 WMSetSliderImage(panel->topaS, pixmap);
1348 WMReleasePixmap(pixmap);
1349 }
1350
1351 WMMapSubwidgets(panel->tcolF);
1352
1353 /****************** Image ******************/
1354 panel->imageF = WMCreateFrame(panel->win);
1355 WMResizeWidget(panel->imageF, 295, 150);
1356 WMMoveWidget(panel->imageF, 15, 150);
1357 WMSetFrameTitle(panel->imageF, _("Image"));
1358
1359 panel->imageL = WMCreateLabel(panel->imageF);
1360 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1361
1362 panel->imageT = WMCreateTextField(panel->imageF);
1363 WMResizeWidget(panel->imageT, 90, 20);
1364 WMMoveWidget(panel->imageT, 190, 25);
1365
1366 panel->imageV = WMCreateScrollView(panel->imageF);
1367 WMResizeWidget(panel->imageV, 165, 115);
1368 WMMoveWidget(panel->imageV, 15, 20);
1369 WMSetScrollViewRelief(panel->imageV, WRSunken);
1370 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1371 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1372 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1373
1374 panel->browB = WMCreateCommandButton(panel->imageF);
1375 WMResizeWidget(panel->browB, 90, 24);
1376 WMMoveWidget(panel->browB, 190, 50);
1377 WMSetButtonText(panel->browB, _("Browse..."));
1378 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1379
1380 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1381 WMResizeWidget(panel->dispB, 90, 24);
1382 WMMoveWidget(panel->dispB, 190, 80);
1383 WMSetButtonText(panel->dispB, _("Show"));
1384 */
1385
1386 panel->arrP = WMCreatePopUpButton(panel->imageF);
1387 WMResizeWidget(panel->arrP, 90, 20);
1388 WMMoveWidget(panel->arrP, 190, 120);
1389 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1390 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1391 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1392 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1393 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1394
1395 WMMapSubwidgets(panel->imageF);
1396
1397 /****/
1398
1399 panel->okB = WMCreateCommandButton(panel->win);
1400 WMResizeWidget(panel->okB, 84, 24);
1401 WMMoveWidget(panel->okB, 225, 390);
1402 WMSetButtonText(panel->okB, _("OK"));
1403 WMSetButtonAction(panel->okB, buttonCallback, panel);
1404
1405 panel->cancelB = WMCreateCommandButton(panel->win);
1406 WMResizeWidget(panel->cancelB, 84, 24);
1407 WMMoveWidget(panel->cancelB, 130, 390);
1408 WMSetButtonText(panel->cancelB, _("Cancel"));
1409 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1410
1411 WMMapWidget(panel->nameF);
1412 WMMapWidget(panel->typeP);
1413 WMMapWidget(panel->okB);
1414 WMMapWidget(panel->cancelB);
1415
1416 WMUnmapWidget(panel->arrP);
1417
1418 WMRealizeWidget(panel->win);
1419
1420 panel->currentType = -1;
1421
1422 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1423
1424 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1425 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1426 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1427
1428 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1429 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1430
1431 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1432 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1433 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1434 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1435 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1436
1437 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1438 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1439 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1440
1441 /* setup for first time */
1442
1443 changeTypeCallback(panel->typeP, panel);
1444
1445 sliderChangeCallback(panel->ghueS, panel);
1446 sliderChangeCallback(panel->gsatS, panel);
1447
1448 return panel;
1449 }
1450
1451 /*
1452 *--------------------------------------------------------------------------
1453 * Test stuff
1454 *--------------------------------------------------------------------------
1455 */
1456
1457 #if 0
1458
1459 char *ProgName = "test";
1460
1461 void testOKButton(WMWidget * self, void *data)
1462 {
1463 char *test;
1464 Display *dpy;
1465 Window win;
1466 Pixmap pix;
1467 RImage *image;
1468
1469 TexturePanel *panel = (TexturePanel *) data;
1470 /* test = GetTexturePanelTextureString(panel); */
1471
1472 wwarning(test);
1473
1474 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1475 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250, 0, 0, 0);
1476 XMapRaised(dpy, win);
1477 XFlush(dpy);
1478
1479 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1480
1481 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1482
1483 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width,
1484 image->height, 0, 0);
1485
1486 wfree(test);
1487
1488 }
1489
1490 void testCancelButton(WMWidget * self, void *data)
1491 {
1492 wwarning("Exiting test....");
1493 exit(0);
1494 }
1495
1496 void wAbort()
1497 {
1498 exit(1);
1499 }
1500
1501 int main(int argc, char **argv)
1502 {
1503 TexturePanel *panel;
1504
1505 Display *dpy = XOpenDisplay("");
1506 WMScreen *scr;
1507
1508 /* char *test; */
1509
1510 WMInitializeApplication("Test", &argc, argv);
1511
1512 if (!dpy) {
1513 wfatal("could not open display");
1514 exit(1);
1515 }
1516
1517 scr = WMCreateSimpleApplicationScreen(dpy);
1518
1519 panel = CreateTexturePanel(scr);
1520
1521 SetTexturePanelOkAction(panel, (WMAction *) testOKButton, panel);
1522 SetTexturePanelCancelAction(panel, (WMAction *) testCancelButton, panel);
1523
1524 SetTexturePanelTexture(panel, "pinky",
1525 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1526
1527 ShowTexturePanel(panel);
1528
1529 WMScreenMainLoop(scr);
1530 return 0;
1531 }
1532 #endif