save the icon filename instead the full path
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobf12f6e9830795601ca3cbfe3f6d3c2d726a89561
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 i, row, rows;
361 WMListItem *item;
362 RColor **colors;
363 RImage *image;
364 WMScreen *scr = WMWidgetScreen(w);
366 hsv.hue = WMGetSliderValue(panel->ghueS);
367 hsv.saturation = WMGetSliderValue(panel->gsatS);
368 hsv.value = WMGetSliderValue(panel->gvalS);
370 rows = WMGetListNumberOfRows(panel->gcolL);
371 row = WMGetListSelectedItemRow(panel->gcolL);
373 if (row < 0 && rows > 0) {
374 row = 0;
375 WMSelectListItem(panel->gcolL, row);
376 item = WMGetListItem(panel->gcolL, row);
377 RRGBtoHSV((RColor *) item->clientData, &hsv);
379 WMSetSliderValue(panel->ghueS, hsv.hue);
380 WMSetSliderValue(panel->gsatS, hsv.saturation);
381 WMSetSliderValue(panel->gvalS, hsv.value);
384 if (row >= 0) {
385 RColor *rgb;
387 item = WMGetListItem(panel->gcolL, row);
389 rgb = (RColor *) item->clientData;
391 RHSVtoRGB(&hsv, rgb);
393 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
396 if (w == panel->ghueS) {
397 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
398 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
399 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
400 } else if (w == panel->gsatS) {
401 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
402 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
403 } else {
404 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
405 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
408 if (rows == 0)
409 return;
411 colors = wmalloc(sizeof(RColor *) * (rows + 1));
413 for (i = 0; i < rows; i++) {
414 item = WMGetListItem(panel->gcolL, i);
416 colors[i] = (RColor *) item->clientData;
418 colors[i] = NULL;
420 if (panel->gimage != None) {
421 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
424 image = RRenderMultiGradient(30, i * WMGetListItemHeight(panel->gcolL), colors, RVerticalGradient);
425 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
426 RReleaseImage(image);
428 wfree(colors);
430 WMRedisplayWidget(panel->gcolL);
432 updateGradButtons(panel);
435 static void paintGradListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
437 TexturePanel *panel = (TexturePanel *) WMGetHangedData(lPtr);
438 WMScreen *scr = WMWidgetScreen(lPtr);
439 WMColor *white = WMWhiteColor(scr);
440 WMColor *black = WMBlackColor(scr);
441 WMColor *gray = WMGrayColor(scr);
442 int width, height, x, y;
443 Display *dpy;
445 dpy = WMScreenDisplay(scr);
447 width = rect->size.width;
448 height = rect->size.height;
449 x = rect->pos.x;
450 y = rect->pos.y;
452 if (state & WLDSSelected)
453 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
454 else
455 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
457 if (panel->gimage) {
458 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
459 0, height * index, 30, height, x + 5, y);
461 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
463 WMReleaseColor(white);
464 WMReleaseColor(black);
465 WMReleaseColor(gray);
468 static void gradAddCallback(WMWidget * w, void *data)
470 TexturePanel *panel = (TexturePanel *) data;
471 WMListItem *item;
472 int row;
473 RColor *rgb;
475 /* Parameter not used, but tell the compiler that it is ok */
476 (void) w;
478 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
479 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
480 rgb = wmalloc(sizeof(RColor));
481 item->clientData = rgb;
483 WMSelectListItem(panel->gcolL, row);
485 updateGradButtons(panel);
487 sliderChangeCallback(panel->ghueS, panel);
489 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
492 static void gradClickCallback(WMWidget * w, void *data)
494 TexturePanel *panel = (TexturePanel *) data;
495 WMListItem *item;
496 int row;
497 RHSVColor hsv;
499 row = WMGetListSelectedItemRow(w);
500 if (row < 0)
501 return;
503 item = WMGetListItem(panel->gcolL, row);
504 RRGBtoHSV((RColor *) item->clientData, &hsv);
506 WMSetSliderValue(panel->ghueS, hsv.hue);
507 WMSetSliderValue(panel->gsatS, hsv.saturation);
508 WMSetSliderValue(panel->gvalS, hsv.value);
510 sliderChangeCallback(panel->ghueS, panel);
511 sliderChangeCallback(panel->gsatS, panel);
514 static void gradDeleteCallback(WMWidget * w, void *data)
516 TexturePanel *panel = (TexturePanel *) data;
517 WMListItem *item;
518 int row, rows;
520 /* Parameter not used, but tell the compiler that it is ok */
521 (void) w;
523 row = WMGetListSelectedItemRow(panel->gcolL);
524 if (row < 0)
525 return;
527 item = WMGetListItem(panel->gcolL, row);
528 wfree(item->clientData);
530 WMRemoveListItem(panel->gcolL, row);
531 if (row > 0)
532 WMSelectListItem(panel->gcolL, row - 1);
533 else {
534 rows = WMGetListNumberOfRows(panel->gcolL);
535 if (rows > 0)
536 WMSelectListItem(panel->gcolL, 0);
539 updateGradButtons(panel);
541 gradClickCallback(panel->gcolL, panel);
543 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
546 /*************** Simple Gradient ***************/
548 static void colorWellObserver(void *self, WMNotification * n)
550 /* Parameter not used, but tell the compiler that it is ok */
551 (void) n;
553 updateSGradButtons(self);
556 static void opaqChangeCallback(WMWidget * w, void *data)
558 TexturePanel *panel = (TexturePanel *) data;
560 /* Parameter not used, but tell the compiler that it is ok */
561 (void) w;
563 updateTGradImage(panel);
566 /****************** Image ******************/
568 static void updateImage(TexturePanel * panel, const char *path)
570 WMScreen *scr = WMWidgetScreen(panel->win);
571 RImage *image;
572 WMPixmap *pixmap;
573 WMSize size;
575 if (path) {
576 image = RLoadImage(WMScreenRContext(scr), path, 0);
577 if (!image) {
578 char *message;
580 message = wstrconcat(_("Could not load the selected file: "),
581 (char *)RMessageForError(RErrorCode));
583 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
585 if (!panel->image)
586 WMSetButtonEnabled(panel->okB, False);
588 wfree(message);
589 return;
592 WMSetButtonEnabled(panel->okB, True);
594 if (panel->image)
595 RReleaseImage(panel->image);
596 panel->image = image;
597 } else {
598 image = panel->image;
601 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
602 if (image) {
603 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
605 size = WMGetPixmapSize(pixmap);
606 WMSetLabelImage(panel->imageL, pixmap);
607 WMResizeWidget(panel->imageL, size.width, size.height);
609 WMReleasePixmap(pixmap);
611 } else {
612 updateTGradImage(panel);
616 static void browseImageCallback(WMWidget * w, void *data)
618 TexturePanel *panel = (TexturePanel *) data;
619 WMOpenPanel *opanel;
620 WMScreen *scr = WMWidgetScreen(w);
621 static char *ipath = NULL;
623 opanel = WMGetOpenPanel(scr);
624 WMSetFilePanelCanChooseDirectories(opanel, False);
625 WMSetFilePanelCanChooseFiles(opanel, True);
627 if (!ipath)
628 ipath = wstrdup(wgethomedir());
630 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
631 char *path, *fullpath;
632 char *tmp, *tmp2;
634 tmp = WMGetFilePanelFileName(opanel);
635 if (!tmp)
636 return;
637 fullpath = tmp;
639 wfree(ipath);
640 ipath = fullpath;
642 path = wstrdup(fullpath);
644 tmp2 = strrchr(fullpath, '/');
645 if (tmp2)
646 tmp2++;
648 tmp = wfindfileinarray(panel->pathList, tmp2);
650 if (tmp) {
651 if (strcmp(fullpath, tmp) == 0) {
652 wfree(path);
653 path = tmp2;
655 wfree(tmp);
658 if (!RGetImageFileFormat(fullpath)) {
659 WMRunAlertPanel(scr, panel->win, _("Error"),
660 _("The selected file does not contain a supported image."),
661 _("OK"), NULL, NULL);
662 wfree(path);
663 } else {
664 updateImage(panel, fullpath);
665 wfree(panel->imageFile);
666 panel->imageFile = path;
668 WMSetTextFieldText(panel->imageT, path);
673 static void buttonCallback(WMWidget * w, void *data)
675 TexturePanel *panel = (TexturePanel *) data;
677 if (w == panel->okB) {
678 (*panel->okAction) (panel->okData);
679 } else {
680 (*panel->cancelAction) (panel->cancelData);
684 static void changeTypeCallback(WMWidget * w, void *data)
686 TexturePanel *panel = (TexturePanel *) data;
687 int newType;
688 int i;
690 newType = WMGetPopUpButtonSelectedItem(w);
691 if (newType == panel->currentType)
692 return;
694 if (panel->currentType >= 0) {
695 for (i = 0; i < MAX_SECTION_PARTS; i++) {
696 if (panel->sectionParts[panel->currentType][i] == NULL)
697 break;
698 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
702 for (i = 0; i < MAX_SECTION_PARTS; i++) {
703 if (panel->sectionParts[newType][i] == NULL)
704 break;
705 WMMapWidget(panel->sectionParts[newType][i]);
707 panel->currentType = newType;
709 switch (newType) {
710 case TYPE_SGRADIENT:
711 updateSGradButtons(panel);
712 WMSetButtonEnabled(panel->okB, True);
713 break;
714 case TYPE_GRADIENT:
715 updateGradButtons(panel);
716 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
717 break;
718 case TYPE_TGRADIENT:
719 case TYPE_PIXMAP:
720 updateImage(panel, NULL);
721 WMSetButtonEnabled(panel->okB, panel->image != NULL);
722 break;
723 default:
724 WMSetButtonEnabled(panel->okB, True);
725 break;
730 *--------------------------------------------------------------------------
731 * Public functions
732 *--------------------------------------------------------------------------
734 void ShowTexturePanel(TexturePanel * panel)
736 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
737 Screen *scr = DefaultScreenOfDisplay(dpy);
739 WMSetWindowInitialPosition(panel->win,
740 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
741 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
742 WMMapWidget(panel->win);
745 void HideTexturePanel(TexturePanel * panel)
747 WMUnmapWidget(panel->win);
750 void SetTexturePanelOkAction(TexturePanel * panel, WMCallback * action, void *clientData)
752 panel->okAction = action;
753 panel->okData = clientData;
756 void SetTexturePanelCancelAction(TexturePanel * panel, WMCallback * action, void *clientData)
758 panel->cancelAction = action;
759 panel->cancelData = clientData;
762 void SetTexturePanelTexture(TexturePanel * panel, const char *name, WMPropList * texture)
764 WMScreen *scr = WMWidgetScreen(panel->win);
765 char *str, *type;
766 WMPropList *p;
767 WMColor *color;
768 int i;
769 char buffer[64];
770 int gradient = 0;
772 WMSetTextFieldText(panel->nameT, name);
774 if (!texture)
775 return;
777 p = WMGetFromPLArray(texture, 0);
778 if (!p) {
779 goto bad_texture;
781 type = WMGetFromPLString(p);
783 /*............................................... */
784 if (strcasecmp(type, "solid") == 0) {
786 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
788 p = WMGetFromPLArray(texture, 1);
789 if (!p) {
790 str = "black";
791 } else {
792 str = WMGetFromPLString(p);
794 color = WMCreateNamedColor(scr, str, False);
796 WMSetColorWellColor(panel->defcW, color);
798 WMReleaseColor(color);
799 /*............................................... */
800 } else if (strcasecmp(type, "hgradient") == 0
801 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
803 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
805 p = WMGetFromPLArray(texture, 1);
806 if (!p) {
807 str = "black";
808 } else {
809 str = WMGetFromPLString(p);
811 color = WMCreateNamedColor(scr, str, False);
813 WMSetColorWellColor(panel->tcol1W, color);
815 WMReleaseColor(color);
817 p = WMGetFromPLArray(texture, 2);
818 if (!p) {
819 str = "black";
820 } else {
821 str = WMGetFromPLString(p);
823 color = WMCreateNamedColor(scr, str, False);
825 WMSetColorWellColor(panel->tcol2W, color);
827 WMReleaseColor(color);
829 gradient = type[0];
830 /*............................................... */
831 } else if (strcasecmp(type, "thgradient") == 0
832 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
833 int i;
835 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
837 gradient = type[1];
839 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
840 if (panel->imageFile)
841 wfree(panel->imageFile);
842 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
844 if (sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i) != 1)
845 i = 180;
846 WMSetSliderValue(panel->topaS, i);
848 p = WMGetFromPLArray(texture, 3);
849 if (!p) {
850 str = "black";
851 } else {
852 str = WMGetFromPLString(p);
854 color = WMCreateNamedColor(scr, str, False);
856 WMSetColorWellColor(panel->tcol1W, color);
858 WMReleaseColor(color);
860 p = WMGetFromPLArray(texture, 4);
861 if (!p) {
862 str = "black";
863 } else {
864 str = WMGetFromPLString(p);
866 color = WMCreateNamedColor(scr, str, False);
868 WMSetColorWellColor(panel->tcol2W, color);
870 WMReleaseColor(color);
872 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
874 if (panel->imageFile)
875 wfree(panel->imageFile);
876 if ((panel->imageFile = wfindfileinarray(panel->pathList,
877 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) !=
878 NULL) {
880 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
881 updateTGradImage(panel);
883 updateSGradButtons(panel);
884 } else
885 wwarning(_("could not load file '%s': %s"), panel->imageFile,
886 RMessageForError(RErrorCode));
888 /*............................................... */
889 } else if (strcasecmp(type, "mhgradient") == 0
890 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
891 WMListItem *item;
893 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
894 item = WMGetListItem(panel->gcolL, i);
895 wfree(item->clientData);
897 WMClearList(panel->gcolL);
899 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
901 p = WMGetFromPLArray(texture, 1);
902 if (!p) {
903 str = "black";
904 } else {
905 str = WMGetFromPLString(p);
907 color = WMCreateNamedColor(scr, str, False);
909 WMSetColorWellColor(panel->defcW, color);
911 WMReleaseColor(color);
913 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
914 RColor *rgb;
915 XColor xcolor;
917 p = WMGetFromPLArray(texture, i);
918 if (!p) {
919 str = "black";
920 } else {
921 str = WMGetFromPLString(p);
924 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
926 rgb = wmalloc(sizeof(RColor));
927 rgb->red = xcolor.red >> 8;
928 rgb->green = xcolor.green >> 8;
929 rgb->blue = xcolor.blue >> 8;
930 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
932 item = WMAddListItem(panel->gcolL, buffer);
933 item->clientData = rgb;
936 sliderChangeCallback(panel->ghueS, panel);
938 gradient = type[1];
939 /*............................................... */
940 } else if (strcasecmp(type, "cpixmap") == 0
941 || strcasecmp(type, "spixmap") == 0
942 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
944 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
946 switch (toupper(type[0])) {
947 case 'C':
948 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
949 break;
950 case 'S':
951 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
952 break;
953 case 'M':
954 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
955 break;
956 default:
957 case 'T':
958 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
959 break;
962 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
964 if (panel->imageFile)
965 wfree(panel->imageFile);
966 panel->imageFile = wfindfileinarray(panel->pathList,
967 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
969 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
970 WMSetColorWellColor(panel->defcW, color);
971 WMReleaseColor(color);
973 updateImage(panel, panel->imageFile);
976 changeTypeCallback(panel->typeP, panel);
978 if (gradient > 0) {
979 updateGradButtons(panel);
981 switch (toupper(gradient)) {
982 case 'H':
983 WMPerformButtonClick(panel->dirhB);
984 break;
985 case 'V':
986 WMPerformButtonClick(panel->dirvB);
987 break;
988 default:
989 case 'D':
990 WMPerformButtonClick(panel->dirdB);
991 break;
995 return;
997 bad_texture:
998 str = WMGetPropListDescription(texture, False);
999 wwarning(_("error creating texture %s"), str);
1000 wfree(str);
1004 char *GetTexturePanelTextureName(TexturePanel * panel)
1006 return WMGetTextFieldText(panel->nameT);
1010 WMPropList *GetTexturePanelTexture(TexturePanel * panel)
1012 WMPropList *prop = NULL;
1013 WMColor *color;
1014 char *str, *str2;
1015 char buff[32];
1016 int i;
1018 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1020 case TYPE_SOLID:
1021 color = WMGetColorWellColor(panel->defcW);
1022 str = WMGetColorRGBDescription(color);
1023 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1024 wfree(str);
1026 break;
1028 case TYPE_PIXMAP:
1029 color = WMGetColorWellColor(panel->defcW);
1030 str = WMGetColorRGBDescription(color);
1032 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1033 case PTYPE_SCALE:
1034 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1035 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1036 break;
1037 case PTYPE_MAXIMIZE:
1038 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1039 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1040 break;
1041 case PTYPE_CENTER:
1042 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1043 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1044 break;
1045 case PTYPE_TILE:
1046 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1047 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1048 break;
1050 wfree(str);
1051 break;
1053 case TYPE_TGRADIENT:
1054 color = WMGetColorWellColor(panel->tcol1W);
1055 str = WMGetColorRGBDescription(color);
1057 color = WMGetColorWellColor(panel->tcol2W);
1058 str2 = WMGetColorRGBDescription(color);
1060 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1062 if (WMGetButtonSelected(panel->dirdB)) {
1063 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1064 WMCreatePLString(panel->imageFile),
1065 WMCreatePLString(buff),
1066 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1067 } else if (WMGetButtonSelected(panel->dirvB)) {
1068 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1069 WMCreatePLString(panel->imageFile),
1070 WMCreatePLString(buff),
1071 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1072 } else {
1073 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1074 WMCreatePLString(panel->imageFile),
1075 WMCreatePLString(buff),
1076 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1078 wfree(str);
1079 wfree(str2);
1080 break;
1082 case TYPE_SGRADIENT:
1083 color = WMGetColorWellColor(panel->tcol1W);
1084 str = WMGetColorRGBDescription(color);
1086 color = WMGetColorWellColor(panel->tcol2W);
1087 str2 = WMGetColorRGBDescription(color);
1089 if (WMGetButtonSelected(panel->dirdB)) {
1090 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1091 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1092 } else if (WMGetButtonSelected(panel->dirvB)) {
1093 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1094 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1095 } else {
1096 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1097 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1099 wfree(str);
1100 wfree(str2);
1101 break;
1103 case TYPE_GRADIENT:
1104 color = WMGetColorWellColor(panel->defcW);
1105 str = WMGetColorRGBDescription(color);
1107 if (WMGetButtonSelected(panel->dirdB)) {
1108 prop = WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str), NULL);
1109 } else if (WMGetButtonSelected(panel->dirvB)) {
1110 prop = WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str), NULL);
1111 } else {
1112 prop = WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str), NULL);
1114 wfree(str);
1116 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1117 RColor *rgb;
1118 WMListItem *item;
1120 item = WMGetListItem(panel->gcolL, i);
1122 rgb = (RColor *) item->clientData;
1124 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1126 WMAddToPLArray(prop, WMCreatePLString(buff));
1128 break;
1131 return prop;
1134 void SetTexturePanelPixmapPath(TexturePanel * panel, WMPropList * array)
1136 panel->pathList = array;
1139 TexturePanel *CreateTexturePanel(WMWindow * keyWindow)
1140 /*CreateTexturePanel(WMScreen *scr)*/
1142 TexturePanel *panel;
1143 WMScreen *scr = WMWidgetScreen(keyWindow);
1145 panel = wmalloc(sizeof(TexturePanel));
1147 panel->listFont = WMSystemFontOfSize(scr, 12);
1149 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1150 WMTitledWindowMask | WMClosableWindowMask);
1152 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1153 WMTitledWindowMask
1154 |WMClosableWindowMask);
1157 WMResizeWidget(panel->win, 325, 423);
1158 WMSetWindowTitle(panel->win, _("Texture Panel"));
1159 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1161 /* texture name */
1162 panel->nameF = WMCreateFrame(panel->win);
1163 WMResizeWidget(panel->nameF, 185, 50);
1164 WMMoveWidget(panel->nameF, 15, 10);
1165 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1167 panel->nameT = WMCreateTextField(panel->nameF);
1168 WMResizeWidget(panel->nameT, 160, 20);
1169 WMMoveWidget(panel->nameT, 12, 18);
1171 WMMapSubwidgets(panel->nameF);
1173 /* texture types */
1174 panel->typeP = WMCreatePopUpButton(panel->win);
1175 WMResizeWidget(panel->typeP, 185, 20);
1176 WMMoveWidget(panel->typeP, 15, 65);
1177 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1178 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1179 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1180 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1181 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1182 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1183 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1185 /* color */
1186 panel->defcF = WMCreateFrame(panel->win);
1187 WMResizeWidget(panel->defcF, 100, 75);
1188 WMMoveWidget(panel->defcF, 210, 10);
1189 WMSetFrameTitle(panel->defcF, _("Default Color"));
1191 panel->defcW = WMCreateColorWell(panel->defcF);
1192 WMResizeWidget(panel->defcW, 60, 45);
1193 WMMoveWidget(panel->defcW, 20, 20);
1195 WMMapSubwidgets(panel->defcF);
1197 /****** Gradient ******/
1198 panel->gcolF = WMCreateFrame(panel->win);
1199 WMResizeWidget(panel->gcolF, 295, 205);
1200 WMMoveWidget(panel->gcolF, 15, 95);
1201 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1203 panel->gcolL = WMCreateList(panel->gcolF);
1204 WMResizeWidget(panel->gcolL, 130, 140);
1205 WMMoveWidget(panel->gcolL, 10, 25);
1206 WMHangData(panel->gcolL, panel);
1207 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1208 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1210 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1211 WMResizeWidget(panel->gcolaB, 64, 24);
1212 WMMoveWidget(panel->gcolaB, 10, 170);
1213 WMSetButtonText(panel->gcolaB, _("Add"));
1214 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1216 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1217 WMResizeWidget(panel->gcoldB, 64, 24);
1218 WMMoveWidget(panel->gcoldB, 75, 170);
1219 WMSetButtonText(panel->gcoldB, _("Delete"));
1220 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1222 #if 0
1223 panel->gbriS = WMCreateSlider(panel->gcolF);
1224 WMResizeWidget(panel->gbriS, 130, 16);
1225 WMMoveWidget(panel->gbriS, 150, 25);
1226 WMSetSliderKnobThickness(panel->gbriS, 8);
1227 WMSetSliderMaxValue(panel->gbriS, 100);
1228 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1230 WMPixmap *pixmap;
1231 WMColor *color;
1233 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1234 color = WMDarkGrayColor(scr);
1235 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1236 WMReleaseColor(color);
1237 color = WMWhiteColor(color);
1238 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1239 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1240 WMSetSliderImage(panel->gbriS, pixmap);
1241 WMReleasePixmap(pixmap);
1244 panel->gconS = WMCreateSlider(panel->gcolF);
1245 WMResizeWidget(panel->gconS, 130, 16);
1246 WMMoveWidget(panel->gconS, 150, 50);
1247 WMSetSliderKnobThickness(panel->gconS, 8);
1248 WMSetSliderMaxValue(panel->gconS, 100);
1249 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1251 WMPixmap *pixmap;
1252 WMColor *color;
1254 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1255 color = WMDarkGrayColor(scr);
1256 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1257 WMReleaseColor(color);
1258 color = WMWhiteColor(scr);
1259 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1260 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1261 WMSetSliderImage(panel->gconS, pixmap);
1262 WMReleasePixmap(pixmap);
1264 #endif
1265 panel->ghueS = WMCreateSlider(panel->gcolF);
1266 WMResizeWidget(panel->ghueS, 130, 16);
1267 WMMoveWidget(panel->ghueS, 150, 100);
1268 WMSetSliderKnobThickness(panel->ghueS, 8);
1269 WMSetSliderMaxValue(panel->ghueS, 359);
1270 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1272 panel->gsatS = WMCreateSlider(panel->gcolF);
1273 WMResizeWidget(panel->gsatS, 130, 16);
1274 WMMoveWidget(panel->gsatS, 150, 125);
1275 WMSetSliderKnobThickness(panel->gsatS, 8);
1276 WMSetSliderMaxValue(panel->gsatS, 255);
1277 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1279 panel->gvalS = WMCreateSlider(panel->gcolF);
1280 WMResizeWidget(panel->gvalS, 130, 16);
1281 WMMoveWidget(panel->gvalS, 150, 150);
1282 WMSetSliderKnobThickness(panel->gvalS, 8);
1283 WMSetSliderMaxValue(panel->gvalS, 255);
1284 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1286 WMMapSubwidgets(panel->gcolF);
1288 /** Direction **/
1289 panel->dirF = WMCreateFrame(panel->win);
1290 WMSetFrameTitle(panel->dirF, _("Direction"));
1291 WMResizeWidget(panel->dirF, 295, 75);
1292 WMMoveWidget(panel->dirF, 15, 305);
1294 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1295 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1296 WMResizeWidget(panel->dirvB, 90, 40);
1297 WMMoveWidget(panel->dirvB, 10, 20);
1299 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1300 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1301 WMResizeWidget(panel->dirhB, 90, 40);
1302 WMMoveWidget(panel->dirhB, 102, 20);
1304 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1305 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1306 WMResizeWidget(panel->dirdB, 90, 40);
1307 WMMoveWidget(panel->dirdB, 194, 20);
1309 WMGroupButtons(panel->dirvB, panel->dirhB);
1310 WMGroupButtons(panel->dirvB, panel->dirdB);
1312 WMMapSubwidgets(panel->dirF);
1314 /****************** Textured Gradient ******************/
1315 panel->tcolF = WMCreateFrame(panel->win);
1316 WMResizeWidget(panel->tcolF, 100, 135);
1317 WMMoveWidget(panel->tcolF, 210, 10);
1318 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1320 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1321 WMResizeWidget(panel->tcol1W, 60, 45);
1322 WMMoveWidget(panel->tcol1W, 20, 25);
1323 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1325 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1326 WMResizeWidget(panel->tcol2W, 60, 45);
1327 WMMoveWidget(panel->tcol2W, 20, 75);
1328 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1330 /** Opacity */
1331 panel->topaF = WMCreateFrame(panel->win);
1332 WMResizeWidget(panel->topaF, 185, 50);
1333 WMMoveWidget(panel->topaF, 15, 95);
1334 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1336 panel->topaS = WMCreateSlider(panel->topaF);
1337 WMResizeWidget(panel->topaS, 155, 18);
1338 WMMoveWidget(panel->topaS, 15, 20);
1339 WMSetSliderMaxValue(panel->topaS, 255);
1340 WMSetSliderValue(panel->topaS, 200);
1341 WMSetSliderContinuous(panel->topaS, False);
1342 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1344 WMMapSubwidgets(panel->topaF);
1347 WMPixmap *pixmap;
1348 Pixmap p;
1349 WMColor *color;
1351 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1352 p = WMGetPixmapXID(pixmap);
1354 color = WMDarkGrayColor(scr);
1355 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1356 WMReleaseColor(color);
1358 color = WMWhiteColor(scr);
1359 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1360 WMDrawString(scr, p, color, panel->listFont,
1361 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1362 WMReleaseColor(color);
1364 WMSetSliderImage(panel->topaS, pixmap);
1365 WMReleasePixmap(pixmap);
1368 WMMapSubwidgets(panel->tcolF);
1370 /****************** Image ******************/
1371 panel->imageF = WMCreateFrame(panel->win);
1372 WMResizeWidget(panel->imageF, 295, 150);
1373 WMMoveWidget(panel->imageF, 15, 150);
1374 WMSetFrameTitle(panel->imageF, _("Image"));
1376 panel->imageL = WMCreateLabel(panel->imageF);
1377 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1379 panel->imageT = WMCreateTextField(panel->imageF);
1380 WMResizeWidget(panel->imageT, 90, 20);
1381 WMMoveWidget(panel->imageT, 190, 25);
1383 panel->imageV = WMCreateScrollView(panel->imageF);
1384 WMResizeWidget(panel->imageV, 165, 115);
1385 WMMoveWidget(panel->imageV, 15, 20);
1386 WMSetScrollViewRelief(panel->imageV, WRSunken);
1387 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1388 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1389 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1391 panel->browB = WMCreateCommandButton(panel->imageF);
1392 WMResizeWidget(panel->browB, 90, 24);
1393 WMMoveWidget(panel->browB, 190, 50);
1394 WMSetButtonText(panel->browB, _("Browse..."));
1395 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1397 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1398 WMResizeWidget(panel->dispB, 90, 24);
1399 WMMoveWidget(panel->dispB, 190, 80);
1400 WMSetButtonText(panel->dispB, _("Show"));
1403 panel->arrP = WMCreatePopUpButton(panel->imageF);
1404 WMResizeWidget(panel->arrP, 90, 20);
1405 WMMoveWidget(panel->arrP, 190, 120);
1406 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1407 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1408 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1409 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1410 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1412 WMMapSubwidgets(panel->imageF);
1414 /****/
1416 panel->okB = WMCreateCommandButton(panel->win);
1417 WMResizeWidget(panel->okB, 84, 24);
1418 WMMoveWidget(panel->okB, 225, 390);
1419 WMSetButtonText(panel->okB, _("OK"));
1420 WMSetButtonAction(panel->okB, buttonCallback, panel);
1422 panel->cancelB = WMCreateCommandButton(panel->win);
1423 WMResizeWidget(panel->cancelB, 84, 24);
1424 WMMoveWidget(panel->cancelB, 130, 390);
1425 WMSetButtonText(panel->cancelB, _("Cancel"));
1426 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1428 WMMapWidget(panel->nameF);
1429 WMMapWidget(panel->typeP);
1430 WMMapWidget(panel->okB);
1431 WMMapWidget(panel->cancelB);
1433 WMUnmapWidget(panel->arrP);
1435 WMRealizeWidget(panel->win);
1437 panel->currentType = -1;
1439 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1441 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1442 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1443 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1445 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1446 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1448 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1449 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1450 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1451 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1452 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1454 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1455 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1456 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1458 /* setup for first time */
1460 changeTypeCallback(panel->typeP, panel);
1462 sliderChangeCallback(panel->ghueS, panel);
1463 sliderChangeCallback(panel->gsatS, panel);
1465 return panel;
1469 *--------------------------------------------------------------------------
1470 * Test stuff
1471 *--------------------------------------------------------------------------
1474 #if 0
1476 char *ProgName = "test";
1478 void testOKButton(WMWidget * self, void *data)
1480 char *test;
1481 Display *dpy;
1482 Window win;
1483 Pixmap pix;
1484 RImage *image;
1486 TexturePanel *panel = (TexturePanel *) data;
1487 /* test = GetTexturePanelTextureString(panel); */
1489 wwarning(test);
1491 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1492 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250, 0, 0, 0);
1493 XMapRaised(dpy, win);
1494 XFlush(dpy);
1496 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1498 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1500 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width,
1501 image->height, 0, 0);
1503 wfree(test);
1507 void testCancelButton(WMWidget * self, void *data)
1509 wwarning("Exiting test....");
1510 exit(0);
1513 void wAbort()
1515 exit(1);
1518 int main(int argc, char **argv)
1520 TexturePanel *panel;
1522 Display *dpy = XOpenDisplay("");
1523 WMScreen *scr;
1525 /* char *test; */
1527 WMInitializeApplication("Test", &argc, argv);
1529 if (!dpy) {
1530 wfatal("could not open display");
1531 exit(1);
1534 scr = WMCreateSimpleApplicationScreen(dpy);
1536 panel = CreateTexturePanel(scr);
1538 SetTexturePanelOkAction(panel, (WMAction *) testOKButton, panel);
1539 SetTexturePanelCancelAction(panel, (WMAction *) testCancelButton, panel);
1541 SetTexturePanelTexture(panel, "pinky",
1542 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1544 ShowTexturePanel(panel);
1546 WMScreenMainLoop(scr);
1547 return 0;
1549 #endif