WPrefs: Marked args as unused for compiler in event callback code
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob3101a165bd6cbb3a0ad401b95e0e50f7f8e4460d
1 /* TexturePanel.c- texture editting panel
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * Copyright (c) 1998 James Thompson
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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <ctype.h>
29 #include <X11/Xlib.h>
31 #include <WINGs/WINGs.h>
33 #include "WPrefs.h"
35 #include "TexturePanel.h"
37 #define MAX_SECTION_PARTS 5
39 typedef struct _TexturePanel {
40 WMWindow *win;
42 /* texture name */
43 WMFrame *nameF;
44 WMTextField *nameT;
46 /* texture type */
47 WMPopUpButton *typeP;
49 /* default color */
50 WMFrame *defcF;
51 WMColorWell *defcW;
53 WMFont *listFont;
55 /*-- Gradient --*/
57 Pixmap gimage;
59 /* colors */
60 WMFrame *gcolF;
61 WMList *gcolL;
62 WMButton *gcolaB;
63 WMButton *gcoldB;
64 WMSlider *ghueS;
65 WMSlider *gsatS;
66 WMSlider *gvalS;
68 WMSlider *gbriS;
69 WMSlider *gconS;
71 /* direction (common) */
72 WMFrame *dirF;
73 WMButton *dirhB;
74 WMButton *dirvB;
75 WMButton *dirdB;
77 /*-- Simple Gradient --*/
79 /*-- Textured Gradient --*/
81 WMFrame *tcolF;
82 WMColorWell *tcol1W;
83 WMColorWell *tcol2W;
85 WMFrame *topaF;
86 WMSlider *topaS;
88 /*-- Image --*/
89 WMFrame *imageF;
90 WMScrollView *imageV;
91 WMTextField *imageT;
92 WMLabel *imageL;
93 WMButton *browB;
94 WMButton *dispB;
95 WMPopUpButton *arrP;
97 RImage *image;
98 char *imageFile;
100 /*****/
102 WMButton *okB;
103 WMButton *cancelB;
105 WMCallback *okAction;
106 void *okData;
108 WMCallback *cancelAction;
109 void *cancelData;
111 /****/
112 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
114 int currentType;
116 WMPropList *pathList;
118 } _TexturePanel;
120 #define TYPE_SOLID 0
121 #define TYPE_GRADIENT 1
122 #define TYPE_SGRADIENT 2
123 #define TYPE_TGRADIENT 3
124 #define TYPE_PIXMAP 4
126 #define PTYPE_TILE 0
127 #define PTYPE_SCALE 1
128 #define PTYPE_CENTER 2
129 #define PTYPE_MAXIMIZE 3
132 *--------------------------------------------------------------------------
133 * Private Functions
134 *--------------------------------------------------------------------------
137 /************/
139 static void updateGradButtons(TexturePanel * panel)
141 RImage *image;
142 WMPixmap *pixmap;
143 int colorn;
144 RColor **colors;
146 colorn = WMGetListNumberOfRows(panel->gcolL);
147 if (colorn < 1) {
148 pixmap = NULL;
149 } else {
150 int i;
151 WMListItem *item;
153 colors = wmalloc(sizeof(RColor *) * (colorn + 1));
155 for (i = 0; i < colorn; i++) {
156 item = WMGetListItem(panel->gcolL, i);
157 colors[i] = (RColor *) item->clientData;
159 colors[i] = NULL;
161 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
162 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
163 RReleaseImage(image);
164 WMSetButtonImage(panel->dirhB, pixmap);
165 WMReleasePixmap(pixmap);
167 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
168 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
169 RReleaseImage(image);
170 WMSetButtonImage(panel->dirvB, pixmap);
171 WMReleasePixmap(pixmap);
173 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
174 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
175 RReleaseImage(image);
176 WMSetButtonImage(panel->dirdB, pixmap);
177 WMReleasePixmap(pixmap);
179 wfree(colors);
183 static void updateTGradImage(TexturePanel * panel)
185 RImage *image, *gradient;
186 WMPixmap *pixmap;
187 RColor from;
188 RColor to;
189 WMColor *color;
191 if (!panel->image)
192 return;
194 color = WMGetColorWellColor(panel->tcol1W);
195 from.red = WMRedComponentOfColor(color) >> 8;
196 from.green = WMGreenComponentOfColor(color) >> 8;
197 from.blue = WMBlueComponentOfColor(color) >> 8;
199 color = WMGetColorWellColor(panel->tcol2W);
200 to.red = WMRedComponentOfColor(color) >> 8;
201 to.green = WMGreenComponentOfColor(color) >> 8;
202 to.blue = WMBlueComponentOfColor(color) >> 8;
204 if (panel->image->width < 141 || panel->image->height < 91) {
205 image = RMakeTiledImage(panel->image, 141, 91);
206 } else {
207 image = RCloneImage(panel->image);
210 if (WMGetButtonSelected(panel->dirhB)) {
211 gradient = RRenderGradient(image->width, image->height, &from, &to, RHorizontalGradient);
212 } else if (WMGetButtonSelected(panel->dirvB)) {
213 gradient = RRenderGradient(image->width, image->height, &from, &to, RVerticalGradient);
214 } else {
215 gradient = RRenderGradient(image->width, image->height, &from, &to, RDiagonalGradient);
218 RCombineImagesWithOpaqueness(image, gradient, WMGetSliderValue(panel->topaS));
219 RReleaseImage(gradient);
220 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win), image, 128);
222 WMSetLabelImage(panel->imageL, pixmap);
223 WMReleasePixmap(pixmap);
224 WMResizeWidget(panel->imageL, image->width, image->height);
225 RReleaseImage(image);
228 static void updateSGradButtons(TexturePanel * panel)
230 RImage *image;
231 WMPixmap *pixmap;
232 RColor from;
233 RColor to;
234 WMColor *color;
236 color = WMGetColorWellColor(panel->tcol1W);
237 from.red = WMRedComponentOfColor(color) >> 8;
238 from.green = WMGreenComponentOfColor(color) >> 8;
239 from.blue = WMBlueComponentOfColor(color) >> 8;
241 color = WMGetColorWellColor(panel->tcol2W);
242 to.red = WMRedComponentOfColor(color) >> 8;
243 to.green = WMGreenComponentOfColor(color) >> 8;
244 to.blue = WMBlueComponentOfColor(color) >> 8;
246 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
247 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
248 RReleaseImage(image);
249 WMSetButtonImage(panel->dirhB, pixmap);
250 WMReleasePixmap(pixmap);
252 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
253 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
254 RReleaseImage(image);
255 WMSetButtonImage(panel->dirvB, pixmap);
256 WMReleasePixmap(pixmap);
258 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
259 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
260 RReleaseImage(image);
261 WMSetButtonImage(panel->dirdB, pixmap);
262 WMReleasePixmap(pixmap);
265 /*********** Gradient ************/
267 static void updateSVSlider(WMSlider * sPtr, Bool saturation, WMFont * font, RHSVColor * hsv)
269 RImage *image;
270 WMPixmap *pixmap;
271 WMScreen *scr = WMWidgetScreen(sPtr);
272 RColor from, to;
273 RHSVColor tmp;
274 char *buffer;
276 tmp = *hsv;
277 if (saturation) {
278 tmp.saturation = 0;
279 RHSVtoRGB(&tmp, &from);
280 tmp.saturation = 255;
281 RHSVtoRGB(&tmp, &to);
282 } else {
283 tmp.value = 0;
284 RHSVtoRGB(&tmp, &from);
285 tmp.value = 255;
286 RHSVtoRGB(&tmp, &to);
288 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
289 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
290 RReleaseImage(image);
292 if (saturation)
293 buffer = wstrdup(_("Saturation"));
294 else
295 buffer = wstrdup(_("Brightness"));
297 if (hsv->value < 128 || !saturation) {
298 WMColor *col = WMWhiteColor(scr);
300 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
301 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
302 WMReleaseColor(col);
303 } else {
304 WMColor *col = WMBlackColor(scr);
306 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
307 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
308 WMReleaseColor(col);
310 wfree(buffer);
311 WMSetSliderImage(sPtr, pixmap);
312 WMReleasePixmap(pixmap);
315 static void updateHueSlider(WMSlider * sPtr, WMFont * font, RHSVColor * hsv)
317 RColor *colors[8];
318 RImage *image;
319 WMPixmap *pixmap;
320 WMScreen *scr = WMWidgetScreen(sPtr);
321 RHSVColor thsv;
322 int i;
324 thsv = *hsv;
325 for (i = 0; i <= 6; i++) {
326 thsv.hue = (360 * i) / 6;
327 colors[i] = wmalloc(sizeof(RColor));
328 RHSVtoRGB(&thsv, colors[i]);
330 colors[i] = NULL;
332 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
333 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
334 RReleaseImage(image);
336 if (hsv->value < 128) {
337 WMColor *col = WMWhiteColor(scr);
339 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
340 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
341 WMReleaseColor(col);
342 } else {
343 WMColor *col = WMBlackColor(scr);
345 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
346 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
347 WMReleaseColor(col);
349 WMSetSliderImage(sPtr, pixmap);
350 WMReleasePixmap(pixmap);
352 for (i = 0; i <= 6; i++)
353 wfree(colors[i]);
356 static void sliderChangeCallback(WMWidget * w, void *data)
358 TexturePanel *panel = (TexturePanel *) data;
359 RHSVColor hsv;
360 int row, rows;
361 WMListItem *item;
362 RColor **colors;
363 int i;
364 RImage *image;
365 WMScreen *scr = WMWidgetScreen(w);
367 hsv.hue = WMGetSliderValue(panel->ghueS);
368 hsv.saturation = WMGetSliderValue(panel->gsatS);
369 hsv.value = WMGetSliderValue(panel->gvalS);
371 row = WMGetListSelectedItemRow(panel->gcolL);
372 if (row >= 0) {
373 RColor *rgb;
375 item = WMGetListItem(panel->gcolL, row);
377 rgb = (RColor *) item->clientData;
379 RHSVtoRGB(&hsv, rgb);
381 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
384 if (w == panel->ghueS) {
385 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
386 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
387 } else if (w == panel->gsatS) {
388 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
389 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
390 } else {
391 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
392 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
395 rows = WMGetListNumberOfRows(panel->gcolL);
396 if (rows == 0)
397 return;
399 colors = wmalloc(sizeof(RColor *) * (rows + 1));
401 for (i = 0; i < rows; i++) {
402 item = WMGetListItem(panel->gcolL, i);
404 colors[i] = (RColor *) item->clientData;
406 colors[i] = NULL;
408 if (panel->gimage != None) {
409 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
412 image = RRenderMultiGradient(30, i * WMGetListItemHeight(panel->gcolL), colors, RVerticalGradient);
413 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
414 RReleaseImage(image);
416 wfree(colors);
418 WMRedisplayWidget(panel->gcolL);
420 updateGradButtons(panel);
423 static void paintGradListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
425 TexturePanel *panel = (TexturePanel *) WMGetHangedData(lPtr);
426 WMScreen *scr = WMWidgetScreen(lPtr);
427 WMColor *white = WMWhiteColor(scr);
428 WMColor *black = WMBlackColor(scr);
429 WMColor *gray = WMGrayColor(scr);
430 int width, height, x, y;
431 Display *dpy;
433 dpy = WMScreenDisplay(scr);
435 width = rect->size.width;
436 height = rect->size.height;
437 x = rect->pos.x;
438 y = rect->pos.y;
440 if (state & WLDSSelected)
441 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
442 else
443 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
445 if (panel->gimage) {
446 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
447 0, height * index, 30, height, x + 5, y);
449 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
451 WMReleaseColor(white);
452 WMReleaseColor(black);
453 WMReleaseColor(gray);
456 static void gradAddCallback(WMWidget * w, void *data)
458 TexturePanel *panel = (TexturePanel *) data;
459 WMListItem *item;
460 int row;
461 RColor *rgb;
463 /* Parameter not used, but tell the compiler that it is ok */
464 (void) w;
466 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
467 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
468 rgb = wmalloc(sizeof(RColor));
469 item->clientData = rgb;
471 WMSelectListItem(panel->gcolL, row);
473 updateGradButtons(panel);
475 sliderChangeCallback(panel->ghueS, panel);
477 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
480 static void gradClickCallback(WMWidget * w, void *data)
482 TexturePanel *panel = (TexturePanel *) data;
483 WMListItem *item;
484 int row;
485 RHSVColor hsv;
487 row = WMGetListSelectedItemRow(w);
488 if (row < 0)
489 return;
491 item = WMGetListItem(panel->gcolL, row);
492 RRGBtoHSV((RColor *) item->clientData, &hsv);
494 WMSetSliderValue(panel->ghueS, hsv.hue);
495 WMSetSliderValue(panel->gsatS, hsv.saturation);
496 WMSetSliderValue(panel->gvalS, hsv.value);
498 sliderChangeCallback(panel->ghueS, panel);
499 sliderChangeCallback(panel->gsatS, panel);
502 static void gradDeleteCallback(WMWidget * w, void *data)
504 TexturePanel *panel = (TexturePanel *) data;
505 WMListItem *item;
506 int row;
508 /* Parameter not used, but tell the compiler that it is ok */
509 (void) w;
511 row = WMGetListSelectedItemRow(panel->gcolL);
512 if (row < 0)
513 return;
515 item = WMGetListItem(panel->gcolL, row);
516 wfree(item->clientData);
518 WMRemoveListItem(panel->gcolL, row);
520 WMSelectListItem(panel->gcolL, row - 1);
522 updateGradButtons(panel);
524 gradClickCallback(panel->gcolL, panel);
526 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
529 /*************** Simple Gradient ***************/
531 static void colorWellObserver(void *self, WMNotification * n)
533 /* Parameter not used, but tell the compiler that it is ok */
534 (void) n;
536 updateSGradButtons(self);
539 static void opaqChangeCallback(WMWidget * w, void *data)
541 TexturePanel *panel = (TexturePanel *) data;
543 /* Parameter not used, but tell the compiler that it is ok */
544 (void) w;
546 updateTGradImage(panel);
549 /****************** Image ******************/
551 static void updateImage(TexturePanel * panel, const char *path)
553 WMScreen *scr = WMWidgetScreen(panel->win);
554 RImage *image;
555 WMPixmap *pixmap;
556 WMSize size;
558 if (path) {
559 image = RLoadImage(WMScreenRContext(scr), path, 0);
560 if (!image) {
561 char *message;
563 message = wstrconcat(_("Could not load the selected file: "),
564 (char *)RMessageForError(RErrorCode));
566 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
568 if (!panel->image)
569 WMSetButtonEnabled(panel->okB, False);
571 wfree(message);
572 return;
575 WMSetButtonEnabled(panel->okB, True);
577 if (panel->image)
578 RReleaseImage(panel->image);
579 panel->image = image;
580 } else {
581 image = panel->image;
584 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
585 if (image) {
586 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
588 size = WMGetPixmapSize(pixmap);
589 WMSetLabelImage(panel->imageL, pixmap);
590 WMResizeWidget(panel->imageL, size.width, size.height);
592 WMReleasePixmap(pixmap);
594 } else {
595 updateTGradImage(panel);
599 static void browseImageCallback(WMWidget * w, void *data)
601 TexturePanel *panel = (TexturePanel *) data;
602 WMOpenPanel *opanel;
603 WMScreen *scr = WMWidgetScreen(w);
604 static char *ipath = NULL;
606 opanel = WMGetOpenPanel(scr);
607 WMSetFilePanelCanChooseDirectories(opanel, False);
608 WMSetFilePanelCanChooseFiles(opanel, True);
610 if (!ipath)
611 ipath = wstrdup(wgethomedir());
613 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
614 char *path, *fullpath;
615 char *tmp, *tmp2;
617 tmp = WMGetFilePanelFileName(opanel);
618 if (!tmp)
619 return;
620 fullpath = tmp;
622 wfree(ipath);
623 ipath = fullpath;
625 path = wstrdup(fullpath);
627 tmp2 = strrchr(fullpath, '/');
628 if (tmp2)
629 tmp2++;
631 tmp = wfindfileinarray(panel->pathList, tmp2);
633 if (tmp) {
634 if (strcmp(fullpath, tmp) == 0) {
635 wfree(path);
636 path = tmp2;
638 wfree(tmp);
641 if (!RGetImageFileFormat(fullpath)) {
642 WMRunAlertPanel(scr, panel->win, _("Error"),
643 _("The selected file does not contain a supported image."),
644 _("OK"), NULL, NULL);
645 wfree(path);
646 } else {
647 updateImage(panel, fullpath);
648 wfree(panel->imageFile);
649 panel->imageFile = path;
651 WMSetTextFieldText(panel->imageT, path);
656 static void buttonCallback(WMWidget * w, void *data)
658 TexturePanel *panel = (TexturePanel *) data;
660 if (w == panel->okB) {
661 (*panel->okAction) (panel->okData);
662 } else {
663 (*panel->cancelAction) (panel->cancelData);
667 static void changeTypeCallback(WMWidget * w, void *data)
669 TexturePanel *panel = (TexturePanel *) data;
670 int newType;
671 int i;
673 newType = WMGetPopUpButtonSelectedItem(w);
674 if (newType == panel->currentType)
675 return;
677 if (panel->currentType >= 0) {
678 for (i = 0; i < MAX_SECTION_PARTS; i++) {
679 if (panel->sectionParts[panel->currentType][i] == NULL)
680 break;
681 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
685 for (i = 0; i < MAX_SECTION_PARTS; i++) {
686 if (panel->sectionParts[newType][i] == NULL)
687 break;
688 WMMapWidget(panel->sectionParts[newType][i]);
690 panel->currentType = newType;
692 switch (newType) {
693 case TYPE_SGRADIENT:
694 updateSGradButtons(panel);
695 WMSetButtonEnabled(panel->okB, True);
696 break;
697 case TYPE_GRADIENT:
698 updateGradButtons(panel);
699 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
700 break;
701 case TYPE_TGRADIENT:
702 case TYPE_PIXMAP:
703 updateImage(panel, NULL);
704 WMSetButtonEnabled(panel->okB, panel->image != NULL);
705 break;
706 default:
707 WMSetButtonEnabled(panel->okB, True);
708 break;
713 *--------------------------------------------------------------------------
714 * Public functions
715 *--------------------------------------------------------------------------
717 void DestroyTexturePanel(TexturePanel * panel)
722 void ShowTexturePanel(TexturePanel * panel)
724 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
725 Screen *scr = DefaultScreenOfDisplay(dpy);
727 WMSetWindowInitialPosition(panel->win,
728 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
729 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
730 WMMapWidget(panel->win);
733 void HideTexturePanel(TexturePanel * panel)
735 WMUnmapWidget(panel->win);
738 void SetTexturePanelOkAction(TexturePanel * panel, WMCallback * action, void *clientData)
740 panel->okAction = action;
741 panel->okData = clientData;
744 void SetTexturePanelCancelAction(TexturePanel * panel, WMCallback * action, void *clientData)
746 panel->cancelAction = action;
747 panel->cancelData = clientData;
750 void SetTexturePanelTexture(TexturePanel * panel, const char *name, WMPropList * texture)
752 WMScreen *scr = WMWidgetScreen(panel->win);
753 char *str, *type;
754 WMPropList *p;
755 WMColor *color;
756 int i;
757 char buffer[64];
758 int gradient = 0;
760 WMSetTextFieldText(panel->nameT, name);
762 if (!texture)
763 return;
765 p = WMGetFromPLArray(texture, 0);
766 if (!p) {
767 goto bad_texture;
769 type = WMGetFromPLString(p);
771 /*............................................... */
772 if (strcasecmp(type, "solid") == 0) {
774 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
776 p = WMGetFromPLArray(texture, 1);
777 if (!p) {
778 str = "black";
779 } else {
780 str = WMGetFromPLString(p);
782 color = WMCreateNamedColor(scr, str, False);
784 WMSetColorWellColor(panel->defcW, color);
786 WMReleaseColor(color);
787 /*............................................... */
788 } else if (strcasecmp(type, "hgradient") == 0
789 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
791 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
793 p = WMGetFromPLArray(texture, 1);
794 if (!p) {
795 str = "black";
796 } else {
797 str = WMGetFromPLString(p);
799 color = WMCreateNamedColor(scr, str, False);
801 WMSetColorWellColor(panel->tcol1W, color);
803 WMReleaseColor(color);
805 p = WMGetFromPLArray(texture, 2);
806 if (!p) {
807 str = "black";
808 } else {
809 str = WMGetFromPLString(p);
811 color = WMCreateNamedColor(scr, str, False);
813 WMSetColorWellColor(panel->tcol2W, color);
815 WMReleaseColor(color);
817 gradient = type[0];
818 /*............................................... */
819 } else if (strcasecmp(type, "thgradient") == 0
820 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
821 int i;
823 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
825 gradient = type[1];
827 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
828 if (panel->imageFile)
829 wfree(panel->imageFile);
830 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
832 i = 180;
833 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
834 WMSetSliderValue(panel->topaS, i);
836 p = WMGetFromPLArray(texture, 3);
837 if (!p) {
838 str = "black";
839 } else {
840 str = WMGetFromPLString(p);
842 color = WMCreateNamedColor(scr, str, False);
844 WMSetColorWellColor(panel->tcol1W, color);
846 WMReleaseColor(color);
848 p = WMGetFromPLArray(texture, 4);
849 if (!p) {
850 str = "black";
851 } else {
852 str = WMGetFromPLString(p);
854 color = WMCreateNamedColor(scr, str, False);
856 WMSetColorWellColor(panel->tcol2W, color);
858 WMReleaseColor(color);
860 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
862 if (panel->imageFile)
863 wfree(panel->imageFile);
864 if ((panel->imageFile = wfindfileinarray(panel->pathList,
865 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) !=
866 NULL) {
868 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
869 updateTGradImage(panel);
871 updateSGradButtons(panel);
872 } else
873 wwarning(_("could not load file '%s': %s"), panel->imageFile,
874 RMessageForError(RErrorCode));
876 /*............................................... */
877 } else if (strcasecmp(type, "mhgradient") == 0
878 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
879 WMListItem *item;
881 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
882 item = WMGetListItem(panel->gcolL, i);
883 wfree(item->clientData);
885 WMClearList(panel->gcolL);
887 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
889 p = WMGetFromPLArray(texture, 1);
890 if (!p) {
891 str = "black";
892 } else {
893 str = WMGetFromPLString(p);
895 color = WMCreateNamedColor(scr, str, False);
897 WMSetColorWellColor(panel->defcW, color);
899 WMReleaseColor(color);
901 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
902 RColor *rgb;
903 XColor xcolor;
905 p = WMGetFromPLArray(texture, i);
906 if (!p) {
907 str = "black";
908 } else {
909 str = WMGetFromPLString(p);
912 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
914 rgb = wmalloc(sizeof(RColor));
915 rgb->red = xcolor.red >> 8;
916 rgb->green = xcolor.green >> 8;
917 rgb->blue = xcolor.blue >> 8;
918 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
920 item = WMAddListItem(panel->gcolL, buffer);
921 item->clientData = rgb;
924 sliderChangeCallback(panel->ghueS, panel);
926 gradient = type[1];
927 /*............................................... */
928 } else if (strcasecmp(type, "cpixmap") == 0
929 || strcasecmp(type, "spixmap") == 0
930 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
932 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
934 switch (toupper(type[0])) {
935 case 'C':
936 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
937 break;
938 case 'S':
939 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
940 break;
941 case 'M':
942 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
943 break;
944 default:
945 case 'T':
946 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
947 break;
950 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
952 if (panel->imageFile)
953 wfree(panel->imageFile);
954 panel->imageFile = wfindfileinarray(panel->pathList,
955 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
957 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
958 WMSetColorWellColor(panel->defcW, color);
959 WMReleaseColor(color);
961 updateImage(panel, panel->imageFile);
964 changeTypeCallback(panel->typeP, panel);
966 if (gradient > 0) {
967 updateGradButtons(panel);
969 switch (toupper(gradient)) {
970 case 'H':
971 WMPerformButtonClick(panel->dirhB);
972 break;
973 case 'V':
974 WMPerformButtonClick(panel->dirvB);
975 break;
976 default:
977 case 'D':
978 WMPerformButtonClick(panel->dirdB);
979 break;
983 return;
985 bad_texture:
986 str = WMGetPropListDescription(texture, False);
987 wwarning(_("error creating texture %s"), str);
988 wfree(str);
992 char *GetTexturePanelTextureName(TexturePanel * panel)
994 return WMGetTextFieldText(panel->nameT);
998 WMPropList *GetTexturePanelTexture(TexturePanel * panel)
1000 WMPropList *prop = NULL;
1001 WMColor *color;
1002 char *str, *str2;
1003 char buff[32];
1004 int i;
1006 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1008 case TYPE_SOLID:
1009 color = WMGetColorWellColor(panel->defcW);
1010 str = WMGetColorRGBDescription(color);
1011 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1012 wfree(str);
1014 break;
1016 case TYPE_PIXMAP:
1017 color = WMGetColorWellColor(panel->defcW);
1018 str = WMGetColorRGBDescription(color);
1020 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1021 case PTYPE_SCALE:
1022 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1023 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1024 break;
1025 case PTYPE_MAXIMIZE:
1026 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1027 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1028 break;
1029 case PTYPE_CENTER:
1030 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1031 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1032 break;
1033 case PTYPE_TILE:
1034 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1035 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1036 break;
1038 wfree(str);
1039 break;
1041 case TYPE_TGRADIENT:
1042 color = WMGetColorWellColor(panel->tcol1W);
1043 str = WMGetColorRGBDescription(color);
1045 color = WMGetColorWellColor(panel->tcol2W);
1046 str2 = WMGetColorRGBDescription(color);
1048 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1050 if (WMGetButtonSelected(panel->dirdB)) {
1051 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1052 WMCreatePLString(panel->imageFile),
1053 WMCreatePLString(buff),
1054 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1055 } else if (WMGetButtonSelected(panel->dirvB)) {
1056 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1057 WMCreatePLString(panel->imageFile),
1058 WMCreatePLString(buff),
1059 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1060 } else {
1061 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1062 WMCreatePLString(panel->imageFile),
1063 WMCreatePLString(buff),
1064 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1066 wfree(str);
1067 wfree(str2);
1068 break;
1070 case TYPE_SGRADIENT:
1071 color = WMGetColorWellColor(panel->tcol1W);
1072 str = WMGetColorRGBDescription(color);
1074 color = WMGetColorWellColor(panel->tcol2W);
1075 str2 = WMGetColorRGBDescription(color);
1077 if (WMGetButtonSelected(panel->dirdB)) {
1078 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1079 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1080 } else if (WMGetButtonSelected(panel->dirvB)) {
1081 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1082 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1083 } else {
1084 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1085 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1087 wfree(str);
1088 wfree(str2);
1089 break;
1091 case TYPE_GRADIENT:
1092 color = WMGetColorWellColor(panel->defcW);
1093 str = WMGetColorRGBDescription(color);
1095 if (WMGetButtonSelected(panel->dirdB)) {
1096 prop = WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str), NULL);
1097 } else if (WMGetButtonSelected(panel->dirvB)) {
1098 prop = WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str), NULL);
1099 } else {
1100 prop = WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str), NULL);
1102 wfree(str);
1104 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1105 RColor *rgb;
1106 WMListItem *item;
1108 item = WMGetListItem(panel->gcolL, i);
1110 rgb = (RColor *) item->clientData;
1112 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1114 WMAddToPLArray(prop, WMCreatePLString(buff));
1116 break;
1119 return prop;
1122 void SetTexturePanelPixmapPath(TexturePanel * panel, WMPropList * array)
1124 panel->pathList = array;
1127 TexturePanel *CreateTexturePanel(WMWindow * keyWindow)
1128 /*CreateTexturePanel(WMScreen *scr)*/
1130 TexturePanel *panel;
1131 WMScreen *scr = WMWidgetScreen(keyWindow);
1133 panel = wmalloc(sizeof(TexturePanel));
1135 panel->listFont = WMSystemFontOfSize(scr, 12);
1137 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1138 WMTitledWindowMask | WMClosableWindowMask);
1140 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1141 WMTitledWindowMask
1142 |WMClosableWindowMask);
1145 WMResizeWidget(panel->win, 325, 423);
1146 WMSetWindowTitle(panel->win, _("Texture Panel"));
1147 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1149 /* texture name */
1150 panel->nameF = WMCreateFrame(panel->win);
1151 WMResizeWidget(panel->nameF, 185, 50);
1152 WMMoveWidget(panel->nameF, 15, 10);
1153 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1155 panel->nameT = WMCreateTextField(panel->nameF);
1156 WMResizeWidget(panel->nameT, 160, 20);
1157 WMMoveWidget(panel->nameT, 12, 18);
1159 WMMapSubwidgets(panel->nameF);
1161 /* texture types */
1162 panel->typeP = WMCreatePopUpButton(panel->win);
1163 WMResizeWidget(panel->typeP, 185, 20);
1164 WMMoveWidget(panel->typeP, 15, 65);
1165 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1166 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1167 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1168 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1169 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1170 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1171 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1173 /* color */
1174 panel->defcF = WMCreateFrame(panel->win);
1175 WMResizeWidget(panel->defcF, 100, 75);
1176 WMMoveWidget(panel->defcF, 210, 10);
1177 WMSetFrameTitle(panel->defcF, _("Default Color"));
1179 panel->defcW = WMCreateColorWell(panel->defcF);
1180 WMResizeWidget(panel->defcW, 60, 45);
1181 WMMoveWidget(panel->defcW, 20, 20);
1183 WMMapSubwidgets(panel->defcF);
1185 /****** Gradient ******/
1186 panel->gcolF = WMCreateFrame(panel->win);
1187 WMResizeWidget(panel->gcolF, 295, 205);
1188 WMMoveWidget(panel->gcolF, 15, 95);
1189 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1191 panel->gcolL = WMCreateList(panel->gcolF);
1192 WMResizeWidget(panel->gcolL, 130, 140);
1193 WMMoveWidget(panel->gcolL, 10, 25);
1194 WMHangData(panel->gcolL, panel);
1195 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1196 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1198 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1199 WMResizeWidget(panel->gcolaB, 64, 24);
1200 WMMoveWidget(panel->gcolaB, 10, 170);
1201 WMSetButtonText(panel->gcolaB, _("Add"));
1202 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1204 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1205 WMResizeWidget(panel->gcoldB, 64, 24);
1206 WMMoveWidget(panel->gcoldB, 75, 170);
1207 WMSetButtonText(panel->gcoldB, _("Delete"));
1208 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1210 #if 0
1211 panel->gbriS = WMCreateSlider(panel->gcolF);
1212 WMResizeWidget(panel->gbriS, 130, 16);
1213 WMMoveWidget(panel->gbriS, 150, 25);
1214 WMSetSliderKnobThickness(panel->gbriS, 8);
1215 WMSetSliderMaxValue(panel->gbriS, 100);
1216 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1218 WMPixmap *pixmap;
1219 WMColor *color;
1221 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1222 color = WMDarkGrayColor(scr);
1223 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1224 WMReleaseColor(color);
1225 color = WMWhiteColor(color);
1226 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1227 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1228 WMSetSliderImage(panel->gbriS, pixmap);
1229 WMReleasePixmap(pixmap);
1232 panel->gconS = WMCreateSlider(panel->gcolF);
1233 WMResizeWidget(panel->gconS, 130, 16);
1234 WMMoveWidget(panel->gconS, 150, 50);
1235 WMSetSliderKnobThickness(panel->gconS, 8);
1236 WMSetSliderMaxValue(panel->gconS, 100);
1237 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1239 WMPixmap *pixmap;
1240 WMColor *color;
1242 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1243 color = WMDarkGrayColor(scr);
1244 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1245 WMReleaseColor(color);
1246 color = WMWhiteColor(scr);
1247 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1248 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1249 WMSetSliderImage(panel->gconS, pixmap);
1250 WMReleasePixmap(pixmap);
1252 #endif
1253 panel->ghueS = WMCreateSlider(panel->gcolF);
1254 WMResizeWidget(panel->ghueS, 130, 16);
1255 WMMoveWidget(panel->ghueS, 150, 100);
1256 WMSetSliderKnobThickness(panel->ghueS, 8);
1257 WMSetSliderMaxValue(panel->ghueS, 359);
1258 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1260 panel->gsatS = WMCreateSlider(panel->gcolF);
1261 WMResizeWidget(panel->gsatS, 130, 16);
1262 WMMoveWidget(panel->gsatS, 150, 125);
1263 WMSetSliderKnobThickness(panel->gsatS, 8);
1264 WMSetSliderMaxValue(panel->gsatS, 255);
1265 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1267 panel->gvalS = WMCreateSlider(panel->gcolF);
1268 WMResizeWidget(panel->gvalS, 130, 16);
1269 WMMoveWidget(panel->gvalS, 150, 150);
1270 WMSetSliderKnobThickness(panel->gvalS, 8);
1271 WMSetSliderMaxValue(panel->gvalS, 255);
1272 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1274 WMMapSubwidgets(panel->gcolF);
1276 /** Direction **/
1277 panel->dirF = WMCreateFrame(panel->win);
1278 WMSetFrameTitle(panel->dirF, _("Direction"));
1279 WMResizeWidget(panel->dirF, 295, 75);
1280 WMMoveWidget(panel->dirF, 15, 305);
1282 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1283 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1284 WMResizeWidget(panel->dirvB, 90, 40);
1285 WMMoveWidget(panel->dirvB, 10, 20);
1287 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1288 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1289 WMResizeWidget(panel->dirhB, 90, 40);
1290 WMMoveWidget(panel->dirhB, 102, 20);
1292 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1293 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1294 WMResizeWidget(panel->dirdB, 90, 40);
1295 WMMoveWidget(panel->dirdB, 194, 20);
1297 WMGroupButtons(panel->dirvB, panel->dirhB);
1298 WMGroupButtons(panel->dirvB, panel->dirdB);
1300 WMMapSubwidgets(panel->dirF);
1302 /****************** Textured Gradient ******************/
1303 panel->tcolF = WMCreateFrame(panel->win);
1304 WMResizeWidget(panel->tcolF, 100, 135);
1305 WMMoveWidget(panel->tcolF, 210, 10);
1306 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1308 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1309 WMResizeWidget(panel->tcol1W, 60, 45);
1310 WMMoveWidget(panel->tcol1W, 20, 25);
1311 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1313 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1314 WMResizeWidget(panel->tcol2W, 60, 45);
1315 WMMoveWidget(panel->tcol2W, 20, 75);
1316 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1318 /** Opacity */
1319 panel->topaF = WMCreateFrame(panel->win);
1320 WMResizeWidget(panel->topaF, 185, 50);
1321 WMMoveWidget(panel->topaF, 15, 95);
1322 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1324 panel->topaS = WMCreateSlider(panel->topaF);
1325 WMResizeWidget(panel->topaS, 155, 18);
1326 WMMoveWidget(panel->topaS, 15, 20);
1327 WMSetSliderMaxValue(panel->topaS, 255);
1328 WMSetSliderValue(panel->topaS, 200);
1329 WMSetSliderContinuous(panel->topaS, False);
1330 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1332 WMMapSubwidgets(panel->topaF);
1335 WMPixmap *pixmap;
1336 Pixmap p;
1337 WMColor *color;
1339 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1340 p = WMGetPixmapXID(pixmap);
1342 color = WMDarkGrayColor(scr);
1343 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1344 WMReleaseColor(color);
1346 color = WMWhiteColor(scr);
1347 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1348 WMDrawString(scr, p, color, panel->listFont,
1349 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1350 WMReleaseColor(color);
1352 WMSetSliderImage(panel->topaS, pixmap);
1353 WMReleasePixmap(pixmap);
1356 WMMapSubwidgets(panel->tcolF);
1358 /****************** Image ******************/
1359 panel->imageF = WMCreateFrame(panel->win);
1360 WMResizeWidget(panel->imageF, 295, 150);
1361 WMMoveWidget(panel->imageF, 15, 150);
1362 WMSetFrameTitle(panel->imageF, _("Image"));
1364 panel->imageL = WMCreateLabel(panel->imageF);
1365 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1367 panel->imageT = WMCreateTextField(panel->imageF);
1368 WMResizeWidget(panel->imageT, 90, 20);
1369 WMMoveWidget(panel->imageT, 190, 25);
1371 panel->imageV = WMCreateScrollView(panel->imageF);
1372 WMResizeWidget(panel->imageV, 165, 115);
1373 WMMoveWidget(panel->imageV, 15, 20);
1374 WMSetScrollViewRelief(panel->imageV, WRSunken);
1375 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1376 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1377 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1379 panel->browB = WMCreateCommandButton(panel->imageF);
1380 WMResizeWidget(panel->browB, 90, 24);
1381 WMMoveWidget(panel->browB, 190, 50);
1382 WMSetButtonText(panel->browB, _("Browse..."));
1383 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1385 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1386 WMResizeWidget(panel->dispB, 90, 24);
1387 WMMoveWidget(panel->dispB, 190, 80);
1388 WMSetButtonText(panel->dispB, _("Show"));
1391 panel->arrP = WMCreatePopUpButton(panel->imageF);
1392 WMResizeWidget(panel->arrP, 90, 20);
1393 WMMoveWidget(panel->arrP, 190, 120);
1394 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1395 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1396 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1397 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1398 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1400 WMMapSubwidgets(panel->imageF);
1402 /****/
1404 panel->okB = WMCreateCommandButton(panel->win);
1405 WMResizeWidget(panel->okB, 84, 24);
1406 WMMoveWidget(panel->okB, 225, 390);
1407 WMSetButtonText(panel->okB, _("OK"));
1408 WMSetButtonAction(panel->okB, buttonCallback, panel);
1410 panel->cancelB = WMCreateCommandButton(panel->win);
1411 WMResizeWidget(panel->cancelB, 84, 24);
1412 WMMoveWidget(panel->cancelB, 130, 390);
1413 WMSetButtonText(panel->cancelB, _("Cancel"));
1414 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1416 WMMapWidget(panel->nameF);
1417 WMMapWidget(panel->typeP);
1418 WMMapWidget(panel->okB);
1419 WMMapWidget(panel->cancelB);
1421 WMUnmapWidget(panel->arrP);
1423 WMRealizeWidget(panel->win);
1425 panel->currentType = -1;
1427 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1429 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1430 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1431 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1433 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1434 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1436 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1437 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1438 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1439 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1440 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1442 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1443 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1444 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1446 /* setup for first time */
1448 changeTypeCallback(panel->typeP, panel);
1450 sliderChangeCallback(panel->ghueS, panel);
1451 sliderChangeCallback(panel->gsatS, panel);
1453 return panel;
1457 *--------------------------------------------------------------------------
1458 * Test stuff
1459 *--------------------------------------------------------------------------
1462 #if 0
1464 char *ProgName = "test";
1466 void testOKButton(WMWidget * self, void *data)
1468 char *test;
1469 Display *dpy;
1470 Window win;
1471 Pixmap pix;
1472 RImage *image;
1474 TexturePanel *panel = (TexturePanel *) data;
1475 /* test = GetTexturePanelTextureString(panel); */
1477 wwarning(test);
1479 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1480 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250, 0, 0, 0);
1481 XMapRaised(dpy, win);
1482 XFlush(dpy);
1484 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1486 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1488 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width,
1489 image->height, 0, 0);
1491 wfree(test);
1495 void testCancelButton(WMWidget * self, void *data)
1497 wwarning("Exiting test....");
1498 exit(0);
1501 void wAbort()
1503 exit(1);
1506 int main(int argc, char **argv)
1508 TexturePanel *panel;
1510 Display *dpy = XOpenDisplay("");
1511 WMScreen *scr;
1513 /* char *test; */
1515 WMInitializeApplication("Test", &argc, argv);
1517 if (!dpy) {
1518 wfatal("could not open display");
1519 exit(1);
1522 scr = WMCreateSimpleApplicationScreen(dpy);
1524 panel = CreateTexturePanel(scr);
1526 SetTexturePanelOkAction(panel, (WMAction *) testOKButton, panel);
1527 SetTexturePanelCancelAction(panel, (WMAction *) testCancelButton, panel);
1529 SetTexturePanelTexture(panel, "pinky",
1530 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1532 ShowTexturePanel(panel);
1534 WMScreenMainLoop(scr);
1535 return 0;
1537 #endif