- fixed the checkTimerHandlers() to flush the ASAP notification queue, even
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobc0f20f61a068279554c7f96b715c3eb3627fea45
1 /* TexturePanel.c- texture editting panel
2 *
3 * WPrefs - WindowMaker Preferences Program
4 *
5 * Copyright (c) 1998, 1999 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.
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.
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.
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <ctype.h>
31 #include <X11/Xlib.h>
34 #include <WINGs.h>
35 #include <WUtil.h>
37 #include "WPrefs.h"
39 #include "TexturePanel.h"
42 #define MAX_SECTION_PARTS 5
44 typedef struct _TexturePanel {
45 WMWindow *win;
47 /* texture name */
48 WMFrame *nameF;
49 WMTextField *nameT;
51 /* texture type */
52 WMPopUpButton *typeP;
54 /* default color */
55 WMFrame *defcF;
56 WMColorWell *defcW;
58 WMFont *listFont;
60 /*-- Gradient --*/
62 Pixmap gimage;
64 /* colors */
65 WMFrame *gcolF;
66 WMList *gcolL;
67 WMButton *gcolaB;
68 WMButton *gcoldB;
69 WMSlider *ghueS;
70 WMSlider *gsatS;
71 WMSlider *gvalS;
73 WMSlider *gbriS;
74 WMSlider *gconS;
76 /* direction (common) */
77 WMFrame *dirF;
78 WMButton *dirhB;
79 WMButton *dirvB;
80 WMButton *dirdB;
82 /*-- Simple Gradient --*/
85 /*-- Textured Gradient --*/
87 WMFrame *tcolF;
88 WMColorWell *tcol1W;
89 WMColorWell *tcol2W;
91 WMFrame *topaF;
92 WMSlider *topaS;
94 /*-- Image --*/
95 WMFrame *imageF;
96 WMScrollView *imageV;
97 WMTextField *imageT;
98 WMLabel *imageL;
99 WMButton *browB;
100 WMButton *dispB;
101 WMPopUpButton *arrP;
103 RImage *image;
104 char *imageFile;
106 /*****/
108 WMButton *okB;
109 WMButton *cancelB;
112 WMCallback *okAction;
113 void *okData;
115 WMCallback *cancelAction;
116 void *cancelData;
118 /****/
119 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
121 int currentType;
124 proplist_t pathList;
126 } _TexturePanel;
130 #define TYPE_SOLID 0
131 #define TYPE_GRADIENT 1
132 #define TYPE_SGRADIENT 2
133 #define TYPE_TGRADIENT 3
134 #define TYPE_PIXMAP 4
137 #define PTYPE_TILE 0
138 #define PTYPE_SCALE 1
139 #define PTYPE_CENTER 2
140 #define PTYPE_MAXIMIZE 3
145 *--------------------------------------------------------------------------
146 * Private Functions
147 *--------------------------------------------------------------------------
150 /************/
152 static void
153 updateGradButtons(TexturePanel *panel)
155 RImage *image;
156 WMPixmap *pixmap;
157 int colorn;
158 RColor **colors;
160 colorn = WMGetListNumberOfRows(panel->gcolL);
161 if (colorn < 1) {
162 pixmap = NULL;
163 } else {
164 int i;
165 WMListItem *item;
167 colors = wmalloc(sizeof(RColor*)*(colorn+1));
169 for (i = 0; i < colorn; i++) {
170 item = WMGetListItem(panel->gcolL, i);
171 colors[i] = (RColor*)item->clientData;
173 colors[i] = NULL;
175 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
176 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
177 image, 128);
178 RDestroyImage(image);
179 WMSetButtonImage(panel->dirhB, pixmap);
180 WMReleasePixmap(pixmap);
182 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
183 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
184 image, 128);
185 RDestroyImage(image);
186 WMSetButtonImage(panel->dirvB, pixmap);
187 WMReleasePixmap(pixmap);
189 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
190 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
191 image, 128);
192 RDestroyImage(image);
193 WMSetButtonImage(panel->dirdB, pixmap);
194 WMReleasePixmap(pixmap);
196 free(colors);
202 static void
203 updateTGradImage(TexturePanel *panel)
205 RImage *image, *gradient;
206 WMPixmap *pixmap;
207 RColor from;
208 RColor to;
209 WMColor *color;
211 if (!panel->image)
212 return;
214 color = WMGetColorWellColor(panel->tcol1W);
215 from.red = WMRedComponentOfColor(color)>>8;
216 from.green = WMGreenComponentOfColor(color)>>8;
217 from.blue = WMBlueComponentOfColor(color)>>8;
219 color = WMGetColorWellColor(panel->tcol2W);
220 to.red = WMRedComponentOfColor(color)>>8;
221 to.green = WMGreenComponentOfColor(color)>>8;
222 to.blue = WMBlueComponentOfColor(color)>>8;
224 if (panel->image->width < 141 || panel->image->height < 91) {
225 image = RMakeTiledImage(panel->image, 141, 91);
226 } else {
227 image = RCloneImage(panel->image);
230 if (WMGetButtonSelected(panel->dirhB)) {
231 gradient = RRenderGradient(image->width, image->height, &from, &to,
232 RHorizontalGradient);
233 } else if (WMGetButtonSelected(panel->dirvB)) {
234 gradient = RRenderGradient(image->width, image->height, &from, &to,
235 RVerticalGradient);
236 } else {
237 gradient = RRenderGradient(image->width, image->height, &from, &to,
238 RDiagonalGradient);
241 RCombineImagesWithOpaqueness(image, gradient,
242 WMGetSliderValue(panel->topaS));
243 RDestroyImage(gradient);
244 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
245 image, 128);
247 WMSetLabelImage(panel->imageL, pixmap);
248 WMReleasePixmap(pixmap);
249 WMResizeWidget(panel->imageL, image->width, image->height);
250 RDestroyImage(image);
254 static void
255 updateSGradButtons(TexturePanel *panel)
257 RImage *image;
258 WMPixmap *pixmap;
259 RColor from;
260 RColor to;
261 WMColor *color;
263 color = WMGetColorWellColor(panel->tcol1W);
264 from.red = WMRedComponentOfColor(color)>>8;
265 from.green = WMGreenComponentOfColor(color)>>8;
266 from.blue = WMBlueComponentOfColor(color)>>8;
268 color = WMGetColorWellColor(panel->tcol2W);
269 to.red = WMRedComponentOfColor(color)>>8;
270 to.green = WMGreenComponentOfColor(color)>>8;
271 to.blue = WMBlueComponentOfColor(color)>>8;
273 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
274 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
275 image, 128);
276 RDestroyImage(image);
277 WMSetButtonImage(panel->dirhB, pixmap);
278 WMReleasePixmap(pixmap);
280 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
281 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
282 image, 128);
283 RDestroyImage(image);
284 WMSetButtonImage(panel->dirvB, pixmap);
285 WMReleasePixmap(pixmap);
287 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
288 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
289 image, 128);
290 RDestroyImage(image);
291 WMSetButtonImage(panel->dirdB, pixmap);
292 WMReleasePixmap(pixmap);
296 /*********** Gradient ************/
298 static void
299 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
301 RImage *image;
302 WMPixmap *pixmap;
303 WMScreen *scr = WMWidgetScreen(sPtr);
304 RColor from, to;
305 RHSVColor tmp;
307 tmp = *hsv;
308 if (saturation) {
309 tmp.saturation = 0;
310 RHSVtoRGB(&tmp, &from);
311 tmp.saturation = 255;
312 RHSVtoRGB(&tmp, &to);
313 } else {
314 tmp.value = 0;
315 RHSVtoRGB(&tmp, &from);
316 tmp.value = 255;
317 RHSVtoRGB(&tmp, &to);
319 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
320 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
321 RDestroyImage(image);
323 if (hsv->value < 128 || !saturation) {
324 WMColor *col = WMWhiteColor(scr);
326 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
327 (16 - WMFontHeight(font))/2 - 1,
328 saturation ? "Saturation" : "Brightness", 10);
329 WMReleaseColor(col);
330 } else {
331 WMColor *col = WMBlackColor(scr);
333 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
334 (16 - WMFontHeight(font))/2 - 1,
335 saturation ? "Saturation" : "Brightness", 10);
336 WMReleaseColor(col);
338 WMSetSliderImage(sPtr, pixmap);
339 WMReleasePixmap(pixmap);
343 static void
344 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
346 RColor *colors[8];
347 RImage *image;
348 WMPixmap *pixmap;
349 WMScreen *scr = WMWidgetScreen(sPtr);
350 RHSVColor thsv;
351 int i;
353 thsv = *hsv;
354 for (i = 0; i <= 6; i++) {
355 thsv.hue = (360*i)/6;
356 colors[i] = wmalloc(sizeof(RColor));
357 RHSVtoRGB(&thsv, colors[i]);
359 colors[i] = NULL;
361 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
362 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
363 RDestroyImage(image);
365 if (hsv->value < 128) {
366 WMColor *col = WMWhiteColor(scr);
368 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
369 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
370 WMReleaseColor(col);
371 } else {
372 WMColor *col = WMBlackColor(scr);
374 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
375 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
376 WMReleaseColor(col);
378 WMSetSliderImage(sPtr, pixmap);
379 WMReleasePixmap(pixmap);
381 for (i = 0; i <= 6; i++)
382 free(colors[i]);
387 static void
388 sliderChangeCallback(WMWidget *w, void *data)
390 TexturePanel *panel = (TexturePanel*)data;
391 RHSVColor hsv;
392 int row, rows;
393 WMListItem *item;
394 RColor **colors;
395 int i;
396 RImage *image;
397 WMScreen *scr = WMWidgetScreen(w);
399 hsv.hue = WMGetSliderValue(panel->ghueS);
400 hsv.saturation = WMGetSliderValue(panel->gsatS);
401 hsv.value = WMGetSliderValue(panel->gvalS);
403 row = WMGetListSelectedItemRow(panel->gcolL);
404 if (row >= 0) {
405 RColor *rgb;
407 item = WMGetListItem(panel->gcolL, row);
409 rgb = (RColor*)item->clientData;
411 RHSVtoRGB(&hsv, rgb);
413 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
416 if (w == panel->ghueS) {
417 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
418 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
419 } else if (w == panel->gsatS) {
420 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
421 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
422 } else {
423 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
424 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
427 rows = WMGetListNumberOfRows(panel->gcolL);
428 if (rows == 0)
429 return;
431 colors = wmalloc(sizeof(RColor*)*(rows+1));
433 for (i = 0; i < rows; i++) {
434 item = WMGetListItem(panel->gcolL, i);
436 colors[i] = (RColor*)item->clientData;
438 colors[i] = NULL;
440 if (panel->gimage != None) {
441 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
444 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
445 colors, RVerticalGradient);
446 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
447 RDestroyImage(image);
449 free(colors);
451 WMRedisplayWidget(panel->gcolL);
453 updateGradButtons(panel);
457 static void
458 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
459 WMRect *rect)
461 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
462 WMScreen *scr = WMWidgetScreen(lPtr);
463 int width, height, x, y;
464 Display *dpy;
465 WMColor *white = WMWhiteColor(scr);
466 WMListItem *item;
467 WMColor *black = WMBlackColor(scr);
469 dpy = WMScreenDisplay(scr);
471 width = rect->size.width;
472 height = rect->size.height;
473 x = rect->pos.x;
474 y = rect->pos.y;
476 if (state & WLDSSelected)
477 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
478 else
479 XClearArea(dpy, d, x, y, width, height, False);
481 item = WMGetListItem(lPtr, index);
483 if (panel->gimage) {
484 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
485 0, height*index, 30, height, x + 5, y);
487 WMDrawString(scr, d, WMColorGC(black), panel->listFont,
488 x + 40, y + 1, text, strlen(text));
490 WMReleaseColor(white);
491 WMReleaseColor(black);
496 static void
497 gradAddCallback(WMWidget *w, void *data)
499 TexturePanel *panel = (TexturePanel*)data;
500 WMListItem *item;
501 int row;
502 RColor *rgb;
504 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
505 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
506 rgb = wmalloc(sizeof(RColor));
507 memset(rgb, 0, sizeof(RColor));
508 item->clientData = rgb;
510 WMSelectListItem(panel->gcolL, row);
512 updateGradButtons(panel);
514 sliderChangeCallback(panel->ghueS, panel);
516 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
521 static void
522 gradClickCallback(WMWidget *w, void *data)
524 TexturePanel *panel = (TexturePanel*)data;
525 WMListItem *item;
526 int row;
527 RHSVColor hsv;
529 row = WMGetListSelectedItemRow(w);
530 if (row < 0)
531 return;
533 item = WMGetListItem(panel->gcolL, row);
534 RRGBtoHSV((RColor*)item->clientData, &hsv);
536 WMSetSliderValue(panel->ghueS, hsv.hue);
537 WMSetSliderValue(panel->gsatS, hsv.saturation);
538 WMSetSliderValue(panel->gvalS, hsv.value);
540 sliderChangeCallback(panel->ghueS, panel);
541 sliderChangeCallback(panel->gsatS, panel);
545 static void
546 gradDeleteCallback(WMWidget *w, void *data)
548 TexturePanel *panel = (TexturePanel*)data;
549 WMListItem *item;
550 int row;
552 row = WMGetListSelectedItemRow(panel->gcolL);
553 if (row < 0)
554 return;
556 item = WMGetListItem(panel->gcolL, row);
557 free(item->clientData);
559 WMRemoveListItem(panel->gcolL, row);
561 WMSelectListItem(panel->gcolL, row - 1);
563 updateGradButtons(panel);
565 gradClickCallback(panel->gcolL, panel);
567 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
571 /*************** Simple Gradient ***************/
573 static void
574 colorWellObserver(void *self, WMNotification *n)
576 updateSGradButtons(self);
582 static void
583 opaqChangeCallback(WMWidget *w, void *data)
585 TexturePanel *panel = (TexturePanel*)data;
587 updateTGradImage(panel);
590 /****************** Image ******************/
592 static void
593 updateImage(TexturePanel *panel, char *path)
595 WMScreen *scr = WMWidgetScreen(panel->win);
596 RImage *image;
597 WMPixmap *pixmap;
598 WMSize size;
600 if (path) {
601 image = RLoadImage(WMScreenRContext(scr), path, 0);
602 if (!image) {
603 char *message;
605 message = wstrappend(_("Could not load the selected file: "),
606 (char*)RMessageForError(RErrorCode));
608 WMRunAlertPanel(scr, panel->win, _("Error"), message,
609 _("OK"), NULL, NULL);
611 if (!panel->image)
612 WMSetButtonEnabled(panel->okB, False);
613 return;
616 WMSetButtonEnabled(panel->okB, True);
618 if (panel->image)
619 RDestroyImage(panel->image);
620 panel->image = image;
621 } else {
622 image = panel->image;
625 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
626 if (image) {
627 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
629 size = WMGetPixmapSize(pixmap);
630 WMSetLabelImage(panel->imageL, pixmap);
631 WMResizeWidget(panel->imageL, size.width, size.height);
633 WMReleasePixmap(pixmap);
635 } else {
636 updateTGradImage(panel);
641 static void
642 browseImageCallback(WMWidget *w, void *data)
644 TexturePanel *panel = (TexturePanel*)data;
645 WMOpenPanel *opanel;
646 WMScreen *scr = WMWidgetScreen(w);
647 static char *ipath = NULL;
649 opanel = WMGetOpenPanel(scr);
650 WMSetFilePanelCanChooseDirectories(opanel, False);
651 WMSetFilePanelCanChooseFiles(opanel, True);
653 if (!ipath)
654 ipath = wstrdup(wgethomedir());
656 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
657 "Open Image", NULL)) {
658 char *path, *fullpath;
659 char *tmp, *tmp2;
661 tmp = WMGetFilePanelFileName(opanel);
662 if (!tmp)
663 return;
664 fullpath = tmp;
666 free(ipath);
667 ipath = fullpath;
669 path = wstrdup(fullpath);
671 tmp2 = strrchr(fullpath, '/');
672 if (tmp2)
673 tmp2++;
675 tmp = wfindfileinarray(panel->pathList, tmp2);
677 if (tmp) {
678 if (strcmp(fullpath, tmp)==0) {
679 free(path);
680 path = tmp2;
682 free(tmp);
685 if (!RGetImageFileFormat(fullpath)) {
686 WMRunAlertPanel(scr, panel->win, _("Error"),
687 _("The selected file does not contain a supported image."),
688 _("OK"), NULL, NULL);
689 free(path);
690 } else {
691 updateImage(panel, fullpath);
692 free(panel->imageFile);
693 panel->imageFile = path;
695 WMSetTextFieldText(panel->imageT, path);
702 static void
703 buttonCallback(WMWidget *w, void *data)
705 TexturePanel *panel = (TexturePanel*)data;
707 if (w == panel->okB) {
708 (*panel->okAction)(panel->okData);
709 } else {
710 (*panel->cancelAction)(panel->cancelData);
716 static void
717 changeTypeCallback(WMWidget *w, void *data)
719 TexturePanel *panel = (TexturePanel*)data;
720 int newType;
721 int i;
723 newType = WMGetPopUpButtonSelectedItem(w);
724 if (newType == panel->currentType)
725 return;
727 if (panel->currentType >= 0) {
728 for (i = 0; i < MAX_SECTION_PARTS; i++) {
729 if (panel->sectionParts[panel->currentType][i] == NULL)
730 break;
731 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
735 for (i = 0; i < MAX_SECTION_PARTS; i++) {
736 if (panel->sectionParts[newType][i] == NULL)
737 break;
738 WMMapWidget(panel->sectionParts[newType][i]);
740 panel->currentType = newType;
742 switch (newType) {
743 case TYPE_SGRADIENT:
744 updateSGradButtons(panel);
745 WMSetButtonEnabled(panel->okB, True);
746 break;
747 case TYPE_GRADIENT:
748 updateGradButtons(panel);
749 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
750 break;
751 case TYPE_TGRADIENT:
752 case TYPE_PIXMAP:
753 updateImage(panel, NULL);
754 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
755 break;
756 default:
757 WMSetButtonEnabled(panel->okB, True);
758 break;
764 *--------------------------------------------------------------------------
765 * Public functions
766 *--------------------------------------------------------------------------
768 void
769 DestroyTexturePanel(TexturePanel *panel)
775 void
776 ShowTexturePanel(TexturePanel *panel)
778 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
779 Screen *scr = DefaultScreenOfDisplay(dpy);
781 WMSetWindowInitialPosition(panel->win,
782 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
783 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
784 WMMapWidget(panel->win);
788 void
789 HideTexturePanel(TexturePanel *panel)
791 WMUnmapWidget(panel->win);
795 void
796 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
798 panel->okAction = action;
799 panel->okData = clientData;
803 void
804 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
806 panel->cancelAction = action;
807 panel->cancelData = clientData;
811 void
812 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
814 WMScreen *scr = WMWidgetScreen(panel->win);
815 char *str, *type;
816 proplist_t p;
817 WMColor *color;
818 int i;
819 char buffer[64];
820 int gradient = 0;
822 WMSetTextFieldText(panel->nameT, name);
824 if (!texture)
825 return;
827 p = PLGetArrayElement(texture, 0);
828 if (!p) {
829 goto bad_texture;
831 type = PLGetString(p);
833 /*...............................................*/
834 if (strcasecmp(type, "solid")==0) {
836 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
838 p = PLGetArrayElement(texture, 1);
839 if (!p) {
840 str = "black";
841 } else {
842 str = PLGetString(p);
844 color = WMCreateNamedColor(scr, str, False);
846 WMSetColorWellColor(panel->defcW, color);
848 WMReleaseColor(color);
849 /*...............................................*/
850 } else if (strcasecmp(type, "hgradient")==0
851 || strcasecmp(type, "vgradient")==0
852 || strcasecmp(type, "dgradient")==0) {
854 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
856 p = PLGetArrayElement(texture, 1);
857 if (!p) {
858 str = "black";
859 } else {
860 str = PLGetString(p);
862 color = WMCreateNamedColor(scr, str, False);
864 WMSetColorWellColor(panel->tcol1W, color);
866 WMReleaseColor(color);
868 p = PLGetArrayElement(texture, 2);
869 if (!p) {
870 str = "black";
871 } else {
872 str = PLGetString(p);
874 color = WMCreateNamedColor(scr, str, False);
876 WMSetColorWellColor(panel->tcol2W, color);
878 WMReleaseColor(color);
880 gradient = type[0];
881 /*...............................................*/
882 } else if (strcasecmp(type, "thgradient")==0
883 || strcasecmp(type, "tvgradient")==0
884 || strcasecmp(type, "tdgradient")==0) {
885 int i;
887 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
889 gradient = type[1];
891 WMSetTextFieldText(panel->imageT,
892 PLGetString(PLGetArrayElement(texture, 1)));
893 if (panel->imageFile)
894 free(panel->imageFile);
895 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
898 i = 180;
899 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
900 WMSetSliderValue(panel->topaS, i);
902 p = PLGetArrayElement(texture, 3);
903 if (!p) {
904 str = "black";
905 } else {
906 str = PLGetString(p);
908 color = WMCreateNamedColor(scr, str, False);
910 WMSetColorWellColor(panel->tcol1W, color);
912 WMReleaseColor(color);
914 p = PLGetArrayElement(texture, 4);
915 if (!p) {
916 str = "black";
917 } else {
918 str = PLGetString(p);
920 color = WMCreateNamedColor(scr, str, False);
922 WMSetColorWellColor(panel->tcol2W, color);
924 WMReleaseColor(color);
926 WMSetTextFieldText(panel->imageT,
927 PLGetString(PLGetArrayElement(texture, 1)));
929 if (panel->imageFile)
930 free(panel->imageFile);
931 panel->imageFile = wfindfileinarray(panel->pathList,
932 PLGetString(PLGetArrayElement(texture, 1)));
934 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
935 updateTGradImage(panel);
937 updateSGradButtons(panel);
939 /*...............................................*/
940 } else if (strcasecmp(type, "mhgradient")==0
941 || strcasecmp(type, "mvgradient")==0
942 || strcasecmp(type, "mdgradient")==0) {
943 WMListItem *item;
945 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
946 item = WMGetListItem(panel->gcolL, i);
947 free(item->clientData);
949 WMClearList(panel->gcolL);
951 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
953 p = PLGetArrayElement(texture, 1);
954 if (!p) {
955 str = "black";
956 } else {
957 str = PLGetString(p);
959 color = WMCreateNamedColor(scr, str, False);
961 WMSetColorWellColor(panel->defcW, color);
963 WMReleaseColor(color);
965 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
966 RColor *rgb;
967 XColor xcolor;
969 p = PLGetArrayElement(texture, i);
970 if (!p) {
971 str = "black";
972 } else {
973 str = PLGetString(p);
976 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
977 str, &xcolor);
979 rgb = wmalloc(sizeof(RColor));
980 rgb->red = xcolor.red >> 8;
981 rgb->green = xcolor.green >> 8;
982 rgb->blue = xcolor.blue >> 8;
983 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
985 item = WMAddListItem(panel->gcolL, buffer);
986 item->clientData = rgb;
989 sliderChangeCallback(panel->ghueS, panel);
991 gradient = type[1];
992 /*...............................................*/
993 } else if (strcasecmp(type, "cpixmap")==0
994 || strcasecmp(type, "spixmap")==0
995 || strcasecmp(type, "mpixmap")==0
996 || strcasecmp(type, "tpixmap")==0) {
998 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1000 switch (toupper(type[0])) {
1001 case 'C':
1002 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1003 break;
1004 case 'S':
1005 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1006 break;
1007 case 'M':
1008 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1009 break;
1010 default:
1011 case 'T':
1012 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1013 break;
1016 WMSetTextFieldText(panel->imageT,
1017 PLGetString(PLGetArrayElement(texture, 1)));
1019 if (panel->imageFile)
1020 free(panel->imageFile);
1021 panel->imageFile = wfindfileinarray(panel->pathList,
1022 PLGetString(PLGetArrayElement(texture, 1)));
1024 color = WMCreateNamedColor(scr,
1025 PLGetString(PLGetArrayElement(texture, 2)), False);
1026 WMSetColorWellColor(panel->defcW, color);
1027 WMReleaseColor(color);
1029 updateImage(panel, panel->imageFile);
1032 changeTypeCallback(panel->typeP, panel);
1034 if (gradient > 0) {
1035 updateGradButtons(panel);
1037 switch (toupper(gradient)) {
1038 case 'H':
1039 WMPerformButtonClick(panel->dirhB);
1040 break;
1041 case 'V':
1042 WMPerformButtonClick(panel->dirvB);
1043 break;
1044 default:
1045 case 'D':
1046 WMPerformButtonClick(panel->dirdB);
1047 break;
1051 return;
1053 bad_texture:
1054 str = PLGetDescription(texture);
1055 wwarning("error creating texture %s", str);
1056 free(str);
1062 char*
1063 GetTexturePanelTextureName(TexturePanel *panel)
1065 return WMGetTextFieldText(panel->nameT);
1071 proplist_t
1072 GetTexturePanelTexture(TexturePanel *panel)
1074 proplist_t prop = NULL;
1075 WMColor *color;
1076 char *str, *str2;
1077 char buff[32];
1078 int i;
1081 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1083 case TYPE_SOLID:
1084 color = WMGetColorWellColor(panel->defcW);
1085 str = WMGetColorRGBDescription(color);
1086 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1087 PLMakeString(str), NULL);
1088 free(str);
1090 break;
1092 case TYPE_PIXMAP:
1093 color = WMGetColorWellColor(panel->defcW);
1094 str = WMGetColorRGBDescription(color);
1096 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1097 case PTYPE_SCALE:
1098 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1099 PLMakeString(panel->imageFile),
1100 PLMakeString(str), NULL);
1101 break;
1102 case PTYPE_MAXIMIZE:
1103 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1104 PLMakeString(panel->imageFile),
1105 PLMakeString(str), NULL);
1106 break;
1107 case PTYPE_CENTER:
1108 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1109 PLMakeString(panel->imageFile),
1110 PLMakeString(str), NULL);
1111 break;
1112 case PTYPE_TILE:
1113 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1114 PLMakeString(panel->imageFile),
1115 PLMakeString(str), NULL);
1116 break;
1118 free(str);
1119 break;
1121 case TYPE_TGRADIENT:
1122 color = WMGetColorWellColor(panel->tcol1W);
1123 str = WMGetColorRGBDescription(color);
1125 color = WMGetColorWellColor(panel->tcol2W);
1126 str2 = WMGetColorRGBDescription(color);
1128 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1130 if (WMGetButtonSelected(panel->dirdB)) {
1131 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1132 PLMakeString(panel->imageFile),
1133 PLMakeString(buff),
1134 PLMakeString(str),
1135 PLMakeString(str2), NULL);
1136 } else if (WMGetButtonSelected(panel->dirvB)) {
1137 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1138 PLMakeString(panel->imageFile),
1139 PLMakeString(buff),
1140 PLMakeString(str),
1141 PLMakeString(str2), NULL);
1142 } else {
1143 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1144 PLMakeString(panel->imageFile),
1145 PLMakeString(buff),
1146 PLMakeString(str),
1147 PLMakeString(str2), NULL);
1149 free(str);
1150 free(str2);
1151 break;
1154 case TYPE_SGRADIENT:
1155 color = WMGetColorWellColor(panel->tcol1W);
1156 str = WMGetColorRGBDescription(color);
1158 color = WMGetColorWellColor(panel->tcol2W);
1159 str2 = WMGetColorRGBDescription(color);
1161 if (WMGetButtonSelected(panel->dirdB)) {
1162 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1163 PLMakeString(str),
1164 PLMakeString(str2), NULL);
1165 } else if (WMGetButtonSelected(panel->dirvB)) {
1166 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1167 PLMakeString(str),
1168 PLMakeString(str2), NULL);
1169 } else {
1170 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1171 PLMakeString(str),
1172 PLMakeString(str2), NULL);
1174 free(str);
1175 free(str2);
1176 break;
1178 case TYPE_GRADIENT:
1179 color = WMGetColorWellColor(panel->defcW);
1180 str = WMGetColorRGBDescription(color);
1182 if (WMGetButtonSelected(panel->dirdB)) {
1183 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1184 PLMakeString(str), NULL);
1185 } else if (WMGetButtonSelected(panel->dirvB)) {
1186 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1187 PLMakeString(str), NULL);
1188 } else {
1189 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1190 PLMakeString(str), NULL);
1192 free(str);
1194 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1195 RColor *rgb;
1196 WMListItem *item;
1198 item = WMGetListItem(panel->gcolL, i);
1200 rgb = (RColor*)item->clientData;
1202 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1204 PLAppendArrayElement(prop, PLMakeString(buff));
1206 break;
1210 return prop;
1215 void
1216 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1218 panel->pathList = array;
1223 TexturePanel*
1224 CreateTexturePanel(WMWindow *keyWindow)
1225 /*CreateTexturePanel(WMScreen *scr)*/
1227 TexturePanel *panel;
1228 WMScreen *scr = WMWidgetScreen(keyWindow);
1230 panel = wmalloc(sizeof(TexturePanel));
1231 memset(panel, 0, sizeof(TexturePanel));
1233 panel->listFont = WMSystemFontOfSize(scr, 12);
1236 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1237 WMTitledWindowMask
1238 |WMClosableWindowMask);
1240 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1241 WMTitledWindowMask
1242 |WMClosableWindowMask);
1245 WMResizeWidget(panel->win, 325, 423);
1246 WMSetWindowTitle(panel->win, _("Texture Panel"));
1247 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1250 /* texture name */
1251 panel->nameF = WMCreateFrame(panel->win);
1252 WMResizeWidget(panel->nameF, 185, 50);
1253 WMMoveWidget(panel->nameF, 15, 10);
1254 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1256 panel->nameT = WMCreateTextField(panel->nameF);
1257 WMResizeWidget(panel->nameT, 160, 20);
1258 WMMoveWidget(panel->nameT, 12, 18);
1260 WMMapSubwidgets(panel->nameF);
1262 /* texture types */
1263 panel->typeP = WMCreatePopUpButton(panel->win);
1264 WMResizeWidget(panel->typeP, 185, 20);
1265 WMMoveWidget(panel->typeP, 15, 65);
1266 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1267 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1268 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1269 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1270 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1271 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1272 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1274 /* color */
1275 panel->defcF = WMCreateFrame(panel->win);
1276 WMResizeWidget(panel->defcF, 100, 75);
1277 WMMoveWidget(panel->defcF, 210, 10);
1278 WMSetFrameTitle(panel->defcF, _("Default Color"));
1280 panel->defcW = WMCreateColorWell(panel->defcF);
1281 WMResizeWidget(panel->defcW, 60, 45);
1282 WMMoveWidget(panel->defcW, 20, 20);
1284 WMMapSubwidgets(panel->defcF);
1286 /****** Gradient ******/
1287 panel->gcolF = WMCreateFrame(panel->win);
1288 WMResizeWidget(panel->gcolF, 295, 205);
1289 WMMoveWidget(panel->gcolF, 15, 95);
1290 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1292 panel->gcolL = WMCreateList(panel->gcolF);
1293 WMResizeWidget(panel->gcolL, 130, 140);
1294 WMMoveWidget(panel->gcolL, 10, 25);
1295 WMHangData(panel->gcolL, panel);
1296 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1297 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1299 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1300 WMResizeWidget(panel->gcolaB, 64, 24);
1301 WMMoveWidget(panel->gcolaB, 10, 170);
1302 WMSetButtonText(panel->gcolaB, _("Add"));
1303 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1305 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1306 WMResizeWidget(panel->gcoldB, 64, 24);
1307 WMMoveWidget(panel->gcoldB, 75, 170);
1308 WMSetButtonText(panel->gcoldB, _("Delete"));
1309 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1311 #if 0
1312 panel->gbriS = WMCreateSlider(panel->gcolF);
1313 WMResizeWidget(panel->gbriS, 130, 16);
1314 WMMoveWidget(panel->gbriS, 150, 25);
1315 WMSetSliderKnobThickness(panel->gbriS, 8);
1316 WMSetSliderMaxValue(panel->gbriS, 100);
1317 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1319 WMPixmap *pixmap;
1320 WMColor *color;
1322 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1323 color = WMDarkGrayColor(scr);
1324 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1325 WMColorGC(color), 0, 0, 130, 16);
1326 WMReleaseColor(color);
1327 color = WMWhiteColor(color);
1328 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1329 panel->listFont, 2,
1330 (16 - WMFontHeight(panel->listFont))/2 - 1,
1331 "Brightness", 10);
1332 WMSetSliderImage(panel->gbriS, pixmap);
1333 WMReleasePixmap(pixmap);
1336 panel->gconS = WMCreateSlider(panel->gcolF);
1337 WMResizeWidget(panel->gconS, 130, 16);
1338 WMMoveWidget(panel->gconS, 150, 50);
1339 WMSetSliderKnobThickness(panel->gconS, 8);
1340 WMSetSliderMaxValue(panel->gconS, 100);
1341 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1343 WMPixmap *pixmap;
1344 WMColor *color;
1346 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1347 color = WMDarkGrayColor(scr);
1348 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1349 WMColorGC(color), 0, 0, 130, 16);
1350 WMReleaseColor(color);
1351 color = WMWhiteColor(scr);
1352 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1353 panel->listFont, 2,
1354 (16 - WMFontHeight(panel->listFont))/2 - 1,
1355 "Contrast", 8);
1356 WMSetSliderImage(panel->gconS, pixmap);
1357 WMReleasePixmap(pixmap);
1359 #endif
1360 panel->ghueS = WMCreateSlider(panel->gcolF);
1361 WMResizeWidget(panel->ghueS, 130, 16);
1362 WMMoveWidget(panel->ghueS, 150, 100);
1363 WMSetSliderKnobThickness(panel->ghueS, 8);
1364 WMSetSliderMaxValue(panel->ghueS, 359);
1365 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1367 panel->gsatS = WMCreateSlider(panel->gcolF);
1368 WMResizeWidget(panel->gsatS, 130, 16);
1369 WMMoveWidget(panel->gsatS, 150, 125);
1370 WMSetSliderKnobThickness(panel->gsatS, 8);
1371 WMSetSliderMaxValue(panel->gsatS, 255);
1372 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1374 panel->gvalS = WMCreateSlider(panel->gcolF);
1375 WMResizeWidget(panel->gvalS, 130, 16);
1376 WMMoveWidget(panel->gvalS, 150, 150);
1377 WMSetSliderKnobThickness(panel->gvalS, 8);
1378 WMSetSliderMaxValue(panel->gvalS, 255);
1379 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1382 WMMapSubwidgets(panel->gcolF);
1384 /** Direction **/
1385 panel->dirF = WMCreateFrame(panel->win);
1386 WMSetFrameTitle(panel->dirF, _("Direction"));
1387 WMResizeWidget(panel->dirF, 295, 75);
1388 WMMoveWidget(panel->dirF, 15, 305);
1390 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1391 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1392 WMResizeWidget(panel->dirvB, 90, 40);
1393 WMMoveWidget(panel->dirvB, 10, 20);
1395 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1396 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1397 WMResizeWidget(panel->dirhB, 90, 40);
1398 WMMoveWidget(panel->dirhB, 102, 20);
1400 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1401 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1402 WMResizeWidget(panel->dirdB, 90, 40);
1403 WMMoveWidget(panel->dirdB, 194, 20);
1405 WMGroupButtons(panel->dirvB, panel->dirhB);
1406 WMGroupButtons(panel->dirvB, panel->dirdB);
1408 WMMapSubwidgets(panel->dirF);
1410 /****************** Textured Gradient ******************/
1411 panel->tcolF = WMCreateFrame(panel->win);
1412 WMResizeWidget(panel->tcolF, 100, 135);
1413 WMMoveWidget(panel->tcolF, 210, 10);
1414 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1416 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1417 WMResizeWidget(panel->tcol1W, 60, 45);
1418 WMMoveWidget(panel->tcol1W, 20, 25);
1419 WMAddNotificationObserver(colorWellObserver, panel,
1420 WMColorWellDidChangeNotification, panel->tcol1W);
1422 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1423 WMResizeWidget(panel->tcol2W, 60, 45);
1424 WMMoveWidget(panel->tcol2W, 20, 75);
1425 WMAddNotificationObserver(colorWellObserver, panel,
1426 WMColorWellDidChangeNotification, panel->tcol2W);
1428 /** Opacity */
1429 panel->topaF = WMCreateFrame(panel->win);
1430 WMResizeWidget(panel->topaF, 185, 50);
1431 WMMoveWidget(panel->topaF, 15, 95);
1432 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1434 panel->topaS = WMCreateSlider(panel->topaF);
1435 WMResizeWidget(panel->topaS, 155, 18);
1436 WMMoveWidget(panel->topaS, 15, 20);
1437 WMSetSliderMaxValue(panel->topaS, 255);
1438 WMSetSliderValue(panel->topaS, 200);
1439 WMSetSliderContinuous(panel->topaS, False);
1440 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1442 WMMapSubwidgets(panel->topaF);
1445 WMPixmap *pixmap;
1446 Pixmap p;
1447 WMColor *color;
1449 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1450 p = WMGetPixmapXID(pixmap);
1452 color = WMDarkGrayColor(scr);
1453 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1454 0, 0, 155, 18);
1455 WMReleaseColor(color);
1457 color = WMWhiteColor(scr);
1458 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1459 2, 1, "0%", 2);
1460 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1461 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1462 "100%", 4);
1463 WMReleaseColor(color);
1465 WMSetSliderImage(panel->topaS, pixmap);
1466 WMReleasePixmap(pixmap);
1469 WMMapSubwidgets(panel->tcolF);
1471 /****************** Image ******************/
1472 panel->imageF = WMCreateFrame(panel->win);
1473 WMResizeWidget(panel->imageF, 295, 150);
1474 WMMoveWidget(panel->imageF, 15, 150);
1475 WMSetFrameTitle(panel->imageF, _("Image"));
1477 panel->imageL = WMCreateLabel(panel->imageF);
1478 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1480 panel->imageT = WMCreateTextField(panel->imageF);
1481 WMResizeWidget(panel->imageT, 90, 20);
1482 WMMoveWidget(panel->imageT, 190, 25);
1484 panel->imageV = WMCreateScrollView(panel->imageF);
1485 WMResizeWidget(panel->imageV, 165, 115);
1486 WMMoveWidget(panel->imageV, 15, 20);
1487 WMSetScrollViewRelief(panel->imageV, WRSunken);
1488 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1489 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1490 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1492 panel->browB = WMCreateCommandButton(panel->imageF);
1493 WMResizeWidget(panel->browB, 90, 24);
1494 WMMoveWidget(panel->browB, 190, 50);
1495 WMSetButtonText(panel->browB, _("Browse..."));
1496 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1498 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1499 WMResizeWidget(panel->dispB, 90, 24);
1500 WMMoveWidget(panel->dispB, 190, 80);
1501 WMSetButtonText(panel->dispB, _("Show"));
1504 panel->arrP = WMCreatePopUpButton(panel->imageF);
1505 WMResizeWidget(panel->arrP, 90, 20);
1506 WMMoveWidget(panel->arrP, 190, 120);
1507 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1508 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1509 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1510 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1511 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1513 WMMapSubwidgets(panel->imageF);
1515 /****/
1517 panel->okB = WMCreateCommandButton(panel->win);
1518 WMResizeWidget(panel->okB, 84, 24);
1519 WMMoveWidget(panel->okB, 225, 390);
1520 WMSetButtonText(panel->okB, _("OK"));
1521 WMSetButtonAction(panel->okB, buttonCallback, panel);
1523 panel->cancelB = WMCreateCommandButton(panel->win);
1524 WMResizeWidget(panel->cancelB, 84, 24);
1525 WMMoveWidget(panel->cancelB, 130, 390);
1526 WMSetButtonText(panel->cancelB, _("Cancel"));
1527 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1529 WMMapWidget(panel->nameF);
1530 WMMapWidget(panel->typeP);
1531 WMMapWidget(panel->okB);
1532 WMMapWidget(panel->cancelB);
1534 WMUnmapWidget(panel->arrP);
1536 WMRealizeWidget(panel->win);
1538 panel->currentType = -1;
1540 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1542 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1543 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1544 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1546 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1547 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1549 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1550 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1551 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1552 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1553 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1555 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1556 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1557 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1560 /* setup for first time */
1562 changeTypeCallback(panel->typeP, panel);
1564 sliderChangeCallback(panel->ghueS, panel);
1565 sliderChangeCallback(panel->gsatS, panel);
1567 return panel;
1573 *--------------------------------------------------------------------------
1574 * Test stuff
1575 *--------------------------------------------------------------------------
1578 #if 0
1580 char *ProgName = "test";
1582 void
1583 testOKButton(WMWidget *self, void *data)
1585 char *test;
1586 Display *dpy;
1587 Window win;
1588 Pixmap pix;
1589 RImage *image;
1591 TexturePanel *panel = (TexturePanel*)data;
1592 /* test = GetTexturePanelTextureString(panel); */
1594 wwarning(test);
1596 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1597 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1598 0, 0, 0);
1599 XMapRaised(dpy, win);
1600 XFlush(dpy);
1602 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1604 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1606 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1607 0, 0);
1609 free (test);
1613 void testCancelButton(WMWidget *self, void *data){
1614 wwarning("Exiting test....");
1615 exit(0);
1618 void wAbort()
1620 exit(1);
1623 int main(int argc, char **argv)
1625 TexturePanel *panel;
1627 Display *dpy = XOpenDisplay("");
1628 WMScreen *scr;
1630 /* char *test; */
1632 WMInitializeApplication("Test", &argc, argv);
1634 if (!dpy) {
1635 wfatal("could not open display");
1636 exit(1);
1639 scr = WMCreateSimpleApplicationScreen(dpy);
1641 panel = CreateTexturePanel(scr);
1643 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1644 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1646 SetTexturePanelTexture(panel, "pinky",
1647 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1649 ShowTexturePanel(panel);
1651 WMScreenMainLoop(scr);
1652 return 0;
1654 #endif