configure.in fix, WPrefs updates
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob99efde95cacb91acd750780ac7b552f1ef49d9ae
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 color = WMGetColorWellColor(panel->tcol1W);
212 from.red = WMRedComponentOfColor(color)>>8;
213 from.green = WMGreenComponentOfColor(color)>>8;
214 from.blue = WMBlueComponentOfColor(color)>>8;
216 color = WMGetColorWellColor(panel->tcol2W);
217 to.red = WMRedComponentOfColor(color)>>8;
218 to.green = WMGreenComponentOfColor(color)>>8;
219 to.blue = WMBlueComponentOfColor(color)>>8;
221 if (WMGetButtonSelected(panel->dirhB)) {
222 gradient = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
223 } else if (WMGetButtonSelected(panel->dirvB)) {
224 gradient = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
225 } else {
226 gradient = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
231 static void
232 updateSGradButtons(TexturePanel *panel)
234 RImage *image;
235 WMPixmap *pixmap;
236 RColor from;
237 RColor to;
238 WMColor *color;
240 color = WMGetColorWellColor(panel->tcol1W);
241 from.red = WMRedComponentOfColor(color)>>8;
242 from.green = WMGreenComponentOfColor(color)>>8;
243 from.blue = WMBlueComponentOfColor(color)>>8;
245 color = WMGetColorWellColor(panel->tcol2W);
246 to.red = WMRedComponentOfColor(color)>>8;
247 to.green = WMGreenComponentOfColor(color)>>8;
248 to.blue = WMBlueComponentOfColor(color)>>8;
250 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
251 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
252 image, 128);
253 RDestroyImage(image);
254 WMSetButtonImage(panel->dirhB, pixmap);
255 WMReleasePixmap(pixmap);
257 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
258 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
259 image, 128);
260 RDestroyImage(image);
261 WMSetButtonImage(panel->dirvB, pixmap);
262 WMReleasePixmap(pixmap);
264 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
265 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
266 image, 128);
267 RDestroyImage(image);
268 WMSetButtonImage(panel->dirdB, pixmap);
269 WMReleasePixmap(pixmap);
273 static void
274 changeTypeCallback(WMWidget *w, void *data)
276 TexturePanel *panel = (TexturePanel*)data;
277 int newType;
278 int i;
280 newType = WMGetPopUpButtonSelectedItem(w);
281 if (newType == panel->currentType)
282 return;
284 if (panel->currentType >= 0) {
285 for (i = 0; i < MAX_SECTION_PARTS; i++) {
286 if (panel->sectionParts[panel->currentType][i] == NULL)
287 break;
288 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
292 for (i = 0; i < MAX_SECTION_PARTS; i++) {
293 if (panel->sectionParts[newType][i] == NULL)
294 break;
295 WMMapWidget(panel->sectionParts[newType][i]);
297 panel->currentType = newType;
299 switch (newType) {
300 case TYPE_SGRADIENT:
301 updateSGradButtons(panel);
302 break;
303 case TYPE_GRADIENT:
304 updateGradButtons(panel);
305 break;
310 /*********** Gradient ************/
312 static void
313 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
315 RImage *image;
316 WMPixmap *pixmap;
317 WMScreen *scr = WMWidgetScreen(sPtr);
318 RColor from, to;
319 RHSVColor tmp;
321 tmp = *hsv;
322 if (saturation) {
323 tmp.saturation = 0;
324 RHSVtoRGB(&tmp, &from);
325 tmp.saturation = 255;
326 RHSVtoRGB(&tmp, &to);
327 } else {
328 tmp.value = 0;
329 RHSVtoRGB(&tmp, &from);
330 tmp.value = 255;
331 RHSVtoRGB(&tmp, &to);
333 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
334 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
335 RDestroyImage(image);
337 if (hsv->value < 128 || !saturation) {
338 WMColor *col = WMWhiteColor(scr);
340 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
341 (16 - WMFontHeight(font))/2 - 1,
342 saturation ? "Saturation" : "Brightness", 10);
343 WMReleaseColor(col);
344 } else {
345 WMColor *col = WMBlackColor(scr);
347 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
348 (16 - WMFontHeight(font))/2 - 1,
349 saturation ? "Saturation" : "Brightness", 10);
350 WMReleaseColor(col);
352 WMSetSliderImage(sPtr, pixmap);
353 WMReleasePixmap(pixmap);
357 static void
358 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
360 RColor *colors[8];
361 RImage *image;
362 WMPixmap *pixmap;
363 WMScreen *scr = WMWidgetScreen(sPtr);
364 RHSVColor thsv;
365 int i;
367 thsv = *hsv;
368 for (i = 0; i <= 6; i++) {
369 thsv.hue = (360*i)/6;
370 colors[i] = wmalloc(sizeof(RColor));
371 RHSVtoRGB(&thsv, colors[i]);
373 colors[i] = NULL;
375 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
376 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
377 RDestroyImage(image);
379 if (hsv->value < 128) {
380 WMColor *col = WMWhiteColor(scr);
382 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
383 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
384 WMReleaseColor(col);
385 } else {
386 WMColor *col = WMBlackColor(scr);
388 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
389 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
390 WMReleaseColor(col);
392 WMSetSliderImage(sPtr, pixmap);
393 WMReleasePixmap(pixmap);
395 for (i = 0; i <= 6; i++)
396 free(colors[i]);
401 static void
402 sliderChangeCallback(WMWidget *w, void *data)
404 TexturePanel *panel = (TexturePanel*)data;
405 RHSVColor hsv, *hsvp;
406 int row, rows;
407 WMListItem *item;
408 RColor **colors;
409 int i;
410 RImage *image;
411 WMScreen *scr = WMWidgetScreen(w);
413 hsv.hue = WMGetSliderValue(panel->ghueS);
414 hsv.saturation = WMGetSliderValue(panel->gsatS);
415 hsv.value = WMGetSliderValue(panel->gvalS);
417 row = WMGetListSelectedItemRow(panel->gcolL);
418 if (row >= 0) {
419 RColor *rgb;
421 item = WMGetListItem(panel->gcolL, row);
423 rgb = (RColor*)item->clientData;
425 RHSVtoRGB(&hsv, rgb);
427 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
430 if (w == panel->ghueS) {
431 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
432 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
433 } else if (w == panel->gsatS) {
434 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
435 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
436 } else {
437 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
438 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
441 rows = WMGetListNumberOfRows(panel->gcolL);
442 if (rows == 0)
443 return;
445 colors = wmalloc(sizeof(RColor*)*(rows+1));
447 for (i = 0; i < rows; i++) {
448 item = WMGetListItem(panel->gcolL, i);
450 colors[i] = (RColor*)item->clientData;
452 colors[i] = NULL;
454 if (panel->gimage != None) {
455 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
458 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
459 colors, RVerticalGradient);
460 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
461 RDestroyImage(image);
463 free(colors);
465 WMRedisplayWidget(panel->gcolL);
467 updateGradButtons(panel);
471 static void
472 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
473 WMRect *rect)
475 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
476 WMScreen *scr = WMWidgetScreen(lPtr);
477 int width, height, x, y;
478 Display *dpy;
479 WMColor *white = WMWhiteColor(scr);
480 WMListItem *item;
481 WMColor *black = WMBlackColor(scr);
483 dpy = WMScreenDisplay(scr);
485 width = rect->size.width;
486 height = rect->size.height;
487 x = rect->pos.x;
488 y = rect->pos.y;
490 if (state & WLDSSelected)
491 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
492 else
493 XClearArea(dpy, d, x, y, width, height, False);
495 item = WMGetListItem(lPtr, index);
497 if (panel->gimage) {
498 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
499 0, height*index, 30, height, x + 5, y);
501 WMDrawString(scr, d, WMColorGC(black), panel->listFont,
502 x + 40, y + 1, text, strlen(text));
504 WMReleaseColor(white);
505 WMReleaseColor(black);
510 static void
511 gradAddCallback(WMWidget *w, void *data)
513 TexturePanel *panel = (TexturePanel*)data;
514 WMListItem *item;
515 int row;
516 RColor *rgb;
518 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
519 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
520 rgb = wmalloc(sizeof(RColor));
521 memset(rgb, 0, sizeof(RColor));
522 item->clientData = rgb;
524 WMSelectListItem(panel->gcolL, row);
526 updateGradButtons(panel);
528 sliderChangeCallback(panel->ghueS, panel);
533 static void
534 gradClickCallback(WMWidget *w, void *data)
536 TexturePanel *panel = (TexturePanel*)data;
537 WMListItem *item;
538 int row;
539 RHSVColor hsv;
541 row = WMGetListSelectedItemRow(w);
542 if (row < 0)
543 return;
545 item = WMGetListItem(panel->gcolL, row);
546 RRGBtoHSV((RColor*)item->clientData, &hsv);
548 WMSetSliderValue(panel->ghueS, hsv.hue);
549 WMSetSliderValue(panel->gsatS, hsv.saturation);
550 WMSetSliderValue(panel->gvalS, hsv.value);
552 sliderChangeCallback(panel->ghueS, panel);
553 sliderChangeCallback(panel->gsatS, panel);
557 static void
558 gradDeleteCallback(WMWidget *w, void *data)
560 TexturePanel *panel = (TexturePanel*)data;
561 WMListItem *item;
562 int row;
564 row = WMGetListSelectedItemRow(panel->gcolL);
565 if (row < 0)
566 return;
568 item = WMGetListItem(panel->gcolL, row);
569 free(item->clientData);
571 WMRemoveListItem(panel->gcolL, row);
573 WMSelectListItem(panel->gcolL, row - 1);
575 updateGradButtons(panel);
577 gradClickCallback(panel->gcolL, panel);
581 /*************** Simple Gradient ***************/
583 static void
584 colorWellObserver(void *self, WMNotification *n)
586 updateSGradButtons(self);
590 /****************** Image ******************/
592 static void
593 browseImageCallback(WMWidget *w, void *data)
595 TexturePanel *panel = (TexturePanel*)data;
596 WMOpenPanel *opanel;
597 WMScreen *scr = WMWidgetScreen(w);
599 opanel = WMGetOpenPanel(scr);
600 WMSetFilePanelCanChooseDirectories(opanel, False);
601 WMSetFilePanelCanChooseFiles(opanel, True);
603 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
604 "Open Image", NULL)) {
605 char *path, *fullpath;
606 char *tmp, *tmp2;
608 fullpath = WMGetFilePanelFileName(opanel);
609 if (!fullpath)
610 return;
611 path = wstrdup(fullpath);
613 tmp2 = strrchr(fullpath, '/');
614 if (tmp2)
615 tmp2++;
617 tmp = wfindfileinarray(panel->pathList, tmp2);
619 if (tmp) {
620 if (strcmp(fullpath, tmp)==0) {
621 free(path);
622 path = tmp2;
624 free(tmp);
627 if (!RGetImageFileFormat(fullpath)) {
628 WMRunAlertPanel(scr, panel->win, _("Error"),
629 _("The selected file does not contain a supported image."),
630 _("OK"), NULL, NULL);
631 free(path);
632 free(fullpath);
633 } else {
634 RImage *image, *scaled;
635 WMPixmap *pixmap;
636 WMSize size;
638 image = RLoadImage(WMScreenRContext(scr), fullpath, 0);
639 if (!image) {
640 char *message;
642 message = wstrappend(_("Could not load the selected file: "),
643 (char*)RMessageForError(RErrorCode));
645 WMRunAlertPanel(scr, panel->win, _("Error"), message,
646 _("OK"), NULL, NULL);
647 free(message);
648 free(path);
649 free(fullpath);
650 return;
653 if (panel->image)
654 RDestroyImage(panel->image);
655 panel->image = image;
657 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
658 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
660 size = WMGetPixmapSize(pixmap);
661 WMSetLabelImage(panel->imageL, pixmap);
662 WMResizeWidget(panel->imageL, size.width, size.height);
664 WMReleasePixmap(pixmap);
665 } else {
666 updateTGradImage(panel);
668 panel->imageFile = path;
670 WMSetTextFieldText(panel->imageT, path);
672 free(fullpath);
679 static void
680 buttonCallback(WMWidget *w, void *data)
682 TexturePanel *panel = (TexturePanel*)data;
684 if (w == panel->okB) {
685 (*panel->okAction)(panel->okData);
686 } else {
687 (*panel->cancelAction)(panel->cancelData);
693 *--------------------------------------------------------------------------
694 * Public functions
695 *--------------------------------------------------------------------------
697 void
698 DestroyTexturePanel(TexturePanel *panel)
704 void
705 ShowTexturePanel(TexturePanel *panel)
707 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
709 WMSetWindowUPosition(panel->win,
710 WidthOfScreen(DefaultScreenOfDisplay(dpy))/2,
711 HeightOfScreen(DefaultScreenOfDisplay(dpy))/2);
712 WMMapWidget(panel->win);
716 void
717 HideTexturePanel(TexturePanel *panel)
719 WMUnmapWidget(panel->win);
723 void
724 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
726 panel->okAction = action;
727 panel->okData = clientData;
731 void
732 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
734 panel->cancelAction = action;
735 panel->cancelData = clientData;
739 void
740 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
742 WMScreen *scr = WMWidgetScreen(panel->win);
743 char *str, *type;
744 proplist_t p;
745 WMColor *color;
746 int i;
747 char buffer[64];
748 int gradient = 0;
750 WMSetTextFieldText(panel->nameT, name);
752 if (!texture)
753 return;
755 p = PLGetArrayElement(texture, 0);
756 if (!p) {
757 goto bad_texture;
759 type = PLGetString(p);
761 /*...............................................*/
762 if (strcasecmp(type, "solid")==0) {
764 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
766 p = PLGetArrayElement(texture, 1);
767 if (!p) {
768 str = "black";
769 } else {
770 str = PLGetString(p);
772 color = WMCreateNamedColor(scr, str, False);
774 WMSetColorWellColor(panel->defcW, color);
776 WMReleaseColor(color);
777 /*...............................................*/
778 } else if (strcasecmp(type, "hgradient")==0
779 || strcasecmp(type, "vgradient")==0
780 || strcasecmp(type, "dgradient")==0) {
782 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
784 p = PLGetArrayElement(texture, 1);
785 if (!p) {
786 str = "black";
787 } else {
788 str = PLGetString(p);
790 color = WMCreateNamedColor(scr, str, False);
792 WMSetColorWellColor(panel->tcol1W, color);
794 WMReleaseColor(color);
796 p = PLGetArrayElement(texture, 2);
797 if (!p) {
798 str = "black";
799 } else {
800 str = PLGetString(p);
802 color = WMCreateNamedColor(scr, str, False);
804 WMSetColorWellColor(panel->tcol2W, color);
806 WMReleaseColor(color);
808 gradient = type[0];
809 /*...............................................*/
810 } else if (strcasecmp(type, "thgradient")==0
811 || strcasecmp(type, "tvgradient")==0
812 || strcasecmp(type, "tdgradient")==0) {
813 int i;
815 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
817 gradient = type[1];
819 WMSetTextFieldText(panel->imageT,
820 PLGetString(PLGetArrayElement(texture, 1)));
822 i = 180;
823 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
824 WMSetSliderValue(panel->topaS, i);
826 p = PLGetArrayElement(texture, 3);
827 if (!p) {
828 str = "black";
829 } else {
830 str = PLGetString(p);
832 color = WMCreateNamedColor(scr, str, False);
834 WMSetColorWellColor(panel->tcol1W, color);
836 WMReleaseColor(color);
838 p = PLGetArrayElement(texture, 4);
839 if (!p) {
840 str = "black";
841 } else {
842 str = PLGetString(p);
844 color = WMCreateNamedColor(scr, str, False);
846 WMSetColorWellColor(panel->tcol2W, color);
848 WMReleaseColor(color);
850 /*...............................................*/
851 } else if (strcasecmp(type, "mhgradient")==0
852 || strcasecmp(type, "mvgradient")==0
853 || strcasecmp(type, "mdgradient")==0) {
854 WMListItem *item;
856 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
857 item = WMGetListItem(panel->gcolL, i);
858 free(item->clientData);
860 WMClearList(panel->gcolL);
862 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
864 p = PLGetArrayElement(texture, 1);
865 if (!p) {
866 str = "black";
867 } else {
868 str = PLGetString(p);
870 color = WMCreateNamedColor(scr, str, False);
872 WMSetColorWellColor(panel->defcW, color);
874 WMReleaseColor(color);
876 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
877 RColor *rgb;
878 XColor xcolor;
880 p = PLGetArrayElement(texture, i);
881 if (!p) {
882 str = "black";
883 } else {
884 str = PLGetString(p);
887 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
888 str, &xcolor);
890 rgb = wmalloc(sizeof(RColor));
891 rgb->red = xcolor.red >> 8;
892 rgb->green = xcolor.green >> 8;
893 rgb->blue = xcolor.blue >> 8;
894 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
896 item = WMAddListItem(panel->gcolL, buffer);
897 item->clientData = rgb;
900 sliderChangeCallback(panel->ghueS, panel);
902 gradient = type[1];
903 /*...............................................*/
904 } else if (strcasecmp(type, "cpixmap")==0
905 || strcasecmp(type, "spixmap")==0
906 || strcasecmp(type, "mpixmap")==0
907 || strcasecmp(type, "tpixmap")==0) {
909 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
911 switch (toupper(type[0])) {
912 case 'C':
913 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
914 break;
915 case 'S':
916 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
917 break;
918 case 'M':
919 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
920 break;
921 default:
922 case 'T':
923 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
924 break;
927 WMSetTextFieldText(panel->imageT,
928 PLGetString(PLGetArrayElement(texture, 1)));
931 changeTypeCallback(panel->typeP, panel);
933 if (gradient > 0) {
934 updateGradButtons(panel);
936 switch (toupper(gradient)) {
937 case 'H':
938 WMPerformButtonClick(panel->dirhB);
939 break;
940 case 'V':
941 WMPerformButtonClick(panel->dirvB);
942 break;
943 default:
944 case 'D':
945 WMPerformButtonClick(panel->dirdB);
946 break;
950 return;
952 bad_texture:
953 str = PLGetDescription(texture);
954 wwarning("error creating texture %s", str);
955 free(str);
961 char*
962 GetTexturePanelTextureName(TexturePanel *panel)
964 return WMGetTextFieldText(panel->nameT);
970 proplist_t
971 GetTexturePanelTexture(TexturePanel *panel)
973 proplist_t prop = NULL;
974 WMColor *color;
975 char *str, *str2;
976 char buff[32];
977 int i;
980 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
982 case TYPE_SOLID:
983 color = WMGetColorWellColor(panel->defcW);
984 str = WMGetColorRGBDescription(color);
985 prop = PLMakeArrayFromElements(PLMakeString("solid"),
986 PLMakeString(str), NULL);
987 free(str);
989 break;
991 case TYPE_PIXMAP:
992 color = WMGetColorWellColor(panel->defcW);
993 str = WMGetColorRGBDescription(color);
995 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
996 case PTYPE_SCALE:
997 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
998 PLMakeString(panel->imageFile),
999 PLMakeString(str), NULL);
1000 break;
1001 case PTYPE_MAXIMIZE:
1002 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1003 PLMakeString(panel->imageFile),
1004 PLMakeString(str), NULL);
1005 break;
1006 case PTYPE_CENTER:
1007 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1008 PLMakeString(panel->imageFile),
1009 PLMakeString(str), NULL);
1010 break;
1011 case PTYPE_TILE:
1012 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1013 PLMakeString(panel->imageFile),
1014 PLMakeString(str), NULL);
1015 break;
1017 free(str);
1018 break;
1020 case TYPE_SGRADIENT:
1021 color = WMGetColorWellColor(panel->tcol1W);
1022 str = WMGetColorRGBDescription(color);
1024 color = WMGetColorWellColor(panel->tcol2W);
1025 str2 = WMGetColorRGBDescription(color);
1027 if (WMGetButtonSelected(panel->dirdB)) {
1028 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1029 PLMakeString(str),
1030 PLMakeString(str2), NULL);
1031 } else if (WMGetButtonSelected(panel->dirvB)) {
1032 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1033 PLMakeString(str),
1034 PLMakeString(str2), NULL);
1035 } else {
1036 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1037 PLMakeString(str),
1038 PLMakeString(str2), NULL);
1040 free(str);
1041 free(str2);
1042 break;
1044 case TYPE_GRADIENT:
1045 color = WMGetColorWellColor(panel->defcW);
1046 str = WMGetColorRGBDescription(color);
1048 if (WMGetButtonSelected(panel->dirdB)) {
1049 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1050 PLMakeString(str), NULL);
1051 } else if (WMGetButtonSelected(panel->dirvB)) {
1052 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1053 PLMakeString(str), NULL);
1054 } else {
1055 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1056 PLMakeString(str), NULL);
1058 free(str);
1060 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1061 RColor *rgb;
1062 WMListItem *item;
1064 item = WMGetListItem(panel->gcolL, i);
1066 rgb = (RColor*)item->clientData;
1068 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1070 PLAppendArrayElement(prop, PLMakeString(buff));
1072 break;
1076 return prop;
1081 void
1082 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1084 panel->pathList = array;
1089 TexturePanel*
1090 CreateTexturePanel(WMWindow *keyWindow)
1091 /*CreateTexturePanel(WMScreen *scr)*/
1093 TexturePanel *panel;
1094 WMScreen *scr = WMWidgetScreen(keyWindow);
1096 panel = wmalloc(sizeof(TexturePanel));
1097 memset(panel, 0, sizeof(TexturePanel));
1099 panel->listFont = WMSystemFontOfSize(scr, 12);
1102 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1103 WMTitledWindowMask
1104 |WMClosableWindowMask);
1106 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1107 WMTitledWindowMask
1108 |WMClosableWindowMask);
1111 WMResizeWidget(panel->win, 325, 423);
1112 WMSetWindowTitle(panel->win, _("Texture Panel"));
1115 /* texture name */
1116 panel->nameF = WMCreateFrame(panel->win);
1117 WMResizeWidget(panel->nameF, 185, 50);
1118 WMMoveWidget(panel->nameF, 15, 10);
1119 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1121 panel->nameT = WMCreateTextField(panel->nameF);
1122 WMResizeWidget(panel->nameT, 160, 20);
1123 WMMoveWidget(panel->nameT, 12, 18);
1125 WMMapSubwidgets(panel->nameF);
1127 /* texture types */
1128 panel->typeP = WMCreatePopUpButton(panel->win);
1129 WMResizeWidget(panel->typeP, 185, 20);
1130 WMMoveWidget(panel->typeP, 15, 65);
1131 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1132 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1133 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1134 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1135 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1136 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1137 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1139 /* color */
1140 panel->defcF = WMCreateFrame(panel->win);
1141 WMResizeWidget(panel->defcF, 100, 75);
1142 WMMoveWidget(panel->defcF, 210, 10);
1143 WMSetFrameTitle(panel->defcF, _("Default Color"));
1145 panel->defcW = WMCreateColorWell(panel->defcF);
1146 WMResizeWidget(panel->defcW, 60, 45);
1147 WMMoveWidget(panel->defcW, 20, 20);
1149 WMMapSubwidgets(panel->defcF);
1151 /****** Gradient ******/
1152 panel->gcolF = WMCreateFrame(panel->win);
1153 WMResizeWidget(panel->gcolF, 295, 205);
1154 WMMoveWidget(panel->gcolF, 15, 95);
1155 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1157 panel->gcolL = WMCreateList(panel->gcolF);
1158 WMResizeWidget(panel->gcolL, 130, 140);
1159 WMMoveWidget(panel->gcolL, 10, 25);
1160 WMHangData(panel->gcolL, panel);
1161 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1162 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1164 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1165 WMResizeWidget(panel->gcolaB, 64, 24);
1166 WMMoveWidget(panel->gcolaB, 10, 170);
1167 WMSetButtonText(panel->gcolaB, _("Add"));
1168 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1170 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1171 WMResizeWidget(panel->gcoldB, 64, 24);
1172 WMMoveWidget(panel->gcoldB, 75, 170);
1173 WMSetButtonText(panel->gcoldB, _("Delete"));
1174 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1176 #if 0
1177 panel->gbriS = WMCreateSlider(panel->gcolF);
1178 WMResizeWidget(panel->gbriS, 130, 16);
1179 WMMoveWidget(panel->gbriS, 150, 25);
1180 WMSetSliderKnobThickness(panel->gbriS, 8);
1181 WMSetSliderMaxValue(panel->gbriS, 100);
1182 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1184 WMPixmap *pixmap;
1185 WMColor *color;
1187 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1188 color = WMDarkGrayColor(scr);
1189 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1190 WMColorGC(color), 0, 0, 130, 16);
1191 WMReleaseColor(color);
1192 color = WMWhiteColor(color);
1193 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1194 panel->listFont, 2,
1195 (16 - WMFontHeight(panel->listFont))/2 - 1,
1196 "Brightness", 10);
1197 WMSetSliderImage(panel->gbriS, pixmap);
1198 WMReleasePixmap(pixmap);
1201 panel->gconS = WMCreateSlider(panel->gcolF);
1202 WMResizeWidget(panel->gconS, 130, 16);
1203 WMMoveWidget(panel->gconS, 150, 50);
1204 WMSetSliderKnobThickness(panel->gconS, 8);
1205 WMSetSliderMaxValue(panel->gconS, 100);
1206 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1208 WMPixmap *pixmap;
1209 WMColor *color;
1211 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1212 color = WMDarkGrayColor(scr);
1213 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1214 WMColorGC(color), 0, 0, 130, 16);
1215 WMReleaseColor(color);
1216 color = WMWhiteColor(scr);
1217 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1218 panel->listFont, 2,
1219 (16 - WMFontHeight(panel->listFont))/2 - 1,
1220 "Contrast", 8);
1221 WMSetSliderImage(panel->gconS, pixmap);
1222 WMReleasePixmap(pixmap);
1224 #endif
1225 panel->ghueS = WMCreateSlider(panel->gcolF);
1226 WMResizeWidget(panel->ghueS, 130, 16);
1227 WMMoveWidget(panel->ghueS, 150, 100);
1228 WMSetSliderKnobThickness(panel->ghueS, 8);
1229 WMSetSliderMaxValue(panel->ghueS, 359);
1230 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1232 panel->gsatS = WMCreateSlider(panel->gcolF);
1233 WMResizeWidget(panel->gsatS, 130, 16);
1234 WMMoveWidget(panel->gsatS, 150, 125);
1235 WMSetSliderKnobThickness(panel->gsatS, 8);
1236 WMSetSliderMaxValue(panel->gsatS, 255);
1237 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1239 panel->gvalS = WMCreateSlider(panel->gcolF);
1240 WMResizeWidget(panel->gvalS, 130, 16);
1241 WMMoveWidget(panel->gvalS, 150, 150);
1242 WMSetSliderKnobThickness(panel->gvalS, 8);
1243 WMSetSliderMaxValue(panel->gvalS, 255);
1244 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1247 WMMapSubwidgets(panel->gcolF);
1249 /** Direction **/
1250 panel->dirF = WMCreateFrame(panel->win);
1251 WMSetFrameTitle(panel->dirF, _("Direction"));
1252 WMResizeWidget(panel->dirF, 295, 75);
1253 WMMoveWidget(panel->dirF, 15, 305);
1255 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1256 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1257 WMResizeWidget(panel->dirvB, 90, 40);
1258 WMMoveWidget(panel->dirvB, 10, 20);
1260 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1261 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1262 WMResizeWidget(panel->dirhB, 90, 40);
1263 WMMoveWidget(panel->dirhB, 102, 20);
1265 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1266 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1267 WMResizeWidget(panel->dirdB, 90, 40);
1268 WMMoveWidget(panel->dirdB, 194, 20);
1270 WMGroupButtons(panel->dirvB, panel->dirhB);
1271 WMGroupButtons(panel->dirvB, panel->dirdB);
1273 WMMapSubwidgets(panel->dirF);
1275 /****************** Textured Gradient ******************/
1276 panel->tcolF = WMCreateFrame(panel->win);
1277 WMResizeWidget(panel->tcolF, 100, 135);
1278 WMMoveWidget(panel->tcolF, 210, 10);
1279 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1281 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1282 WMResizeWidget(panel->tcol1W, 60, 45);
1283 WMMoveWidget(panel->tcol1W, 20, 25);
1284 WMAddNotificationObserver(colorWellObserver, panel,
1285 WMColorWellDidChangeNotification, panel->tcol1W);
1287 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1288 WMResizeWidget(panel->tcol2W, 60, 45);
1289 WMMoveWidget(panel->tcol2W, 20, 75);
1290 WMAddNotificationObserver(colorWellObserver, panel,
1291 WMColorWellDidChangeNotification, panel->tcol2W);
1293 /** Opacity */
1294 panel->topaF = WMCreateFrame(panel->win);
1295 WMResizeWidget(panel->topaF, 185, 50);
1296 WMMoveWidget(panel->topaF, 15, 95);
1297 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1299 panel->topaS = WMCreateSlider(panel->topaF);
1300 WMResizeWidget(panel->topaS, 155, 18);
1301 WMMoveWidget(panel->topaS, 15, 20);
1302 WMSetSliderMaxValue(panel->topaS, 255);
1303 WMSetSliderValue(panel->topaS, 200);
1304 WMMapSubwidgets(panel->topaF);
1307 WMPixmap *pixmap;
1308 Pixmap p;
1309 WMColor *color;
1311 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1312 p = WMGetPixmapXID(pixmap);
1314 color = WMDarkGrayColor(scr);
1315 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1316 0, 0, 155, 18);
1317 WMReleaseColor(color);
1319 color = WMWhiteColor(scr);
1320 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1321 2, 1, "0%", 2);
1322 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1323 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1324 "100%", 4);
1325 WMReleaseColor(color);
1327 WMSetSliderImage(panel->topaS, pixmap);
1328 WMReleasePixmap(pixmap);
1331 WMMapSubwidgets(panel->tcolF);
1333 /****************** Image ******************/
1334 panel->imageF = WMCreateFrame(panel->win);
1335 WMResizeWidget(panel->imageF, 295, 150);
1336 WMMoveWidget(panel->imageF, 15, 150);
1337 WMSetFrameTitle(panel->imageF, _("Image"));
1339 panel->imageL = WMCreateLabel(panel->imageF);
1340 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1342 panel->imageT = WMCreateTextField(panel->imageF);
1343 WMResizeWidget(panel->imageT, 90, 20);
1344 WMMoveWidget(panel->imageT, 190, 25);
1346 panel->imageV = WMCreateScrollView(panel->imageF);
1347 WMResizeWidget(panel->imageV, 165, 115);
1348 WMMoveWidget(panel->imageV, 15, 20);
1349 WMSetScrollViewRelief(panel->imageV, WRSunken);
1350 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1351 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1352 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1354 panel->browB = WMCreateCommandButton(panel->imageF);
1355 WMResizeWidget(panel->browB, 90, 24);
1356 WMMoveWidget(panel->browB, 190, 50);
1357 WMSetButtonText(panel->browB, _("Browse..."));
1358 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1360 panel->dispB = WMCreateCommandButton(panel->imageF);
1361 WMResizeWidget(panel->dispB, 90, 24);
1362 WMMoveWidget(panel->dispB, 190, 80);
1363 WMSetButtonText(panel->dispB, _("Show"));
1365 panel->arrP = WMCreatePopUpButton(panel->imageF);
1366 WMResizeWidget(panel->arrP, 90, 20);
1367 WMMoveWidget(panel->arrP, 190, 120);
1368 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1369 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1370 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1371 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1372 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1374 WMMapSubwidgets(panel->imageF);
1376 /****/
1378 panel->okB = WMCreateCommandButton(panel->win);
1379 WMResizeWidget(panel->okB, 84, 24);
1380 WMMoveWidget(panel->okB, 225, 390);
1381 WMSetButtonText(panel->okB, _("OK"));
1382 WMSetButtonAction(panel->okB, buttonCallback, panel);
1384 panel->cancelB = WMCreateCommandButton(panel->win);
1385 WMResizeWidget(panel->cancelB, 84, 24);
1386 WMMoveWidget(panel->cancelB, 130, 390);
1387 WMSetButtonText(panel->cancelB, _("Cancel"));
1388 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1390 WMMapWidget(panel->nameF);
1391 WMMapWidget(panel->typeP);
1392 WMMapWidget(panel->okB);
1393 WMMapWidget(panel->cancelB);
1395 WMUnmapWidget(panel->arrP);
1397 WMRealizeWidget(panel->win);
1399 panel->currentType = -1;
1401 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1403 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1404 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1405 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1407 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1408 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1410 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1411 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1412 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1413 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1414 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1416 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1417 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1418 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1421 /* setup for first time */
1423 changeTypeCallback(panel->typeP, panel);
1425 sliderChangeCallback(panel->ghueS, panel);
1426 sliderChangeCallback(panel->gsatS, panel);
1428 return panel;
1434 *--------------------------------------------------------------------------
1435 * Test stuff
1436 *--------------------------------------------------------------------------
1439 #if 0
1441 char *ProgName = "test";
1443 void
1444 testOKButton(WMWidget *self, void *data)
1446 char *test;
1447 Display *dpy;
1448 Window win;
1449 Pixmap pix;
1450 RImage *image;
1452 TexturePanel *panel = (TexturePanel*)data;
1453 // test = GetTexturePanelTextureString(panel);
1455 wwarning(test);
1457 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1458 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1459 0, 0, 0);
1460 XMapRaised(dpy, win);
1461 XFlush(dpy);
1463 // image = RenderTexturePanelTexture(panel, 250, 250);
1465 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1467 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1468 0, 0);
1470 free (test);
1474 void testCancelButton(WMWidget *self, void *data){
1475 wwarning("Exiting test....");
1476 exit(0);
1479 void wAbort()
1481 exit(1);
1484 int main(int argc, char **argv)
1486 TexturePanel *panel;
1488 Display *dpy = XOpenDisplay("");
1489 WMScreen *scr;
1491 /* char *test; */
1493 WMInitializeApplication("Test", &argc, argv);
1495 if (!dpy) {
1496 wfatal("could not open display");
1497 exit(1);
1500 scr = WMCreateSimpleApplicationScreen(dpy);
1502 panel = CreateTexturePanel(scr);
1504 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1505 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1507 SetTexturePanelTexture(panel, "pinky",
1508 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1510 ShowTexturePanel(panel);
1512 WMScreenMainLoop(scr);
1513 return 0;
1515 #endif