*** empty log message ***
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob68bd431f6dc97d1189784979550dc41b5ba11258
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 WMResizeWidget(panel->imageL, image->width, image->height);
249 RDestroyImage(image);
253 static void
254 updateSGradButtons(TexturePanel *panel)
256 RImage *image;
257 WMPixmap *pixmap;
258 RColor from;
259 RColor to;
260 WMColor *color;
262 color = WMGetColorWellColor(panel->tcol1W);
263 from.red = WMRedComponentOfColor(color)>>8;
264 from.green = WMGreenComponentOfColor(color)>>8;
265 from.blue = WMBlueComponentOfColor(color)>>8;
267 color = WMGetColorWellColor(panel->tcol2W);
268 to.red = WMRedComponentOfColor(color)>>8;
269 to.green = WMGreenComponentOfColor(color)>>8;
270 to.blue = WMBlueComponentOfColor(color)>>8;
272 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
273 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
274 image, 128);
275 RDestroyImage(image);
276 WMSetButtonImage(panel->dirhB, pixmap);
277 WMReleasePixmap(pixmap);
279 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
280 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
281 image, 128);
282 RDestroyImage(image);
283 WMSetButtonImage(panel->dirvB, pixmap);
284 WMReleasePixmap(pixmap);
286 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
287 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
288 image, 128);
289 RDestroyImage(image);
290 WMSetButtonImage(panel->dirdB, pixmap);
291 WMReleasePixmap(pixmap);
295 /*********** Gradient ************/
297 static void
298 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
300 RImage *image;
301 WMPixmap *pixmap;
302 WMScreen *scr = WMWidgetScreen(sPtr);
303 RColor from, to;
304 RHSVColor tmp;
306 tmp = *hsv;
307 if (saturation) {
308 tmp.saturation = 0;
309 RHSVtoRGB(&tmp, &from);
310 tmp.saturation = 255;
311 RHSVtoRGB(&tmp, &to);
312 } else {
313 tmp.value = 0;
314 RHSVtoRGB(&tmp, &from);
315 tmp.value = 255;
316 RHSVtoRGB(&tmp, &to);
318 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
319 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
320 RDestroyImage(image);
322 if (hsv->value < 128 || !saturation) {
323 WMColor *col = WMWhiteColor(scr);
325 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
326 (16 - WMFontHeight(font))/2 - 1,
327 saturation ? "Saturation" : "Brightness", 10);
328 WMReleaseColor(col);
329 } else {
330 WMColor *col = WMBlackColor(scr);
332 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
333 (16 - WMFontHeight(font))/2 - 1,
334 saturation ? "Saturation" : "Brightness", 10);
335 WMReleaseColor(col);
337 WMSetSliderImage(sPtr, pixmap);
338 WMReleasePixmap(pixmap);
342 static void
343 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
345 RColor *colors[8];
346 RImage *image;
347 WMPixmap *pixmap;
348 WMScreen *scr = WMWidgetScreen(sPtr);
349 RHSVColor thsv;
350 int i;
352 thsv = *hsv;
353 for (i = 0; i <= 6; i++) {
354 thsv.hue = (360*i)/6;
355 colors[i] = wmalloc(sizeof(RColor));
356 RHSVtoRGB(&thsv, colors[i]);
358 colors[i] = NULL;
360 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
361 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
362 RDestroyImage(image);
364 if (hsv->value < 128) {
365 WMColor *col = WMWhiteColor(scr);
367 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
368 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
369 WMReleaseColor(col);
370 } else {
371 WMColor *col = WMBlackColor(scr);
373 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
374 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
375 WMReleaseColor(col);
377 WMSetSliderImage(sPtr, pixmap);
378 WMReleasePixmap(pixmap);
380 for (i = 0; i <= 6; i++)
381 free(colors[i]);
386 static void
387 sliderChangeCallback(WMWidget *w, void *data)
389 TexturePanel *panel = (TexturePanel*)data;
390 RHSVColor hsv, *hsvp;
391 int row, rows;
392 WMListItem *item;
393 RColor **colors;
394 int i;
395 RImage *image;
396 WMScreen *scr = WMWidgetScreen(w);
398 hsv.hue = WMGetSliderValue(panel->ghueS);
399 hsv.saturation = WMGetSliderValue(panel->gsatS);
400 hsv.value = WMGetSliderValue(panel->gvalS);
402 row = WMGetListSelectedItemRow(panel->gcolL);
403 if (row >= 0) {
404 RColor *rgb;
406 item = WMGetListItem(panel->gcolL, row);
408 rgb = (RColor*)item->clientData;
410 RHSVtoRGB(&hsv, rgb);
412 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
415 if (w == panel->ghueS) {
416 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
417 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
418 } else if (w == panel->gsatS) {
419 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
420 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
421 } else {
422 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
423 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
426 rows = WMGetListNumberOfRows(panel->gcolL);
427 if (rows == 0)
428 return;
430 colors = wmalloc(sizeof(RColor*)*(rows+1));
432 for (i = 0; i < rows; i++) {
433 item = WMGetListItem(panel->gcolL, i);
435 colors[i] = (RColor*)item->clientData;
437 colors[i] = NULL;
439 if (panel->gimage != None) {
440 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
443 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
444 colors, RVerticalGradient);
445 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
446 RDestroyImage(image);
448 free(colors);
450 WMRedisplayWidget(panel->gcolL);
452 updateGradButtons(panel);
456 static void
457 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
458 WMRect *rect)
460 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
461 WMScreen *scr = WMWidgetScreen(lPtr);
462 int width, height, x, y;
463 Display *dpy;
464 WMColor *white = WMWhiteColor(scr);
465 WMListItem *item;
466 WMColor *black = WMBlackColor(scr);
468 dpy = WMScreenDisplay(scr);
470 width = rect->size.width;
471 height = rect->size.height;
472 x = rect->pos.x;
473 y = rect->pos.y;
475 if (state & WLDSSelected)
476 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
477 else
478 XClearArea(dpy, d, x, y, width, height, False);
480 item = WMGetListItem(lPtr, index);
482 if (panel->gimage) {
483 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
484 0, height*index, 30, height, x + 5, y);
486 WMDrawString(scr, d, WMColorGC(black), panel->listFont,
487 x + 40, y + 1, text, strlen(text));
489 WMReleaseColor(white);
490 WMReleaseColor(black);
495 static void
496 gradAddCallback(WMWidget *w, void *data)
498 TexturePanel *panel = (TexturePanel*)data;
499 WMListItem *item;
500 int row;
501 RColor *rgb;
503 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
504 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
505 rgb = wmalloc(sizeof(RColor));
506 memset(rgb, 0, sizeof(RColor));
507 item->clientData = rgb;
509 WMSelectListItem(panel->gcolL, row);
511 updateGradButtons(panel);
513 sliderChangeCallback(panel->ghueS, panel);
518 static void
519 gradClickCallback(WMWidget *w, void *data)
521 TexturePanel *panel = (TexturePanel*)data;
522 WMListItem *item;
523 int row;
524 RHSVColor hsv;
526 row = WMGetListSelectedItemRow(w);
527 if (row < 0)
528 return;
530 item = WMGetListItem(panel->gcolL, row);
531 RRGBtoHSV((RColor*)item->clientData, &hsv);
533 WMSetSliderValue(panel->ghueS, hsv.hue);
534 WMSetSliderValue(panel->gsatS, hsv.saturation);
535 WMSetSliderValue(panel->gvalS, hsv.value);
537 sliderChangeCallback(panel->ghueS, panel);
538 sliderChangeCallback(panel->gsatS, panel);
542 static void
543 gradDeleteCallback(WMWidget *w, void *data)
545 TexturePanel *panel = (TexturePanel*)data;
546 WMListItem *item;
547 int row;
549 row = WMGetListSelectedItemRow(panel->gcolL);
550 if (row < 0)
551 return;
553 item = WMGetListItem(panel->gcolL, row);
554 free(item->clientData);
556 WMRemoveListItem(panel->gcolL, row);
558 WMSelectListItem(panel->gcolL, row - 1);
560 updateGradButtons(panel);
562 gradClickCallback(panel->gcolL, panel);
566 /*************** Simple Gradient ***************/
568 static void
569 colorWellObserver(void *self, WMNotification *n)
571 updateSGradButtons(self);
577 static void
578 opaqChangeCallback(WMWidget *w, void *data)
580 TexturePanel *panel = (TexturePanel*)data;
582 updateTGradImage(panel);
585 /****************** Image ******************/
587 static void
588 updateImage(TexturePanel *panel, char *path)
590 WMScreen *scr = WMWidgetScreen(panel->win);
591 RImage *image, *scaled;
592 WMPixmap *pixmap;
593 WMSize size;
595 if (path) {
596 image = RLoadImage(WMScreenRContext(scr), path, 0);
597 if (!image) {
598 char *message;
600 message = wstrappend(_("Could not load the selected file: "),
601 (char*)RMessageForError(RErrorCode));
603 WMRunAlertPanel(scr, panel->win, _("Error"), message,
604 _("OK"), NULL, NULL);
605 return;
608 if (panel->image)
609 RDestroyImage(panel->image);
610 panel->image = image;
611 } else {
612 image = panel->image;
615 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
616 if (image) {
617 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
619 size = WMGetPixmapSize(pixmap);
620 WMSetLabelImage(panel->imageL, pixmap);
621 WMResizeWidget(panel->imageL, size.width, size.height);
623 WMReleasePixmap(pixmap);
625 } else {
626 updateTGradImage(panel);
631 static void
632 browseImageCallback(WMWidget *w, void *data)
634 TexturePanel *panel = (TexturePanel*)data;
635 WMOpenPanel *opanel;
636 WMScreen *scr = WMWidgetScreen(w);
637 static char *ipath = NULL;
639 opanel = WMGetOpenPanel(scr);
640 WMSetFilePanelCanChooseDirectories(opanel, False);
641 WMSetFilePanelCanChooseFiles(opanel, True);
643 if (!ipath)
644 ipath = wstrdup(wgethomedir());
646 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
647 "Open Image", NULL)) {
648 char *path, *fullpath;
649 char *tmp, *tmp2;
651 tmp = WMGetFilePanelFileName(opanel);
652 if (!tmp)
653 return;
654 fullpath = tmp;
656 free(ipath);
657 ipath = fullpath;
659 path = wstrdup(fullpath);
661 tmp2 = strrchr(fullpath, '/');
662 if (tmp2)
663 tmp2++;
665 tmp = wfindfileinarray(panel->pathList, tmp2);
667 if (tmp) {
668 if (strcmp(fullpath, tmp)==0) {
669 free(path);
670 path = tmp2;
672 free(tmp);
675 if (!RGetImageFileFormat(fullpath)) {
676 WMRunAlertPanel(scr, panel->win, _("Error"),
677 _("The selected file does not contain a supported image."),
678 _("OK"), NULL, NULL);
679 free(path);
680 } else {
681 updateImage(panel, fullpath);
682 free(panel->imageFile);
683 panel->imageFile = path;
685 WMSetTextFieldText(panel->imageT, path);
692 static void
693 buttonCallback(WMWidget *w, void *data)
695 TexturePanel *panel = (TexturePanel*)data;
697 if (w == panel->okB) {
698 (*panel->okAction)(panel->okData);
699 } else {
700 (*panel->cancelAction)(panel->cancelData);
706 static void
707 changeTypeCallback(WMWidget *w, void *data)
709 TexturePanel *panel = (TexturePanel*)data;
710 int newType;
711 int i;
713 newType = WMGetPopUpButtonSelectedItem(w);
714 if (newType == panel->currentType)
715 return;
717 if (panel->currentType >= 0) {
718 for (i = 0; i < MAX_SECTION_PARTS; i++) {
719 if (panel->sectionParts[panel->currentType][i] == NULL)
720 break;
721 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
725 for (i = 0; i < MAX_SECTION_PARTS; i++) {
726 if (panel->sectionParts[newType][i] == NULL)
727 break;
728 WMMapWidget(panel->sectionParts[newType][i]);
730 panel->currentType = newType;
732 switch (newType) {
733 case TYPE_SGRADIENT:
734 updateSGradButtons(panel);
735 break;
736 case TYPE_GRADIENT:
737 updateGradButtons(panel);
738 break;
739 case TYPE_TGRADIENT:
740 case TYPE_PIXMAP:
741 updateImage(panel, NULL);
742 break;
748 *--------------------------------------------------------------------------
749 * Public functions
750 *--------------------------------------------------------------------------
752 void
753 DestroyTexturePanel(TexturePanel *panel)
759 void
760 ShowTexturePanel(TexturePanel *panel)
762 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
763 Screen *scr = DefaultScreenOfDisplay(dpy);
765 WMSetWindowUPosition(panel->win,
766 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
767 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
768 WMMapWidget(panel->win);
772 void
773 HideTexturePanel(TexturePanel *panel)
775 WMUnmapWidget(panel->win);
779 void
780 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
782 panel->okAction = action;
783 panel->okData = clientData;
787 void
788 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
790 panel->cancelAction = action;
791 panel->cancelData = clientData;
795 void
796 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
798 WMScreen *scr = WMWidgetScreen(panel->win);
799 char *str, *type;
800 proplist_t p;
801 WMColor *color;
802 int i;
803 char buffer[64];
804 int gradient = 0;
806 WMSetTextFieldText(panel->nameT, name);
808 if (!texture)
809 return;
811 p = PLGetArrayElement(texture, 0);
812 if (!p) {
813 goto bad_texture;
815 type = PLGetString(p);
817 /*...............................................*/
818 if (strcasecmp(type, "solid")==0) {
820 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
822 p = PLGetArrayElement(texture, 1);
823 if (!p) {
824 str = "black";
825 } else {
826 str = PLGetString(p);
828 color = WMCreateNamedColor(scr, str, False);
830 WMSetColorWellColor(panel->defcW, color);
832 WMReleaseColor(color);
833 /*...............................................*/
834 } else if (strcasecmp(type, "hgradient")==0
835 || strcasecmp(type, "vgradient")==0
836 || strcasecmp(type, "dgradient")==0) {
838 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
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->tcol1W, color);
850 WMReleaseColor(color);
852 p = PLGetArrayElement(texture, 2);
853 if (!p) {
854 str = "black";
855 } else {
856 str = PLGetString(p);
858 color = WMCreateNamedColor(scr, str, False);
860 WMSetColorWellColor(panel->tcol2W, color);
862 WMReleaseColor(color);
864 gradient = type[0];
865 /*...............................................*/
866 } else if (strcasecmp(type, "thgradient")==0
867 || strcasecmp(type, "tvgradient")==0
868 || strcasecmp(type, "tdgradient")==0) {
869 int i;
871 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
873 gradient = type[1];
875 WMSetTextFieldText(panel->imageT,
876 PLGetString(PLGetArrayElement(texture, 1)));
877 if (panel->imageFile)
878 free(panel->imageFile);
879 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
882 i = 180;
883 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
884 WMSetSliderValue(panel->topaS, i);
886 p = PLGetArrayElement(texture, 3);
887 if (!p) {
888 str = "black";
889 } else {
890 str = PLGetString(p);
892 color = WMCreateNamedColor(scr, str, False);
894 WMSetColorWellColor(panel->tcol1W, color);
896 WMReleaseColor(color);
898 p = PLGetArrayElement(texture, 4);
899 if (!p) {
900 str = "black";
901 } else {
902 str = PLGetString(p);
904 color = WMCreateNamedColor(scr, str, False);
906 WMSetColorWellColor(panel->tcol2W, color);
908 WMReleaseColor(color);
910 WMSetTextFieldText(panel->imageT,
911 PLGetString(PLGetArrayElement(texture, 1)));
913 if (panel->imageFile)
914 free(panel->imageFile);
915 panel->imageFile = wfindfileinarray(panel->pathList,
916 PLGetString(PLGetArrayElement(texture, 1)));
918 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
919 updateTGradImage(panel);
921 updateSGradButtons(panel);
923 /*...............................................*/
924 } else if (strcasecmp(type, "mhgradient")==0
925 || strcasecmp(type, "mvgradient")==0
926 || strcasecmp(type, "mdgradient")==0) {
927 WMListItem *item;
929 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
930 item = WMGetListItem(panel->gcolL, i);
931 free(item->clientData);
933 WMClearList(panel->gcolL);
935 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
937 p = PLGetArrayElement(texture, 1);
938 if (!p) {
939 str = "black";
940 } else {
941 str = PLGetString(p);
943 color = WMCreateNamedColor(scr, str, False);
945 WMSetColorWellColor(panel->defcW, color);
947 WMReleaseColor(color);
949 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
950 RColor *rgb;
951 XColor xcolor;
953 p = PLGetArrayElement(texture, i);
954 if (!p) {
955 str = "black";
956 } else {
957 str = PLGetString(p);
960 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
961 str, &xcolor);
963 rgb = wmalloc(sizeof(RColor));
964 rgb->red = xcolor.red >> 8;
965 rgb->green = xcolor.green >> 8;
966 rgb->blue = xcolor.blue >> 8;
967 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
969 item = WMAddListItem(panel->gcolL, buffer);
970 item->clientData = rgb;
973 sliderChangeCallback(panel->ghueS, panel);
975 gradient = type[1];
976 /*...............................................*/
977 } else if (strcasecmp(type, "cpixmap")==0
978 || strcasecmp(type, "spixmap")==0
979 || strcasecmp(type, "mpixmap")==0
980 || strcasecmp(type, "tpixmap")==0) {
982 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
984 switch (toupper(type[0])) {
985 case 'C':
986 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
987 break;
988 case 'S':
989 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
990 break;
991 case 'M':
992 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
993 break;
994 default:
995 case 'T':
996 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
997 break;
1000 WMSetTextFieldText(panel->imageT,
1001 PLGetString(PLGetArrayElement(texture, 1)));
1003 if (panel->imageFile)
1004 free(panel->imageFile);
1005 panel->imageFile = wfindfileinarray(panel->pathList,
1006 PLGetString(PLGetArrayElement(texture, 1)));
1008 color = WMCreateNamedColor(scr,
1009 PLGetString(PLGetArrayElement(texture, 2)), False);
1010 WMSetColorWellColor(panel->defcW, color);
1011 WMReleaseColor(color);
1013 updateImage(panel, panel->imageFile);
1016 changeTypeCallback(panel->typeP, panel);
1018 if (gradient > 0) {
1019 updateGradButtons(panel);
1021 switch (toupper(gradient)) {
1022 case 'H':
1023 WMPerformButtonClick(panel->dirhB);
1024 break;
1025 case 'V':
1026 WMPerformButtonClick(panel->dirvB);
1027 break;
1028 default:
1029 case 'D':
1030 WMPerformButtonClick(panel->dirdB);
1031 break;
1035 return;
1037 bad_texture:
1038 str = PLGetDescription(texture);
1039 wwarning("error creating texture %s", str);
1040 free(str);
1046 char*
1047 GetTexturePanelTextureName(TexturePanel *panel)
1049 return WMGetTextFieldText(panel->nameT);
1055 proplist_t
1056 GetTexturePanelTexture(TexturePanel *panel)
1058 proplist_t prop = NULL;
1059 WMColor *color;
1060 char *str, *str2;
1061 char buff[32];
1062 int i;
1065 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1067 case TYPE_SOLID:
1068 color = WMGetColorWellColor(panel->defcW);
1069 str = WMGetColorRGBDescription(color);
1070 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1071 PLMakeString(str), NULL);
1072 free(str);
1074 break;
1076 case TYPE_PIXMAP:
1077 color = WMGetColorWellColor(panel->defcW);
1078 str = WMGetColorRGBDescription(color);
1080 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1081 case PTYPE_SCALE:
1082 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1083 PLMakeString(panel->imageFile),
1084 PLMakeString(str), NULL);
1085 break;
1086 case PTYPE_MAXIMIZE:
1087 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1088 PLMakeString(panel->imageFile),
1089 PLMakeString(str), NULL);
1090 break;
1091 case PTYPE_CENTER:
1092 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1093 PLMakeString(panel->imageFile),
1094 PLMakeString(str), NULL);
1095 break;
1096 case PTYPE_TILE:
1097 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1098 PLMakeString(panel->imageFile),
1099 PLMakeString(str), NULL);
1100 break;
1102 free(str);
1103 break;
1105 case TYPE_TGRADIENT:
1106 color = WMGetColorWellColor(panel->tcol1W);
1107 str = WMGetColorRGBDescription(color);
1109 color = WMGetColorWellColor(panel->tcol2W);
1110 str2 = WMGetColorRGBDescription(color);
1112 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1114 if (WMGetButtonSelected(panel->dirdB)) {
1115 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1116 PLMakeString(panel->imageFile),
1117 PLMakeString(buff),
1118 PLMakeString(str),
1119 PLMakeString(str2), NULL);
1120 } else if (WMGetButtonSelected(panel->dirvB)) {
1121 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1122 PLMakeString(panel->imageFile),
1123 PLMakeString(buff),
1124 PLMakeString(str),
1125 PLMakeString(str2), NULL);
1126 } else {
1127 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1128 PLMakeString(panel->imageFile),
1129 PLMakeString(buff),
1130 PLMakeString(str),
1131 PLMakeString(str2), NULL);
1133 free(str);
1134 free(str2);
1135 break;
1138 case TYPE_SGRADIENT:
1139 color = WMGetColorWellColor(panel->tcol1W);
1140 str = WMGetColorRGBDescription(color);
1142 color = WMGetColorWellColor(panel->tcol2W);
1143 str2 = WMGetColorRGBDescription(color);
1145 if (WMGetButtonSelected(panel->dirdB)) {
1146 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1147 PLMakeString(str),
1148 PLMakeString(str2), NULL);
1149 } else if (WMGetButtonSelected(panel->dirvB)) {
1150 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1151 PLMakeString(str),
1152 PLMakeString(str2), NULL);
1153 } else {
1154 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1155 PLMakeString(str),
1156 PLMakeString(str2), NULL);
1158 free(str);
1159 free(str2);
1160 break;
1162 case TYPE_GRADIENT:
1163 color = WMGetColorWellColor(panel->defcW);
1164 str = WMGetColorRGBDescription(color);
1166 if (WMGetButtonSelected(panel->dirdB)) {
1167 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1168 PLMakeString(str), NULL);
1169 } else if (WMGetButtonSelected(panel->dirvB)) {
1170 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1171 PLMakeString(str), NULL);
1172 } else {
1173 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1174 PLMakeString(str), NULL);
1176 free(str);
1178 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1179 RColor *rgb;
1180 WMListItem *item;
1182 item = WMGetListItem(panel->gcolL, i);
1184 rgb = (RColor*)item->clientData;
1186 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1188 PLAppendArrayElement(prop, PLMakeString(buff));
1190 break;
1194 return prop;
1199 void
1200 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1202 panel->pathList = array;
1207 TexturePanel*
1208 CreateTexturePanel(WMWindow *keyWindow)
1209 /*CreateTexturePanel(WMScreen *scr)*/
1211 TexturePanel *panel;
1212 WMScreen *scr = WMWidgetScreen(keyWindow);
1214 panel = wmalloc(sizeof(TexturePanel));
1215 memset(panel, 0, sizeof(TexturePanel));
1217 panel->listFont = WMSystemFontOfSize(scr, 12);
1220 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1221 WMTitledWindowMask
1222 |WMClosableWindowMask);
1224 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1225 WMTitledWindowMask
1226 |WMClosableWindowMask);
1229 WMResizeWidget(panel->win, 325, 423);
1230 WMSetWindowTitle(panel->win, _("Texture Panel"));
1231 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1234 /* texture name */
1235 panel->nameF = WMCreateFrame(panel->win);
1236 WMResizeWidget(panel->nameF, 185, 50);
1237 WMMoveWidget(panel->nameF, 15, 10);
1238 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1240 panel->nameT = WMCreateTextField(panel->nameF);
1241 WMResizeWidget(panel->nameT, 160, 20);
1242 WMMoveWidget(panel->nameT, 12, 18);
1244 WMMapSubwidgets(panel->nameF);
1246 /* texture types */
1247 panel->typeP = WMCreatePopUpButton(panel->win);
1248 WMResizeWidget(panel->typeP, 185, 20);
1249 WMMoveWidget(panel->typeP, 15, 65);
1250 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1251 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1252 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1253 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1254 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1255 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1256 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1258 /* color */
1259 panel->defcF = WMCreateFrame(panel->win);
1260 WMResizeWidget(panel->defcF, 100, 75);
1261 WMMoveWidget(panel->defcF, 210, 10);
1262 WMSetFrameTitle(panel->defcF, _("Default Color"));
1264 panel->defcW = WMCreateColorWell(panel->defcF);
1265 WMResizeWidget(panel->defcW, 60, 45);
1266 WMMoveWidget(panel->defcW, 20, 20);
1268 WMMapSubwidgets(panel->defcF);
1270 /****** Gradient ******/
1271 panel->gcolF = WMCreateFrame(panel->win);
1272 WMResizeWidget(panel->gcolF, 295, 205);
1273 WMMoveWidget(panel->gcolF, 15, 95);
1274 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1276 panel->gcolL = WMCreateList(panel->gcolF);
1277 WMResizeWidget(panel->gcolL, 130, 140);
1278 WMMoveWidget(panel->gcolL, 10, 25);
1279 WMHangData(panel->gcolL, panel);
1280 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1281 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1283 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1284 WMResizeWidget(panel->gcolaB, 64, 24);
1285 WMMoveWidget(panel->gcolaB, 10, 170);
1286 WMSetButtonText(panel->gcolaB, _("Add"));
1287 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1289 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1290 WMResizeWidget(panel->gcoldB, 64, 24);
1291 WMMoveWidget(panel->gcoldB, 75, 170);
1292 WMSetButtonText(panel->gcoldB, _("Delete"));
1293 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1295 #if 0
1296 panel->gbriS = WMCreateSlider(panel->gcolF);
1297 WMResizeWidget(panel->gbriS, 130, 16);
1298 WMMoveWidget(panel->gbriS, 150, 25);
1299 WMSetSliderKnobThickness(panel->gbriS, 8);
1300 WMSetSliderMaxValue(panel->gbriS, 100);
1301 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1303 WMPixmap *pixmap;
1304 WMColor *color;
1306 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1307 color = WMDarkGrayColor(scr);
1308 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1309 WMColorGC(color), 0, 0, 130, 16);
1310 WMReleaseColor(color);
1311 color = WMWhiteColor(color);
1312 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1313 panel->listFont, 2,
1314 (16 - WMFontHeight(panel->listFont))/2 - 1,
1315 "Brightness", 10);
1316 WMSetSliderImage(panel->gbriS, pixmap);
1317 WMReleasePixmap(pixmap);
1320 panel->gconS = WMCreateSlider(panel->gcolF);
1321 WMResizeWidget(panel->gconS, 130, 16);
1322 WMMoveWidget(panel->gconS, 150, 50);
1323 WMSetSliderKnobThickness(panel->gconS, 8);
1324 WMSetSliderMaxValue(panel->gconS, 100);
1325 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1327 WMPixmap *pixmap;
1328 WMColor *color;
1330 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1331 color = WMDarkGrayColor(scr);
1332 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1333 WMColorGC(color), 0, 0, 130, 16);
1334 WMReleaseColor(color);
1335 color = WMWhiteColor(scr);
1336 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1337 panel->listFont, 2,
1338 (16 - WMFontHeight(panel->listFont))/2 - 1,
1339 "Contrast", 8);
1340 WMSetSliderImage(panel->gconS, pixmap);
1341 WMReleasePixmap(pixmap);
1343 #endif
1344 panel->ghueS = WMCreateSlider(panel->gcolF);
1345 WMResizeWidget(panel->ghueS, 130, 16);
1346 WMMoveWidget(panel->ghueS, 150, 100);
1347 WMSetSliderKnobThickness(panel->ghueS, 8);
1348 WMSetSliderMaxValue(panel->ghueS, 359);
1349 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1351 panel->gsatS = WMCreateSlider(panel->gcolF);
1352 WMResizeWidget(panel->gsatS, 130, 16);
1353 WMMoveWidget(panel->gsatS, 150, 125);
1354 WMSetSliderKnobThickness(panel->gsatS, 8);
1355 WMSetSliderMaxValue(panel->gsatS, 255);
1356 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1358 panel->gvalS = WMCreateSlider(panel->gcolF);
1359 WMResizeWidget(panel->gvalS, 130, 16);
1360 WMMoveWidget(panel->gvalS, 150, 150);
1361 WMSetSliderKnobThickness(panel->gvalS, 8);
1362 WMSetSliderMaxValue(panel->gvalS, 255);
1363 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1366 WMMapSubwidgets(panel->gcolF);
1368 /** Direction **/
1369 panel->dirF = WMCreateFrame(panel->win);
1370 WMSetFrameTitle(panel->dirF, _("Direction"));
1371 WMResizeWidget(panel->dirF, 295, 75);
1372 WMMoveWidget(panel->dirF, 15, 305);
1374 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1375 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1376 WMResizeWidget(panel->dirvB, 90, 40);
1377 WMMoveWidget(panel->dirvB, 10, 20);
1379 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1380 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1381 WMResizeWidget(panel->dirhB, 90, 40);
1382 WMMoveWidget(panel->dirhB, 102, 20);
1384 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1385 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1386 WMResizeWidget(panel->dirdB, 90, 40);
1387 WMMoveWidget(panel->dirdB, 194, 20);
1389 WMGroupButtons(panel->dirvB, panel->dirhB);
1390 WMGroupButtons(panel->dirvB, panel->dirdB);
1392 WMMapSubwidgets(panel->dirF);
1394 /****************** Textured Gradient ******************/
1395 panel->tcolF = WMCreateFrame(panel->win);
1396 WMResizeWidget(panel->tcolF, 100, 135);
1397 WMMoveWidget(panel->tcolF, 210, 10);
1398 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1400 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1401 WMResizeWidget(panel->tcol1W, 60, 45);
1402 WMMoveWidget(panel->tcol1W, 20, 25);
1403 WMAddNotificationObserver(colorWellObserver, panel,
1404 WMColorWellDidChangeNotification, panel->tcol1W);
1406 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1407 WMResizeWidget(panel->tcol2W, 60, 45);
1408 WMMoveWidget(panel->tcol2W, 20, 75);
1409 WMAddNotificationObserver(colorWellObserver, panel,
1410 WMColorWellDidChangeNotification, panel->tcol2W);
1412 /** Opacity */
1413 panel->topaF = WMCreateFrame(panel->win);
1414 WMResizeWidget(panel->topaF, 185, 50);
1415 WMMoveWidget(panel->topaF, 15, 95);
1416 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1418 panel->topaS = WMCreateSlider(panel->topaF);
1419 WMResizeWidget(panel->topaS, 155, 18);
1420 WMMoveWidget(panel->topaS, 15, 20);
1421 WMSetSliderMaxValue(panel->topaS, 255);
1422 WMSetSliderValue(panel->topaS, 200);
1423 WMSetSliderContinuous(panel->topaS, False);
1424 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1426 WMMapSubwidgets(panel->topaF);
1429 WMPixmap *pixmap;
1430 Pixmap p;
1431 WMColor *color;
1433 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1434 p = WMGetPixmapXID(pixmap);
1436 color = WMDarkGrayColor(scr);
1437 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1438 0, 0, 155, 18);
1439 WMReleaseColor(color);
1441 color = WMWhiteColor(scr);
1442 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1443 2, 1, "0%", 2);
1444 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1445 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1446 "100%", 4);
1447 WMReleaseColor(color);
1449 WMSetSliderImage(panel->topaS, pixmap);
1450 WMReleasePixmap(pixmap);
1453 WMMapSubwidgets(panel->tcolF);
1455 /****************** Image ******************/
1456 panel->imageF = WMCreateFrame(panel->win);
1457 WMResizeWidget(panel->imageF, 295, 150);
1458 WMMoveWidget(panel->imageF, 15, 150);
1459 WMSetFrameTitle(panel->imageF, _("Image"));
1461 panel->imageL = WMCreateLabel(panel->imageF);
1462 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1464 panel->imageT = WMCreateTextField(panel->imageF);
1465 WMResizeWidget(panel->imageT, 90, 20);
1466 WMMoveWidget(panel->imageT, 190, 25);
1468 panel->imageV = WMCreateScrollView(panel->imageF);
1469 WMResizeWidget(panel->imageV, 165, 115);
1470 WMMoveWidget(panel->imageV, 15, 20);
1471 WMSetScrollViewRelief(panel->imageV, WRSunken);
1472 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1473 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1474 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1476 panel->browB = WMCreateCommandButton(panel->imageF);
1477 WMResizeWidget(panel->browB, 90, 24);
1478 WMMoveWidget(panel->browB, 190, 50);
1479 WMSetButtonText(panel->browB, _("Browse..."));
1480 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1482 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1483 WMResizeWidget(panel->dispB, 90, 24);
1484 WMMoveWidget(panel->dispB, 190, 80);
1485 WMSetButtonText(panel->dispB, _("Show"));
1488 panel->arrP = WMCreatePopUpButton(panel->imageF);
1489 WMResizeWidget(panel->arrP, 90, 20);
1490 WMMoveWidget(panel->arrP, 190, 120);
1491 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1492 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1493 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1494 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1495 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1497 WMMapSubwidgets(panel->imageF);
1499 /****/
1501 panel->okB = WMCreateCommandButton(panel->win);
1502 WMResizeWidget(panel->okB, 84, 24);
1503 WMMoveWidget(panel->okB, 225, 390);
1504 WMSetButtonText(panel->okB, _("OK"));
1505 WMSetButtonAction(panel->okB, buttonCallback, panel);
1507 panel->cancelB = WMCreateCommandButton(panel->win);
1508 WMResizeWidget(panel->cancelB, 84, 24);
1509 WMMoveWidget(panel->cancelB, 130, 390);
1510 WMSetButtonText(panel->cancelB, _("Cancel"));
1511 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1513 WMMapWidget(panel->nameF);
1514 WMMapWidget(panel->typeP);
1515 WMMapWidget(panel->okB);
1516 WMMapWidget(panel->cancelB);
1518 WMUnmapWidget(panel->arrP);
1520 WMRealizeWidget(panel->win);
1522 panel->currentType = -1;
1524 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1526 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1527 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1528 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1530 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1531 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1533 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1534 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1535 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1536 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1537 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1539 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1540 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1541 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1544 /* setup for first time */
1546 changeTypeCallback(panel->typeP, panel);
1548 sliderChangeCallback(panel->ghueS, panel);
1549 sliderChangeCallback(panel->gsatS, panel);
1551 return panel;
1557 *--------------------------------------------------------------------------
1558 * Test stuff
1559 *--------------------------------------------------------------------------
1562 #if 0
1564 char *ProgName = "test";
1566 void
1567 testOKButton(WMWidget *self, void *data)
1569 char *test;
1570 Display *dpy;
1571 Window win;
1572 Pixmap pix;
1573 RImage *image;
1575 TexturePanel *panel = (TexturePanel*)data;
1576 /* test = GetTexturePanelTextureString(panel); */
1578 wwarning(test);
1580 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1581 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1582 0, 0, 0);
1583 XMapRaised(dpy, win);
1584 XFlush(dpy);
1586 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1588 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1590 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1591 0, 0);
1593 free (test);
1597 void testCancelButton(WMWidget *self, void *data){
1598 wwarning("Exiting test....");
1599 exit(0);
1602 void wAbort()
1604 exit(1);
1607 int main(int argc, char **argv)
1609 TexturePanel *panel;
1611 Display *dpy = XOpenDisplay("");
1612 WMScreen *scr;
1614 /* char *test; */
1616 WMInitializeApplication("Test", &argc, argv);
1618 if (!dpy) {
1619 wfatal("could not open display");
1620 exit(1);
1623 scr = WMCreateSimpleApplicationScreen(dpy);
1625 panel = CreateTexturePanel(scr);
1627 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1628 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1630 SetTexturePanelTexture(panel, "pinky",
1631 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1633 ShowTexturePanel(panel);
1635 WMScreenMainLoop(scr);
1636 return 0;
1638 #endif