A few small fixes before 0.52.0 release.
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob2c365a89595aebb9d45e288cab7ca1e05342b25e
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 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
618 size = WMGetPixmapSize(pixmap);
619 WMSetLabelImage(panel->imageL, pixmap);
620 WMResizeWidget(panel->imageL, size.width, size.height);
622 WMReleasePixmap(pixmap);
623 } else {
624 updateTGradImage(panel);
629 static void
630 browseImageCallback(WMWidget *w, void *data)
632 TexturePanel *panel = (TexturePanel*)data;
633 WMOpenPanel *opanel;
634 WMScreen *scr = WMWidgetScreen(w);
635 static char *ipath = NULL;
637 opanel = WMGetOpenPanel(scr);
638 WMSetFilePanelCanChooseDirectories(opanel, False);
639 WMSetFilePanelCanChooseFiles(opanel, True);
641 if (!ipath)
642 ipath = wstrdup(wgethomedir());
644 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
645 "Open Image", NULL)) {
646 char *path, *fullpath;
647 char *tmp, *tmp2;
649 tmp = WMGetFilePanelFileName(opanel);
650 if (!tmp)
651 return;
652 fullpath = tmp;
654 free(ipath);
655 ipath = fullpath;
657 path = wstrdup(fullpath);
659 tmp2 = strrchr(fullpath, '/');
660 if (tmp2)
661 tmp2++;
663 tmp = wfindfileinarray(panel->pathList, tmp2);
665 if (tmp) {
666 if (strcmp(fullpath, tmp)==0) {
667 free(path);
668 path = tmp2;
670 free(tmp);
673 if (!RGetImageFileFormat(fullpath)) {
674 WMRunAlertPanel(scr, panel->win, _("Error"),
675 _("The selected file does not contain a supported image."),
676 _("OK"), NULL, NULL);
677 free(path);
678 } else {
679 updateImage(panel, fullpath);
680 free(panel->imageFile);
681 panel->imageFile = path;
683 WMSetTextFieldText(panel->imageT, path);
690 static void
691 buttonCallback(WMWidget *w, void *data)
693 TexturePanel *panel = (TexturePanel*)data;
695 if (w == panel->okB) {
696 (*panel->okAction)(panel->okData);
697 } else {
698 (*panel->cancelAction)(panel->cancelData);
704 static void
705 changeTypeCallback(WMWidget *w, void *data)
707 TexturePanel *panel = (TexturePanel*)data;
708 int newType;
709 int i;
711 newType = WMGetPopUpButtonSelectedItem(w);
712 if (newType == panel->currentType)
713 return;
715 if (panel->currentType >= 0) {
716 for (i = 0; i < MAX_SECTION_PARTS; i++) {
717 if (panel->sectionParts[panel->currentType][i] == NULL)
718 break;
719 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
723 for (i = 0; i < MAX_SECTION_PARTS; i++) {
724 if (panel->sectionParts[newType][i] == NULL)
725 break;
726 WMMapWidget(panel->sectionParts[newType][i]);
728 panel->currentType = newType;
730 switch (newType) {
731 case TYPE_SGRADIENT:
732 updateSGradButtons(panel);
733 break;
734 case TYPE_GRADIENT:
735 updateGradButtons(panel);
736 break;
737 case TYPE_TGRADIENT:
738 case TYPE_PIXMAP:
739 updateImage(panel, NULL);
740 break;
746 *--------------------------------------------------------------------------
747 * Public functions
748 *--------------------------------------------------------------------------
750 void
751 DestroyTexturePanel(TexturePanel *panel)
757 void
758 ShowTexturePanel(TexturePanel *panel)
760 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
761 Screen *scr = DefaultScreenOfDisplay(dpy);
763 WMSetWindowUPosition(panel->win,
764 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
765 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
766 WMMapWidget(panel->win);
770 void
771 HideTexturePanel(TexturePanel *panel)
773 WMUnmapWidget(panel->win);
777 void
778 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
780 panel->okAction = action;
781 panel->okData = clientData;
785 void
786 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
788 panel->cancelAction = action;
789 panel->cancelData = clientData;
793 void
794 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
796 WMScreen *scr = WMWidgetScreen(panel->win);
797 char *str, *type;
798 proplist_t p;
799 WMColor *color;
800 int i;
801 char buffer[64];
802 int gradient = 0;
804 WMSetTextFieldText(panel->nameT, name);
806 if (!texture)
807 return;
809 p = PLGetArrayElement(texture, 0);
810 if (!p) {
811 goto bad_texture;
813 type = PLGetString(p);
815 /*...............................................*/
816 if (strcasecmp(type, "solid")==0) {
818 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
820 p = PLGetArrayElement(texture, 1);
821 if (!p) {
822 str = "black";
823 } else {
824 str = PLGetString(p);
826 color = WMCreateNamedColor(scr, str, False);
828 WMSetColorWellColor(panel->defcW, color);
830 WMReleaseColor(color);
831 /*...............................................*/
832 } else if (strcasecmp(type, "hgradient")==0
833 || strcasecmp(type, "vgradient")==0
834 || strcasecmp(type, "dgradient")==0) {
836 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
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->tcol1W, color);
848 WMReleaseColor(color);
850 p = PLGetArrayElement(texture, 2);
851 if (!p) {
852 str = "black";
853 } else {
854 str = PLGetString(p);
856 color = WMCreateNamedColor(scr, str, False);
858 WMSetColorWellColor(panel->tcol2W, color);
860 WMReleaseColor(color);
862 gradient = type[0];
863 /*...............................................*/
864 } else if (strcasecmp(type, "thgradient")==0
865 || strcasecmp(type, "tvgradient")==0
866 || strcasecmp(type, "tdgradient")==0) {
867 int i;
869 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
871 gradient = type[1];
873 WMSetTextFieldText(panel->imageT,
874 PLGetString(PLGetArrayElement(texture, 1)));
875 if (panel->imageFile)
876 free(panel->imageFile);
877 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
880 i = 180;
881 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
882 WMSetSliderValue(panel->topaS, i);
884 p = PLGetArrayElement(texture, 3);
885 if (!p) {
886 str = "black";
887 } else {
888 str = PLGetString(p);
890 color = WMCreateNamedColor(scr, str, False);
892 WMSetColorWellColor(panel->tcol1W, color);
894 WMReleaseColor(color);
896 p = PLGetArrayElement(texture, 4);
897 if (!p) {
898 str = "black";
899 } else {
900 str = PLGetString(p);
902 color = WMCreateNamedColor(scr, str, False);
904 WMSetColorWellColor(panel->tcol2W, color);
906 WMReleaseColor(color);
908 WMSetTextFieldText(panel->imageT,
909 PLGetString(PLGetArrayElement(texture, 1)));
911 if (panel->imageFile)
912 free(panel->imageFile);
913 panel->imageFile = wfindfileinarray(panel->pathList,
914 PLGetString(PLGetArrayElement(texture, 1)));
916 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
917 updateTGradImage(panel);
919 updateSGradButtons(panel);
921 /*...............................................*/
922 } else if (strcasecmp(type, "mhgradient")==0
923 || strcasecmp(type, "mvgradient")==0
924 || strcasecmp(type, "mdgradient")==0) {
925 WMListItem *item;
927 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
928 item = WMGetListItem(panel->gcolL, i);
929 free(item->clientData);
931 WMClearList(panel->gcolL);
933 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
935 p = PLGetArrayElement(texture, 1);
936 if (!p) {
937 str = "black";
938 } else {
939 str = PLGetString(p);
941 color = WMCreateNamedColor(scr, str, False);
943 WMSetColorWellColor(panel->defcW, color);
945 WMReleaseColor(color);
947 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
948 RColor *rgb;
949 XColor xcolor;
951 p = PLGetArrayElement(texture, i);
952 if (!p) {
953 str = "black";
954 } else {
955 str = PLGetString(p);
958 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
959 str, &xcolor);
961 rgb = wmalloc(sizeof(RColor));
962 rgb->red = xcolor.red >> 8;
963 rgb->green = xcolor.green >> 8;
964 rgb->blue = xcolor.blue >> 8;
965 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
967 item = WMAddListItem(panel->gcolL, buffer);
968 item->clientData = rgb;
971 sliderChangeCallback(panel->ghueS, panel);
973 gradient = type[1];
974 /*...............................................*/
975 } else if (strcasecmp(type, "cpixmap")==0
976 || strcasecmp(type, "spixmap")==0
977 || strcasecmp(type, "mpixmap")==0
978 || strcasecmp(type, "tpixmap")==0) {
980 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
982 switch (toupper(type[0])) {
983 case 'C':
984 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
985 break;
986 case 'S':
987 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
988 break;
989 case 'M':
990 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
991 break;
992 default:
993 case 'T':
994 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
995 break;
998 WMSetTextFieldText(panel->imageT,
999 PLGetString(PLGetArrayElement(texture, 1)));
1001 if (panel->imageFile)
1002 free(panel->imageFile);
1003 panel->imageFile = wfindfileinarray(panel->pathList,
1004 PLGetString(PLGetArrayElement(texture, 1)));
1006 color = WMCreateNamedColor(scr,
1007 PLGetString(PLGetArrayElement(texture, 2)), False);
1008 WMSetColorWellColor(panel->defcW, color);
1009 WMReleaseColor(color);
1011 updateImage(panel, panel->imageFile);
1014 changeTypeCallback(panel->typeP, panel);
1016 if (gradient > 0) {
1017 updateGradButtons(panel);
1019 switch (toupper(gradient)) {
1020 case 'H':
1021 WMPerformButtonClick(panel->dirhB);
1022 break;
1023 case 'V':
1024 WMPerformButtonClick(panel->dirvB);
1025 break;
1026 default:
1027 case 'D':
1028 WMPerformButtonClick(panel->dirdB);
1029 break;
1033 return;
1035 bad_texture:
1036 str = PLGetDescription(texture);
1037 wwarning("error creating texture %s", str);
1038 free(str);
1044 char*
1045 GetTexturePanelTextureName(TexturePanel *panel)
1047 return WMGetTextFieldText(panel->nameT);
1053 proplist_t
1054 GetTexturePanelTexture(TexturePanel *panel)
1056 proplist_t prop = NULL;
1057 WMColor *color;
1058 char *str, *str2;
1059 char buff[32];
1060 int i;
1063 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1065 case TYPE_SOLID:
1066 color = WMGetColorWellColor(panel->defcW);
1067 str = WMGetColorRGBDescription(color);
1068 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1069 PLMakeString(str), NULL);
1070 free(str);
1072 break;
1074 case TYPE_PIXMAP:
1075 color = WMGetColorWellColor(panel->defcW);
1076 str = WMGetColorRGBDescription(color);
1078 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1079 case PTYPE_SCALE:
1080 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1081 PLMakeString(panel->imageFile),
1082 PLMakeString(str), NULL);
1083 break;
1084 case PTYPE_MAXIMIZE:
1085 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1086 PLMakeString(panel->imageFile),
1087 PLMakeString(str), NULL);
1088 break;
1089 case PTYPE_CENTER:
1090 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1091 PLMakeString(panel->imageFile),
1092 PLMakeString(str), NULL);
1093 break;
1094 case PTYPE_TILE:
1095 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1096 PLMakeString(panel->imageFile),
1097 PLMakeString(str), NULL);
1098 break;
1100 free(str);
1101 break;
1103 case TYPE_TGRADIENT:
1104 color = WMGetColorWellColor(panel->tcol1W);
1105 str = WMGetColorRGBDescription(color);
1107 color = WMGetColorWellColor(panel->tcol2W);
1108 str2 = WMGetColorRGBDescription(color);
1110 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1112 if (WMGetButtonSelected(panel->dirdB)) {
1113 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1114 PLMakeString(panel->imageFile),
1115 PLMakeString(buff),
1116 PLMakeString(str),
1117 PLMakeString(str2), NULL);
1118 } else if (WMGetButtonSelected(panel->dirvB)) {
1119 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1120 PLMakeString(panel->imageFile),
1121 PLMakeString(buff),
1122 PLMakeString(str),
1123 PLMakeString(str2), NULL);
1124 } else {
1125 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1126 PLMakeString(panel->imageFile),
1127 PLMakeString(buff),
1128 PLMakeString(str),
1129 PLMakeString(str2), NULL);
1131 free(str);
1132 free(str2);
1133 break;
1136 case TYPE_SGRADIENT:
1137 color = WMGetColorWellColor(panel->tcol1W);
1138 str = WMGetColorRGBDescription(color);
1140 color = WMGetColorWellColor(panel->tcol2W);
1141 str2 = WMGetColorRGBDescription(color);
1143 if (WMGetButtonSelected(panel->dirdB)) {
1144 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1145 PLMakeString(str),
1146 PLMakeString(str2), NULL);
1147 } else if (WMGetButtonSelected(panel->dirvB)) {
1148 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1149 PLMakeString(str),
1150 PLMakeString(str2), NULL);
1151 } else {
1152 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1153 PLMakeString(str),
1154 PLMakeString(str2), NULL);
1156 free(str);
1157 free(str2);
1158 break;
1160 case TYPE_GRADIENT:
1161 color = WMGetColorWellColor(panel->defcW);
1162 str = WMGetColorRGBDescription(color);
1164 if (WMGetButtonSelected(panel->dirdB)) {
1165 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1166 PLMakeString(str), NULL);
1167 } else if (WMGetButtonSelected(panel->dirvB)) {
1168 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1169 PLMakeString(str), NULL);
1170 } else {
1171 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1172 PLMakeString(str), NULL);
1174 free(str);
1176 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1177 RColor *rgb;
1178 WMListItem *item;
1180 item = WMGetListItem(panel->gcolL, i);
1182 rgb = (RColor*)item->clientData;
1184 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1186 PLAppendArrayElement(prop, PLMakeString(buff));
1188 break;
1192 return prop;
1197 void
1198 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1200 panel->pathList = array;
1205 TexturePanel*
1206 CreateTexturePanel(WMWindow *keyWindow)
1207 /*CreateTexturePanel(WMScreen *scr)*/
1209 TexturePanel *panel;
1210 WMScreen *scr = WMWidgetScreen(keyWindow);
1212 panel = wmalloc(sizeof(TexturePanel));
1213 memset(panel, 0, sizeof(TexturePanel));
1215 panel->listFont = WMSystemFontOfSize(scr, 12);
1218 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1219 WMTitledWindowMask
1220 |WMClosableWindowMask);
1222 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1223 WMTitledWindowMask
1224 |WMClosableWindowMask);
1227 WMResizeWidget(panel->win, 325, 423);
1228 WMSetWindowTitle(panel->win, _("Texture Panel"));
1229 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1232 /* texture name */
1233 panel->nameF = WMCreateFrame(panel->win);
1234 WMResizeWidget(panel->nameF, 185, 50);
1235 WMMoveWidget(panel->nameF, 15, 10);
1236 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1238 panel->nameT = WMCreateTextField(panel->nameF);
1239 WMResizeWidget(panel->nameT, 160, 20);
1240 WMMoveWidget(panel->nameT, 12, 18);
1242 WMMapSubwidgets(panel->nameF);
1244 /* texture types */
1245 panel->typeP = WMCreatePopUpButton(panel->win);
1246 WMResizeWidget(panel->typeP, 185, 20);
1247 WMMoveWidget(panel->typeP, 15, 65);
1248 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1249 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1250 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1251 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1252 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1253 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1254 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1256 /* color */
1257 panel->defcF = WMCreateFrame(panel->win);
1258 WMResizeWidget(panel->defcF, 100, 75);
1259 WMMoveWidget(panel->defcF, 210, 10);
1260 WMSetFrameTitle(panel->defcF, _("Default Color"));
1262 panel->defcW = WMCreateColorWell(panel->defcF);
1263 WMResizeWidget(panel->defcW, 60, 45);
1264 WMMoveWidget(panel->defcW, 20, 20);
1266 WMMapSubwidgets(panel->defcF);
1268 /****** Gradient ******/
1269 panel->gcolF = WMCreateFrame(panel->win);
1270 WMResizeWidget(panel->gcolF, 295, 205);
1271 WMMoveWidget(panel->gcolF, 15, 95);
1272 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1274 panel->gcolL = WMCreateList(panel->gcolF);
1275 WMResizeWidget(panel->gcolL, 130, 140);
1276 WMMoveWidget(panel->gcolL, 10, 25);
1277 WMHangData(panel->gcolL, panel);
1278 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1279 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1281 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1282 WMResizeWidget(panel->gcolaB, 64, 24);
1283 WMMoveWidget(panel->gcolaB, 10, 170);
1284 WMSetButtonText(panel->gcolaB, _("Add"));
1285 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1287 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1288 WMResizeWidget(panel->gcoldB, 64, 24);
1289 WMMoveWidget(panel->gcoldB, 75, 170);
1290 WMSetButtonText(panel->gcoldB, _("Delete"));
1291 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1293 #if 0
1294 panel->gbriS = WMCreateSlider(panel->gcolF);
1295 WMResizeWidget(panel->gbriS, 130, 16);
1296 WMMoveWidget(panel->gbriS, 150, 25);
1297 WMSetSliderKnobThickness(panel->gbriS, 8);
1298 WMSetSliderMaxValue(panel->gbriS, 100);
1299 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1301 WMPixmap *pixmap;
1302 WMColor *color;
1304 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1305 color = WMDarkGrayColor(scr);
1306 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1307 WMColorGC(color), 0, 0, 130, 16);
1308 WMReleaseColor(color);
1309 color = WMWhiteColor(color);
1310 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1311 panel->listFont, 2,
1312 (16 - WMFontHeight(panel->listFont))/2 - 1,
1313 "Brightness", 10);
1314 WMSetSliderImage(panel->gbriS, pixmap);
1315 WMReleasePixmap(pixmap);
1318 panel->gconS = WMCreateSlider(panel->gcolF);
1319 WMResizeWidget(panel->gconS, 130, 16);
1320 WMMoveWidget(panel->gconS, 150, 50);
1321 WMSetSliderKnobThickness(panel->gconS, 8);
1322 WMSetSliderMaxValue(panel->gconS, 100);
1323 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1325 WMPixmap *pixmap;
1326 WMColor *color;
1328 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1329 color = WMDarkGrayColor(scr);
1330 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1331 WMColorGC(color), 0, 0, 130, 16);
1332 WMReleaseColor(color);
1333 color = WMWhiteColor(scr);
1334 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1335 panel->listFont, 2,
1336 (16 - WMFontHeight(panel->listFont))/2 - 1,
1337 "Contrast", 8);
1338 WMSetSliderImage(panel->gconS, pixmap);
1339 WMReleasePixmap(pixmap);
1341 #endif
1342 panel->ghueS = WMCreateSlider(panel->gcolF);
1343 WMResizeWidget(panel->ghueS, 130, 16);
1344 WMMoveWidget(panel->ghueS, 150, 100);
1345 WMSetSliderKnobThickness(panel->ghueS, 8);
1346 WMSetSliderMaxValue(panel->ghueS, 359);
1347 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1349 panel->gsatS = WMCreateSlider(panel->gcolF);
1350 WMResizeWidget(panel->gsatS, 130, 16);
1351 WMMoveWidget(panel->gsatS, 150, 125);
1352 WMSetSliderKnobThickness(panel->gsatS, 8);
1353 WMSetSliderMaxValue(panel->gsatS, 255);
1354 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1356 panel->gvalS = WMCreateSlider(panel->gcolF);
1357 WMResizeWidget(panel->gvalS, 130, 16);
1358 WMMoveWidget(panel->gvalS, 150, 150);
1359 WMSetSliderKnobThickness(panel->gvalS, 8);
1360 WMSetSliderMaxValue(panel->gvalS, 255);
1361 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1364 WMMapSubwidgets(panel->gcolF);
1366 /** Direction **/
1367 panel->dirF = WMCreateFrame(panel->win);
1368 WMSetFrameTitle(panel->dirF, _("Direction"));
1369 WMResizeWidget(panel->dirF, 295, 75);
1370 WMMoveWidget(panel->dirF, 15, 305);
1372 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1373 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1374 WMResizeWidget(panel->dirvB, 90, 40);
1375 WMMoveWidget(panel->dirvB, 10, 20);
1377 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1378 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1379 WMResizeWidget(panel->dirhB, 90, 40);
1380 WMMoveWidget(panel->dirhB, 102, 20);
1382 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1383 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1384 WMResizeWidget(panel->dirdB, 90, 40);
1385 WMMoveWidget(panel->dirdB, 194, 20);
1387 WMGroupButtons(panel->dirvB, panel->dirhB);
1388 WMGroupButtons(panel->dirvB, panel->dirdB);
1390 WMMapSubwidgets(panel->dirF);
1392 /****************** Textured Gradient ******************/
1393 panel->tcolF = WMCreateFrame(panel->win);
1394 WMResizeWidget(panel->tcolF, 100, 135);
1395 WMMoveWidget(panel->tcolF, 210, 10);
1396 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1398 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1399 WMResizeWidget(panel->tcol1W, 60, 45);
1400 WMMoveWidget(panel->tcol1W, 20, 25);
1401 WMAddNotificationObserver(colorWellObserver, panel,
1402 WMColorWellDidChangeNotification, panel->tcol1W);
1404 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1405 WMResizeWidget(panel->tcol2W, 60, 45);
1406 WMMoveWidget(panel->tcol2W, 20, 75);
1407 WMAddNotificationObserver(colorWellObserver, panel,
1408 WMColorWellDidChangeNotification, panel->tcol2W);
1410 /** Opacity */
1411 panel->topaF = WMCreateFrame(panel->win);
1412 WMResizeWidget(panel->topaF, 185, 50);
1413 WMMoveWidget(panel->topaF, 15, 95);
1414 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1416 panel->topaS = WMCreateSlider(panel->topaF);
1417 WMResizeWidget(panel->topaS, 155, 18);
1418 WMMoveWidget(panel->topaS, 15, 20);
1419 WMSetSliderMaxValue(panel->topaS, 255);
1420 WMSetSliderValue(panel->topaS, 200);
1421 WMSetSliderContinuous(panel->topaS, False);
1422 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1424 WMMapSubwidgets(panel->topaF);
1427 WMPixmap *pixmap;
1428 Pixmap p;
1429 WMColor *color;
1431 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1432 p = WMGetPixmapXID(pixmap);
1434 color = WMDarkGrayColor(scr);
1435 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1436 0, 0, 155, 18);
1437 WMReleaseColor(color);
1439 color = WMWhiteColor(scr);
1440 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1441 2, 1, "0%", 2);
1442 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1443 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1444 "100%", 4);
1445 WMReleaseColor(color);
1447 WMSetSliderImage(panel->topaS, pixmap);
1448 WMReleasePixmap(pixmap);
1451 WMMapSubwidgets(panel->tcolF);
1453 /****************** Image ******************/
1454 panel->imageF = WMCreateFrame(panel->win);
1455 WMResizeWidget(panel->imageF, 295, 150);
1456 WMMoveWidget(panel->imageF, 15, 150);
1457 WMSetFrameTitle(panel->imageF, _("Image"));
1459 panel->imageL = WMCreateLabel(panel->imageF);
1460 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1462 panel->imageT = WMCreateTextField(panel->imageF);
1463 WMResizeWidget(panel->imageT, 90, 20);
1464 WMMoveWidget(panel->imageT, 190, 25);
1466 panel->imageV = WMCreateScrollView(panel->imageF);
1467 WMResizeWidget(panel->imageV, 165, 115);
1468 WMMoveWidget(panel->imageV, 15, 20);
1469 WMSetScrollViewRelief(panel->imageV, WRSunken);
1470 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1471 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1472 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1474 panel->browB = WMCreateCommandButton(panel->imageF);
1475 WMResizeWidget(panel->browB, 90, 24);
1476 WMMoveWidget(panel->browB, 190, 50);
1477 WMSetButtonText(panel->browB, _("Browse..."));
1478 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1480 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1481 WMResizeWidget(panel->dispB, 90, 24);
1482 WMMoveWidget(panel->dispB, 190, 80);
1483 WMSetButtonText(panel->dispB, _("Show"));
1486 panel->arrP = WMCreatePopUpButton(panel->imageF);
1487 WMResizeWidget(panel->arrP, 90, 20);
1488 WMMoveWidget(panel->arrP, 190, 120);
1489 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1490 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1491 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1492 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1493 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1495 WMMapSubwidgets(panel->imageF);
1497 /****/
1499 panel->okB = WMCreateCommandButton(panel->win);
1500 WMResizeWidget(panel->okB, 84, 24);
1501 WMMoveWidget(panel->okB, 225, 390);
1502 WMSetButtonText(panel->okB, _("OK"));
1503 WMSetButtonAction(panel->okB, buttonCallback, panel);
1505 panel->cancelB = WMCreateCommandButton(panel->win);
1506 WMResizeWidget(panel->cancelB, 84, 24);
1507 WMMoveWidget(panel->cancelB, 130, 390);
1508 WMSetButtonText(panel->cancelB, _("Cancel"));
1509 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1511 WMMapWidget(panel->nameF);
1512 WMMapWidget(panel->typeP);
1513 WMMapWidget(panel->okB);
1514 WMMapWidget(panel->cancelB);
1516 WMUnmapWidget(panel->arrP);
1518 WMRealizeWidget(panel->win);
1520 panel->currentType = -1;
1522 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1524 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1525 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1526 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1528 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1529 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1531 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1532 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1533 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1534 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1535 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1537 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1538 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1539 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1542 /* setup for first time */
1544 changeTypeCallback(panel->typeP, panel);
1546 sliderChangeCallback(panel->ghueS, panel);
1547 sliderChangeCallback(panel->gsatS, panel);
1549 return panel;
1555 *--------------------------------------------------------------------------
1556 * Test stuff
1557 *--------------------------------------------------------------------------
1560 #if 0
1562 char *ProgName = "test";
1564 void
1565 testOKButton(WMWidget *self, void *data)
1567 char *test;
1568 Display *dpy;
1569 Window win;
1570 Pixmap pix;
1571 RImage *image;
1573 TexturePanel *panel = (TexturePanel*)data;
1574 /* test = GetTexturePanelTextureString(panel); */
1576 wwarning(test);
1578 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1579 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1580 0, 0, 0);
1581 XMapRaised(dpy, win);
1582 XFlush(dpy);
1584 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1586 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1588 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1589 0, 0);
1591 free (test);
1595 void testCancelButton(WMWidget *self, void *data){
1596 wwarning("Exiting test....");
1597 exit(0);
1600 void wAbort()
1602 exit(1);
1605 int main(int argc, char **argv)
1607 TexturePanel *panel;
1609 Display *dpy = XOpenDisplay("");
1610 WMScreen *scr;
1612 /* char *test; */
1614 WMInitializeApplication("Test", &argc, argv);
1616 if (!dpy) {
1617 wfatal("could not open display");
1618 exit(1);
1621 scr = WMCreateSimpleApplicationScreen(dpy);
1623 panel = CreateTexturePanel(scr);
1625 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1626 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1628 SetTexturePanelTexture(panel, "pinky",
1629 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1631 ShowTexturePanel(panel);
1633 WMScreenMainLoop(scr);
1634 return 0;
1636 #endif