- renamed wstrappend() to wstrconcat().
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob6ccf7d20cc32c68f15fae9f19ce1234e327cc620
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 wfree(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 wfree(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 wfree(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 wfree(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 = wstrconcat(_("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);
614 wfree(message);
615 return;
618 WMSetButtonEnabled(panel->okB, True);
620 if (panel->image)
621 RDestroyImage(panel->image);
622 panel->image = image;
623 } else {
624 image = panel->image;
627 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
628 if (image) {
629 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
631 size = WMGetPixmapSize(pixmap);
632 WMSetLabelImage(panel->imageL, pixmap);
633 WMResizeWidget(panel->imageL, size.width, size.height);
635 WMReleasePixmap(pixmap);
637 } else {
638 updateTGradImage(panel);
643 static void
644 browseImageCallback(WMWidget *w, void *data)
646 TexturePanel *panel = (TexturePanel*)data;
647 WMOpenPanel *opanel;
648 WMScreen *scr = WMWidgetScreen(w);
649 static char *ipath = NULL;
651 opanel = WMGetOpenPanel(scr);
652 WMSetFilePanelCanChooseDirectories(opanel, False);
653 WMSetFilePanelCanChooseFiles(opanel, True);
655 if (!ipath)
656 ipath = wstrdup(wgethomedir());
658 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
659 "Open Image", NULL)) {
660 char *path, *fullpath;
661 char *tmp, *tmp2;
663 tmp = WMGetFilePanelFileName(opanel);
664 if (!tmp)
665 return;
666 fullpath = tmp;
668 wfree(ipath);
669 ipath = fullpath;
671 path = wstrdup(fullpath);
673 tmp2 = strrchr(fullpath, '/');
674 if (tmp2)
675 tmp2++;
677 tmp = wfindfileinarray(panel->pathList, tmp2);
679 if (tmp) {
680 if (strcmp(fullpath, tmp)==0) {
681 wfree(path);
682 path = tmp2;
684 wfree(tmp);
687 if (!RGetImageFileFormat(fullpath)) {
688 WMRunAlertPanel(scr, panel->win, _("Error"),
689 _("The selected file does not contain a supported image."),
690 _("OK"), NULL, NULL);
691 wfree(path);
692 } else {
693 updateImage(panel, fullpath);
694 wfree(panel->imageFile);
695 panel->imageFile = path;
697 WMSetTextFieldText(panel->imageT, path);
704 static void
705 buttonCallback(WMWidget *w, void *data)
707 TexturePanel *panel = (TexturePanel*)data;
709 if (w == panel->okB) {
710 (*panel->okAction)(panel->okData);
711 } else {
712 (*panel->cancelAction)(panel->cancelData);
718 static void
719 changeTypeCallback(WMWidget *w, void *data)
721 TexturePanel *panel = (TexturePanel*)data;
722 int newType;
723 int i;
725 newType = WMGetPopUpButtonSelectedItem(w);
726 if (newType == panel->currentType)
727 return;
729 if (panel->currentType >= 0) {
730 for (i = 0; i < MAX_SECTION_PARTS; i++) {
731 if (panel->sectionParts[panel->currentType][i] == NULL)
732 break;
733 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
737 for (i = 0; i < MAX_SECTION_PARTS; i++) {
738 if (panel->sectionParts[newType][i] == NULL)
739 break;
740 WMMapWidget(panel->sectionParts[newType][i]);
742 panel->currentType = newType;
744 switch (newType) {
745 case TYPE_SGRADIENT:
746 updateSGradButtons(panel);
747 WMSetButtonEnabled(panel->okB, True);
748 break;
749 case TYPE_GRADIENT:
750 updateGradButtons(panel);
751 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
752 break;
753 case TYPE_TGRADIENT:
754 case TYPE_PIXMAP:
755 updateImage(panel, NULL);
756 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
757 break;
758 default:
759 WMSetButtonEnabled(panel->okB, True);
760 break;
766 *--------------------------------------------------------------------------
767 * Public functions
768 *--------------------------------------------------------------------------
770 void
771 DestroyTexturePanel(TexturePanel *panel)
777 void
778 ShowTexturePanel(TexturePanel *panel)
780 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
781 Screen *scr = DefaultScreenOfDisplay(dpy);
783 WMSetWindowInitialPosition(panel->win,
784 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
785 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
786 WMMapWidget(panel->win);
790 void
791 HideTexturePanel(TexturePanel *panel)
793 WMUnmapWidget(panel->win);
797 void
798 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
800 panel->okAction = action;
801 panel->okData = clientData;
805 void
806 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
808 panel->cancelAction = action;
809 panel->cancelData = clientData;
813 void
814 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
816 WMScreen *scr = WMWidgetScreen(panel->win);
817 char *str, *type;
818 proplist_t p;
819 WMColor *color;
820 int i;
821 char buffer[64];
822 int gradient = 0;
824 WMSetTextFieldText(panel->nameT, name);
826 if (!texture)
827 return;
829 p = PLGetArrayElement(texture, 0);
830 if (!p) {
831 goto bad_texture;
833 type = PLGetString(p);
835 /*...............................................*/
836 if (strcasecmp(type, "solid")==0) {
838 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
840 p = PLGetArrayElement(texture, 1);
841 if (!p) {
842 str = "black";
843 } else {
844 str = PLGetString(p);
846 color = WMCreateNamedColor(scr, str, False);
848 WMSetColorWellColor(panel->defcW, color);
850 WMReleaseColor(color);
851 /*...............................................*/
852 } else if (strcasecmp(type, "hgradient")==0
853 || strcasecmp(type, "vgradient")==0
854 || strcasecmp(type, "dgradient")==0) {
856 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
858 p = PLGetArrayElement(texture, 1);
859 if (!p) {
860 str = "black";
861 } else {
862 str = PLGetString(p);
864 color = WMCreateNamedColor(scr, str, False);
866 WMSetColorWellColor(panel->tcol1W, color);
868 WMReleaseColor(color);
870 p = PLGetArrayElement(texture, 2);
871 if (!p) {
872 str = "black";
873 } else {
874 str = PLGetString(p);
876 color = WMCreateNamedColor(scr, str, False);
878 WMSetColorWellColor(panel->tcol2W, color);
880 WMReleaseColor(color);
882 gradient = type[0];
883 /*...............................................*/
884 } else if (strcasecmp(type, "thgradient")==0
885 || strcasecmp(type, "tvgradient")==0
886 || strcasecmp(type, "tdgradient")==0) {
887 int i;
889 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
891 gradient = type[1];
893 WMSetTextFieldText(panel->imageT,
894 PLGetString(PLGetArrayElement(texture, 1)));
895 if (panel->imageFile)
896 wfree(panel->imageFile);
897 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
900 i = 180;
901 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
902 WMSetSliderValue(panel->topaS, i);
904 p = PLGetArrayElement(texture, 3);
905 if (!p) {
906 str = "black";
907 } else {
908 str = PLGetString(p);
910 color = WMCreateNamedColor(scr, str, False);
912 WMSetColorWellColor(panel->tcol1W, color);
914 WMReleaseColor(color);
916 p = PLGetArrayElement(texture, 4);
917 if (!p) {
918 str = "black";
919 } else {
920 str = PLGetString(p);
922 color = WMCreateNamedColor(scr, str, False);
924 WMSetColorWellColor(panel->tcol2W, color);
926 WMReleaseColor(color);
928 WMSetTextFieldText(panel->imageT,
929 PLGetString(PLGetArrayElement(texture, 1)));
931 if (panel->imageFile)
932 wfree(panel->imageFile);
933 if ((panel->imageFile = wfindfileinarray(panel->pathList,
934 PLGetString(PLGetArrayElement(texture, 1)))) != NULL) {
936 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
937 updateTGradImage(panel);
939 updateSGradButtons(panel);
940 } else wwarning("could not load file '%s': %s", panel->imageFile,
941 RMessageForError(RErrorCode));
943 /*...............................................*/
944 } else if (strcasecmp(type, "mhgradient")==0
945 || strcasecmp(type, "mvgradient")==0
946 || strcasecmp(type, "mdgradient")==0) {
947 WMListItem *item;
949 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
950 item = WMGetListItem(panel->gcolL, i);
951 wfree(item->clientData);
953 WMClearList(panel->gcolL);
955 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
957 p = PLGetArrayElement(texture, 1);
958 if (!p) {
959 str = "black";
960 } else {
961 str = PLGetString(p);
963 color = WMCreateNamedColor(scr, str, False);
965 WMSetColorWellColor(panel->defcW, color);
967 WMReleaseColor(color);
969 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
970 RColor *rgb;
971 XColor xcolor;
973 p = PLGetArrayElement(texture, i);
974 if (!p) {
975 str = "black";
976 } else {
977 str = PLGetString(p);
980 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
981 str, &xcolor);
983 rgb = wmalloc(sizeof(RColor));
984 rgb->red = xcolor.red >> 8;
985 rgb->green = xcolor.green >> 8;
986 rgb->blue = xcolor.blue >> 8;
987 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
989 item = WMAddListItem(panel->gcolL, buffer);
990 item->clientData = rgb;
993 sliderChangeCallback(panel->ghueS, panel);
995 gradient = type[1];
996 /*...............................................*/
997 } else if (strcasecmp(type, "cpixmap")==0
998 || strcasecmp(type, "spixmap")==0
999 || strcasecmp(type, "mpixmap")==0
1000 || strcasecmp(type, "tpixmap")==0) {
1002 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1004 switch (toupper(type[0])) {
1005 case 'C':
1006 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1007 break;
1008 case 'S':
1009 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1010 break;
1011 case 'M':
1012 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1013 break;
1014 default:
1015 case 'T':
1016 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1017 break;
1020 WMSetTextFieldText(panel->imageT,
1021 PLGetString(PLGetArrayElement(texture, 1)));
1023 if (panel->imageFile)
1024 wfree(panel->imageFile);
1025 panel->imageFile = wfindfileinarray(panel->pathList,
1026 PLGetString(PLGetArrayElement(texture, 1)));
1028 color = WMCreateNamedColor(scr,
1029 PLGetString(PLGetArrayElement(texture, 2)), False);
1030 WMSetColorWellColor(panel->defcW, color);
1031 WMReleaseColor(color);
1033 updateImage(panel, panel->imageFile);
1036 changeTypeCallback(panel->typeP, panel);
1038 if (gradient > 0) {
1039 updateGradButtons(panel);
1041 switch (toupper(gradient)) {
1042 case 'H':
1043 WMPerformButtonClick(panel->dirhB);
1044 break;
1045 case 'V':
1046 WMPerformButtonClick(panel->dirvB);
1047 break;
1048 default:
1049 case 'D':
1050 WMPerformButtonClick(panel->dirdB);
1051 break;
1055 return;
1057 bad_texture:
1058 str = PLGetDescription(texture);
1059 wwarning("error creating texture %s", str);
1060 wfree(str);
1066 char*
1067 GetTexturePanelTextureName(TexturePanel *panel)
1069 return WMGetTextFieldText(panel->nameT);
1075 proplist_t
1076 GetTexturePanelTexture(TexturePanel *panel)
1078 proplist_t prop = NULL;
1079 WMColor *color;
1080 char *str, *str2;
1081 char buff[32];
1082 int i;
1085 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1087 case TYPE_SOLID:
1088 color = WMGetColorWellColor(panel->defcW);
1089 str = WMGetColorRGBDescription(color);
1090 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1091 PLMakeString(str), NULL);
1092 wfree(str);
1094 break;
1096 case TYPE_PIXMAP:
1097 color = WMGetColorWellColor(panel->defcW);
1098 str = WMGetColorRGBDescription(color);
1100 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1101 case PTYPE_SCALE:
1102 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1103 PLMakeString(panel->imageFile),
1104 PLMakeString(str), NULL);
1105 break;
1106 case PTYPE_MAXIMIZE:
1107 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1108 PLMakeString(panel->imageFile),
1109 PLMakeString(str), NULL);
1110 break;
1111 case PTYPE_CENTER:
1112 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1113 PLMakeString(panel->imageFile),
1114 PLMakeString(str), NULL);
1115 break;
1116 case PTYPE_TILE:
1117 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1118 PLMakeString(panel->imageFile),
1119 PLMakeString(str), NULL);
1120 break;
1122 wfree(str);
1123 break;
1125 case TYPE_TGRADIENT:
1126 color = WMGetColorWellColor(panel->tcol1W);
1127 str = WMGetColorRGBDescription(color);
1129 color = WMGetColorWellColor(panel->tcol2W);
1130 str2 = WMGetColorRGBDescription(color);
1132 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1134 if (WMGetButtonSelected(panel->dirdB)) {
1135 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1136 PLMakeString(panel->imageFile),
1137 PLMakeString(buff),
1138 PLMakeString(str),
1139 PLMakeString(str2), NULL);
1140 } else if (WMGetButtonSelected(panel->dirvB)) {
1141 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1142 PLMakeString(panel->imageFile),
1143 PLMakeString(buff),
1144 PLMakeString(str),
1145 PLMakeString(str2), NULL);
1146 } else {
1147 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1148 PLMakeString(panel->imageFile),
1149 PLMakeString(buff),
1150 PLMakeString(str),
1151 PLMakeString(str2), NULL);
1153 wfree(str);
1154 wfree(str2);
1155 break;
1158 case TYPE_SGRADIENT:
1159 color = WMGetColorWellColor(panel->tcol1W);
1160 str = WMGetColorRGBDescription(color);
1162 color = WMGetColorWellColor(panel->tcol2W);
1163 str2 = WMGetColorRGBDescription(color);
1165 if (WMGetButtonSelected(panel->dirdB)) {
1166 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1167 PLMakeString(str),
1168 PLMakeString(str2), NULL);
1169 } else if (WMGetButtonSelected(panel->dirvB)) {
1170 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1171 PLMakeString(str),
1172 PLMakeString(str2), NULL);
1173 } else {
1174 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1175 PLMakeString(str),
1176 PLMakeString(str2), NULL);
1178 wfree(str);
1179 wfree(str2);
1180 break;
1182 case TYPE_GRADIENT:
1183 color = WMGetColorWellColor(panel->defcW);
1184 str = WMGetColorRGBDescription(color);
1186 if (WMGetButtonSelected(panel->dirdB)) {
1187 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1188 PLMakeString(str), NULL);
1189 } else if (WMGetButtonSelected(panel->dirvB)) {
1190 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1191 PLMakeString(str), NULL);
1192 } else {
1193 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1194 PLMakeString(str), NULL);
1196 wfree(str);
1198 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1199 RColor *rgb;
1200 WMListItem *item;
1202 item = WMGetListItem(panel->gcolL, i);
1204 rgb = (RColor*)item->clientData;
1206 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1208 PLAppendArrayElement(prop, PLMakeString(buff));
1210 break;
1214 return prop;
1219 void
1220 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1222 panel->pathList = array;
1227 TexturePanel*
1228 CreateTexturePanel(WMWindow *keyWindow)
1229 /*CreateTexturePanel(WMScreen *scr)*/
1231 TexturePanel *panel;
1232 WMScreen *scr = WMWidgetScreen(keyWindow);
1234 panel = wmalloc(sizeof(TexturePanel));
1235 memset(panel, 0, sizeof(TexturePanel));
1237 panel->listFont = WMSystemFontOfSize(scr, 12);
1240 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1241 WMTitledWindowMask
1242 |WMClosableWindowMask);
1244 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1245 WMTitledWindowMask
1246 |WMClosableWindowMask);
1249 WMResizeWidget(panel->win, 325, 423);
1250 WMSetWindowTitle(panel->win, _("Texture Panel"));
1251 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1254 /* texture name */
1255 panel->nameF = WMCreateFrame(panel->win);
1256 WMResizeWidget(panel->nameF, 185, 50);
1257 WMMoveWidget(panel->nameF, 15, 10);
1258 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1260 panel->nameT = WMCreateTextField(panel->nameF);
1261 WMResizeWidget(panel->nameT, 160, 20);
1262 WMMoveWidget(panel->nameT, 12, 18);
1264 WMMapSubwidgets(panel->nameF);
1266 /* texture types */
1267 panel->typeP = WMCreatePopUpButton(panel->win);
1268 WMResizeWidget(panel->typeP, 185, 20);
1269 WMMoveWidget(panel->typeP, 15, 65);
1270 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1271 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1272 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1273 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1274 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1275 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1276 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1278 /* color */
1279 panel->defcF = WMCreateFrame(panel->win);
1280 WMResizeWidget(panel->defcF, 100, 75);
1281 WMMoveWidget(panel->defcF, 210, 10);
1282 WMSetFrameTitle(panel->defcF, _("Default Color"));
1284 panel->defcW = WMCreateColorWell(panel->defcF);
1285 WMResizeWidget(panel->defcW, 60, 45);
1286 WMMoveWidget(panel->defcW, 20, 20);
1288 WMMapSubwidgets(panel->defcF);
1290 /****** Gradient ******/
1291 panel->gcolF = WMCreateFrame(panel->win);
1292 WMResizeWidget(panel->gcolF, 295, 205);
1293 WMMoveWidget(panel->gcolF, 15, 95);
1294 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1296 panel->gcolL = WMCreateList(panel->gcolF);
1297 WMResizeWidget(panel->gcolL, 130, 140);
1298 WMMoveWidget(panel->gcolL, 10, 25);
1299 WMHangData(panel->gcolL, panel);
1300 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1301 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1303 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1304 WMResizeWidget(panel->gcolaB, 64, 24);
1305 WMMoveWidget(panel->gcolaB, 10, 170);
1306 WMSetButtonText(panel->gcolaB, _("Add"));
1307 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1309 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1310 WMResizeWidget(panel->gcoldB, 64, 24);
1311 WMMoveWidget(panel->gcoldB, 75, 170);
1312 WMSetButtonText(panel->gcoldB, _("Delete"));
1313 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1315 #if 0
1316 panel->gbriS = WMCreateSlider(panel->gcolF);
1317 WMResizeWidget(panel->gbriS, 130, 16);
1318 WMMoveWidget(panel->gbriS, 150, 25);
1319 WMSetSliderKnobThickness(panel->gbriS, 8);
1320 WMSetSliderMaxValue(panel->gbriS, 100);
1321 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1323 WMPixmap *pixmap;
1324 WMColor *color;
1326 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1327 color = WMDarkGrayColor(scr);
1328 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1329 WMColorGC(color), 0, 0, 130, 16);
1330 WMReleaseColor(color);
1331 color = WMWhiteColor(color);
1332 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1333 panel->listFont, 2,
1334 (16 - WMFontHeight(panel->listFont))/2 - 1,
1335 "Brightness", 10);
1336 WMSetSliderImage(panel->gbriS, pixmap);
1337 WMReleasePixmap(pixmap);
1340 panel->gconS = WMCreateSlider(panel->gcolF);
1341 WMResizeWidget(panel->gconS, 130, 16);
1342 WMMoveWidget(panel->gconS, 150, 50);
1343 WMSetSliderKnobThickness(panel->gconS, 8);
1344 WMSetSliderMaxValue(panel->gconS, 100);
1345 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1347 WMPixmap *pixmap;
1348 WMColor *color;
1350 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1351 color = WMDarkGrayColor(scr);
1352 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1353 WMColorGC(color), 0, 0, 130, 16);
1354 WMReleaseColor(color);
1355 color = WMWhiteColor(scr);
1356 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1357 panel->listFont, 2,
1358 (16 - WMFontHeight(panel->listFont))/2 - 1,
1359 "Contrast", 8);
1360 WMSetSliderImage(panel->gconS, pixmap);
1361 WMReleasePixmap(pixmap);
1363 #endif
1364 panel->ghueS = WMCreateSlider(panel->gcolF);
1365 WMResizeWidget(panel->ghueS, 130, 16);
1366 WMMoveWidget(panel->ghueS, 150, 100);
1367 WMSetSliderKnobThickness(panel->ghueS, 8);
1368 WMSetSliderMaxValue(panel->ghueS, 359);
1369 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1371 panel->gsatS = WMCreateSlider(panel->gcolF);
1372 WMResizeWidget(panel->gsatS, 130, 16);
1373 WMMoveWidget(panel->gsatS, 150, 125);
1374 WMSetSliderKnobThickness(panel->gsatS, 8);
1375 WMSetSliderMaxValue(panel->gsatS, 255);
1376 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1378 panel->gvalS = WMCreateSlider(panel->gcolF);
1379 WMResizeWidget(panel->gvalS, 130, 16);
1380 WMMoveWidget(panel->gvalS, 150, 150);
1381 WMSetSliderKnobThickness(panel->gvalS, 8);
1382 WMSetSliderMaxValue(panel->gvalS, 255);
1383 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1386 WMMapSubwidgets(panel->gcolF);
1388 /** Direction **/
1389 panel->dirF = WMCreateFrame(panel->win);
1390 WMSetFrameTitle(panel->dirF, _("Direction"));
1391 WMResizeWidget(panel->dirF, 295, 75);
1392 WMMoveWidget(panel->dirF, 15, 305);
1394 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1395 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1396 WMResizeWidget(panel->dirvB, 90, 40);
1397 WMMoveWidget(panel->dirvB, 10, 20);
1399 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1400 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1401 WMResizeWidget(panel->dirhB, 90, 40);
1402 WMMoveWidget(panel->dirhB, 102, 20);
1404 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1405 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1406 WMResizeWidget(panel->dirdB, 90, 40);
1407 WMMoveWidget(panel->dirdB, 194, 20);
1409 WMGroupButtons(panel->dirvB, panel->dirhB);
1410 WMGroupButtons(panel->dirvB, panel->dirdB);
1412 WMMapSubwidgets(panel->dirF);
1414 /****************** Textured Gradient ******************/
1415 panel->tcolF = WMCreateFrame(panel->win);
1416 WMResizeWidget(panel->tcolF, 100, 135);
1417 WMMoveWidget(panel->tcolF, 210, 10);
1418 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1420 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1421 WMResizeWidget(panel->tcol1W, 60, 45);
1422 WMMoveWidget(panel->tcol1W, 20, 25);
1423 WMAddNotificationObserver(colorWellObserver, panel,
1424 WMColorWellDidChangeNotification, panel->tcol1W);
1426 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1427 WMResizeWidget(panel->tcol2W, 60, 45);
1428 WMMoveWidget(panel->tcol2W, 20, 75);
1429 WMAddNotificationObserver(colorWellObserver, panel,
1430 WMColorWellDidChangeNotification, panel->tcol2W);
1432 /** Opacity */
1433 panel->topaF = WMCreateFrame(panel->win);
1434 WMResizeWidget(panel->topaF, 185, 50);
1435 WMMoveWidget(panel->topaF, 15, 95);
1436 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1438 panel->topaS = WMCreateSlider(panel->topaF);
1439 WMResizeWidget(panel->topaS, 155, 18);
1440 WMMoveWidget(panel->topaS, 15, 20);
1441 WMSetSliderMaxValue(panel->topaS, 255);
1442 WMSetSliderValue(panel->topaS, 200);
1443 WMSetSliderContinuous(panel->topaS, False);
1444 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1446 WMMapSubwidgets(panel->topaF);
1449 WMPixmap *pixmap;
1450 Pixmap p;
1451 WMColor *color;
1453 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1454 p = WMGetPixmapXID(pixmap);
1456 color = WMDarkGrayColor(scr);
1457 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1458 0, 0, 155, 18);
1459 WMReleaseColor(color);
1461 color = WMWhiteColor(scr);
1462 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1463 2, 1, "0%", 2);
1464 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1465 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1466 "100%", 4);
1467 WMReleaseColor(color);
1469 WMSetSliderImage(panel->topaS, pixmap);
1470 WMReleasePixmap(pixmap);
1473 WMMapSubwidgets(panel->tcolF);
1475 /****************** Image ******************/
1476 panel->imageF = WMCreateFrame(panel->win);
1477 WMResizeWidget(panel->imageF, 295, 150);
1478 WMMoveWidget(panel->imageF, 15, 150);
1479 WMSetFrameTitle(panel->imageF, _("Image"));
1481 panel->imageL = WMCreateLabel(panel->imageF);
1482 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1484 panel->imageT = WMCreateTextField(panel->imageF);
1485 WMResizeWidget(panel->imageT, 90, 20);
1486 WMMoveWidget(panel->imageT, 190, 25);
1488 panel->imageV = WMCreateScrollView(panel->imageF);
1489 WMResizeWidget(panel->imageV, 165, 115);
1490 WMMoveWidget(panel->imageV, 15, 20);
1491 WMSetScrollViewRelief(panel->imageV, WRSunken);
1492 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1493 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1494 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1496 panel->browB = WMCreateCommandButton(panel->imageF);
1497 WMResizeWidget(panel->browB, 90, 24);
1498 WMMoveWidget(panel->browB, 190, 50);
1499 WMSetButtonText(panel->browB, _("Browse..."));
1500 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1502 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1503 WMResizeWidget(panel->dispB, 90, 24);
1504 WMMoveWidget(panel->dispB, 190, 80);
1505 WMSetButtonText(panel->dispB, _("Show"));
1508 panel->arrP = WMCreatePopUpButton(panel->imageF);
1509 WMResizeWidget(panel->arrP, 90, 20);
1510 WMMoveWidget(panel->arrP, 190, 120);
1511 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1512 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1513 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1514 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1515 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1517 WMMapSubwidgets(panel->imageF);
1519 /****/
1521 panel->okB = WMCreateCommandButton(panel->win);
1522 WMResizeWidget(panel->okB, 84, 24);
1523 WMMoveWidget(panel->okB, 225, 390);
1524 WMSetButtonText(panel->okB, _("OK"));
1525 WMSetButtonAction(panel->okB, buttonCallback, panel);
1527 panel->cancelB = WMCreateCommandButton(panel->win);
1528 WMResizeWidget(panel->cancelB, 84, 24);
1529 WMMoveWidget(panel->cancelB, 130, 390);
1530 WMSetButtonText(panel->cancelB, _("Cancel"));
1531 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1533 WMMapWidget(panel->nameF);
1534 WMMapWidget(panel->typeP);
1535 WMMapWidget(panel->okB);
1536 WMMapWidget(panel->cancelB);
1538 WMUnmapWidget(panel->arrP);
1540 WMRealizeWidget(panel->win);
1542 panel->currentType = -1;
1544 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1546 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1547 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1548 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1550 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1551 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1553 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1554 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1555 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1556 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1557 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1559 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1560 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1561 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1564 /* setup for first time */
1566 changeTypeCallback(panel->typeP, panel);
1568 sliderChangeCallback(panel->ghueS, panel);
1569 sliderChangeCallback(panel->gsatS, panel);
1571 return panel;
1577 *--------------------------------------------------------------------------
1578 * Test stuff
1579 *--------------------------------------------------------------------------
1582 #if 0
1584 char *ProgName = "test";
1586 void
1587 testOKButton(WMWidget *self, void *data)
1589 char *test;
1590 Display *dpy;
1591 Window win;
1592 Pixmap pix;
1593 RImage *image;
1595 TexturePanel *panel = (TexturePanel*)data;
1596 /* test = GetTexturePanelTextureString(panel); */
1598 wwarning(test);
1600 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1601 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1602 0, 0, 0);
1603 XMapRaised(dpy, win);
1604 XFlush(dpy);
1606 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1608 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1610 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1611 0, 0);
1613 wfree (test);
1617 void testCancelButton(WMWidget *self, void *data){
1618 wwarning("Exiting test....");
1619 exit(0);
1622 void wAbort()
1624 exit(1);
1627 int main(int argc, char **argv)
1629 TexturePanel *panel;
1631 Display *dpy = XOpenDisplay("");
1632 WMScreen *scr;
1634 /* char *test; */
1636 WMInitializeApplication("Test", &argc, argv);
1638 if (!dpy) {
1639 wfatal("could not open display");
1640 exit(1);
1643 scr = WMCreateSimpleApplicationScreen(dpy);
1645 panel = CreateTexturePanel(scr);
1647 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1648 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1650 SetTexturePanelTexture(panel, "pinky",
1651 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1653 ShowTexturePanel(panel);
1655 WMScreenMainLoop(scr);
1656 return 0;
1658 #endif