fixed bug in texture panel
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobd234e23fbbdd20017f870196c3ba1db93776c964
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 4
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);
519 static void
520 gradClickCallback(WMWidget *w, void *data)
522 TexturePanel *panel = (TexturePanel*)data;
523 WMListItem *item;
524 int row;
525 RHSVColor hsv;
527 row = WMGetListSelectedItemRow(w);
528 if (row < 0)
529 return;
531 item = WMGetListItem(panel->gcolL, row);
532 RRGBtoHSV((RColor*)item->clientData, &hsv);
534 WMSetSliderValue(panel->ghueS, hsv.hue);
535 WMSetSliderValue(panel->gsatS, hsv.saturation);
536 WMSetSliderValue(panel->gvalS, hsv.value);
538 sliderChangeCallback(panel->ghueS, panel);
539 sliderChangeCallback(panel->gsatS, panel);
543 static void
544 gradDeleteCallback(WMWidget *w, void *data)
546 TexturePanel *panel = (TexturePanel*)data;
547 WMListItem *item;
548 int row;
550 row = WMGetListSelectedItemRow(panel->gcolL);
551 if (row < 0)
552 return;
554 item = WMGetListItem(panel->gcolL, row);
555 free(item->clientData);
557 WMRemoveListItem(panel->gcolL, row);
559 WMSelectListItem(panel->gcolL, row - 1);
561 updateGradButtons(panel);
563 gradClickCallback(panel->gcolL, panel);
567 /*************** Simple Gradient ***************/
569 static void
570 colorWellObserver(void *self, WMNotification *n)
572 updateSGradButtons(self);
578 static void
579 opaqChangeCallback(WMWidget *w, void *data)
581 TexturePanel *panel = (TexturePanel*)data;
583 updateTGradImage(panel);
586 /****************** Image ******************/
588 static void
589 updateImage(TexturePanel *panel, char *path)
591 WMScreen *scr = WMWidgetScreen(panel->win);
592 RImage *image;
593 WMPixmap *pixmap;
594 WMSize size;
596 if (path) {
597 image = RLoadImage(WMScreenRContext(scr), path, 0);
598 if (!image) {
599 char *message;
601 message = wstrappend(_("Could not load the selected file: "),
602 (char*)RMessageForError(RErrorCode));
604 WMRunAlertPanel(scr, panel->win, _("Error"), message,
605 _("OK"), NULL, NULL);
606 return;
609 if (panel->image)
610 RDestroyImage(panel->image);
611 panel->image = image;
612 } else {
613 image = panel->image;
616 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
617 if (image) {
618 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
620 size = WMGetPixmapSize(pixmap);
621 WMSetLabelImage(panel->imageL, pixmap);
622 WMResizeWidget(panel->imageL, size.width, size.height);
624 WMReleasePixmap(pixmap);
626 } else {
627 updateTGradImage(panel);
632 static void
633 browseImageCallback(WMWidget *w, void *data)
635 TexturePanel *panel = (TexturePanel*)data;
636 WMOpenPanel *opanel;
637 WMScreen *scr = WMWidgetScreen(w);
638 static char *ipath = NULL;
640 opanel = WMGetOpenPanel(scr);
641 WMSetFilePanelCanChooseDirectories(opanel, False);
642 WMSetFilePanelCanChooseFiles(opanel, True);
644 if (!ipath)
645 ipath = wstrdup(wgethomedir());
647 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
648 "Open Image", NULL)) {
649 char *path, *fullpath;
650 char *tmp, *tmp2;
652 tmp = WMGetFilePanelFileName(opanel);
653 if (!tmp)
654 return;
655 fullpath = tmp;
657 free(ipath);
658 ipath = fullpath;
660 path = wstrdup(fullpath);
662 tmp2 = strrchr(fullpath, '/');
663 if (tmp2)
664 tmp2++;
666 tmp = wfindfileinarray(panel->pathList, tmp2);
668 if (tmp) {
669 if (strcmp(fullpath, tmp)==0) {
670 free(path);
671 path = tmp2;
673 free(tmp);
676 if (!RGetImageFileFormat(fullpath)) {
677 WMRunAlertPanel(scr, panel->win, _("Error"),
678 _("The selected file does not contain a supported image."),
679 _("OK"), NULL, NULL);
680 free(path);
681 } else {
682 updateImage(panel, fullpath);
683 free(panel->imageFile);
684 panel->imageFile = path;
686 WMSetTextFieldText(panel->imageT, path);
693 static void
694 buttonCallback(WMWidget *w, void *data)
696 TexturePanel *panel = (TexturePanel*)data;
698 if (w == panel->okB) {
699 (*panel->okAction)(panel->okData);
700 } else {
701 (*panel->cancelAction)(panel->cancelData);
707 static void
708 changeTypeCallback(WMWidget *w, void *data)
710 TexturePanel *panel = (TexturePanel*)data;
711 int newType;
712 int i;
714 newType = WMGetPopUpButtonSelectedItem(w);
715 if (newType == panel->currentType)
716 return;
718 if (panel->currentType >= 0) {
719 for (i = 0; i < MAX_SECTION_PARTS; i++) {
720 if (panel->sectionParts[panel->currentType][i] == NULL)
721 break;
722 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
726 for (i = 0; i < MAX_SECTION_PARTS; i++) {
727 if (panel->sectionParts[newType][i] == NULL)
728 break;
729 WMMapWidget(panel->sectionParts[newType][i]);
731 panel->currentType = newType;
733 switch (newType) {
734 case TYPE_SGRADIENT:
735 updateSGradButtons(panel);
736 break;
737 case TYPE_GRADIENT:
738 updateGradButtons(panel);
739 break;
740 case TYPE_TGRADIENT:
741 case TYPE_PIXMAP:
742 updateImage(panel, NULL);
743 break;
749 *--------------------------------------------------------------------------
750 * Public functions
751 *--------------------------------------------------------------------------
753 void
754 DestroyTexturePanel(TexturePanel *panel)
760 void
761 ShowTexturePanel(TexturePanel *panel)
763 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
764 Screen *scr = DefaultScreenOfDisplay(dpy);
766 WMSetWindowUPosition(panel->win,
767 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
768 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
769 WMMapWidget(panel->win);
773 void
774 HideTexturePanel(TexturePanel *panel)
776 WMUnmapWidget(panel->win);
780 void
781 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
783 panel->okAction = action;
784 panel->okData = clientData;
788 void
789 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
791 panel->cancelAction = action;
792 panel->cancelData = clientData;
796 void
797 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
799 WMScreen *scr = WMWidgetScreen(panel->win);
800 char *str, *type;
801 proplist_t p;
802 WMColor *color;
803 int i;
804 char buffer[64];
805 int gradient = 0;
807 WMSetTextFieldText(panel->nameT, name);
809 if (!texture)
810 return;
812 p = PLGetArrayElement(texture, 0);
813 if (!p) {
814 goto bad_texture;
816 type = PLGetString(p);
818 /*...............................................*/
819 if (strcasecmp(type, "solid")==0) {
821 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
823 p = PLGetArrayElement(texture, 1);
824 if (!p) {
825 str = "black";
826 } else {
827 str = PLGetString(p);
829 color = WMCreateNamedColor(scr, str, False);
831 WMSetColorWellColor(panel->defcW, color);
833 WMReleaseColor(color);
834 /*...............................................*/
835 } else if (strcasecmp(type, "hgradient")==0
836 || strcasecmp(type, "vgradient")==0
837 || strcasecmp(type, "dgradient")==0) {
839 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
841 p = PLGetArrayElement(texture, 1);
842 if (!p) {
843 str = "black";
844 } else {
845 str = PLGetString(p);
847 color = WMCreateNamedColor(scr, str, False);
849 WMSetColorWellColor(panel->tcol1W, color);
851 WMReleaseColor(color);
853 p = PLGetArrayElement(texture, 2);
854 if (!p) {
855 str = "black";
856 } else {
857 str = PLGetString(p);
859 color = WMCreateNamedColor(scr, str, False);
861 WMSetColorWellColor(panel->tcol2W, color);
863 WMReleaseColor(color);
865 gradient = type[0];
866 /*...............................................*/
867 } else if (strcasecmp(type, "thgradient")==0
868 || strcasecmp(type, "tvgradient")==0
869 || strcasecmp(type, "tdgradient")==0) {
870 int i;
872 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
874 gradient = type[1];
876 WMSetTextFieldText(panel->imageT,
877 PLGetString(PLGetArrayElement(texture, 1)));
878 if (panel->imageFile)
879 free(panel->imageFile);
880 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
883 i = 180;
884 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
885 WMSetSliderValue(panel->topaS, i);
887 p = PLGetArrayElement(texture, 3);
888 if (!p) {
889 str = "black";
890 } else {
891 str = PLGetString(p);
893 color = WMCreateNamedColor(scr, str, False);
895 WMSetColorWellColor(panel->tcol1W, color);
897 WMReleaseColor(color);
899 p = PLGetArrayElement(texture, 4);
900 if (!p) {
901 str = "black";
902 } else {
903 str = PLGetString(p);
905 color = WMCreateNamedColor(scr, str, False);
907 WMSetColorWellColor(panel->tcol2W, color);
909 WMReleaseColor(color);
911 WMSetTextFieldText(panel->imageT,
912 PLGetString(PLGetArrayElement(texture, 1)));
914 if (panel->imageFile)
915 free(panel->imageFile);
916 panel->imageFile = wfindfileinarray(panel->pathList,
917 PLGetString(PLGetArrayElement(texture, 1)));
919 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
920 updateTGradImage(panel);
922 updateSGradButtons(panel);
924 /*...............................................*/
925 } else if (strcasecmp(type, "mhgradient")==0
926 || strcasecmp(type, "mvgradient")==0
927 || strcasecmp(type, "mdgradient")==0) {
928 WMListItem *item;
930 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
931 item = WMGetListItem(panel->gcolL, i);
932 free(item->clientData);
934 WMClearList(panel->gcolL);
936 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
938 p = PLGetArrayElement(texture, 1);
939 if (!p) {
940 str = "black";
941 } else {
942 str = PLGetString(p);
944 color = WMCreateNamedColor(scr, str, False);
946 WMSetColorWellColor(panel->defcW, color);
948 WMReleaseColor(color);
950 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
951 RColor *rgb;
952 XColor xcolor;
954 p = PLGetArrayElement(texture, i);
955 if (!p) {
956 str = "black";
957 } else {
958 str = PLGetString(p);
961 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
962 str, &xcolor);
964 rgb = wmalloc(sizeof(RColor));
965 rgb->red = xcolor.red >> 8;
966 rgb->green = xcolor.green >> 8;
967 rgb->blue = xcolor.blue >> 8;
968 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
970 item = WMAddListItem(panel->gcolL, buffer);
971 item->clientData = rgb;
974 sliderChangeCallback(panel->ghueS, panel);
976 gradient = type[1];
977 /*...............................................*/
978 } else if (strcasecmp(type, "cpixmap")==0
979 || strcasecmp(type, "spixmap")==0
980 || strcasecmp(type, "mpixmap")==0
981 || strcasecmp(type, "tpixmap")==0) {
983 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
985 switch (toupper(type[0])) {
986 case 'C':
987 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
988 break;
989 case 'S':
990 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
991 break;
992 case 'M':
993 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
994 break;
995 default:
996 case 'T':
997 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
998 break;
1001 WMSetTextFieldText(panel->imageT,
1002 PLGetString(PLGetArrayElement(texture, 1)));
1004 if (panel->imageFile)
1005 free(panel->imageFile);
1006 panel->imageFile = wfindfileinarray(panel->pathList,
1007 PLGetString(PLGetArrayElement(texture, 1)));
1009 color = WMCreateNamedColor(scr,
1010 PLGetString(PLGetArrayElement(texture, 2)), False);
1011 WMSetColorWellColor(panel->defcW, color);
1012 WMReleaseColor(color);
1014 updateImage(panel, panel->imageFile);
1017 changeTypeCallback(panel->typeP, panel);
1019 if (gradient > 0) {
1020 updateGradButtons(panel);
1022 switch (toupper(gradient)) {
1023 case 'H':
1024 WMPerformButtonClick(panel->dirhB);
1025 break;
1026 case 'V':
1027 WMPerformButtonClick(panel->dirvB);
1028 break;
1029 default:
1030 case 'D':
1031 WMPerformButtonClick(panel->dirdB);
1032 break;
1036 return;
1038 bad_texture:
1039 str = PLGetDescription(texture);
1040 wwarning("error creating texture %s", str);
1041 free(str);
1047 char*
1048 GetTexturePanelTextureName(TexturePanel *panel)
1050 return WMGetTextFieldText(panel->nameT);
1056 proplist_t
1057 GetTexturePanelTexture(TexturePanel *panel)
1059 proplist_t prop = NULL;
1060 WMColor *color;
1061 char *str, *str2;
1062 char buff[32];
1063 int i;
1066 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1068 case TYPE_SOLID:
1069 color = WMGetColorWellColor(panel->defcW);
1070 str = WMGetColorRGBDescription(color);
1071 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1072 PLMakeString(str), NULL);
1073 free(str);
1075 break;
1077 case TYPE_PIXMAP:
1078 color = WMGetColorWellColor(panel->defcW);
1079 str = WMGetColorRGBDescription(color);
1081 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1082 case PTYPE_SCALE:
1083 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1084 PLMakeString(panel->imageFile),
1085 PLMakeString(str), NULL);
1086 break;
1087 case PTYPE_MAXIMIZE:
1088 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1089 PLMakeString(panel->imageFile),
1090 PLMakeString(str), NULL);
1091 break;
1092 case PTYPE_CENTER:
1093 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1094 PLMakeString(panel->imageFile),
1095 PLMakeString(str), NULL);
1096 break;
1097 case PTYPE_TILE:
1098 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1099 PLMakeString(panel->imageFile),
1100 PLMakeString(str), NULL);
1101 break;
1103 free(str);
1104 break;
1106 case TYPE_TGRADIENT:
1107 color = WMGetColorWellColor(panel->tcol1W);
1108 str = WMGetColorRGBDescription(color);
1110 color = WMGetColorWellColor(panel->tcol2W);
1111 str2 = WMGetColorRGBDescription(color);
1113 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1115 if (WMGetButtonSelected(panel->dirdB)) {
1116 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1117 PLMakeString(panel->imageFile),
1118 PLMakeString(buff),
1119 PLMakeString(str),
1120 PLMakeString(str2), NULL);
1121 } else if (WMGetButtonSelected(panel->dirvB)) {
1122 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1123 PLMakeString(panel->imageFile),
1124 PLMakeString(buff),
1125 PLMakeString(str),
1126 PLMakeString(str2), NULL);
1127 } else {
1128 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1129 PLMakeString(panel->imageFile),
1130 PLMakeString(buff),
1131 PLMakeString(str),
1132 PLMakeString(str2), NULL);
1134 free(str);
1135 free(str2);
1136 break;
1139 case TYPE_SGRADIENT:
1140 color = WMGetColorWellColor(panel->tcol1W);
1141 str = WMGetColorRGBDescription(color);
1143 color = WMGetColorWellColor(panel->tcol2W);
1144 str2 = WMGetColorRGBDescription(color);
1146 if (WMGetButtonSelected(panel->dirdB)) {
1147 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1148 PLMakeString(str),
1149 PLMakeString(str2), NULL);
1150 } else if (WMGetButtonSelected(panel->dirvB)) {
1151 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1152 PLMakeString(str),
1153 PLMakeString(str2), NULL);
1154 } else {
1155 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1156 PLMakeString(str),
1157 PLMakeString(str2), NULL);
1159 free(str);
1160 free(str2);
1161 break;
1163 case TYPE_GRADIENT:
1164 color = WMGetColorWellColor(panel->defcW);
1165 str = WMGetColorRGBDescription(color);
1167 if (WMGetButtonSelected(panel->dirdB)) {
1168 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1169 PLMakeString(str), NULL);
1170 } else if (WMGetButtonSelected(panel->dirvB)) {
1171 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1172 PLMakeString(str), NULL);
1173 } else {
1174 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1175 PLMakeString(str), NULL);
1177 free(str);
1179 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1180 RColor *rgb;
1181 WMListItem *item;
1183 item = WMGetListItem(panel->gcolL, i);
1185 rgb = (RColor*)item->clientData;
1187 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1189 PLAppendArrayElement(prop, PLMakeString(buff));
1191 break;
1195 return prop;
1200 void
1201 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1203 panel->pathList = array;
1208 TexturePanel*
1209 CreateTexturePanel(WMWindow *keyWindow)
1210 /*CreateTexturePanel(WMScreen *scr)*/
1212 TexturePanel *panel;
1213 WMScreen *scr = WMWidgetScreen(keyWindow);
1215 panel = wmalloc(sizeof(TexturePanel));
1216 memset(panel, 0, sizeof(TexturePanel));
1218 panel->listFont = WMSystemFontOfSize(scr, 12);
1221 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1222 WMTitledWindowMask
1223 |WMClosableWindowMask);
1225 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1226 WMTitledWindowMask
1227 |WMClosableWindowMask);
1230 WMResizeWidget(panel->win, 325, 423);
1231 WMSetWindowTitle(panel->win, _("Texture Panel"));
1232 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1235 /* texture name */
1236 panel->nameF = WMCreateFrame(panel->win);
1237 WMResizeWidget(panel->nameF, 185, 50);
1238 WMMoveWidget(panel->nameF, 15, 10);
1239 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1241 panel->nameT = WMCreateTextField(panel->nameF);
1242 WMResizeWidget(panel->nameT, 160, 20);
1243 WMMoveWidget(panel->nameT, 12, 18);
1245 WMMapSubwidgets(panel->nameF);
1247 /* texture types */
1248 panel->typeP = WMCreatePopUpButton(panel->win);
1249 WMResizeWidget(panel->typeP, 185, 20);
1250 WMMoveWidget(panel->typeP, 15, 65);
1251 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1252 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1253 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1254 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1255 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1256 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1257 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1259 /* color */
1260 panel->defcF = WMCreateFrame(panel->win);
1261 WMResizeWidget(panel->defcF, 100, 75);
1262 WMMoveWidget(panel->defcF, 210, 10);
1263 WMSetFrameTitle(panel->defcF, _("Default Color"));
1265 panel->defcW = WMCreateColorWell(panel->defcF);
1266 WMResizeWidget(panel->defcW, 60, 45);
1267 WMMoveWidget(panel->defcW, 20, 20);
1269 WMMapSubwidgets(panel->defcF);
1271 /****** Gradient ******/
1272 panel->gcolF = WMCreateFrame(panel->win);
1273 WMResizeWidget(panel->gcolF, 295, 205);
1274 WMMoveWidget(panel->gcolF, 15, 95);
1275 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1277 panel->gcolL = WMCreateList(panel->gcolF);
1278 WMResizeWidget(panel->gcolL, 130, 140);
1279 WMMoveWidget(panel->gcolL, 10, 25);
1280 WMHangData(panel->gcolL, panel);
1281 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1282 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1284 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1285 WMResizeWidget(panel->gcolaB, 64, 24);
1286 WMMoveWidget(panel->gcolaB, 10, 170);
1287 WMSetButtonText(panel->gcolaB, _("Add"));
1288 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1290 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1291 WMResizeWidget(panel->gcoldB, 64, 24);
1292 WMMoveWidget(panel->gcoldB, 75, 170);
1293 WMSetButtonText(panel->gcoldB, _("Delete"));
1294 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1296 #if 0
1297 panel->gbriS = WMCreateSlider(panel->gcolF);
1298 WMResizeWidget(panel->gbriS, 130, 16);
1299 WMMoveWidget(panel->gbriS, 150, 25);
1300 WMSetSliderKnobThickness(panel->gbriS, 8);
1301 WMSetSliderMaxValue(panel->gbriS, 100);
1302 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1304 WMPixmap *pixmap;
1305 WMColor *color;
1307 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1308 color = WMDarkGrayColor(scr);
1309 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1310 WMColorGC(color), 0, 0, 130, 16);
1311 WMReleaseColor(color);
1312 color = WMWhiteColor(color);
1313 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1314 panel->listFont, 2,
1315 (16 - WMFontHeight(panel->listFont))/2 - 1,
1316 "Brightness", 10);
1317 WMSetSliderImage(panel->gbriS, pixmap);
1318 WMReleasePixmap(pixmap);
1321 panel->gconS = WMCreateSlider(panel->gcolF);
1322 WMResizeWidget(panel->gconS, 130, 16);
1323 WMMoveWidget(panel->gconS, 150, 50);
1324 WMSetSliderKnobThickness(panel->gconS, 8);
1325 WMSetSliderMaxValue(panel->gconS, 100);
1326 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1328 WMPixmap *pixmap;
1329 WMColor *color;
1331 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1332 color = WMDarkGrayColor(scr);
1333 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1334 WMColorGC(color), 0, 0, 130, 16);
1335 WMReleaseColor(color);
1336 color = WMWhiteColor(scr);
1337 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1338 panel->listFont, 2,
1339 (16 - WMFontHeight(panel->listFont))/2 - 1,
1340 "Contrast", 8);
1341 WMSetSliderImage(panel->gconS, pixmap);
1342 WMReleasePixmap(pixmap);
1344 #endif
1345 panel->ghueS = WMCreateSlider(panel->gcolF);
1346 WMResizeWidget(panel->ghueS, 130, 16);
1347 WMMoveWidget(panel->ghueS, 150, 100);
1348 WMSetSliderKnobThickness(panel->ghueS, 8);
1349 WMSetSliderMaxValue(panel->ghueS, 359);
1350 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1352 panel->gsatS = WMCreateSlider(panel->gcolF);
1353 WMResizeWidget(panel->gsatS, 130, 16);
1354 WMMoveWidget(panel->gsatS, 150, 125);
1355 WMSetSliderKnobThickness(panel->gsatS, 8);
1356 WMSetSliderMaxValue(panel->gsatS, 255);
1357 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1359 panel->gvalS = WMCreateSlider(panel->gcolF);
1360 WMResizeWidget(panel->gvalS, 130, 16);
1361 WMMoveWidget(panel->gvalS, 150, 150);
1362 WMSetSliderKnobThickness(panel->gvalS, 8);
1363 WMSetSliderMaxValue(panel->gvalS, 255);
1364 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1367 WMMapSubwidgets(panel->gcolF);
1369 /** Direction **/
1370 panel->dirF = WMCreateFrame(panel->win);
1371 WMSetFrameTitle(panel->dirF, _("Direction"));
1372 WMResizeWidget(panel->dirF, 295, 75);
1373 WMMoveWidget(panel->dirF, 15, 305);
1375 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1376 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1377 WMResizeWidget(panel->dirvB, 90, 40);
1378 WMMoveWidget(panel->dirvB, 10, 20);
1380 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1381 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1382 WMResizeWidget(panel->dirhB, 90, 40);
1383 WMMoveWidget(panel->dirhB, 102, 20);
1385 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1386 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1387 WMResizeWidget(panel->dirdB, 90, 40);
1388 WMMoveWidget(panel->dirdB, 194, 20);
1390 WMGroupButtons(panel->dirvB, panel->dirhB);
1391 WMGroupButtons(panel->dirvB, panel->dirdB);
1393 WMMapSubwidgets(panel->dirF);
1395 /****************** Textured Gradient ******************/
1396 panel->tcolF = WMCreateFrame(panel->win);
1397 WMResizeWidget(panel->tcolF, 100, 135);
1398 WMMoveWidget(panel->tcolF, 210, 10);
1399 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1401 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1402 WMResizeWidget(panel->tcol1W, 60, 45);
1403 WMMoveWidget(panel->tcol1W, 20, 25);
1404 WMAddNotificationObserver(colorWellObserver, panel,
1405 WMColorWellDidChangeNotification, panel->tcol1W);
1407 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1408 WMResizeWidget(panel->tcol2W, 60, 45);
1409 WMMoveWidget(panel->tcol2W, 20, 75);
1410 WMAddNotificationObserver(colorWellObserver, panel,
1411 WMColorWellDidChangeNotification, panel->tcol2W);
1413 /** Opacity */
1414 panel->topaF = WMCreateFrame(panel->win);
1415 WMResizeWidget(panel->topaF, 185, 50);
1416 WMMoveWidget(panel->topaF, 15, 95);
1417 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1419 panel->topaS = WMCreateSlider(panel->topaF);
1420 WMResizeWidget(panel->topaS, 155, 18);
1421 WMMoveWidget(panel->topaS, 15, 20);
1422 WMSetSliderMaxValue(panel->topaS, 255);
1423 WMSetSliderValue(panel->topaS, 200);
1424 WMSetSliderContinuous(panel->topaS, False);
1425 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1427 WMMapSubwidgets(panel->topaF);
1430 WMPixmap *pixmap;
1431 Pixmap p;
1432 WMColor *color;
1434 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1435 p = WMGetPixmapXID(pixmap);
1437 color = WMDarkGrayColor(scr);
1438 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1439 0, 0, 155, 18);
1440 WMReleaseColor(color);
1442 color = WMWhiteColor(scr);
1443 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1444 2, 1, "0%", 2);
1445 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1446 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1447 "100%", 4);
1448 WMReleaseColor(color);
1450 WMSetSliderImage(panel->topaS, pixmap);
1451 WMReleasePixmap(pixmap);
1454 WMMapSubwidgets(panel->tcolF);
1456 /****************** Image ******************/
1457 panel->imageF = WMCreateFrame(panel->win);
1458 WMResizeWidget(panel->imageF, 295, 150);
1459 WMMoveWidget(panel->imageF, 15, 150);
1460 WMSetFrameTitle(panel->imageF, _("Image"));
1462 panel->imageL = WMCreateLabel(panel->imageF);
1463 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1465 panel->imageT = WMCreateTextField(panel->imageF);
1466 WMResizeWidget(panel->imageT, 90, 20);
1467 WMMoveWidget(panel->imageT, 190, 25);
1469 panel->imageV = WMCreateScrollView(panel->imageF);
1470 WMResizeWidget(panel->imageV, 165, 115);
1471 WMMoveWidget(panel->imageV, 15, 20);
1472 WMSetScrollViewRelief(panel->imageV, WRSunken);
1473 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1474 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1475 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1477 panel->browB = WMCreateCommandButton(panel->imageF);
1478 WMResizeWidget(panel->browB, 90, 24);
1479 WMMoveWidget(panel->browB, 190, 50);
1480 WMSetButtonText(panel->browB, _("Browse..."));
1481 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1483 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1484 WMResizeWidget(panel->dispB, 90, 24);
1485 WMMoveWidget(panel->dispB, 190, 80);
1486 WMSetButtonText(panel->dispB, _("Show"));
1489 panel->arrP = WMCreatePopUpButton(panel->imageF);
1490 WMResizeWidget(panel->arrP, 90, 20);
1491 WMMoveWidget(panel->arrP, 190, 120);
1492 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1493 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1494 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1495 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1496 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1498 WMMapSubwidgets(panel->imageF);
1500 /****/
1502 panel->okB = WMCreateCommandButton(panel->win);
1503 WMResizeWidget(panel->okB, 84, 24);
1504 WMMoveWidget(panel->okB, 225, 390);
1505 WMSetButtonText(panel->okB, _("OK"));
1506 WMSetButtonAction(panel->okB, buttonCallback, panel);
1508 panel->cancelB = WMCreateCommandButton(panel->win);
1509 WMResizeWidget(panel->cancelB, 84, 24);
1510 WMMoveWidget(panel->cancelB, 130, 390);
1511 WMSetButtonText(panel->cancelB, _("Cancel"));
1512 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1514 WMMapWidget(panel->nameF);
1515 WMMapWidget(panel->typeP);
1516 WMMapWidget(panel->okB);
1517 WMMapWidget(panel->cancelB);
1519 WMUnmapWidget(panel->arrP);
1521 WMRealizeWidget(panel->win);
1523 panel->currentType = -1;
1525 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1527 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1528 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1529 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1531 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1532 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1534 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1535 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1536 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1537 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1538 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1540 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1541 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1542 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1545 /* setup for first time */
1547 changeTypeCallback(panel->typeP, panel);
1549 sliderChangeCallback(panel->ghueS, panel);
1550 sliderChangeCallback(panel->gsatS, panel);
1552 return panel;
1558 *--------------------------------------------------------------------------
1559 * Test stuff
1560 *--------------------------------------------------------------------------
1563 #if 0
1565 char *ProgName = "test";
1567 void
1568 testOKButton(WMWidget *self, void *data)
1570 char *test;
1571 Display *dpy;
1572 Window win;
1573 Pixmap pix;
1574 RImage *image;
1576 TexturePanel *panel = (TexturePanel*)data;
1577 /* test = GetTexturePanelTextureString(panel); */
1579 wwarning(test);
1581 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1582 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1583 0, 0, 0);
1584 XMapRaised(dpy, win);
1585 XFlush(dpy);
1587 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1589 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1591 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1592 0, 0);
1594 free (test);
1598 void testCancelButton(WMWidget *self, void *data){
1599 wwarning("Exiting test....");
1600 exit(0);
1603 void wAbort()
1605 exit(1);
1608 int main(int argc, char **argv)
1610 TexturePanel *panel;
1612 Display *dpy = XOpenDisplay("");
1613 WMScreen *scr;
1615 /* char *test; */
1617 WMInitializeApplication("Test", &argc, argv);
1619 if (!dpy) {
1620 wfatal("could not open display");
1621 exit(1);
1624 scr = WMCreateSimpleApplicationScreen(dpy);
1626 panel = CreateTexturePanel(scr);
1628 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1629 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1631 SetTexturePanelTexture(panel, "pinky",
1632 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1634 ShowTexturePanel(panel);
1636 WMScreenMainLoop(scr);
1637 return 0;
1639 #endif