Update Serbian translation from master branch
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobf5863a3bafd466d2c5bffdcfef87bde5b0c3d3f8
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 enum {
121 TYPE_SOLID,
122 TYPE_GRADIENT,
123 TYPE_SGRADIENT,
124 TYPE_TGRADIENT,
125 TYPE_PIXMAP
128 enum {
129 PTYPE_TILE,
130 PTYPE_SCALE,
131 PTYPE_CENTER,
132 PTYPE_MAXIMIZE,
133 PTYPE_FILL
137 *--------------------------------------------------------------------------
138 * Private Functions
139 *--------------------------------------------------------------------------
142 /************/
144 static void updateGradButtons(TexturePanel *panel)
146 RImage *image;
147 WMPixmap *pixmap;
148 int colorn;
149 RColor **colors;
151 colorn = WMGetListNumberOfRows(panel->gcolL);
152 if (colorn < 1) {
153 pixmap = NULL;
154 } else {
155 int i;
156 WMListItem *item;
158 colors = wmalloc(sizeof(RColor *) * (colorn + 1));
160 for (i = 0; i < colorn; i++) {
161 item = WMGetListItem(panel->gcolL, i);
162 colors[i] = (RColor *) item->clientData;
164 colors[i] = NULL;
166 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
167 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
168 RReleaseImage(image);
169 WMSetButtonImage(panel->dirhB, pixmap);
170 WMReleasePixmap(pixmap);
172 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
173 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
174 RReleaseImage(image);
175 WMSetButtonImage(panel->dirvB, pixmap);
176 WMReleasePixmap(pixmap);
178 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
179 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
180 RReleaseImage(image);
181 WMSetButtonImage(panel->dirdB, pixmap);
182 WMReleasePixmap(pixmap);
184 wfree(colors);
188 static void updateTGradImage(TexturePanel *panel)
190 RImage *image, *gradient;
191 WMPixmap *pixmap;
192 RColor from;
193 RColor to;
194 WMColor *color;
196 if (!panel->image)
197 return;
199 color = WMGetColorWellColor(panel->tcol1W);
200 from.red = WMRedComponentOfColor(color) >> 8;
201 from.green = WMGreenComponentOfColor(color) >> 8;
202 from.blue = WMBlueComponentOfColor(color) >> 8;
204 color = WMGetColorWellColor(panel->tcol2W);
205 to.red = WMRedComponentOfColor(color) >> 8;
206 to.green = WMGreenComponentOfColor(color) >> 8;
207 to.blue = WMBlueComponentOfColor(color) >> 8;
209 if (panel->image->width < 141 || panel->image->height < 91)
210 image = RMakeTiledImage(panel->image, 141, 91);
211 else
212 image = RCloneImage(panel->image);
214 if (WMGetButtonSelected(panel->dirhB))
215 gradient = RRenderGradient(image->width, image->height, &from, &to, RHorizontalGradient);
216 else if (WMGetButtonSelected(panel->dirvB))
217 gradient = RRenderGradient(image->width, image->height, &from, &to, RVerticalGradient);
218 else
219 gradient = RRenderGradient(image->width, image->height, &from, &to, RDiagonalGradient);
221 RCombineImagesWithOpaqueness(image, gradient, WMGetSliderValue(panel->topaS));
222 RReleaseImage(gradient);
223 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win), image, 128);
225 WMSetLabelImage(panel->imageL, pixmap);
226 WMReleasePixmap(pixmap);
227 WMResizeWidget(panel->imageL, image->width, image->height);
228 RReleaseImage(image);
231 static void updateSGradButtons(TexturePanel *panel)
233 RImage *image;
234 WMPixmap *pixmap;
235 RColor from;
236 RColor to;
237 WMColor *color;
239 color = WMGetColorWellColor(panel->tcol1W);
240 from.red = WMRedComponentOfColor(color) >> 8;
241 from.green = WMGreenComponentOfColor(color) >> 8;
242 from.blue = WMBlueComponentOfColor(color) >> 8;
244 color = WMGetColorWellColor(panel->tcol2W);
245 to.red = WMRedComponentOfColor(color) >> 8;
246 to.green = WMGreenComponentOfColor(color) >> 8;
247 to.blue = WMBlueComponentOfColor(color) >> 8;
249 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
250 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
251 RReleaseImage(image);
252 WMSetButtonImage(panel->dirhB, pixmap);
253 WMReleasePixmap(pixmap);
255 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
256 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
257 RReleaseImage(image);
258 WMSetButtonImage(panel->dirvB, pixmap);
259 WMReleasePixmap(pixmap);
261 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
262 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
263 RReleaseImage(image);
264 WMSetButtonImage(panel->dirdB, pixmap);
265 WMReleasePixmap(pixmap);
268 /*********** Gradient ************/
270 static void updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
272 RImage *image;
273 WMPixmap *pixmap;
274 WMScreen *scr = WMWidgetScreen(sPtr);
275 RColor from, to;
276 RHSVColor tmp;
277 char *buffer;
279 tmp = *hsv;
280 if (saturation) {
281 tmp.saturation = 0;
282 RHSVtoRGB(&tmp, &from);
283 tmp.saturation = 255;
284 RHSVtoRGB(&tmp, &to);
285 } else {
286 tmp.value = 0;
287 RHSVtoRGB(&tmp, &from);
288 tmp.value = 255;
289 RHSVtoRGB(&tmp, &to);
291 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
292 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
293 RReleaseImage(image);
295 if (saturation)
296 buffer = wstrdup(_("Saturation"));
297 else
298 buffer = wstrdup(_("Brightness"));
300 if (hsv->value < 128 || !saturation) {
301 WMColor *col = WMWhiteColor(scr);
303 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
304 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
305 WMReleaseColor(col);
306 } else {
307 WMColor *col = WMBlackColor(scr);
309 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
310 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
311 WMReleaseColor(col);
313 wfree(buffer);
314 WMSetSliderImage(sPtr, pixmap);
315 WMReleasePixmap(pixmap);
318 static void updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
320 RColor *colors[8];
321 RImage *image;
322 WMPixmap *pixmap;
323 WMScreen *scr = WMWidgetScreen(sPtr);
324 RHSVColor thsv;
325 int i;
327 thsv = *hsv;
328 for (i = 0; i <= 6; i++) {
329 thsv.hue = (360 * i) / 6;
330 colors[i] = wmalloc(sizeof(RColor));
331 RHSVtoRGB(&thsv, colors[i]);
333 colors[i] = NULL;
335 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
336 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
337 RReleaseImage(image);
339 if (hsv->value < 128) {
340 WMColor *col = WMWhiteColor(scr);
342 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
343 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
344 WMReleaseColor(col);
345 } else {
346 WMColor *col = WMBlackColor(scr);
348 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
349 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
350 WMReleaseColor(col);
352 WMSetSliderImage(sPtr, pixmap);
353 WMReleasePixmap(pixmap);
355 for (i = 0; i <= 6; i++)
356 wfree(colors[i]);
359 static void sliderChangeCallback(WMWidget *w, void *data)
361 TexturePanel *panel = (TexturePanel *) data;
362 RHSVColor hsv;
363 int i, row, rows;
364 WMListItem *item;
365 RColor **colors;
366 RImage *image;
367 WMScreen *scr = WMWidgetScreen(w);
369 hsv.hue = WMGetSliderValue(panel->ghueS);
370 hsv.saturation = WMGetSliderValue(panel->gsatS);
371 hsv.value = WMGetSliderValue(panel->gvalS);
373 rows = WMGetListNumberOfRows(panel->gcolL);
374 row = WMGetListSelectedItemRow(panel->gcolL);
376 if (row < 0 && rows > 0) {
377 row = 0;
378 WMSelectListItem(panel->gcolL, row);
379 item = WMGetListItem(panel->gcolL, row);
380 RRGBtoHSV((RColor *) item->clientData, &hsv);
382 WMSetSliderValue(panel->ghueS, hsv.hue);
383 WMSetSliderValue(panel->gsatS, hsv.saturation);
384 WMSetSliderValue(panel->gvalS, hsv.value);
387 if (row >= 0) {
388 RColor *rgb;
390 item = WMGetListItem(panel->gcolL, row);
392 rgb = (RColor *) item->clientData;
394 RHSVtoRGB(&hsv, rgb);
396 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
399 if (w == panel->ghueS) {
400 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
401 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
402 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
403 } else if (w == panel->gsatS) {
404 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
405 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
406 } else {
407 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
408 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
411 if (rows == 0)
412 return;
414 colors = wmalloc(sizeof(RColor *) * (rows + 1));
416 for (i = 0; i < rows; i++) {
417 item = WMGetListItem(panel->gcolL, i);
419 colors[i] = (RColor *) item->clientData;
421 colors[i] = NULL;
423 if (panel->gimage != None)
424 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
426 image = RRenderMultiGradient(30, i * WMGetListItemHeight(panel->gcolL), colors, RVerticalGradient);
427 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
428 RReleaseImage(image);
430 wfree(colors);
432 WMRedisplayWidget(panel->gcolL);
434 updateGradButtons(panel);
437 static void paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect)
439 TexturePanel *panel = (TexturePanel *) WMGetHangedData(lPtr);
440 WMScreen *scr = WMWidgetScreen(lPtr);
441 WMColor *white = WMWhiteColor(scr);
442 WMColor *black = WMBlackColor(scr);
443 WMColor *gray = WMGrayColor(scr);
444 int width, height, x, y;
445 Display *dpy;
447 dpy = WMScreenDisplay(scr);
449 width = rect->size.width;
450 height = rect->size.height;
451 x = rect->pos.x;
452 y = rect->pos.y;
454 if (state & WLDSSelected)
455 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
456 else
457 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
459 if (panel->gimage) {
460 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
461 0, height * index, 30, height, x + 5, y);
463 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
465 WMReleaseColor(white);
466 WMReleaseColor(black);
467 WMReleaseColor(gray);
470 static void gradAddCallback(WMWidget *w, void *data)
472 TexturePanel *panel = (TexturePanel *) data;
473 WMListItem *item;
474 int row;
475 RColor *rgb;
477 /* Parameter not used, but tell the compiler that it is ok */
478 (void) w;
480 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
481 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
482 rgb = wmalloc(sizeof(RColor));
483 item->clientData = rgb;
485 WMSelectListItem(panel->gcolL, row);
487 updateGradButtons(panel);
489 sliderChangeCallback(panel->ghueS, panel);
491 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
494 static void gradClickCallback(WMWidget *w, void *data)
496 TexturePanel *panel = (TexturePanel *) data;
497 WMListItem *item;
498 int row;
499 RHSVColor hsv;
501 row = WMGetListSelectedItemRow(w);
502 if (row < 0)
503 return;
505 item = WMGetListItem(panel->gcolL, row);
506 RRGBtoHSV((RColor *) item->clientData, &hsv);
508 WMSetSliderValue(panel->ghueS, hsv.hue);
509 WMSetSliderValue(panel->gsatS, hsv.saturation);
510 WMSetSliderValue(panel->gvalS, hsv.value);
512 sliderChangeCallback(panel->ghueS, panel);
513 sliderChangeCallback(panel->gsatS, panel);
516 static void gradDeleteCallback(WMWidget *w, void *data)
518 TexturePanel *panel = (TexturePanel *) data;
519 WMListItem *item;
520 int row, rows;
522 /* Parameter not used, but tell the compiler that it is ok */
523 (void) w;
525 row = WMGetListSelectedItemRow(panel->gcolL);
526 if (row < 0)
527 return;
529 item = WMGetListItem(panel->gcolL, row);
530 wfree(item->clientData);
532 WMRemoveListItem(panel->gcolL, row);
533 if (row > 0)
534 WMSelectListItem(panel->gcolL, row - 1);
535 else {
536 rows = WMGetListNumberOfRows(panel->gcolL);
537 if (rows > 0)
538 WMSelectListItem(panel->gcolL, 0);
541 updateGradButtons(panel);
543 gradClickCallback(panel->gcolL, panel);
545 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
548 /*************** Simple Gradient ***************/
550 static void colorWellObserver(void *self, WMNotification *n)
552 /* Parameter not used, but tell the compiler that it is ok */
553 (void) n;
555 updateSGradButtons(self);
558 static void opaqChangeCallback(WMWidget *w, void *data)
560 TexturePanel *panel = (TexturePanel *) data;
562 /* Parameter not used, but tell the compiler that it is ok */
563 (void) w;
565 updateTGradImage(panel);
568 /****************** Image ******************/
570 static void updateImage(TexturePanel *panel, const char *path)
572 WMScreen *scr = WMWidgetScreen(panel->win);
573 RImage *image;
574 WMPixmap *pixmap;
575 WMSize size;
577 if (path) {
578 image = RLoadImage(WMScreenRContext(scr), path, 0);
579 if (!image) {
580 char *message;
582 message = wstrconcat(_("Could not load the selected file: "),
583 (char *)RMessageForError(RErrorCode));
585 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
587 if (!panel->image)
588 WMSetButtonEnabled(panel->okB, False);
590 wfree(message);
591 return;
594 WMSetButtonEnabled(panel->okB, True);
596 if (panel->image)
597 RReleaseImage(panel->image);
598 panel->image = image;
599 } else {
600 image = panel->image;
603 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
604 if (image) {
605 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
607 size = WMGetPixmapSize(pixmap);
608 WMSetLabelImage(panel->imageL, pixmap);
609 WMResizeWidget(panel->imageL, size.width, size.height);
611 WMReleasePixmap(pixmap);
613 } else {
614 updateTGradImage(panel);
618 static void browseImageCallback(WMWidget *w, void *data)
620 TexturePanel *panel = (TexturePanel *) data;
621 WMOpenPanel *opanel;
622 WMScreen *scr = WMWidgetScreen(w);
623 static char *ipath;
625 opanel = WMGetOpenPanel(scr);
626 WMSetFilePanelCanChooseDirectories(opanel, False);
627 WMSetFilePanelCanChooseFiles(opanel, True);
629 if (!ipath)
630 ipath = wstrdup(wgethomedir());
632 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
633 char *path, *fullpath;
634 char *tmp, *tmp2;
636 tmp = WMGetFilePanelFileName(opanel);
637 if (!tmp)
638 return;
639 fullpath = tmp;
641 wfree(ipath);
642 ipath = fullpath;
644 path = wstrdup(fullpath);
646 tmp2 = strrchr(fullpath, '/');
647 if (tmp2)
648 tmp2++;
650 tmp = wfindfileinarray(panel->pathList, tmp2);
652 if (tmp) {
653 if (strcmp(fullpath, tmp) == 0) {
654 wfree(path);
655 path = tmp2;
657 wfree(tmp);
660 if (!RGetImageFileFormat(fullpath)) {
661 WMRunAlertPanel(scr, panel->win, _("Error"),
662 _("The selected file does not contain a supported image."),
663 _("OK"), NULL, NULL);
664 wfree(path);
665 } else {
666 updateImage(panel, fullpath);
667 wfree(panel->imageFile);
668 panel->imageFile = path;
670 WMSetTextFieldText(panel->imageT, path);
675 static void buttonCallback(WMWidget *w, void *data)
677 TexturePanel *panel = (TexturePanel *) data;
679 if (w == panel->okB)
680 (*panel->okAction) (panel->okData);
681 else
682 (*panel->cancelAction) (panel->cancelData);
685 static void changeTypeCallback(WMWidget *w, void *data)
687 TexturePanel *panel = (TexturePanel *) data;
688 int newType;
689 int i;
691 newType = WMGetPopUpButtonSelectedItem(w);
692 if (newType < 0 || newType == panel->currentType)
693 return;
695 if (panel->currentType >= 0) {
696 for (i = 0; i < MAX_SECTION_PARTS; i++) {
697 if (panel->sectionParts[panel->currentType][i] == NULL)
698 break;
699 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
703 for (i = 0; i < MAX_SECTION_PARTS; i++) {
704 if (panel->sectionParts[newType][i] == NULL)
705 break;
706 WMMapWidget(panel->sectionParts[newType][i]);
708 panel->currentType = newType;
710 switch (newType) {
711 case TYPE_SGRADIENT:
712 updateSGradButtons(panel);
713 WMSetButtonEnabled(panel->okB, True);
714 break;
715 case TYPE_GRADIENT:
716 updateGradButtons(panel);
717 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
718 break;
719 case TYPE_TGRADIENT:
720 case TYPE_PIXMAP:
721 updateImage(panel, NULL);
722 WMSetButtonEnabled(panel->okB, panel->image != NULL);
723 break;
724 default:
725 WMSetButtonEnabled(panel->okB, True);
726 break;
731 *--------------------------------------------------------------------------
732 * Public functions
733 *--------------------------------------------------------------------------
735 void ShowTexturePanel(TexturePanel *panel)
737 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
738 Screen *scr = DefaultScreenOfDisplay(dpy);
740 WMSetWindowInitialPosition(panel->win,
741 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
742 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
743 WMMapWidget(panel->win);
746 void HideTexturePanel(TexturePanel *panel)
748 WMUnmapWidget(panel->win);
751 void SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
753 panel->okAction = action;
754 panel->okData = clientData;
757 void SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
759 panel->cancelAction = action;
760 panel->cancelData = clientData;
763 void SetTexturePanelTexture(TexturePanel *panel, const char *name, WMPropList *texture)
765 WMScreen *scr = WMWidgetScreen(panel->win);
766 char *str, *type;
767 WMPropList *p;
768 WMColor *color;
769 int i;
770 char buffer[64];
771 int gradient = 0;
773 WMSetTextFieldText(panel->nameT, name);
775 if (!texture)
776 return;
778 p = WMGetFromPLArray(texture, 0);
779 if (!p)
780 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);
793 color = WMCreateNamedColor(scr, str, False);
795 WMSetColorWellColor(panel->defcW, color);
797 WMReleaseColor(color);
798 /*............................................... */
799 } else if (strcasecmp(type, "hgradient") == 0
800 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
802 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
804 p = WMGetFromPLArray(texture, 1);
805 if (!p)
806 str = "black";
807 else
808 str = WMGetFromPLString(p);
809 color = WMCreateNamedColor(scr, str, False);
811 WMSetColorWellColor(panel->tcol1W, color);
813 WMReleaseColor(color);
815 p = WMGetFromPLArray(texture, 2);
816 if (!p)
817 str = "black";
818 else
819 str = WMGetFromPLString(p);
820 color = WMCreateNamedColor(scr, str, False);
822 WMSetColorWellColor(panel->tcol2W, color);
824 WMReleaseColor(color);
826 gradient = type[0];
827 /*............................................... */
828 } else if (strcasecmp(type, "thgradient") == 0
829 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
830 int i;
832 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
834 gradient = type[1];
836 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
837 if (panel->imageFile)
838 wfree(panel->imageFile);
839 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
841 if (sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i) != 1)
842 i = 180;
843 WMSetSliderValue(panel->topaS, i);
845 p = WMGetFromPLArray(texture, 3);
846 if (!p)
847 str = "black";
848 else
849 str = WMGetFromPLString(p);
850 color = WMCreateNamedColor(scr, str, False);
852 WMSetColorWellColor(panel->tcol1W, color);
854 WMReleaseColor(color);
856 p = WMGetFromPLArray(texture, 4);
857 if (!p)
858 str = "black";
859 else
860 str = WMGetFromPLString(p);
861 color = WMCreateNamedColor(scr, str, False);
863 WMSetColorWellColor(panel->tcol2W, color);
865 WMReleaseColor(color);
867 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
869 if (panel->imageFile)
870 wfree(panel->imageFile);
871 panel->imageFile = wfindfileinarray(panel->pathList,
872 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
873 if (panel->imageFile != NULL) {
875 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
876 updateTGradImage(panel);
878 updateSGradButtons(panel);
879 } else
880 wwarning(_("could not load file '%s': %s"), panel->imageFile,
881 RMessageForError(RErrorCode));
883 /*............................................... */
884 } else if (strcasecmp(type, "mhgradient") == 0
885 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
886 WMListItem *item;
888 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
889 item = WMGetListItem(panel->gcolL, i);
890 wfree(item->clientData);
892 WMClearList(panel->gcolL);
894 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
896 p = WMGetFromPLArray(texture, 1);
897 if (!p)
898 str = "black";
899 else
900 str = WMGetFromPLString(p);
901 color = WMCreateNamedColor(scr, str, False);
903 WMSetColorWellColor(panel->defcW, color);
905 WMReleaseColor(color);
907 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
908 RColor *rgb;
909 XColor xcolor;
911 p = WMGetFromPLArray(texture, i);
912 if (!p)
913 str = "black";
914 else
915 str = WMGetFromPLString(p);
917 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
919 rgb = wmalloc(sizeof(RColor));
920 rgb->red = xcolor.red >> 8;
921 rgb->green = xcolor.green >> 8;
922 rgb->blue = xcolor.blue >> 8;
923 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
925 item = WMAddListItem(panel->gcolL, buffer);
926 item->clientData = rgb;
929 sliderChangeCallback(panel->ghueS, panel);
931 gradient = type[1];
932 /*............................................... */
933 } else if (strcasecmp(type, "cpixmap") == 0
934 || strcasecmp(type, "spixmap") == 0
935 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
937 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
939 switch (toupper(type[0])) {
940 case 'C':
941 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
942 break;
943 case 'S':
944 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
945 break;
946 case 'M':
947 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
948 break;
949 case 'F':
950 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_FILL);
951 break;
952 default:
953 case 'T':
954 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
955 break;
958 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
960 if (panel->imageFile)
961 wfree(panel->imageFile);
962 panel->imageFile = wfindfileinarray(panel->pathList,
963 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
965 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
966 WMSetColorWellColor(panel->defcW, color);
967 WMReleaseColor(color);
969 updateImage(panel, panel->imageFile);
972 changeTypeCallback(panel->typeP, panel);
974 if (gradient > 0) {
975 updateGradButtons(panel);
977 switch (toupper(gradient)) {
978 case 'H':
979 WMPerformButtonClick(panel->dirhB);
980 break;
981 case 'V':
982 WMPerformButtonClick(panel->dirvB);
983 break;
984 default:
985 case 'D':
986 WMPerformButtonClick(panel->dirdB);
987 break;
991 return;
993 bad_texture:
994 str = WMGetPropListDescription(texture, False);
995 wwarning(_("error creating texture %s"), str);
996 wfree(str);
1000 char *GetTexturePanelTextureName(TexturePanel *panel)
1002 return WMGetTextFieldText(panel->nameT);
1006 WMPropList *GetTexturePanelTexture(TexturePanel *panel)
1008 WMPropList *prop = NULL;
1009 WMColor *color;
1010 char *str, *str2;
1011 char buff[32];
1012 int i;
1014 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1016 case TYPE_SOLID:
1017 color = WMGetColorWellColor(panel->defcW);
1018 str = WMGetColorRGBDescription(color);
1019 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1020 wfree(str);
1022 break;
1024 case TYPE_PIXMAP:
1025 color = WMGetColorWellColor(panel->defcW);
1026 str = WMGetColorRGBDescription(color);
1028 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1029 case PTYPE_SCALE:
1030 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1031 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1032 break;
1033 case PTYPE_MAXIMIZE:
1034 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1035 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1036 break;
1037 case PTYPE_FILL:
1038 prop = WMCreatePLArray(WMCreatePLString("fpixmap"),
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);
1113 wfree(str);
1115 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1116 RColor *rgb;
1117 WMListItem *item;
1119 item = WMGetListItem(panel->gcolL, i);
1121 rgb = (RColor *) item->clientData;
1123 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1125 WMAddToPLArray(prop, WMCreatePLString(buff));
1127 break;
1130 return prop;
1133 void SetTexturePanelPixmapPath(TexturePanel *panel, WMPropList *array)
1135 panel->pathList = array;
1138 TexturePanel *CreateTexturePanel(WMWindow *keyWindow)
1139 /*CreateTexturePanel(WMScreen *scr)*/
1141 TexturePanel *panel;
1142 WMScreen *scr = WMWidgetScreen(keyWindow);
1144 panel = wmalloc(sizeof(TexturePanel));
1146 panel->listFont = WMSystemFontOfSize(scr, 12);
1148 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1149 WMTitledWindowMask | WMClosableWindowMask);
1151 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1152 WMTitledWindowMask
1153 |WMClosableWindowMask);
1156 WMResizeWidget(panel->win, 325, 423);
1157 WMSetWindowTitle(panel->win, _("Texture Panel"));
1158 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1160 /* texture name */
1161 panel->nameF = WMCreateFrame(panel->win);
1162 WMResizeWidget(panel->nameF, 185, 50);
1163 WMMoveWidget(panel->nameF, 15, 10);
1164 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1166 panel->nameT = WMCreateTextField(panel->nameF);
1167 WMResizeWidget(panel->nameT, 160, 20);
1168 WMMoveWidget(panel->nameT, 12, 18);
1170 WMMapSubwidgets(panel->nameF);
1172 /* texture types */
1173 panel->typeP = WMCreatePopUpButton(panel->win);
1174 WMResizeWidget(panel->typeP, 185, 20);
1175 WMMoveWidget(panel->typeP, 15, 65);
1176 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1177 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1178 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1179 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1180 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1181 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1182 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1184 /* color */
1185 panel->defcF = WMCreateFrame(panel->win);
1186 WMResizeWidget(panel->defcF, 100, 75);
1187 WMMoveWidget(panel->defcF, 210, 10);
1188 WMSetFrameTitle(panel->defcF, _("Default Color"));
1190 panel->defcW = WMCreateColorWell(panel->defcF);
1191 WMResizeWidget(panel->defcW, 60, 45);
1192 WMMoveWidget(panel->defcW, 20, 20);
1194 WMMapSubwidgets(panel->defcF);
1196 /****** Gradient ******/
1197 panel->gcolF = WMCreateFrame(panel->win);
1198 WMResizeWidget(panel->gcolF, 295, 205);
1199 WMMoveWidget(panel->gcolF, 15, 95);
1200 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1202 panel->gcolL = WMCreateList(panel->gcolF);
1203 WMResizeWidget(panel->gcolL, 130, 140);
1204 WMMoveWidget(panel->gcolL, 10, 25);
1205 WMHangData(panel->gcolL, panel);
1206 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1207 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1209 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1210 WMResizeWidget(panel->gcolaB, 64, 24);
1211 WMMoveWidget(panel->gcolaB, 10, 170);
1212 WMSetButtonText(panel->gcolaB, _("Add"));
1213 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1215 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1216 WMResizeWidget(panel->gcoldB, 64, 24);
1217 WMMoveWidget(panel->gcoldB, 75, 170);
1218 WMSetButtonText(panel->gcoldB, _("Delete"));
1219 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1221 #if 0
1222 panel->gbriS = WMCreateSlider(panel->gcolF);
1223 WMResizeWidget(panel->gbriS, 130, 16);
1224 WMMoveWidget(panel->gbriS, 150, 25);
1225 WMSetSliderKnobThickness(panel->gbriS, 8);
1226 WMSetSliderMaxValue(panel->gbriS, 100);
1227 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1229 WMPixmap *pixmap;
1230 WMColor *color;
1232 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1233 color = WMDarkGrayColor(scr);
1234 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1235 WMReleaseColor(color);
1236 color = WMWhiteColor(color);
1237 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1238 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1239 WMSetSliderImage(panel->gbriS, pixmap);
1240 WMReleasePixmap(pixmap);
1243 panel->gconS = WMCreateSlider(panel->gcolF);
1244 WMResizeWidget(panel->gconS, 130, 16);
1245 WMMoveWidget(panel->gconS, 150, 50);
1246 WMSetSliderKnobThickness(panel->gconS, 8);
1247 WMSetSliderMaxValue(panel->gconS, 100);
1248 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1250 WMPixmap *pixmap;
1251 WMColor *color;
1253 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1254 color = WMDarkGrayColor(scr);
1255 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1256 WMReleaseColor(color);
1257 color = WMWhiteColor(scr);
1258 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1259 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1260 WMSetSliderImage(panel->gconS, pixmap);
1261 WMReleasePixmap(pixmap);
1263 #endif
1264 panel->ghueS = WMCreateSlider(panel->gcolF);
1265 WMResizeWidget(panel->ghueS, 130, 16);
1266 WMMoveWidget(panel->ghueS, 150, 100);
1267 WMSetSliderKnobThickness(panel->ghueS, 8);
1268 WMSetSliderMaxValue(panel->ghueS, 359);
1269 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1271 panel->gsatS = WMCreateSlider(panel->gcolF);
1272 WMResizeWidget(panel->gsatS, 130, 16);
1273 WMMoveWidget(panel->gsatS, 150, 125);
1274 WMSetSliderKnobThickness(panel->gsatS, 8);
1275 WMSetSliderMaxValue(panel->gsatS, 255);
1276 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1278 panel->gvalS = WMCreateSlider(panel->gcolF);
1279 WMResizeWidget(panel->gvalS, 130, 16);
1280 WMMoveWidget(panel->gvalS, 150, 150);
1281 WMSetSliderKnobThickness(panel->gvalS, 8);
1282 WMSetSliderMaxValue(panel->gvalS, 255);
1283 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1285 WMMapSubwidgets(panel->gcolF);
1287 /** Direction **/
1288 panel->dirF = WMCreateFrame(panel->win);
1289 WMSetFrameTitle(panel->dirF, _("Direction"));
1290 WMResizeWidget(panel->dirF, 295, 75);
1291 WMMoveWidget(panel->dirF, 15, 305);
1293 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1294 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1295 WMResizeWidget(panel->dirvB, 90, 40);
1296 WMMoveWidget(panel->dirvB, 10, 20);
1298 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1299 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1300 WMResizeWidget(panel->dirhB, 90, 40);
1301 WMMoveWidget(panel->dirhB, 102, 20);
1303 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1304 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1305 WMResizeWidget(panel->dirdB, 90, 40);
1306 WMMoveWidget(panel->dirdB, 194, 20);
1308 WMGroupButtons(panel->dirvB, panel->dirhB);
1309 WMGroupButtons(panel->dirvB, panel->dirdB);
1311 WMMapSubwidgets(panel->dirF);
1313 /****************** Textured Gradient ******************/
1314 panel->tcolF = WMCreateFrame(panel->win);
1315 WMResizeWidget(panel->tcolF, 100, 135);
1316 WMMoveWidget(panel->tcolF, 210, 10);
1317 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1319 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1320 WMResizeWidget(panel->tcol1W, 60, 45);
1321 WMMoveWidget(panel->tcol1W, 20, 25);
1322 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1324 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1325 WMResizeWidget(panel->tcol2W, 60, 45);
1326 WMMoveWidget(panel->tcol2W, 20, 75);
1327 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1329 /** Opacity */
1330 panel->topaF = WMCreateFrame(panel->win);
1331 WMResizeWidget(panel->topaF, 185, 50);
1332 WMMoveWidget(panel->topaF, 15, 95);
1333 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1335 panel->topaS = WMCreateSlider(panel->topaF);
1336 WMResizeWidget(panel->topaS, 155, 18);
1337 WMMoveWidget(panel->topaS, 15, 20);
1338 WMSetSliderMaxValue(panel->topaS, 255);
1339 WMSetSliderValue(panel->topaS, 200);
1340 WMSetSliderContinuous(panel->topaS, False);
1341 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1343 WMMapSubwidgets(panel->topaF);
1346 WMPixmap *pixmap;
1347 Pixmap p;
1348 WMColor *color;
1350 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1351 p = WMGetPixmapXID(pixmap);
1353 color = WMDarkGrayColor(scr);
1354 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1355 WMReleaseColor(color);
1357 color = WMWhiteColor(scr);
1358 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1359 WMDrawString(scr, p, color, panel->listFont,
1360 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1361 WMReleaseColor(color);
1363 WMSetSliderImage(panel->topaS, pixmap);
1364 WMReleasePixmap(pixmap);
1367 WMMapSubwidgets(panel->tcolF);
1369 /****************** Image ******************/
1370 panel->imageF = WMCreateFrame(panel->win);
1371 WMResizeWidget(panel->imageF, 295, 150);
1372 WMMoveWidget(panel->imageF, 15, 150);
1373 WMSetFrameTitle(panel->imageF, _("Image"));
1375 panel->imageL = WMCreateLabel(panel->imageF);
1376 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1378 panel->imageT = WMCreateTextField(panel->imageF);
1379 WMResizeWidget(panel->imageT, 90, 20);
1380 WMMoveWidget(panel->imageT, 190, 25);
1382 panel->imageV = WMCreateScrollView(panel->imageF);
1383 WMResizeWidget(panel->imageV, 165, 115);
1384 WMMoveWidget(panel->imageV, 15, 20);
1385 WMSetScrollViewRelief(panel->imageV, WRSunken);
1386 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1387 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1388 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1390 panel->browB = WMCreateCommandButton(panel->imageF);
1391 WMResizeWidget(panel->browB, 90, 24);
1392 WMMoveWidget(panel->browB, 190, 50);
1393 WMSetButtonText(panel->browB, _("Browse..."));
1394 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1396 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1397 WMResizeWidget(panel->dispB, 90, 24);
1398 WMMoveWidget(panel->dispB, 190, 80);
1399 WMSetButtonText(panel->dispB, _("Show"));
1402 panel->arrP = WMCreatePopUpButton(panel->imageF);
1403 WMResizeWidget(panel->arrP, 90, 20);
1404 WMMoveWidget(panel->arrP, 190, 120);
1405 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1406 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1407 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1408 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1409 WMAddPopUpButtonItem(panel->arrP, _("Fill"));
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(void)
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