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