wmgenmenu: Add French and Spanish translations
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob15dd890b82baf37fda5cfc410b70f28390a6a3e8
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 WMListItem *item;
431 int width, height, x, y;
432 Display *dpy;
434 dpy = WMScreenDisplay(scr);
436 width = rect->size.width;
437 height = rect->size.height;
438 x = rect->pos.x;
439 y = rect->pos.y;
441 if (state & WLDSSelected)
442 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
443 else
444 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
446 item = WMGetListItem(lPtr, index);
448 if (panel->gimage) {
449 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
450 0, height * index, 30, height, x + 5, y);
452 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
454 WMReleaseColor(white);
455 WMReleaseColor(black);
456 WMReleaseColor(gray);
459 static void gradAddCallback(WMWidget * w, void *data)
461 TexturePanel *panel = (TexturePanel *) data;
462 WMListItem *item;
463 int row;
464 RColor *rgb;
466 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
467 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
468 rgb = wmalloc(sizeof(RColor));
469 memset(rgb, 0, sizeof(RColor));
470 item->clientData = rgb;
472 WMSelectListItem(panel->gcolL, row);
474 updateGradButtons(panel);
476 sliderChangeCallback(panel->ghueS, panel);
478 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
481 static void gradClickCallback(WMWidget * w, void *data)
483 TexturePanel *panel = (TexturePanel *) data;
484 WMListItem *item;
485 int row;
486 RHSVColor hsv;
488 row = WMGetListSelectedItemRow(w);
489 if (row < 0)
490 return;
492 item = WMGetListItem(panel->gcolL, row);
493 RRGBtoHSV((RColor *) item->clientData, &hsv);
495 WMSetSliderValue(panel->ghueS, hsv.hue);
496 WMSetSliderValue(panel->gsatS, hsv.saturation);
497 WMSetSliderValue(panel->gvalS, hsv.value);
499 sliderChangeCallback(panel->ghueS, panel);
500 sliderChangeCallback(panel->gsatS, panel);
503 static void gradDeleteCallback(WMWidget * w, void *data)
505 TexturePanel *panel = (TexturePanel *) data;
506 WMListItem *item;
507 int row;
509 row = WMGetListSelectedItemRow(panel->gcolL);
510 if (row < 0)
511 return;
513 item = WMGetListItem(panel->gcolL, row);
514 wfree(item->clientData);
516 WMRemoveListItem(panel->gcolL, row);
518 WMSelectListItem(panel->gcolL, row - 1);
520 updateGradButtons(panel);
522 gradClickCallback(panel->gcolL, panel);
524 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
527 /*************** Simple Gradient ***************/
529 static void colorWellObserver(void *self, WMNotification * n)
531 updateSGradButtons(self);
534 static void opaqChangeCallback(WMWidget * w, void *data)
536 TexturePanel *panel = (TexturePanel *) data;
538 updateTGradImage(panel);
541 /****************** Image ******************/
543 static void updateImage(TexturePanel * panel, char *path)
545 WMScreen *scr = WMWidgetScreen(panel->win);
546 RImage *image;
547 WMPixmap *pixmap;
548 WMSize size;
550 if (path) {
551 image = RLoadImage(WMScreenRContext(scr), path, 0);
552 if (!image) {
553 char *message;
555 message = wstrconcat(_("Could not load the selected file: "),
556 (char *)RMessageForError(RErrorCode));
558 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
560 if (!panel->image)
561 WMSetButtonEnabled(panel->okB, False);
563 wfree(message);
564 return;
567 WMSetButtonEnabled(panel->okB, True);
569 if (panel->image)
570 RReleaseImage(panel->image);
571 panel->image = image;
572 } else {
573 image = panel->image;
576 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
577 if (image) {
578 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
580 size = WMGetPixmapSize(pixmap);
581 WMSetLabelImage(panel->imageL, pixmap);
582 WMResizeWidget(panel->imageL, size.width, size.height);
584 WMReleasePixmap(pixmap);
586 } else {
587 updateTGradImage(panel);
591 static void browseImageCallback(WMWidget * w, void *data)
593 TexturePanel *panel = (TexturePanel *) data;
594 WMOpenPanel *opanel;
595 WMScreen *scr = WMWidgetScreen(w);
596 static char *ipath = NULL;
598 opanel = WMGetOpenPanel(scr);
599 WMSetFilePanelCanChooseDirectories(opanel, False);
600 WMSetFilePanelCanChooseFiles(opanel, True);
602 if (!ipath)
603 ipath = wstrdup(wgethomedir());
605 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
606 char *path, *fullpath;
607 char *tmp, *tmp2;
609 tmp = WMGetFilePanelFileName(opanel);
610 if (!tmp)
611 return;
612 fullpath = tmp;
614 wfree(ipath);
615 ipath = fullpath;
617 path = wstrdup(fullpath);
619 tmp2 = strrchr(fullpath, '/');
620 if (tmp2)
621 tmp2++;
623 tmp = wfindfileinarray(panel->pathList, tmp2);
625 if (tmp) {
626 if (strcmp(fullpath, tmp) == 0) {
627 wfree(path);
628 path = tmp2;
630 wfree(tmp);
633 if (!RGetImageFileFormat(fullpath)) {
634 WMRunAlertPanel(scr, panel->win, _("Error"),
635 _("The selected file does not contain a supported image."),
636 _("OK"), NULL, NULL);
637 wfree(path);
638 } else {
639 updateImage(panel, fullpath);
640 wfree(panel->imageFile);
641 panel->imageFile = path;
643 WMSetTextFieldText(panel->imageT, path);
648 static void buttonCallback(WMWidget * w, void *data)
650 TexturePanel *panel = (TexturePanel *) data;
652 if (w == panel->okB) {
653 (*panel->okAction) (panel->okData);
654 } else {
655 (*panel->cancelAction) (panel->cancelData);
659 static void changeTypeCallback(WMWidget * w, void *data)
661 TexturePanel *panel = (TexturePanel *) data;
662 int newType;
663 int i;
665 newType = WMGetPopUpButtonSelectedItem(w);
666 if (newType == panel->currentType)
667 return;
669 if (panel->currentType >= 0) {
670 for (i = 0; i < MAX_SECTION_PARTS; i++) {
671 if (panel->sectionParts[panel->currentType][i] == NULL)
672 break;
673 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
677 for (i = 0; i < MAX_SECTION_PARTS; i++) {
678 if (panel->sectionParts[newType][i] == NULL)
679 break;
680 WMMapWidget(panel->sectionParts[newType][i]);
682 panel->currentType = newType;
684 switch (newType) {
685 case TYPE_SGRADIENT:
686 updateSGradButtons(panel);
687 WMSetButtonEnabled(panel->okB, True);
688 break;
689 case TYPE_GRADIENT:
690 updateGradButtons(panel);
691 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
692 break;
693 case TYPE_TGRADIENT:
694 case TYPE_PIXMAP:
695 updateImage(panel, NULL);
696 WMSetButtonEnabled(panel->okB, panel->image != NULL);
697 break;
698 default:
699 WMSetButtonEnabled(panel->okB, True);
700 break;
705 *--------------------------------------------------------------------------
706 * Public functions
707 *--------------------------------------------------------------------------
709 void DestroyTexturePanel(TexturePanel * panel)
714 void ShowTexturePanel(TexturePanel * panel)
716 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
717 Screen *scr = DefaultScreenOfDisplay(dpy);
719 WMSetWindowInitialPosition(panel->win,
720 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
721 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
722 WMMapWidget(panel->win);
725 void HideTexturePanel(TexturePanel * panel)
727 WMUnmapWidget(panel->win);
730 void SetTexturePanelOkAction(TexturePanel * panel, WMCallback * action, void *clientData)
732 panel->okAction = action;
733 panel->okData = clientData;
736 void SetTexturePanelCancelAction(TexturePanel * panel, WMCallback * action, void *clientData)
738 panel->cancelAction = action;
739 panel->cancelData = clientData;
742 void SetTexturePanelTexture(TexturePanel * panel, char *name, WMPropList * texture)
744 WMScreen *scr = WMWidgetScreen(panel->win);
745 char *str, *type;
746 WMPropList *p;
747 WMColor *color;
748 int i;
749 char buffer[64];
750 int gradient = 0;
752 WMSetTextFieldText(panel->nameT, name);
754 if (!texture)
755 return;
757 p = WMGetFromPLArray(texture, 0);
758 if (!p) {
759 goto bad_texture;
761 type = WMGetFromPLString(p);
763 /*............................................... */
764 if (strcasecmp(type, "solid") == 0) {
766 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
768 p = WMGetFromPLArray(texture, 1);
769 if (!p) {
770 str = "black";
771 } else {
772 str = WMGetFromPLString(p);
774 color = WMCreateNamedColor(scr, str, False);
776 WMSetColorWellColor(panel->defcW, color);
778 WMReleaseColor(color);
779 /*............................................... */
780 } else if (strcasecmp(type, "hgradient") == 0
781 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
783 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
785 p = WMGetFromPLArray(texture, 1);
786 if (!p) {
787 str = "black";
788 } else {
789 str = WMGetFromPLString(p);
791 color = WMCreateNamedColor(scr, str, False);
793 WMSetColorWellColor(panel->tcol1W, color);
795 WMReleaseColor(color);
797 p = WMGetFromPLArray(texture, 2);
798 if (!p) {
799 str = "black";
800 } else {
801 str = WMGetFromPLString(p);
803 color = WMCreateNamedColor(scr, str, False);
805 WMSetColorWellColor(panel->tcol2W, color);
807 WMReleaseColor(color);
809 gradient = type[0];
810 /*............................................... */
811 } else if (strcasecmp(type, "thgradient") == 0
812 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
813 int i;
815 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
817 gradient = type[1];
819 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
820 if (panel->imageFile)
821 wfree(panel->imageFile);
822 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
824 i = 180;
825 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
826 WMSetSliderValue(panel->topaS, i);
828 p = WMGetFromPLArray(texture, 3);
829 if (!p) {
830 str = "black";
831 } else {
832 str = WMGetFromPLString(p);
834 color = WMCreateNamedColor(scr, str, False);
836 WMSetColorWellColor(panel->tcol1W, color);
838 WMReleaseColor(color);
840 p = WMGetFromPLArray(texture, 4);
841 if (!p) {
842 str = "black";
843 } else {
844 str = WMGetFromPLString(p);
846 color = WMCreateNamedColor(scr, str, False);
848 WMSetColorWellColor(panel->tcol2W, color);
850 WMReleaseColor(color);
852 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
854 if (panel->imageFile)
855 wfree(panel->imageFile);
856 if ((panel->imageFile = wfindfileinarray(panel->pathList,
857 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) !=
858 NULL) {
860 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
861 updateTGradImage(panel);
863 updateSGradButtons(panel);
864 } else
865 wwarning(_("could not load file '%s': %s"), panel->imageFile,
866 RMessageForError(RErrorCode));
868 /*............................................... */
869 } else if (strcasecmp(type, "mhgradient") == 0
870 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
871 WMListItem *item;
873 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
874 item = WMGetListItem(panel->gcolL, i);
875 wfree(item->clientData);
877 WMClearList(panel->gcolL);
879 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
881 p = WMGetFromPLArray(texture, 1);
882 if (!p) {
883 str = "black";
884 } else {
885 str = WMGetFromPLString(p);
887 color = WMCreateNamedColor(scr, str, False);
889 WMSetColorWellColor(panel->defcW, color);
891 WMReleaseColor(color);
893 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
894 RColor *rgb;
895 XColor xcolor;
897 p = WMGetFromPLArray(texture, i);
898 if (!p) {
899 str = "black";
900 } else {
901 str = WMGetFromPLString(p);
904 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
906 rgb = wmalloc(sizeof(RColor));
907 rgb->red = xcolor.red >> 8;
908 rgb->green = xcolor.green >> 8;
909 rgb->blue = xcolor.blue >> 8;
910 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
912 item = WMAddListItem(panel->gcolL, buffer);
913 item->clientData = rgb;
916 sliderChangeCallback(panel->ghueS, panel);
918 gradient = type[1];
919 /*............................................... */
920 } else if (strcasecmp(type, "cpixmap") == 0
921 || strcasecmp(type, "spixmap") == 0
922 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
924 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
926 switch (toupper(type[0])) {
927 case 'C':
928 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
929 break;
930 case 'S':
931 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
932 break;
933 case 'M':
934 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
935 break;
936 default:
937 case 'T':
938 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
939 break;
942 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
944 if (panel->imageFile)
945 wfree(panel->imageFile);
946 panel->imageFile = wfindfileinarray(panel->pathList,
947 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
949 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
950 WMSetColorWellColor(panel->defcW, color);
951 WMReleaseColor(color);
953 updateImage(panel, panel->imageFile);
956 changeTypeCallback(panel->typeP, panel);
958 if (gradient > 0) {
959 updateGradButtons(panel);
961 switch (toupper(gradient)) {
962 case 'H':
963 WMPerformButtonClick(panel->dirhB);
964 break;
965 case 'V':
966 WMPerformButtonClick(panel->dirvB);
967 break;
968 default:
969 case 'D':
970 WMPerformButtonClick(panel->dirdB);
971 break;
975 return;
977 bad_texture:
978 str = WMGetPropListDescription(texture, False);
979 wwarning(_("error creating texture %s"), str);
980 wfree(str);
984 char *GetTexturePanelTextureName(TexturePanel * panel)
986 return WMGetTextFieldText(panel->nameT);
990 WMPropList *GetTexturePanelTexture(TexturePanel * panel)
992 WMPropList *prop = NULL;
993 WMColor *color;
994 char *str, *str2;
995 char buff[32];
996 int i;
998 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1000 case TYPE_SOLID:
1001 color = WMGetColorWellColor(panel->defcW);
1002 str = WMGetColorRGBDescription(color);
1003 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1004 wfree(str);
1006 break;
1008 case TYPE_PIXMAP:
1009 color = WMGetColorWellColor(panel->defcW);
1010 str = WMGetColorRGBDescription(color);
1012 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1013 case PTYPE_SCALE:
1014 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1015 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1016 break;
1017 case PTYPE_MAXIMIZE:
1018 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1019 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1020 break;
1021 case PTYPE_CENTER:
1022 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1023 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1024 break;
1025 case PTYPE_TILE:
1026 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1027 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1028 break;
1030 wfree(str);
1031 break;
1033 case TYPE_TGRADIENT:
1034 color = WMGetColorWellColor(panel->tcol1W);
1035 str = WMGetColorRGBDescription(color);
1037 color = WMGetColorWellColor(panel->tcol2W);
1038 str2 = WMGetColorRGBDescription(color);
1040 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1042 if (WMGetButtonSelected(panel->dirdB)) {
1043 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1044 WMCreatePLString(panel->imageFile),
1045 WMCreatePLString(buff),
1046 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1047 } else if (WMGetButtonSelected(panel->dirvB)) {
1048 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1049 WMCreatePLString(panel->imageFile),
1050 WMCreatePLString(buff),
1051 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1052 } else {
1053 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1054 WMCreatePLString(panel->imageFile),
1055 WMCreatePLString(buff),
1056 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1058 wfree(str);
1059 wfree(str2);
1060 break;
1062 case TYPE_SGRADIENT:
1063 color = WMGetColorWellColor(panel->tcol1W);
1064 str = WMGetColorRGBDescription(color);
1066 color = WMGetColorWellColor(panel->tcol2W);
1067 str2 = WMGetColorRGBDescription(color);
1069 if (WMGetButtonSelected(panel->dirdB)) {
1070 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1071 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1072 } else if (WMGetButtonSelected(panel->dirvB)) {
1073 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1074 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1075 } else {
1076 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1077 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1079 wfree(str);
1080 wfree(str2);
1081 break;
1083 case TYPE_GRADIENT:
1084 color = WMGetColorWellColor(panel->defcW);
1085 str = WMGetColorRGBDescription(color);
1087 if (WMGetButtonSelected(panel->dirdB)) {
1088 prop = WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str), NULL);
1089 } else if (WMGetButtonSelected(panel->dirvB)) {
1090 prop = WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str), NULL);
1091 } else {
1092 prop = WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str), NULL);
1094 wfree(str);
1096 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1097 RColor *rgb;
1098 WMListItem *item;
1100 item = WMGetListItem(panel->gcolL, i);
1102 rgb = (RColor *) item->clientData;
1104 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1106 WMAddToPLArray(prop, WMCreatePLString(buff));
1108 break;
1111 return prop;
1114 void SetTexturePanelPixmapPath(TexturePanel * panel, WMPropList * array)
1116 panel->pathList = array;
1119 TexturePanel *CreateTexturePanel(WMWindow * keyWindow)
1120 /*CreateTexturePanel(WMScreen *scr)*/
1122 TexturePanel *panel;
1123 WMScreen *scr = WMWidgetScreen(keyWindow);
1125 panel = wmalloc(sizeof(TexturePanel));
1126 memset(panel, 0, sizeof(TexturePanel));
1128 panel->listFont = WMSystemFontOfSize(scr, 12);
1130 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1131 WMTitledWindowMask | WMClosableWindowMask);
1133 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1134 WMTitledWindowMask
1135 |WMClosableWindowMask);
1138 WMResizeWidget(panel->win, 325, 423);
1139 WMSetWindowTitle(panel->win, _("Texture Panel"));
1140 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1142 /* texture name */
1143 panel->nameF = WMCreateFrame(panel->win);
1144 WMResizeWidget(panel->nameF, 185, 50);
1145 WMMoveWidget(panel->nameF, 15, 10);
1146 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1148 panel->nameT = WMCreateTextField(panel->nameF);
1149 WMResizeWidget(panel->nameT, 160, 20);
1150 WMMoveWidget(panel->nameT, 12, 18);
1152 WMMapSubwidgets(panel->nameF);
1154 /* texture types */
1155 panel->typeP = WMCreatePopUpButton(panel->win);
1156 WMResizeWidget(panel->typeP, 185, 20);
1157 WMMoveWidget(panel->typeP, 15, 65);
1158 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1159 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1160 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1161 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1162 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1163 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1164 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1166 /* color */
1167 panel->defcF = WMCreateFrame(panel->win);
1168 WMResizeWidget(panel->defcF, 100, 75);
1169 WMMoveWidget(panel->defcF, 210, 10);
1170 WMSetFrameTitle(panel->defcF, _("Default Color"));
1172 panel->defcW = WMCreateColorWell(panel->defcF);
1173 WMResizeWidget(panel->defcW, 60, 45);
1174 WMMoveWidget(panel->defcW, 20, 20);
1176 WMMapSubwidgets(panel->defcF);
1178 /****** Gradient ******/
1179 panel->gcolF = WMCreateFrame(panel->win);
1180 WMResizeWidget(panel->gcolF, 295, 205);
1181 WMMoveWidget(panel->gcolF, 15, 95);
1182 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1184 panel->gcolL = WMCreateList(panel->gcolF);
1185 WMResizeWidget(panel->gcolL, 130, 140);
1186 WMMoveWidget(panel->gcolL, 10, 25);
1187 WMHangData(panel->gcolL, panel);
1188 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1189 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1191 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1192 WMResizeWidget(panel->gcolaB, 64, 24);
1193 WMMoveWidget(panel->gcolaB, 10, 170);
1194 WMSetButtonText(panel->gcolaB, _("Add"));
1195 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1197 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1198 WMResizeWidget(panel->gcoldB, 64, 24);
1199 WMMoveWidget(panel->gcoldB, 75, 170);
1200 WMSetButtonText(panel->gcoldB, _("Delete"));
1201 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1203 #if 0
1204 panel->gbriS = WMCreateSlider(panel->gcolF);
1205 WMResizeWidget(panel->gbriS, 130, 16);
1206 WMMoveWidget(panel->gbriS, 150, 25);
1207 WMSetSliderKnobThickness(panel->gbriS, 8);
1208 WMSetSliderMaxValue(panel->gbriS, 100);
1209 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1211 WMPixmap *pixmap;
1212 WMColor *color;
1214 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1215 color = WMDarkGrayColor(scr);
1216 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1217 WMReleaseColor(color);
1218 color = WMWhiteColor(color);
1219 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1220 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1221 WMSetSliderImage(panel->gbriS, pixmap);
1222 WMReleasePixmap(pixmap);
1225 panel->gconS = WMCreateSlider(panel->gcolF);
1226 WMResizeWidget(panel->gconS, 130, 16);
1227 WMMoveWidget(panel->gconS, 150, 50);
1228 WMSetSliderKnobThickness(panel->gconS, 8);
1229 WMSetSliderMaxValue(panel->gconS, 100);
1230 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1232 WMPixmap *pixmap;
1233 WMColor *color;
1235 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1236 color = WMDarkGrayColor(scr);
1237 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1238 WMReleaseColor(color);
1239 color = WMWhiteColor(scr);
1240 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1241 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1242 WMSetSliderImage(panel->gconS, pixmap);
1243 WMReleasePixmap(pixmap);
1245 #endif
1246 panel->ghueS = WMCreateSlider(panel->gcolF);
1247 WMResizeWidget(panel->ghueS, 130, 16);
1248 WMMoveWidget(panel->ghueS, 150, 100);
1249 WMSetSliderKnobThickness(panel->ghueS, 8);
1250 WMSetSliderMaxValue(panel->ghueS, 359);
1251 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1253 panel->gsatS = WMCreateSlider(panel->gcolF);
1254 WMResizeWidget(panel->gsatS, 130, 16);
1255 WMMoveWidget(panel->gsatS, 150, 125);
1256 WMSetSliderKnobThickness(panel->gsatS, 8);
1257 WMSetSliderMaxValue(panel->gsatS, 255);
1258 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1260 panel->gvalS = WMCreateSlider(panel->gcolF);
1261 WMResizeWidget(panel->gvalS, 130, 16);
1262 WMMoveWidget(panel->gvalS, 150, 150);
1263 WMSetSliderKnobThickness(panel->gvalS, 8);
1264 WMSetSliderMaxValue(panel->gvalS, 255);
1265 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1267 WMMapSubwidgets(panel->gcolF);
1269 /** Direction **/
1270 panel->dirF = WMCreateFrame(panel->win);
1271 WMSetFrameTitle(panel->dirF, _("Direction"));
1272 WMResizeWidget(panel->dirF, 295, 75);
1273 WMMoveWidget(panel->dirF, 15, 305);
1275 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1276 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1277 WMResizeWidget(panel->dirvB, 90, 40);
1278 WMMoveWidget(panel->dirvB, 10, 20);
1280 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1281 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1282 WMResizeWidget(panel->dirhB, 90, 40);
1283 WMMoveWidget(panel->dirhB, 102, 20);
1285 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1286 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1287 WMResizeWidget(panel->dirdB, 90, 40);
1288 WMMoveWidget(panel->dirdB, 194, 20);
1290 WMGroupButtons(panel->dirvB, panel->dirhB);
1291 WMGroupButtons(panel->dirvB, panel->dirdB);
1293 WMMapSubwidgets(panel->dirF);
1295 /****************** Textured Gradient ******************/
1296 panel->tcolF = WMCreateFrame(panel->win);
1297 WMResizeWidget(panel->tcolF, 100, 135);
1298 WMMoveWidget(panel->tcolF, 210, 10);
1299 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1301 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1302 WMResizeWidget(panel->tcol1W, 60, 45);
1303 WMMoveWidget(panel->tcol1W, 20, 25);
1304 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1306 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1307 WMResizeWidget(panel->tcol2W, 60, 45);
1308 WMMoveWidget(panel->tcol2W, 20, 75);
1309 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1311 /** Opacity */
1312 panel->topaF = WMCreateFrame(panel->win);
1313 WMResizeWidget(panel->topaF, 185, 50);
1314 WMMoveWidget(panel->topaF, 15, 95);
1315 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1317 panel->topaS = WMCreateSlider(panel->topaF);
1318 WMResizeWidget(panel->topaS, 155, 18);
1319 WMMoveWidget(panel->topaS, 15, 20);
1320 WMSetSliderMaxValue(panel->topaS, 255);
1321 WMSetSliderValue(panel->topaS, 200);
1322 WMSetSliderContinuous(panel->topaS, False);
1323 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1325 WMMapSubwidgets(panel->topaF);
1328 WMPixmap *pixmap;
1329 Pixmap p;
1330 WMColor *color;
1332 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1333 p = WMGetPixmapXID(pixmap);
1335 color = WMDarkGrayColor(scr);
1336 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1337 WMReleaseColor(color);
1339 color = WMWhiteColor(scr);
1340 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1341 WMDrawString(scr, p, color, panel->listFont,
1342 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1343 WMReleaseColor(color);
1345 WMSetSliderImage(panel->topaS, pixmap);
1346 WMReleasePixmap(pixmap);
1349 WMMapSubwidgets(panel->tcolF);
1351 /****************** Image ******************/
1352 panel->imageF = WMCreateFrame(panel->win);
1353 WMResizeWidget(panel->imageF, 295, 150);
1354 WMMoveWidget(panel->imageF, 15, 150);
1355 WMSetFrameTitle(panel->imageF, _("Image"));
1357 panel->imageL = WMCreateLabel(panel->imageF);
1358 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1360 panel->imageT = WMCreateTextField(panel->imageF);
1361 WMResizeWidget(panel->imageT, 90, 20);
1362 WMMoveWidget(panel->imageT, 190, 25);
1364 panel->imageV = WMCreateScrollView(panel->imageF);
1365 WMResizeWidget(panel->imageV, 165, 115);
1366 WMMoveWidget(panel->imageV, 15, 20);
1367 WMSetScrollViewRelief(panel->imageV, WRSunken);
1368 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1369 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1370 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1372 panel->browB = WMCreateCommandButton(panel->imageF);
1373 WMResizeWidget(panel->browB, 90, 24);
1374 WMMoveWidget(panel->browB, 190, 50);
1375 WMSetButtonText(panel->browB, _("Browse..."));
1376 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1378 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1379 WMResizeWidget(panel->dispB, 90, 24);
1380 WMMoveWidget(panel->dispB, 190, 80);
1381 WMSetButtonText(panel->dispB, _("Show"));
1384 panel->arrP = WMCreatePopUpButton(panel->imageF);
1385 WMResizeWidget(panel->arrP, 90, 20);
1386 WMMoveWidget(panel->arrP, 190, 120);
1387 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1388 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1389 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1390 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1391 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1393 WMMapSubwidgets(panel->imageF);
1395 /****/
1397 panel->okB = WMCreateCommandButton(panel->win);
1398 WMResizeWidget(panel->okB, 84, 24);
1399 WMMoveWidget(panel->okB, 225, 390);
1400 WMSetButtonText(panel->okB, _("OK"));
1401 WMSetButtonAction(panel->okB, buttonCallback, panel);
1403 panel->cancelB = WMCreateCommandButton(panel->win);
1404 WMResizeWidget(panel->cancelB, 84, 24);
1405 WMMoveWidget(panel->cancelB, 130, 390);
1406 WMSetButtonText(panel->cancelB, _("Cancel"));
1407 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1409 WMMapWidget(panel->nameF);
1410 WMMapWidget(panel->typeP);
1411 WMMapWidget(panel->okB);
1412 WMMapWidget(panel->cancelB);
1414 WMUnmapWidget(panel->arrP);
1416 WMRealizeWidget(panel->win);
1418 panel->currentType = -1;
1420 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1422 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1423 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1424 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1426 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1427 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1429 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1430 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1431 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1432 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1433 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1435 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1436 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1437 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1439 /* setup for first time */
1441 changeTypeCallback(panel->typeP, panel);
1443 sliderChangeCallback(panel->ghueS, panel);
1444 sliderChangeCallback(panel->gsatS, panel);
1446 return panel;
1450 *--------------------------------------------------------------------------
1451 * Test stuff
1452 *--------------------------------------------------------------------------
1455 #if 0
1457 char *ProgName = "test";
1459 void testOKButton(WMWidget * self, void *data)
1461 char *test;
1462 Display *dpy;
1463 Window win;
1464 Pixmap pix;
1465 RImage *image;
1467 TexturePanel *panel = (TexturePanel *) data;
1468 /* test = GetTexturePanelTextureString(panel); */
1470 wwarning(test);
1472 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1473 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250, 0, 0, 0);
1474 XMapRaised(dpy, win);
1475 XFlush(dpy);
1477 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1479 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1481 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width,
1482 image->height, 0, 0);
1484 wfree(test);
1488 void testCancelButton(WMWidget * self, void *data)
1490 wwarning("Exiting test....");
1491 exit(0);
1494 void wAbort()
1496 exit(1);
1499 int main(int argc, char **argv)
1501 TexturePanel *panel;
1503 Display *dpy = XOpenDisplay("");
1504 WMScreen *scr;
1506 /* char *test; */
1508 WMInitializeApplication("Test", &argc, argv);
1510 if (!dpy) {
1511 wfatal("could not open display");
1512 exit(1);
1515 scr = WMCreateSimpleApplicationScreen(dpy);
1517 panel = CreateTexturePanel(scr);
1519 SetTexturePanelOkAction(panel, (WMAction *) testOKButton, panel);
1520 SetTexturePanelCancelAction(panel, (WMAction *) testCancelButton, panel);
1522 SetTexturePanelTexture(panel, "pinky",
1523 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1525 ShowTexturePanel(panel);
1527 WMScreenMainLoop(scr);
1528 return 0;
1530 #endif