- API change in WINGs for WMDraw*String().
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob0279e6ab37e333fd0cb24f89c5314c7413b7d9f9
1 /* TexturePanel.c- texture editting panel
2 *
3 * WPrefs - WindowMaker Preferences Program
4 *
5 * Copyright (c) 1998-2002 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/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 int width, height, x, y;
469 Display *dpy;
470 WMColor *white = WMWhiteColor(scr);
471 WMListItem *item;
472 WMColor *black = WMBlackColor(scr);
474 dpy = WMScreenDisplay(scr);
476 width = rect->size.width;
477 height = rect->size.height;
478 x = rect->pos.x;
479 y = rect->pos.y;
481 if (state & WLDSSelected)
482 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
483 else
484 XClearArea(dpy, d, x, y, width, height, False);
486 item = WMGetListItem(lPtr, index);
488 if (panel->gimage) {
489 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
490 0, height*index, 30, height, x + 5, y);
492 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1,
493 text, strlen(text));
495 WMReleaseColor(white);
496 WMReleaseColor(black);
501 static void
502 gradAddCallback(WMWidget *w, void *data)
504 TexturePanel *panel = (TexturePanel*)data;
505 WMListItem *item;
506 int row;
507 RColor *rgb;
509 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
510 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
511 rgb = wmalloc(sizeof(RColor));
512 memset(rgb, 0, sizeof(RColor));
513 item->clientData = rgb;
515 WMSelectListItem(panel->gcolL, row);
517 updateGradButtons(panel);
519 sliderChangeCallback(panel->ghueS, panel);
521 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
526 static void
527 gradClickCallback(WMWidget *w, void *data)
529 TexturePanel *panel = (TexturePanel*)data;
530 WMListItem *item;
531 int row;
532 RHSVColor hsv;
534 row = WMGetListSelectedItemRow(w);
535 if (row < 0)
536 return;
538 item = WMGetListItem(panel->gcolL, row);
539 RRGBtoHSV((RColor*)item->clientData, &hsv);
541 WMSetSliderValue(panel->ghueS, hsv.hue);
542 WMSetSliderValue(panel->gsatS, hsv.saturation);
543 WMSetSliderValue(panel->gvalS, hsv.value);
545 sliderChangeCallback(panel->ghueS, panel);
546 sliderChangeCallback(panel->gsatS, panel);
550 static void
551 gradDeleteCallback(WMWidget *w, void *data)
553 TexturePanel *panel = (TexturePanel*)data;
554 WMListItem *item;
555 int row;
557 row = WMGetListSelectedItemRow(panel->gcolL);
558 if (row < 0)
559 return;
561 item = WMGetListItem(panel->gcolL, row);
562 wfree(item->clientData);
564 WMRemoveListItem(panel->gcolL, row);
566 WMSelectListItem(panel->gcolL, row - 1);
568 updateGradButtons(panel);
570 gradClickCallback(panel->gcolL, panel);
572 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
576 /*************** Simple Gradient ***************/
578 static void
579 colorWellObserver(void *self, WMNotification *n)
581 updateSGradButtons(self);
587 static void
588 opaqChangeCallback(WMWidget *w, void *data)
590 TexturePanel *panel = (TexturePanel*)data;
592 updateTGradImage(panel);
595 /****************** Image ******************/
597 static void
598 updateImage(TexturePanel *panel, char *path)
600 WMScreen *scr = WMWidgetScreen(panel->win);
601 RImage *image;
602 WMPixmap *pixmap;
603 WMSize size;
605 if (path) {
606 image = RLoadImage(WMScreenRContext(scr), path, 0);
607 if (!image) {
608 char *message;
610 message = wstrconcat(_("Could not load the selected file: "),
611 (char*)RMessageForError(RErrorCode));
613 WMRunAlertPanel(scr, panel->win, _("Error"), message,
614 _("OK"), NULL, NULL);
616 if (!panel->image)
617 WMSetButtonEnabled(panel->okB, False);
619 wfree(message);
620 return;
623 WMSetButtonEnabled(panel->okB, True);
625 if (panel->image)
626 RReleaseImage(panel->image);
627 panel->image = image;
628 } else {
629 image = panel->image;
632 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
633 if (image) {
634 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
636 size = WMGetPixmapSize(pixmap);
637 WMSetLabelImage(panel->imageL, pixmap);
638 WMResizeWidget(panel->imageL, size.width, size.height);
640 WMReleasePixmap(pixmap);
642 } else {
643 updateTGradImage(panel);
648 static void
649 browseImageCallback(WMWidget *w, void *data)
651 TexturePanel *panel = (TexturePanel*)data;
652 WMOpenPanel *opanel;
653 WMScreen *scr = WMWidgetScreen(w);
654 static char *ipath = NULL;
656 opanel = WMGetOpenPanel(scr);
657 WMSetFilePanelCanChooseDirectories(opanel, False);
658 WMSetFilePanelCanChooseFiles(opanel, True);
660 if (!ipath)
661 ipath = wstrdup(wgethomedir());
663 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
664 _("Open Image"), NULL)) {
665 char *path, *fullpath;
666 char *tmp, *tmp2;
668 tmp = WMGetFilePanelFileName(opanel);
669 if (!tmp)
670 return;
671 fullpath = tmp;
673 wfree(ipath);
674 ipath = fullpath;
676 path = wstrdup(fullpath);
678 tmp2 = strrchr(fullpath, '/');
679 if (tmp2)
680 tmp2++;
682 tmp = wfindfileinarray(panel->pathList, tmp2);
684 if (tmp) {
685 if (strcmp(fullpath, tmp)==0) {
686 wfree(path);
687 path = tmp2;
689 wfree(tmp);
692 if (!RGetImageFileFormat(fullpath)) {
693 WMRunAlertPanel(scr, panel->win, _("Error"),
694 _("The selected file does not contain a supported image."),
695 _("OK"), NULL, NULL);
696 wfree(path);
697 } else {
698 updateImage(panel, fullpath);
699 wfree(panel->imageFile);
700 panel->imageFile = path;
702 WMSetTextFieldText(panel->imageT, path);
709 static void
710 buttonCallback(WMWidget *w, void *data)
712 TexturePanel *panel = (TexturePanel*)data;
714 if (w == panel->okB) {
715 (*panel->okAction)(panel->okData);
716 } else {
717 (*panel->cancelAction)(panel->cancelData);
723 static void
724 changeTypeCallback(WMWidget *w, void *data)
726 TexturePanel *panel = (TexturePanel*)data;
727 int newType;
728 int i;
730 newType = WMGetPopUpButtonSelectedItem(w);
731 if (newType == panel->currentType)
732 return;
734 if (panel->currentType >= 0) {
735 for (i = 0; i < MAX_SECTION_PARTS; i++) {
736 if (panel->sectionParts[panel->currentType][i] == NULL)
737 break;
738 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
742 for (i = 0; i < MAX_SECTION_PARTS; i++) {
743 if (panel->sectionParts[newType][i] == NULL)
744 break;
745 WMMapWidget(panel->sectionParts[newType][i]);
747 panel->currentType = newType;
749 switch (newType) {
750 case TYPE_SGRADIENT:
751 updateSGradButtons(panel);
752 WMSetButtonEnabled(panel->okB, True);
753 break;
754 case TYPE_GRADIENT:
755 updateGradButtons(panel);
756 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
757 break;
758 case TYPE_TGRADIENT:
759 case TYPE_PIXMAP:
760 updateImage(panel, NULL);
761 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
762 break;
763 default:
764 WMSetButtonEnabled(panel->okB, True);
765 break;
771 *--------------------------------------------------------------------------
772 * Public functions
773 *--------------------------------------------------------------------------
775 void
776 DestroyTexturePanel(TexturePanel *panel)
782 void
783 ShowTexturePanel(TexturePanel *panel)
785 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
786 Screen *scr = DefaultScreenOfDisplay(dpy);
788 WMSetWindowInitialPosition(panel->win,
789 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
790 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
791 WMMapWidget(panel->win);
795 void
796 HideTexturePanel(TexturePanel *panel)
798 WMUnmapWidget(panel->win);
802 void
803 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
805 panel->okAction = action;
806 panel->okData = clientData;
810 void
811 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
813 panel->cancelAction = action;
814 panel->cancelData = clientData;
818 void
819 SetTexturePanelTexture(TexturePanel *panel, char *name, WMPropList *texture)
821 WMScreen *scr = WMWidgetScreen(panel->win);
822 char *str, *type;
823 WMPropList *p;
824 WMColor *color;
825 int i;
826 char buffer[64];
827 int gradient = 0;
829 WMSetTextFieldText(panel->nameT, name);
831 if (!texture)
832 return;
834 p = WMGetFromPLArray(texture, 0);
835 if (!p) {
836 goto bad_texture;
838 type = WMGetFromPLString(p);
840 /*...............................................*/
841 if (strcasecmp(type, "solid")==0) {
843 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
845 p = WMGetFromPLArray(texture, 1);
846 if (!p) {
847 str = "black";
848 } else {
849 str = WMGetFromPLString(p);
851 color = WMCreateNamedColor(scr, str, False);
853 WMSetColorWellColor(panel->defcW, color);
855 WMReleaseColor(color);
856 /*...............................................*/
857 } else if (strcasecmp(type, "hgradient")==0
858 || strcasecmp(type, "vgradient")==0
859 || strcasecmp(type, "dgradient")==0) {
861 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
863 p = WMGetFromPLArray(texture, 1);
864 if (!p) {
865 str = "black";
866 } else {
867 str = WMGetFromPLString(p);
869 color = WMCreateNamedColor(scr, str, False);
871 WMSetColorWellColor(panel->tcol1W, color);
873 WMReleaseColor(color);
875 p = WMGetFromPLArray(texture, 2);
876 if (!p) {
877 str = "black";
878 } else {
879 str = WMGetFromPLString(p);
881 color = WMCreateNamedColor(scr, str, False);
883 WMSetColorWellColor(panel->tcol2W, color);
885 WMReleaseColor(color);
887 gradient = type[0];
888 /*...............................................*/
889 } else if (strcasecmp(type, "thgradient")==0
890 || strcasecmp(type, "tvgradient")==0
891 || strcasecmp(type, "tdgradient")==0) {
892 int i;
894 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
896 gradient = type[1];
898 WMSetTextFieldText(panel->imageT,
899 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
900 if (panel->imageFile)
901 wfree(panel->imageFile);
902 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
905 i = 180;
906 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
907 WMSetSliderValue(panel->topaS, i);
909 p = WMGetFromPLArray(texture, 3);
910 if (!p) {
911 str = "black";
912 } else {
913 str = WMGetFromPLString(p);
915 color = WMCreateNamedColor(scr, str, False);
917 WMSetColorWellColor(panel->tcol1W, color);
919 WMReleaseColor(color);
921 p = WMGetFromPLArray(texture, 4);
922 if (!p) {
923 str = "black";
924 } else {
925 str = WMGetFromPLString(p);
927 color = WMCreateNamedColor(scr, str, False);
929 WMSetColorWellColor(panel->tcol2W, color);
931 WMReleaseColor(color);
933 WMSetTextFieldText(panel->imageT,
934 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
936 if (panel->imageFile)
937 wfree(panel->imageFile);
938 if ((panel->imageFile = wfindfileinarray(panel->pathList,
939 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) != NULL) {
941 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
942 updateTGradImage(panel);
944 updateSGradButtons(panel);
945 } else wwarning(_("could not load file '%s': %s"), panel->imageFile,
946 RMessageForError(RErrorCode));
948 /*...............................................*/
949 } else if (strcasecmp(type, "mhgradient")==0
950 || strcasecmp(type, "mvgradient")==0
951 || strcasecmp(type, "mdgradient")==0) {
952 WMListItem *item;
954 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
955 item = WMGetListItem(panel->gcolL, i);
956 wfree(item->clientData);
958 WMClearList(panel->gcolL);
960 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
962 p = WMGetFromPLArray(texture, 1);
963 if (!p) {
964 str = "black";
965 } else {
966 str = WMGetFromPLString(p);
968 color = WMCreateNamedColor(scr, str, False);
970 WMSetColorWellColor(panel->defcW, color);
972 WMReleaseColor(color);
974 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
975 RColor *rgb;
976 XColor xcolor;
978 p = WMGetFromPLArray(texture, i);
979 if (!p) {
980 str = "black";
981 } else {
982 str = WMGetFromPLString(p);
985 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
986 str, &xcolor);
988 rgb = wmalloc(sizeof(RColor));
989 rgb->red = xcolor.red >> 8;
990 rgb->green = xcolor.green >> 8;
991 rgb->blue = xcolor.blue >> 8;
992 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
994 item = WMAddListItem(panel->gcolL, buffer);
995 item->clientData = rgb;
998 sliderChangeCallback(panel->ghueS, panel);
1000 gradient = type[1];
1001 /*...............................................*/
1002 } else if (strcasecmp(type, "cpixmap")==0
1003 || strcasecmp(type, "spixmap")==0
1004 || strcasecmp(type, "mpixmap")==0
1005 || strcasecmp(type, "tpixmap")==0) {
1007 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1009 switch (toupper(type[0])) {
1010 case 'C':
1011 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1012 break;
1013 case 'S':
1014 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1015 break;
1016 case 'M':
1017 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1018 break;
1019 default:
1020 case 'T':
1021 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1022 break;
1025 WMSetTextFieldText(panel->imageT,
1026 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
1028 if (panel->imageFile)
1029 wfree(panel->imageFile);
1030 panel->imageFile = wfindfileinarray(panel->pathList,
1031 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
1033 color = WMCreateNamedColor(scr,
1034 WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
1035 WMSetColorWellColor(panel->defcW, color);
1036 WMReleaseColor(color);
1038 updateImage(panel, panel->imageFile);
1041 changeTypeCallback(panel->typeP, panel);
1043 if (gradient > 0) {
1044 updateGradButtons(panel);
1046 switch (toupper(gradient)) {
1047 case 'H':
1048 WMPerformButtonClick(panel->dirhB);
1049 break;
1050 case 'V':
1051 WMPerformButtonClick(panel->dirvB);
1052 break;
1053 default:
1054 case 'D':
1055 WMPerformButtonClick(panel->dirdB);
1056 break;
1060 return;
1062 bad_texture:
1063 str = WMGetPropListDescription(texture, False);
1064 wwarning(_("error creating texture %s"), str);
1065 wfree(str);
1071 char*
1072 GetTexturePanelTextureName(TexturePanel *panel)
1074 return WMGetTextFieldText(panel->nameT);
1079 WMPropList*
1080 GetTexturePanelTexture(TexturePanel *panel)
1082 WMPropList *prop = NULL;
1083 WMColor *color;
1084 char *str, *str2;
1085 char buff[32];
1086 int i;
1089 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1091 case TYPE_SOLID:
1092 color = WMGetColorWellColor(panel->defcW);
1093 str = WMGetColorRGBDescription(color);
1094 prop = WMCreatePLArray(WMCreatePLString("solid"),
1095 WMCreatePLString(str), NULL);
1096 wfree(str);
1098 break;
1100 case TYPE_PIXMAP:
1101 color = WMGetColorWellColor(panel->defcW);
1102 str = WMGetColorRGBDescription(color);
1104 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1105 case PTYPE_SCALE:
1106 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1107 WMCreatePLString(panel->imageFile),
1108 WMCreatePLString(str), NULL);
1109 break;
1110 case PTYPE_MAXIMIZE:
1111 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1112 WMCreatePLString(panel->imageFile),
1113 WMCreatePLString(str), NULL);
1114 break;
1115 case PTYPE_CENTER:
1116 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1117 WMCreatePLString(panel->imageFile),
1118 WMCreatePLString(str), NULL);
1119 break;
1120 case PTYPE_TILE:
1121 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1122 WMCreatePLString(panel->imageFile),
1123 WMCreatePLString(str), NULL);
1124 break;
1126 wfree(str);
1127 break;
1129 case TYPE_TGRADIENT:
1130 color = WMGetColorWellColor(panel->tcol1W);
1131 str = WMGetColorRGBDescription(color);
1133 color = WMGetColorWellColor(panel->tcol2W);
1134 str2 = WMGetColorRGBDescription(color);
1136 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1138 if (WMGetButtonSelected(panel->dirdB)) {
1139 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1140 WMCreatePLString(panel->imageFile),
1141 WMCreatePLString(buff),
1142 WMCreatePLString(str),
1143 WMCreatePLString(str2), NULL);
1144 } else if (WMGetButtonSelected(panel->dirvB)) {
1145 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1146 WMCreatePLString(panel->imageFile),
1147 WMCreatePLString(buff),
1148 WMCreatePLString(str),
1149 WMCreatePLString(str2), NULL);
1150 } else {
1151 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1152 WMCreatePLString(panel->imageFile),
1153 WMCreatePLString(buff),
1154 WMCreatePLString(str),
1155 WMCreatePLString(str2), NULL);
1157 wfree(str);
1158 wfree(str2);
1159 break;
1162 case TYPE_SGRADIENT:
1163 color = WMGetColorWellColor(panel->tcol1W);
1164 str = WMGetColorRGBDescription(color);
1166 color = WMGetColorWellColor(panel->tcol2W);
1167 str2 = WMGetColorRGBDescription(color);
1169 if (WMGetButtonSelected(panel->dirdB)) {
1170 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1171 WMCreatePLString(str),
1172 WMCreatePLString(str2), NULL);
1173 } else if (WMGetButtonSelected(panel->dirvB)) {
1174 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1175 WMCreatePLString(str),
1176 WMCreatePLString(str2), NULL);
1177 } else {
1178 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1179 WMCreatePLString(str),
1180 WMCreatePLString(str2), NULL);
1182 wfree(str);
1183 wfree(str2);
1184 break;
1186 case TYPE_GRADIENT:
1187 color = WMGetColorWellColor(panel->defcW);
1188 str = WMGetColorRGBDescription(color);
1190 if (WMGetButtonSelected(panel->dirdB)) {
1191 prop = WMCreatePLArray(WMCreatePLString("mdgradient"),
1192 WMCreatePLString(str), NULL);
1193 } else if (WMGetButtonSelected(panel->dirvB)) {
1194 prop = WMCreatePLArray(WMCreatePLString("mvgradient"),
1195 WMCreatePLString(str), NULL);
1196 } else {
1197 prop = WMCreatePLArray(WMCreatePLString("mhgradient"),
1198 WMCreatePLString(str), NULL);
1200 wfree(str);
1202 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1203 RColor *rgb;
1204 WMListItem *item;
1206 item = WMGetListItem(panel->gcolL, i);
1208 rgb = (RColor*)item->clientData;
1210 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1212 WMAddToPLArray(prop, WMCreatePLString(buff));
1214 break;
1218 return prop;
1223 void
1224 SetTexturePanelPixmapPath(TexturePanel *panel, WMPropList *array)
1226 panel->pathList = array;
1231 TexturePanel*
1232 CreateTexturePanel(WMWindow *keyWindow)
1233 /*CreateTexturePanel(WMScreen *scr)*/
1235 TexturePanel *panel;
1236 WMScreen *scr = WMWidgetScreen(keyWindow);
1238 panel = wmalloc(sizeof(TexturePanel));
1239 memset(panel, 0, sizeof(TexturePanel));
1241 panel->listFont = WMSystemFontOfSize(scr, 12);
1244 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1245 WMTitledWindowMask
1246 |WMClosableWindowMask);
1248 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1249 WMTitledWindowMask
1250 |WMClosableWindowMask);
1253 WMResizeWidget(panel->win, 325, 423);
1254 WMSetWindowTitle(panel->win, _("Texture Panel"));
1255 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1258 /* texture name */
1259 panel->nameF = WMCreateFrame(panel->win);
1260 WMResizeWidget(panel->nameF, 185, 50);
1261 WMMoveWidget(panel->nameF, 15, 10);
1262 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1264 panel->nameT = WMCreateTextField(panel->nameF);
1265 WMResizeWidget(panel->nameT, 160, 20);
1266 WMMoveWidget(panel->nameT, 12, 18);
1268 WMMapSubwidgets(panel->nameF);
1270 /* texture types */
1271 panel->typeP = WMCreatePopUpButton(panel->win);
1272 WMResizeWidget(panel->typeP, 185, 20);
1273 WMMoveWidget(panel->typeP, 15, 65);
1274 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1275 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1276 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1277 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1278 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1279 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1280 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1282 /* color */
1283 panel->defcF = WMCreateFrame(panel->win);
1284 WMResizeWidget(panel->defcF, 100, 75);
1285 WMMoveWidget(panel->defcF, 210, 10);
1286 WMSetFrameTitle(panel->defcF, _("Default Color"));
1288 panel->defcW = WMCreateColorWell(panel->defcF);
1289 WMResizeWidget(panel->defcW, 60, 45);
1290 WMMoveWidget(panel->defcW, 20, 20);
1292 WMMapSubwidgets(panel->defcF);
1294 /****** Gradient ******/
1295 panel->gcolF = WMCreateFrame(panel->win);
1296 WMResizeWidget(panel->gcolF, 295, 205);
1297 WMMoveWidget(panel->gcolF, 15, 95);
1298 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1300 panel->gcolL = WMCreateList(panel->gcolF);
1301 WMResizeWidget(panel->gcolL, 130, 140);
1302 WMMoveWidget(panel->gcolL, 10, 25);
1303 WMHangData(panel->gcolL, panel);
1304 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1305 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1307 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1308 WMResizeWidget(panel->gcolaB, 64, 24);
1309 WMMoveWidget(panel->gcolaB, 10, 170);
1310 WMSetButtonText(panel->gcolaB, _("Add"));
1311 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1313 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1314 WMResizeWidget(panel->gcoldB, 64, 24);
1315 WMMoveWidget(panel->gcoldB, 75, 170);
1316 WMSetButtonText(panel->gcoldB, _("Delete"));
1317 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1319 #if 0
1320 panel->gbriS = WMCreateSlider(panel->gcolF);
1321 WMResizeWidget(panel->gbriS, 130, 16);
1322 WMMoveWidget(panel->gbriS, 150, 25);
1323 WMSetSliderKnobThickness(panel->gbriS, 8);
1324 WMSetSliderMaxValue(panel->gbriS, 100);
1325 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1327 WMPixmap *pixmap;
1328 WMColor *color;
1330 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1331 color = WMDarkGrayColor(scr);
1332 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1333 WMColorGC(color), 0, 0, 130, 16);
1334 WMReleaseColor(color);
1335 color = WMWhiteColor(color);
1336 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1337 panel->listFont, 2,
1338 (16 - WMFontHeight(panel->listFont))/2 - 1,
1339 "Brightness", 10);
1340 WMSetSliderImage(panel->gbriS, pixmap);
1341 WMReleasePixmap(pixmap);
1344 panel->gconS = WMCreateSlider(panel->gcolF);
1345 WMResizeWidget(panel->gconS, 130, 16);
1346 WMMoveWidget(panel->gconS, 150, 50);
1347 WMSetSliderKnobThickness(panel->gconS, 8);
1348 WMSetSliderMaxValue(panel->gconS, 100);
1349 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1351 WMPixmap *pixmap;
1352 WMColor *color;
1354 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1355 color = WMDarkGrayColor(scr);
1356 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1357 WMColorGC(color), 0, 0, 130, 16);
1358 WMReleaseColor(color);
1359 color = WMWhiteColor(scr);
1360 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1361 panel->listFont, 2,
1362 (16 - WMFontHeight(panel->listFont))/2 - 1,
1363 "Contrast", 8);
1364 WMSetSliderImage(panel->gconS, pixmap);
1365 WMReleasePixmap(pixmap);
1367 #endif
1368 panel->ghueS = WMCreateSlider(panel->gcolF);
1369 WMResizeWidget(panel->ghueS, 130, 16);
1370 WMMoveWidget(panel->ghueS, 150, 100);
1371 WMSetSliderKnobThickness(panel->ghueS, 8);
1372 WMSetSliderMaxValue(panel->ghueS, 359);
1373 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1375 panel->gsatS = WMCreateSlider(panel->gcolF);
1376 WMResizeWidget(panel->gsatS, 130, 16);
1377 WMMoveWidget(panel->gsatS, 150, 125);
1378 WMSetSliderKnobThickness(panel->gsatS, 8);
1379 WMSetSliderMaxValue(panel->gsatS, 255);
1380 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1382 panel->gvalS = WMCreateSlider(panel->gcolF);
1383 WMResizeWidget(panel->gvalS, 130, 16);
1384 WMMoveWidget(panel->gvalS, 150, 150);
1385 WMSetSliderKnobThickness(panel->gvalS, 8);
1386 WMSetSliderMaxValue(panel->gvalS, 255);
1387 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1390 WMMapSubwidgets(panel->gcolF);
1392 /** Direction **/
1393 panel->dirF = WMCreateFrame(panel->win);
1394 WMSetFrameTitle(panel->dirF, _("Direction"));
1395 WMResizeWidget(panel->dirF, 295, 75);
1396 WMMoveWidget(panel->dirF, 15, 305);
1398 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1399 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1400 WMResizeWidget(panel->dirvB, 90, 40);
1401 WMMoveWidget(panel->dirvB, 10, 20);
1403 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1404 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1405 WMResizeWidget(panel->dirhB, 90, 40);
1406 WMMoveWidget(panel->dirhB, 102, 20);
1408 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1409 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1410 WMResizeWidget(panel->dirdB, 90, 40);
1411 WMMoveWidget(panel->dirdB, 194, 20);
1413 WMGroupButtons(panel->dirvB, panel->dirhB);
1414 WMGroupButtons(panel->dirvB, panel->dirdB);
1416 WMMapSubwidgets(panel->dirF);
1418 /****************** Textured Gradient ******************/
1419 panel->tcolF = WMCreateFrame(panel->win);
1420 WMResizeWidget(panel->tcolF, 100, 135);
1421 WMMoveWidget(panel->tcolF, 210, 10);
1422 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1424 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1425 WMResizeWidget(panel->tcol1W, 60, 45);
1426 WMMoveWidget(panel->tcol1W, 20, 25);
1427 WMAddNotificationObserver(colorWellObserver, panel,
1428 WMColorWellDidChangeNotification, panel->tcol1W);
1430 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1431 WMResizeWidget(panel->tcol2W, 60, 45);
1432 WMMoveWidget(panel->tcol2W, 20, 75);
1433 WMAddNotificationObserver(colorWellObserver, panel,
1434 WMColorWellDidChangeNotification, panel->tcol2W);
1436 /** Opacity */
1437 panel->topaF = WMCreateFrame(panel->win);
1438 WMResizeWidget(panel->topaF, 185, 50);
1439 WMMoveWidget(panel->topaF, 15, 95);
1440 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1442 panel->topaS = WMCreateSlider(panel->topaF);
1443 WMResizeWidget(panel->topaS, 155, 18);
1444 WMMoveWidget(panel->topaS, 15, 20);
1445 WMSetSliderMaxValue(panel->topaS, 255);
1446 WMSetSliderValue(panel->topaS, 200);
1447 WMSetSliderContinuous(panel->topaS, False);
1448 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1450 WMMapSubwidgets(panel->topaF);
1453 WMPixmap *pixmap;
1454 Pixmap p;
1455 WMColor *color;
1457 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1458 p = WMGetPixmapXID(pixmap);
1460 color = WMDarkGrayColor(scr);
1461 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1462 0, 0, 155, 18);
1463 WMReleaseColor(color);
1465 color = WMWhiteColor(scr);
1466 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1467 WMDrawString(scr, p, color, panel->listFont,
1468 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1469 "100%", 4);
1470 WMReleaseColor(color);
1472 WMSetSliderImage(panel->topaS, pixmap);
1473 WMReleasePixmap(pixmap);
1476 WMMapSubwidgets(panel->tcolF);
1478 /****************** Image ******************/
1479 panel->imageF = WMCreateFrame(panel->win);
1480 WMResizeWidget(panel->imageF, 295, 150);
1481 WMMoveWidget(panel->imageF, 15, 150);
1482 WMSetFrameTitle(panel->imageF, _("Image"));
1484 panel->imageL = WMCreateLabel(panel->imageF);
1485 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1487 panel->imageT = WMCreateTextField(panel->imageF);
1488 WMResizeWidget(panel->imageT, 90, 20);
1489 WMMoveWidget(panel->imageT, 190, 25);
1491 panel->imageV = WMCreateScrollView(panel->imageF);
1492 WMResizeWidget(panel->imageV, 165, 115);
1493 WMMoveWidget(panel->imageV, 15, 20);
1494 WMSetScrollViewRelief(panel->imageV, WRSunken);
1495 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1496 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1497 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1499 panel->browB = WMCreateCommandButton(panel->imageF);
1500 WMResizeWidget(panel->browB, 90, 24);
1501 WMMoveWidget(panel->browB, 190, 50);
1502 WMSetButtonText(panel->browB, _("Browse..."));
1503 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1505 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1506 WMResizeWidget(panel->dispB, 90, 24);
1507 WMMoveWidget(panel->dispB, 190, 80);
1508 WMSetButtonText(panel->dispB, _("Show"));
1511 panel->arrP = WMCreatePopUpButton(panel->imageF);
1512 WMResizeWidget(panel->arrP, 90, 20);
1513 WMMoveWidget(panel->arrP, 190, 120);
1514 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1515 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1516 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1517 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1518 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1520 WMMapSubwidgets(panel->imageF);
1522 /****/
1524 panel->okB = WMCreateCommandButton(panel->win);
1525 WMResizeWidget(panel->okB, 84, 24);
1526 WMMoveWidget(panel->okB, 225, 390);
1527 WMSetButtonText(panel->okB, _("OK"));
1528 WMSetButtonAction(panel->okB, buttonCallback, panel);
1530 panel->cancelB = WMCreateCommandButton(panel->win);
1531 WMResizeWidget(panel->cancelB, 84, 24);
1532 WMMoveWidget(panel->cancelB, 130, 390);
1533 WMSetButtonText(panel->cancelB, _("Cancel"));
1534 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1536 WMMapWidget(panel->nameF);
1537 WMMapWidget(panel->typeP);
1538 WMMapWidget(panel->okB);
1539 WMMapWidget(panel->cancelB);
1541 WMUnmapWidget(panel->arrP);
1543 WMRealizeWidget(panel->win);
1545 panel->currentType = -1;
1547 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1549 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1550 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1551 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1553 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1554 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1556 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1557 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1558 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1559 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1560 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1562 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1563 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1564 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1567 /* setup for first time */
1569 changeTypeCallback(panel->typeP, panel);
1571 sliderChangeCallback(panel->ghueS, panel);
1572 sliderChangeCallback(panel->gsatS, panel);
1574 return panel;
1580 *--------------------------------------------------------------------------
1581 * Test stuff
1582 *--------------------------------------------------------------------------
1585 #if 0
1587 char *ProgName = "test";
1589 void
1590 testOKButton(WMWidget *self, void *data)
1592 char *test;
1593 Display *dpy;
1594 Window win;
1595 Pixmap pix;
1596 RImage *image;
1598 TexturePanel *panel = (TexturePanel*)data;
1599 /* test = GetTexturePanelTextureString(panel); */
1601 wwarning(test);
1603 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1604 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1605 0, 0, 0);
1606 XMapRaised(dpy, win);
1607 XFlush(dpy);
1609 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1611 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1613 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1614 0, 0);
1616 wfree (test);
1620 void testCancelButton(WMWidget *self, void *data){
1621 wwarning("Exiting test....");
1622 exit(0);
1625 void wAbort()
1627 exit(1);
1630 int main(int argc, char **argv)
1632 TexturePanel *panel;
1634 Display *dpy = XOpenDisplay("");
1635 WMScreen *scr;
1637 /* char *test; */
1639 WMInitializeApplication("Test", &argc, argv);
1641 if (!dpy) {
1642 wfatal("could not open display");
1643 exit(1);
1646 scr = WMCreateSimpleApplicationScreen(dpy);
1648 panel = CreateTexturePanel(scr);
1650 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1651 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1653 SetTexturePanelTexture(panel, "pinky",
1654 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1656 ShowTexturePanel(panel);
1658 WMScreenMainLoop(scr);
1659 return 0;
1661 #endif