Check for argc==0 when calling wtokensplit()
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob058db9aa6c76fdd5d8f5055f2665536c3acdd784
1 /* TexturePanel.c- texture editting panel
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * Copyright (c) 1998 James Thompson
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/WINGs.h>
36 #include "WPrefs.h"
38 #include "TexturePanel.h"
40 #define MAX_SECTION_PARTS 5
42 typedef struct _TexturePanel {
43 WMWindow *win;
45 /* texture name */
46 WMFrame *nameF;
47 WMTextField *nameT;
49 /* texture type */
50 WMPopUpButton *typeP;
52 /* default color */
53 WMFrame *defcF;
54 WMColorWell *defcW;
56 WMFont *listFont;
58 /*-- Gradient --*/
60 Pixmap gimage;
62 /* colors */
63 WMFrame *gcolF;
64 WMList *gcolL;
65 WMButton *gcolaB;
66 WMButton *gcoldB;
67 WMSlider *ghueS;
68 WMSlider *gsatS;
69 WMSlider *gvalS;
71 WMSlider *gbriS;
72 WMSlider *gconS;
74 /* direction (common) */
75 WMFrame *dirF;
76 WMButton *dirhB;
77 WMButton *dirvB;
78 WMButton *dirdB;
80 /*-- Simple Gradient --*/
83 /*-- Textured Gradient --*/
85 WMFrame *tcolF;
86 WMColorWell *tcol1W;
87 WMColorWell *tcol2W;
89 WMFrame *topaF;
90 WMSlider *topaS;
92 /*-- Image --*/
93 WMFrame *imageF;
94 WMScrollView *imageV;
95 WMTextField *imageT;
96 WMLabel *imageL;
97 WMButton *browB;
98 WMButton *dispB;
99 WMPopUpButton *arrP;
101 RImage *image;
102 char *imageFile;
104 /*****/
106 WMButton *okB;
107 WMButton *cancelB;
110 WMCallback *okAction;
111 void *okData;
113 WMCallback *cancelAction;
114 void *cancelData;
116 /****/
117 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
119 int currentType;
122 WMPropList *pathList;
124 } _TexturePanel;
128 #define TYPE_SOLID 0
129 #define TYPE_GRADIENT 1
130 #define TYPE_SGRADIENT 2
131 #define TYPE_TGRADIENT 3
132 #define TYPE_PIXMAP 4
135 #define PTYPE_TILE 0
136 #define PTYPE_SCALE 1
137 #define PTYPE_CENTER 2
138 #define PTYPE_MAXIMIZE 3
143 *--------------------------------------------------------------------------
144 * Private Functions
145 *--------------------------------------------------------------------------
148 /************/
150 static void
151 updateGradButtons(TexturePanel *panel)
153 RImage *image;
154 WMPixmap *pixmap;
155 int colorn;
156 RColor **colors;
158 colorn = WMGetListNumberOfRows(panel->gcolL);
159 if (colorn < 1) {
160 pixmap = NULL;
161 } else {
162 int i;
163 WMListItem *item;
165 colors = wmalloc(sizeof(RColor*)*(colorn+1));
167 for (i = 0; i < colorn; i++) {
168 item = WMGetListItem(panel->gcolL, i);
169 colors[i] = (RColor*)item->clientData;
171 colors[i] = NULL;
173 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
174 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
175 image, 128);
176 RReleaseImage(image);
177 WMSetButtonImage(panel->dirhB, pixmap);
178 WMReleasePixmap(pixmap);
180 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
181 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
182 image, 128);
183 RReleaseImage(image);
184 WMSetButtonImage(panel->dirvB, pixmap);
185 WMReleasePixmap(pixmap);
187 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
188 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
189 image, 128);
190 RReleaseImage(image);
191 WMSetButtonImage(panel->dirdB, pixmap);
192 WMReleasePixmap(pixmap);
194 wfree(colors);
200 static void
201 updateTGradImage(TexturePanel *panel)
203 RImage *image, *gradient;
204 WMPixmap *pixmap;
205 RColor from;
206 RColor to;
207 WMColor *color;
209 if (!panel->image)
210 return;
212 color = WMGetColorWellColor(panel->tcol1W);
213 from.red = WMRedComponentOfColor(color)>>8;
214 from.green = WMGreenComponentOfColor(color)>>8;
215 from.blue = WMBlueComponentOfColor(color)>>8;
217 color = WMGetColorWellColor(panel->tcol2W);
218 to.red = WMRedComponentOfColor(color)>>8;
219 to.green = WMGreenComponentOfColor(color)>>8;
220 to.blue = WMBlueComponentOfColor(color)>>8;
222 if (panel->image->width < 141 || panel->image->height < 91) {
223 image = RMakeTiledImage(panel->image, 141, 91);
224 } else {
225 image = RCloneImage(panel->image);
228 if (WMGetButtonSelected(panel->dirhB)) {
229 gradient = RRenderGradient(image->width, image->height, &from, &to,
230 RHorizontalGradient);
231 } else if (WMGetButtonSelected(panel->dirvB)) {
232 gradient = RRenderGradient(image->width, image->height, &from, &to,
233 RVerticalGradient);
234 } else {
235 gradient = RRenderGradient(image->width, image->height, &from, &to,
236 RDiagonalGradient);
239 RCombineImagesWithOpaqueness(image, gradient,
240 WMGetSliderValue(panel->topaS));
241 RReleaseImage(gradient);
242 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
243 image, 128);
245 WMSetLabelImage(panel->imageL, pixmap);
246 WMReleasePixmap(pixmap);
247 WMResizeWidget(panel->imageL, image->width, image->height);
248 RReleaseImage(image);
252 static void
253 updateSGradButtons(TexturePanel *panel)
255 RImage *image;
256 WMPixmap *pixmap;
257 RColor from;
258 RColor to;
259 WMColor *color;
261 color = WMGetColorWellColor(panel->tcol1W);
262 from.red = WMRedComponentOfColor(color)>>8;
263 from.green = WMGreenComponentOfColor(color)>>8;
264 from.blue = WMBlueComponentOfColor(color)>>8;
266 color = WMGetColorWellColor(panel->tcol2W);
267 to.red = WMRedComponentOfColor(color)>>8;
268 to.green = WMGreenComponentOfColor(color)>>8;
269 to.blue = WMBlueComponentOfColor(color)>>8;
271 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
272 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
273 image, 128);
274 RReleaseImage(image);
275 WMSetButtonImage(panel->dirhB, pixmap);
276 WMReleasePixmap(pixmap);
278 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
279 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
280 image, 128);
281 RReleaseImage(image);
282 WMSetButtonImage(panel->dirvB, pixmap);
283 WMReleasePixmap(pixmap);
285 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
286 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
287 image, 128);
288 RReleaseImage(image);
289 WMSetButtonImage(panel->dirdB, pixmap);
290 WMReleasePixmap(pixmap);
294 /*********** Gradient ************/
296 static void
297 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
299 RImage *image;
300 WMPixmap *pixmap;
301 WMScreen *scr = WMWidgetScreen(sPtr);
302 RColor from, to;
303 RHSVColor tmp;
304 char *buffer;
306 tmp = *hsv;
307 if (saturation) {
308 tmp.saturation = 0;
309 RHSVtoRGB(&tmp, &from);
310 tmp.saturation = 255;
311 RHSVtoRGB(&tmp, &to);
312 } else {
313 tmp.value = 0;
314 RHSVtoRGB(&tmp, &from);
315 tmp.value = 255;
316 RHSVtoRGB(&tmp, &to);
318 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
319 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
320 RReleaseImage(image);
322 if (saturation)
323 buffer = wstrdup(_("Saturation"));
324 else
325 buffer = wstrdup(_("Brightness"));
327 if (hsv->value < 128 || !saturation) {
328 WMColor *col = WMWhiteColor(scr);
330 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
331 (16 - WMFontHeight(font))/2 - 1, buffer, strlen(buffer));
332 WMReleaseColor(col);
333 } else {
334 WMColor *col = WMBlackColor(scr);
336 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
337 (16 - WMFontHeight(font))/2 - 1, buffer, strlen(buffer));
338 WMReleaseColor(col);
340 wfree(buffer);
341 WMSetSliderImage(sPtr, pixmap);
342 WMReleasePixmap(pixmap);
346 static void
347 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
349 RColor *colors[8];
350 RImage *image;
351 WMPixmap *pixmap;
352 WMScreen *scr = WMWidgetScreen(sPtr);
353 RHSVColor thsv;
354 int i;
356 thsv = *hsv;
357 for (i = 0; i <= 6; i++) {
358 thsv.hue = (360*i)/6;
359 colors[i] = wmalloc(sizeof(RColor));
360 RHSVtoRGB(&thsv, colors[i]);
362 colors[i] = NULL;
364 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
365 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
366 RReleaseImage(image);
368 if (hsv->value < 128) {
369 WMColor *col = WMWhiteColor(scr);
371 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
372 (16 - WMFontHeight(font))/2 - 1,
373 _("Hue"), strlen(_("Hue")));
374 WMReleaseColor(col);
375 } else {
376 WMColor *col = WMBlackColor(scr);
378 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
379 (16 - WMFontHeight(font))/2 - 1,
380 _("Hue"), strlen(_("Hue")));
381 WMReleaseColor(col);
383 WMSetSliderImage(sPtr, pixmap);
384 WMReleasePixmap(pixmap);
386 for (i = 0; i <= 6; i++)
387 wfree(colors[i]);
392 static void
393 sliderChangeCallback(WMWidget *w, void *data)
395 TexturePanel *panel = (TexturePanel*)data;
396 RHSVColor hsv;
397 int row, rows;
398 WMListItem *item;
399 RColor **colors;
400 int i;
401 RImage *image;
402 WMScreen *scr = WMWidgetScreen(w);
404 hsv.hue = WMGetSliderValue(panel->ghueS);
405 hsv.saturation = WMGetSliderValue(panel->gsatS);
406 hsv.value = WMGetSliderValue(panel->gvalS);
408 row = WMGetListSelectedItemRow(panel->gcolL);
409 if (row >= 0) {
410 RColor *rgb;
412 item = WMGetListItem(panel->gcolL, row);
414 rgb = (RColor*)item->clientData;
416 RHSVtoRGB(&hsv, rgb);
418 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
421 if (w == panel->ghueS) {
422 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
423 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
424 } else if (w == panel->gsatS) {
425 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
426 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
427 } else {
428 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
429 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
432 rows = WMGetListNumberOfRows(panel->gcolL);
433 if (rows == 0)
434 return;
436 colors = wmalloc(sizeof(RColor*)*(rows+1));
438 for (i = 0; i < rows; i++) {
439 item = WMGetListItem(panel->gcolL, i);
441 colors[i] = (RColor*)item->clientData;
443 colors[i] = NULL;
445 if (panel->gimage != None) {
446 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
449 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
450 colors, RVerticalGradient);
451 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
452 RReleaseImage(image);
454 wfree(colors);
456 WMRedisplayWidget(panel->gcolL);
458 updateGradButtons(panel);
462 static void
463 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
464 WMRect *rect)
466 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
467 WMScreen *scr = WMWidgetScreen(lPtr);
468 WMColor *white = WMWhiteColor(scr);
469 WMColor *black = WMBlackColor(scr);
470 WMColor *gray = WMGrayColor(scr);
471 WMListItem *item;
472 int width, height, x, y;
473 Display *dpy;
475 dpy = WMScreenDisplay(scr);
477 width = rect->size.width;
478 height = rect->size.height;
479 x = rect->pos.x;
480 y = rect->pos.y;
482 if (state & WLDSSelected)
483 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
484 else
485 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
487 item = WMGetListItem(lPtr, index);
489 if (panel->gimage) {
490 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
491 0, height*index, 30, height, x + 5, y);
493 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1,
494 text, strlen(text));
496 WMReleaseColor(white);
497 WMReleaseColor(black);
498 WMReleaseColor(gray);
503 static void
504 gradAddCallback(WMWidget *w, void *data)
506 TexturePanel *panel = (TexturePanel*)data;
507 WMListItem *item;
508 int row;
509 RColor *rgb;
511 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
512 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
513 rgb = wmalloc(sizeof(RColor));
514 memset(rgb, 0, sizeof(RColor));
515 item->clientData = rgb;
517 WMSelectListItem(panel->gcolL, row);
519 updateGradButtons(panel);
521 sliderChangeCallback(panel->ghueS, panel);
523 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
528 static void
529 gradClickCallback(WMWidget *w, void *data)
531 TexturePanel *panel = (TexturePanel*)data;
532 WMListItem *item;
533 int row;
534 RHSVColor hsv;
536 row = WMGetListSelectedItemRow(w);
537 if (row < 0)
538 return;
540 item = WMGetListItem(panel->gcolL, row);
541 RRGBtoHSV((RColor*)item->clientData, &hsv);
543 WMSetSliderValue(panel->ghueS, hsv.hue);
544 WMSetSliderValue(panel->gsatS, hsv.saturation);
545 WMSetSliderValue(panel->gvalS, hsv.value);
547 sliderChangeCallback(panel->ghueS, panel);
548 sliderChangeCallback(panel->gsatS, panel);
552 static void
553 gradDeleteCallback(WMWidget *w, void *data)
555 TexturePanel *panel = (TexturePanel*)data;
556 WMListItem *item;
557 int row;
559 row = WMGetListSelectedItemRow(panel->gcolL);
560 if (row < 0)
561 return;
563 item = WMGetListItem(panel->gcolL, row);
564 wfree(item->clientData);
566 WMRemoveListItem(panel->gcolL, row);
568 WMSelectListItem(panel->gcolL, row - 1);
570 updateGradButtons(panel);
572 gradClickCallback(panel->gcolL, panel);
574 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
578 /*************** Simple Gradient ***************/
580 static void
581 colorWellObserver(void *self, WMNotification *n)
583 updateSGradButtons(self);
589 static void
590 opaqChangeCallback(WMWidget *w, void *data)
592 TexturePanel *panel = (TexturePanel*)data;
594 updateTGradImage(panel);
597 /****************** Image ******************/
599 static void
600 updateImage(TexturePanel *panel, char *path)
602 WMScreen *scr = WMWidgetScreen(panel->win);
603 RImage *image;
604 WMPixmap *pixmap;
605 WMSize size;
607 if (path) {
608 image = RLoadImage(WMScreenRContext(scr), path, 0);
609 if (!image) {
610 char *message;
612 message = wstrconcat(_("Could not load the selected file: "),
613 (char*)RMessageForError(RErrorCode));
615 WMRunAlertPanel(scr, panel->win, _("Error"), message,
616 _("OK"), NULL, NULL);
618 if (!panel->image)
619 WMSetButtonEnabled(panel->okB, False);
621 wfree(message);
622 return;
625 WMSetButtonEnabled(panel->okB, True);
627 if (panel->image)
628 RReleaseImage(panel->image);
629 panel->image = image;
630 } else {
631 image = panel->image;
634 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
635 if (image) {
636 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
638 size = WMGetPixmapSize(pixmap);
639 WMSetLabelImage(panel->imageL, pixmap);
640 WMResizeWidget(panel->imageL, size.width, size.height);
642 WMReleasePixmap(pixmap);
644 } else {
645 updateTGradImage(panel);
650 static void
651 browseImageCallback(WMWidget *w, void *data)
653 TexturePanel *panel = (TexturePanel*)data;
654 WMOpenPanel *opanel;
655 WMScreen *scr = WMWidgetScreen(w);
656 static char *ipath = NULL;
658 opanel = WMGetOpenPanel(scr);
659 WMSetFilePanelCanChooseDirectories(opanel, False);
660 WMSetFilePanelCanChooseFiles(opanel, True);
662 if (!ipath)
663 ipath = wstrdup(wgethomedir());
665 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
666 _("Open Image"), NULL)) {
667 char *path, *fullpath;
668 char *tmp, *tmp2;
670 tmp = WMGetFilePanelFileName(opanel);
671 if (!tmp)
672 return;
673 fullpath = tmp;
675 wfree(ipath);
676 ipath = fullpath;
678 path = wstrdup(fullpath);
680 tmp2 = strrchr(fullpath, '/');
681 if (tmp2)
682 tmp2++;
684 tmp = wfindfileinarray(panel->pathList, tmp2);
686 if (tmp) {
687 if (strcmp(fullpath, tmp)==0) {
688 wfree(path);
689 path = tmp2;
691 wfree(tmp);
694 if (!RGetImageFileFormat(fullpath)) {
695 WMRunAlertPanel(scr, panel->win, _("Error"),
696 _("The selected file does not contain a supported image."),
697 _("OK"), NULL, NULL);
698 wfree(path);
699 } else {
700 updateImage(panel, fullpath);
701 wfree(panel->imageFile);
702 panel->imageFile = path;
704 WMSetTextFieldText(panel->imageT, path);
711 static void
712 buttonCallback(WMWidget *w, void *data)
714 TexturePanel *panel = (TexturePanel*)data;
716 if (w == panel->okB) {
717 (*panel->okAction)(panel->okData);
718 } else {
719 (*panel->cancelAction)(panel->cancelData);
725 static void
726 changeTypeCallback(WMWidget *w, void *data)
728 TexturePanel *panel = (TexturePanel*)data;
729 int newType;
730 int i;
732 newType = WMGetPopUpButtonSelectedItem(w);
733 if (newType == panel->currentType)
734 return;
736 if (panel->currentType >= 0) {
737 for (i = 0; i < MAX_SECTION_PARTS; i++) {
738 if (panel->sectionParts[panel->currentType][i] == NULL)
739 break;
740 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
744 for (i = 0; i < MAX_SECTION_PARTS; i++) {
745 if (panel->sectionParts[newType][i] == NULL)
746 break;
747 WMMapWidget(panel->sectionParts[newType][i]);
749 panel->currentType = newType;
751 switch (newType) {
752 case TYPE_SGRADIENT:
753 updateSGradButtons(panel);
754 WMSetButtonEnabled(panel->okB, True);
755 break;
756 case TYPE_GRADIENT:
757 updateGradButtons(panel);
758 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
759 break;
760 case TYPE_TGRADIENT:
761 case TYPE_PIXMAP:
762 updateImage(panel, NULL);
763 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
764 break;
765 default:
766 WMSetButtonEnabled(panel->okB, True);
767 break;
773 *--------------------------------------------------------------------------
774 * Public functions
775 *--------------------------------------------------------------------------
777 void
778 DestroyTexturePanel(TexturePanel *panel)
784 void
785 ShowTexturePanel(TexturePanel *panel)
787 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
788 Screen *scr = DefaultScreenOfDisplay(dpy);
790 WMSetWindowInitialPosition(panel->win,
791 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
792 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
793 WMMapWidget(panel->win);
797 void
798 HideTexturePanel(TexturePanel *panel)
800 WMUnmapWidget(panel->win);
804 void
805 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
807 panel->okAction = action;
808 panel->okData = clientData;
812 void
813 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
815 panel->cancelAction = action;
816 panel->cancelData = clientData;
820 void
821 SetTexturePanelTexture(TexturePanel *panel, char *name, WMPropList *texture)
823 WMScreen *scr = WMWidgetScreen(panel->win);
824 char *str, *type;
825 WMPropList *p;
826 WMColor *color;
827 int i;
828 char buffer[64];
829 int gradient = 0;
831 WMSetTextFieldText(panel->nameT, name);
833 if (!texture)
834 return;
836 p = WMGetFromPLArray(texture, 0);
837 if (!p) {
838 goto bad_texture;
840 type = WMGetFromPLString(p);
842 /*...............................................*/
843 if (strcasecmp(type, "solid")==0) {
845 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
847 p = WMGetFromPLArray(texture, 1);
848 if (!p) {
849 str = "black";
850 } else {
851 str = WMGetFromPLString(p);
853 color = WMCreateNamedColor(scr, str, False);
855 WMSetColorWellColor(panel->defcW, color);
857 WMReleaseColor(color);
858 /*...............................................*/
859 } else if (strcasecmp(type, "hgradient")==0
860 || strcasecmp(type, "vgradient")==0
861 || strcasecmp(type, "dgradient")==0) {
863 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
865 p = WMGetFromPLArray(texture, 1);
866 if (!p) {
867 str = "black";
868 } else {
869 str = WMGetFromPLString(p);
871 color = WMCreateNamedColor(scr, str, False);
873 WMSetColorWellColor(panel->tcol1W, color);
875 WMReleaseColor(color);
877 p = WMGetFromPLArray(texture, 2);
878 if (!p) {
879 str = "black";
880 } else {
881 str = WMGetFromPLString(p);
883 color = WMCreateNamedColor(scr, str, False);
885 WMSetColorWellColor(panel->tcol2W, color);
887 WMReleaseColor(color);
889 gradient = type[0];
890 /*...............................................*/
891 } else if (strcasecmp(type, "thgradient")==0
892 || strcasecmp(type, "tvgradient")==0
893 || strcasecmp(type, "tdgradient")==0) {
894 int i;
896 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
898 gradient = type[1];
900 WMSetTextFieldText(panel->imageT,
901 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
902 if (panel->imageFile)
903 wfree(panel->imageFile);
904 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
907 i = 180;
908 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
909 WMSetSliderValue(panel->topaS, i);
911 p = WMGetFromPLArray(texture, 3);
912 if (!p) {
913 str = "black";
914 } else {
915 str = WMGetFromPLString(p);
917 color = WMCreateNamedColor(scr, str, False);
919 WMSetColorWellColor(panel->tcol1W, color);
921 WMReleaseColor(color);
923 p = WMGetFromPLArray(texture, 4);
924 if (!p) {
925 str = "black";
926 } else {
927 str = WMGetFromPLString(p);
929 color = WMCreateNamedColor(scr, str, False);
931 WMSetColorWellColor(panel->tcol2W, color);
933 WMReleaseColor(color);
935 WMSetTextFieldText(panel->imageT,
936 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
938 if (panel->imageFile)
939 wfree(panel->imageFile);
940 if ((panel->imageFile = wfindfileinarray(panel->pathList,
941 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) != NULL) {
943 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
944 updateTGradImage(panel);
946 updateSGradButtons(panel);
947 } else wwarning(_("could not load file '%s': %s"), panel->imageFile,
948 RMessageForError(RErrorCode));
950 /*...............................................*/
951 } else if (strcasecmp(type, "mhgradient")==0
952 || strcasecmp(type, "mvgradient")==0
953 || strcasecmp(type, "mdgradient")==0) {
954 WMListItem *item;
956 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
957 item = WMGetListItem(panel->gcolL, i);
958 wfree(item->clientData);
960 WMClearList(panel->gcolL);
962 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
964 p = WMGetFromPLArray(texture, 1);
965 if (!p) {
966 str = "black";
967 } else {
968 str = WMGetFromPLString(p);
970 color = WMCreateNamedColor(scr, str, False);
972 WMSetColorWellColor(panel->defcW, color);
974 WMReleaseColor(color);
976 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
977 RColor *rgb;
978 XColor xcolor;
980 p = WMGetFromPLArray(texture, i);
981 if (!p) {
982 str = "black";
983 } else {
984 str = WMGetFromPLString(p);
987 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
988 str, &xcolor);
990 rgb = wmalloc(sizeof(RColor));
991 rgb->red = xcolor.red >> 8;
992 rgb->green = xcolor.green >> 8;
993 rgb->blue = xcolor.blue >> 8;
994 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
996 item = WMAddListItem(panel->gcolL, buffer);
997 item->clientData = rgb;
1000 sliderChangeCallback(panel->ghueS, panel);
1002 gradient = type[1];
1003 /*...............................................*/
1004 } else if (strcasecmp(type, "cpixmap")==0
1005 || strcasecmp(type, "spixmap")==0
1006 || strcasecmp(type, "mpixmap")==0
1007 || strcasecmp(type, "tpixmap")==0) {
1009 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1011 switch (toupper(type[0])) {
1012 case 'C':
1013 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1014 break;
1015 case 'S':
1016 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1017 break;
1018 case 'M':
1019 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1020 break;
1021 default:
1022 case 'T':
1023 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1024 break;
1027 WMSetTextFieldText(panel->imageT,
1028 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
1030 if (panel->imageFile)
1031 wfree(panel->imageFile);
1032 panel->imageFile = wfindfileinarray(panel->pathList,
1033 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
1035 color = WMCreateNamedColor(scr,
1036 WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
1037 WMSetColorWellColor(panel->defcW, color);
1038 WMReleaseColor(color);
1040 updateImage(panel, panel->imageFile);
1043 changeTypeCallback(panel->typeP, panel);
1045 if (gradient > 0) {
1046 updateGradButtons(panel);
1048 switch (toupper(gradient)) {
1049 case 'H':
1050 WMPerformButtonClick(panel->dirhB);
1051 break;
1052 case 'V':
1053 WMPerformButtonClick(panel->dirvB);
1054 break;
1055 default:
1056 case 'D':
1057 WMPerformButtonClick(panel->dirdB);
1058 break;
1062 return;
1064 bad_texture:
1065 str = WMGetPropListDescription(texture, False);
1066 wwarning(_("error creating texture %s"), str);
1067 wfree(str);
1073 char*
1074 GetTexturePanelTextureName(TexturePanel *panel)
1076 return WMGetTextFieldText(panel->nameT);
1081 WMPropList*
1082 GetTexturePanelTexture(TexturePanel *panel)
1084 WMPropList *prop = NULL;
1085 WMColor *color;
1086 char *str, *str2;
1087 char buff[32];
1088 int i;
1091 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1093 case TYPE_SOLID:
1094 color = WMGetColorWellColor(panel->defcW);
1095 str = WMGetColorRGBDescription(color);
1096 prop = WMCreatePLArray(WMCreatePLString("solid"),
1097 WMCreatePLString(str), NULL);
1098 wfree(str);
1100 break;
1102 case TYPE_PIXMAP:
1103 color = WMGetColorWellColor(panel->defcW);
1104 str = WMGetColorRGBDescription(color);
1106 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1107 case PTYPE_SCALE:
1108 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1109 WMCreatePLString(panel->imageFile),
1110 WMCreatePLString(str), NULL);
1111 break;
1112 case PTYPE_MAXIMIZE:
1113 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1114 WMCreatePLString(panel->imageFile),
1115 WMCreatePLString(str), NULL);
1116 break;
1117 case PTYPE_CENTER:
1118 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1119 WMCreatePLString(panel->imageFile),
1120 WMCreatePLString(str), NULL);
1121 break;
1122 case PTYPE_TILE:
1123 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1124 WMCreatePLString(panel->imageFile),
1125 WMCreatePLString(str), NULL);
1126 break;
1128 wfree(str);
1129 break;
1131 case TYPE_TGRADIENT:
1132 color = WMGetColorWellColor(panel->tcol1W);
1133 str = WMGetColorRGBDescription(color);
1135 color = WMGetColorWellColor(panel->tcol2W);
1136 str2 = WMGetColorRGBDescription(color);
1138 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1140 if (WMGetButtonSelected(panel->dirdB)) {
1141 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1142 WMCreatePLString(panel->imageFile),
1143 WMCreatePLString(buff),
1144 WMCreatePLString(str),
1145 WMCreatePLString(str2), NULL);
1146 } else if (WMGetButtonSelected(panel->dirvB)) {
1147 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1148 WMCreatePLString(panel->imageFile),
1149 WMCreatePLString(buff),
1150 WMCreatePLString(str),
1151 WMCreatePLString(str2), NULL);
1152 } else {
1153 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1154 WMCreatePLString(panel->imageFile),
1155 WMCreatePLString(buff),
1156 WMCreatePLString(str),
1157 WMCreatePLString(str2), NULL);
1159 wfree(str);
1160 wfree(str2);
1161 break;
1164 case TYPE_SGRADIENT:
1165 color = WMGetColorWellColor(panel->tcol1W);
1166 str = WMGetColorRGBDescription(color);
1168 color = WMGetColorWellColor(panel->tcol2W);
1169 str2 = WMGetColorRGBDescription(color);
1171 if (WMGetButtonSelected(panel->dirdB)) {
1172 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1173 WMCreatePLString(str),
1174 WMCreatePLString(str2), NULL);
1175 } else if (WMGetButtonSelected(panel->dirvB)) {
1176 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1177 WMCreatePLString(str),
1178 WMCreatePLString(str2), NULL);
1179 } else {
1180 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1181 WMCreatePLString(str),
1182 WMCreatePLString(str2), NULL);
1184 wfree(str);
1185 wfree(str2);
1186 break;
1188 case TYPE_GRADIENT:
1189 color = WMGetColorWellColor(panel->defcW);
1190 str = WMGetColorRGBDescription(color);
1192 if (WMGetButtonSelected(panel->dirdB)) {
1193 prop = WMCreatePLArray(WMCreatePLString("mdgradient"),
1194 WMCreatePLString(str), NULL);
1195 } else if (WMGetButtonSelected(panel->dirvB)) {
1196 prop = WMCreatePLArray(WMCreatePLString("mvgradient"),
1197 WMCreatePLString(str), NULL);
1198 } else {
1199 prop = WMCreatePLArray(WMCreatePLString("mhgradient"),
1200 WMCreatePLString(str), NULL);
1202 wfree(str);
1204 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1205 RColor *rgb;
1206 WMListItem *item;
1208 item = WMGetListItem(panel->gcolL, i);
1210 rgb = (RColor*)item->clientData;
1212 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1214 WMAddToPLArray(prop, WMCreatePLString(buff));
1216 break;
1220 return prop;
1225 void
1226 SetTexturePanelPixmapPath(TexturePanel *panel, WMPropList *array)
1228 panel->pathList = array;
1233 TexturePanel*
1234 CreateTexturePanel(WMWindow *keyWindow)
1235 /*CreateTexturePanel(WMScreen *scr)*/
1237 TexturePanel *panel;
1238 WMScreen *scr = WMWidgetScreen(keyWindow);
1240 panel = wmalloc(sizeof(TexturePanel));
1241 memset(panel, 0, sizeof(TexturePanel));
1243 panel->listFont = WMSystemFontOfSize(scr, 12);
1246 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1247 WMTitledWindowMask
1248 |WMClosableWindowMask);
1250 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1251 WMTitledWindowMask
1252 |WMClosableWindowMask);
1255 WMResizeWidget(panel->win, 325, 423);
1256 WMSetWindowTitle(panel->win, _("Texture Panel"));
1257 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1260 /* texture name */
1261 panel->nameF = WMCreateFrame(panel->win);
1262 WMResizeWidget(panel->nameF, 185, 50);
1263 WMMoveWidget(panel->nameF, 15, 10);
1264 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1266 panel->nameT = WMCreateTextField(panel->nameF);
1267 WMResizeWidget(panel->nameT, 160, 20);
1268 WMMoveWidget(panel->nameT, 12, 18);
1270 WMMapSubwidgets(panel->nameF);
1272 /* texture types */
1273 panel->typeP = WMCreatePopUpButton(panel->win);
1274 WMResizeWidget(panel->typeP, 185, 20);
1275 WMMoveWidget(panel->typeP, 15, 65);
1276 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1277 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1278 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1279 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1280 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1281 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1282 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1284 /* color */
1285 panel->defcF = WMCreateFrame(panel->win);
1286 WMResizeWidget(panel->defcF, 100, 75);
1287 WMMoveWidget(panel->defcF, 210, 10);
1288 WMSetFrameTitle(panel->defcF, _("Default Color"));
1290 panel->defcW = WMCreateColorWell(panel->defcF);
1291 WMResizeWidget(panel->defcW, 60, 45);
1292 WMMoveWidget(panel->defcW, 20, 20);
1294 WMMapSubwidgets(panel->defcF);
1296 /****** Gradient ******/
1297 panel->gcolF = WMCreateFrame(panel->win);
1298 WMResizeWidget(panel->gcolF, 295, 205);
1299 WMMoveWidget(panel->gcolF, 15, 95);
1300 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1302 panel->gcolL = WMCreateList(panel->gcolF);
1303 WMResizeWidget(panel->gcolL, 130, 140);
1304 WMMoveWidget(panel->gcolL, 10, 25);
1305 WMHangData(panel->gcolL, panel);
1306 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1307 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1309 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1310 WMResizeWidget(panel->gcolaB, 64, 24);
1311 WMMoveWidget(panel->gcolaB, 10, 170);
1312 WMSetButtonText(panel->gcolaB, _("Add"));
1313 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1315 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1316 WMResizeWidget(panel->gcoldB, 64, 24);
1317 WMMoveWidget(panel->gcoldB, 75, 170);
1318 WMSetButtonText(panel->gcoldB, _("Delete"));
1319 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1321 #if 0
1322 panel->gbriS = WMCreateSlider(panel->gcolF);
1323 WMResizeWidget(panel->gbriS, 130, 16);
1324 WMMoveWidget(panel->gbriS, 150, 25);
1325 WMSetSliderKnobThickness(panel->gbriS, 8);
1326 WMSetSliderMaxValue(panel->gbriS, 100);
1327 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1329 WMPixmap *pixmap;
1330 WMColor *color;
1332 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1333 color = WMDarkGrayColor(scr);
1334 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1335 WMColorGC(color), 0, 0, 130, 16);
1336 WMReleaseColor(color);
1337 color = WMWhiteColor(color);
1338 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1339 panel->listFont, 2,
1340 (16 - WMFontHeight(panel->listFont))/2 - 1,
1341 "Brightness", 10);
1342 WMSetSliderImage(panel->gbriS, pixmap);
1343 WMReleasePixmap(pixmap);
1346 panel->gconS = WMCreateSlider(panel->gcolF);
1347 WMResizeWidget(panel->gconS, 130, 16);
1348 WMMoveWidget(panel->gconS, 150, 50);
1349 WMSetSliderKnobThickness(panel->gconS, 8);
1350 WMSetSliderMaxValue(panel->gconS, 100);
1351 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1353 WMPixmap *pixmap;
1354 WMColor *color;
1356 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1357 color = WMDarkGrayColor(scr);
1358 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1359 WMColorGC(color), 0, 0, 130, 16);
1360 WMReleaseColor(color);
1361 color = WMWhiteColor(scr);
1362 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1363 panel->listFont, 2,
1364 (16 - WMFontHeight(panel->listFont))/2 - 1,
1365 "Contrast", 8);
1366 WMSetSliderImage(panel->gconS, pixmap);
1367 WMReleasePixmap(pixmap);
1369 #endif
1370 panel->ghueS = WMCreateSlider(panel->gcolF);
1371 WMResizeWidget(panel->ghueS, 130, 16);
1372 WMMoveWidget(panel->ghueS, 150, 100);
1373 WMSetSliderKnobThickness(panel->ghueS, 8);
1374 WMSetSliderMaxValue(panel->ghueS, 359);
1375 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1377 panel->gsatS = WMCreateSlider(panel->gcolF);
1378 WMResizeWidget(panel->gsatS, 130, 16);
1379 WMMoveWidget(panel->gsatS, 150, 125);
1380 WMSetSliderKnobThickness(panel->gsatS, 8);
1381 WMSetSliderMaxValue(panel->gsatS, 255);
1382 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1384 panel->gvalS = WMCreateSlider(panel->gcolF);
1385 WMResizeWidget(panel->gvalS, 130, 16);
1386 WMMoveWidget(panel->gvalS, 150, 150);
1387 WMSetSliderKnobThickness(panel->gvalS, 8);
1388 WMSetSliderMaxValue(panel->gvalS, 255);
1389 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1392 WMMapSubwidgets(panel->gcolF);
1394 /** Direction **/
1395 panel->dirF = WMCreateFrame(panel->win);
1396 WMSetFrameTitle(panel->dirF, _("Direction"));
1397 WMResizeWidget(panel->dirF, 295, 75);
1398 WMMoveWidget(panel->dirF, 15, 305);
1400 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1401 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1402 WMResizeWidget(panel->dirvB, 90, 40);
1403 WMMoveWidget(panel->dirvB, 10, 20);
1405 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1406 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1407 WMResizeWidget(panel->dirhB, 90, 40);
1408 WMMoveWidget(panel->dirhB, 102, 20);
1410 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1411 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1412 WMResizeWidget(panel->dirdB, 90, 40);
1413 WMMoveWidget(panel->dirdB, 194, 20);
1415 WMGroupButtons(panel->dirvB, panel->dirhB);
1416 WMGroupButtons(panel->dirvB, panel->dirdB);
1418 WMMapSubwidgets(panel->dirF);
1420 /****************** Textured Gradient ******************/
1421 panel->tcolF = WMCreateFrame(panel->win);
1422 WMResizeWidget(panel->tcolF, 100, 135);
1423 WMMoveWidget(panel->tcolF, 210, 10);
1424 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1426 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1427 WMResizeWidget(panel->tcol1W, 60, 45);
1428 WMMoveWidget(panel->tcol1W, 20, 25);
1429 WMAddNotificationObserver(colorWellObserver, panel,
1430 WMColorWellDidChangeNotification, panel->tcol1W);
1432 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1433 WMResizeWidget(panel->tcol2W, 60, 45);
1434 WMMoveWidget(panel->tcol2W, 20, 75);
1435 WMAddNotificationObserver(colorWellObserver, panel,
1436 WMColorWellDidChangeNotification, panel->tcol2W);
1438 /** Opacity */
1439 panel->topaF = WMCreateFrame(panel->win);
1440 WMResizeWidget(panel->topaF, 185, 50);
1441 WMMoveWidget(panel->topaF, 15, 95);
1442 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1444 panel->topaS = WMCreateSlider(panel->topaF);
1445 WMResizeWidget(panel->topaS, 155, 18);
1446 WMMoveWidget(panel->topaS, 15, 20);
1447 WMSetSliderMaxValue(panel->topaS, 255);
1448 WMSetSliderValue(panel->topaS, 200);
1449 WMSetSliderContinuous(panel->topaS, False);
1450 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1452 WMMapSubwidgets(panel->topaF);
1455 WMPixmap *pixmap;
1456 Pixmap p;
1457 WMColor *color;
1459 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1460 p = WMGetPixmapXID(pixmap);
1462 color = WMDarkGrayColor(scr);
1463 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1464 0, 0, 155, 18);
1465 WMReleaseColor(color);
1467 color = WMWhiteColor(scr);
1468 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1469 WMDrawString(scr, p, color, panel->listFont,
1470 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1471 "100%", 4);
1472 WMReleaseColor(color);
1474 WMSetSliderImage(panel->topaS, pixmap);
1475 WMReleasePixmap(pixmap);
1478 WMMapSubwidgets(panel->tcolF);
1480 /****************** Image ******************/
1481 panel->imageF = WMCreateFrame(panel->win);
1482 WMResizeWidget(panel->imageF, 295, 150);
1483 WMMoveWidget(panel->imageF, 15, 150);
1484 WMSetFrameTitle(panel->imageF, _("Image"));
1486 panel->imageL = WMCreateLabel(panel->imageF);
1487 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1489 panel->imageT = WMCreateTextField(panel->imageF);
1490 WMResizeWidget(panel->imageT, 90, 20);
1491 WMMoveWidget(panel->imageT, 190, 25);
1493 panel->imageV = WMCreateScrollView(panel->imageF);
1494 WMResizeWidget(panel->imageV, 165, 115);
1495 WMMoveWidget(panel->imageV, 15, 20);
1496 WMSetScrollViewRelief(panel->imageV, WRSunken);
1497 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1498 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1499 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1501 panel->browB = WMCreateCommandButton(panel->imageF);
1502 WMResizeWidget(panel->browB, 90, 24);
1503 WMMoveWidget(panel->browB, 190, 50);
1504 WMSetButtonText(panel->browB, _("Browse..."));
1505 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1507 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1508 WMResizeWidget(panel->dispB, 90, 24);
1509 WMMoveWidget(panel->dispB, 190, 80);
1510 WMSetButtonText(panel->dispB, _("Show"));
1513 panel->arrP = WMCreatePopUpButton(panel->imageF);
1514 WMResizeWidget(panel->arrP, 90, 20);
1515 WMMoveWidget(panel->arrP, 190, 120);
1516 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1517 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1518 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1519 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1520 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1522 WMMapSubwidgets(panel->imageF);
1524 /****/
1526 panel->okB = WMCreateCommandButton(panel->win);
1527 WMResizeWidget(panel->okB, 84, 24);
1528 WMMoveWidget(panel->okB, 225, 390);
1529 WMSetButtonText(panel->okB, _("OK"));
1530 WMSetButtonAction(panel->okB, buttonCallback, panel);
1532 panel->cancelB = WMCreateCommandButton(panel->win);
1533 WMResizeWidget(panel->cancelB, 84, 24);
1534 WMMoveWidget(panel->cancelB, 130, 390);
1535 WMSetButtonText(panel->cancelB, _("Cancel"));
1536 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1538 WMMapWidget(panel->nameF);
1539 WMMapWidget(panel->typeP);
1540 WMMapWidget(panel->okB);
1541 WMMapWidget(panel->cancelB);
1543 WMUnmapWidget(panel->arrP);
1545 WMRealizeWidget(panel->win);
1547 panel->currentType = -1;
1549 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1551 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1552 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1553 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1555 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1556 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1558 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1559 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1560 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1561 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1562 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1564 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1565 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1566 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1569 /* setup for first time */
1571 changeTypeCallback(panel->typeP, panel);
1573 sliderChangeCallback(panel->ghueS, panel);
1574 sliderChangeCallback(panel->gsatS, panel);
1576 return panel;
1582 *--------------------------------------------------------------------------
1583 * Test stuff
1584 *--------------------------------------------------------------------------
1587 #if 0
1589 char *ProgName = "test";
1591 void
1592 testOKButton(WMWidget *self, void *data)
1594 char *test;
1595 Display *dpy;
1596 Window win;
1597 Pixmap pix;
1598 RImage *image;
1600 TexturePanel *panel = (TexturePanel*)data;
1601 /* test = GetTexturePanelTextureString(panel); */
1603 wwarning(test);
1605 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1606 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1607 0, 0, 0);
1608 XMapRaised(dpy, win);
1609 XFlush(dpy);
1611 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1613 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1615 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1616 0, 0);
1618 wfree (test);
1622 void
1623 testCancelButton(WMWidget *self, void *data)
1625 wwarning("Exiting test....");
1626 exit(0);
1629 void
1630 wAbort()
1632 exit(1);
1636 main(int argc, char **argv)
1638 TexturePanel *panel;
1640 Display *dpy = XOpenDisplay("");
1641 WMScreen *scr;
1643 /* char *test; */
1645 WMInitializeApplication("Test", &argc, argv);
1647 if (!dpy) {
1648 wfatal("could not open display");
1649 exit(1);
1652 scr = WMCreateSimpleApplicationScreen(dpy);
1654 panel = CreateTexturePanel(scr);
1656 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1657 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1659 SetTexturePanelTexture(panel, "pinky",
1660 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1662 ShowTexturePanel(panel);
1664 WMScreenMainLoop(scr);
1665 return 0;
1667 #endif