For libwraster:
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobb5793955091157e5afc52e690474b9c152cb99c1
1 /* TexturePanel.c- texture editting panel
2 *
3 * WPrefs - WindowMaker Preferences Program
4 *
5 * Copyright (c) 1998, 1999 Alfredo K. Kojima
6 * Copyright (c) 1998 James Thompson
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <ctype.h>
31 #include <X11/Xlib.h>
34 #include <WINGs/WINGs.h>
36 #include "WPrefs.h"
38 #include "TexturePanel.h"
40 #define MAX_SECTION_PARTS 5
42 typedef struct _TexturePanel {
43 WMWindow *win;
45 /* texture name */
46 WMFrame *nameF;
47 WMTextField *nameT;
49 /* texture type */
50 WMPopUpButton *typeP;
52 /* default color */
53 WMFrame *defcF;
54 WMColorWell *defcW;
56 WMFont *listFont;
58 /*-- Gradient --*/
60 Pixmap gimage;
62 /* colors */
63 WMFrame *gcolF;
64 WMList *gcolL;
65 WMButton *gcolaB;
66 WMButton *gcoldB;
67 WMSlider *ghueS;
68 WMSlider *gsatS;
69 WMSlider *gvalS;
71 WMSlider *gbriS;
72 WMSlider *gconS;
74 /* direction (common) */
75 WMFrame *dirF;
76 WMButton *dirhB;
77 WMButton *dirvB;
78 WMButton *dirdB;
80 /*-- Simple Gradient --*/
83 /*-- Textured Gradient --*/
85 WMFrame *tcolF;
86 WMColorWell *tcol1W;
87 WMColorWell *tcol2W;
89 WMFrame *topaF;
90 WMSlider *topaS;
92 /*-- Image --*/
93 WMFrame *imageF;
94 WMScrollView *imageV;
95 WMTextField *imageT;
96 WMLabel *imageL;
97 WMButton *browB;
98 WMButton *dispB;
99 WMPopUpButton *arrP;
101 RImage *image;
102 char *imageFile;
104 /*****/
106 WMButton *okB;
107 WMButton *cancelB;
110 WMCallback *okAction;
111 void *okData;
113 WMCallback *cancelAction;
114 void *cancelData;
116 /****/
117 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
119 int currentType;
122 proplist_t pathList;
124 } _TexturePanel;
128 #define TYPE_SOLID 0
129 #define TYPE_GRADIENT 1
130 #define TYPE_SGRADIENT 2
131 #define TYPE_TGRADIENT 3
132 #define TYPE_PIXMAP 4
135 #define PTYPE_TILE 0
136 #define PTYPE_SCALE 1
137 #define PTYPE_CENTER 2
138 #define PTYPE_MAXIMIZE 3
143 *--------------------------------------------------------------------------
144 * Private Functions
145 *--------------------------------------------------------------------------
148 /************/
150 static void
151 updateGradButtons(TexturePanel *panel)
153 RImage *image;
154 WMPixmap *pixmap;
155 int colorn;
156 RColor **colors;
158 colorn = WMGetListNumberOfRows(panel->gcolL);
159 if (colorn < 1) {
160 pixmap = NULL;
161 } else {
162 int i;
163 WMListItem *item;
165 colors = wmalloc(sizeof(RColor*)*(colorn+1));
167 for (i = 0; i < colorn; i++) {
168 item = WMGetListItem(panel->gcolL, i);
169 colors[i] = (RColor*)item->clientData;
171 colors[i] = NULL;
173 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
174 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
175 image, 128);
176 RReleaseImage(image);
177 WMSetButtonImage(panel->dirhB, pixmap);
178 WMReleasePixmap(pixmap);
180 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
181 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
182 image, 128);
183 RReleaseImage(image);
184 WMSetButtonImage(panel->dirvB, pixmap);
185 WMReleasePixmap(pixmap);
187 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
188 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
189 image, 128);
190 RReleaseImage(image);
191 WMSetButtonImage(panel->dirdB, pixmap);
192 WMReleasePixmap(pixmap);
194 wfree(colors);
200 static void
201 updateTGradImage(TexturePanel *panel)
203 RImage *image, *gradient;
204 WMPixmap *pixmap;
205 RColor from;
206 RColor to;
207 WMColor *color;
209 if (!panel->image)
210 return;
212 color = WMGetColorWellColor(panel->tcol1W);
213 from.red = WMRedComponentOfColor(color)>>8;
214 from.green = WMGreenComponentOfColor(color)>>8;
215 from.blue = WMBlueComponentOfColor(color)>>8;
217 color = WMGetColorWellColor(panel->tcol2W);
218 to.red = WMRedComponentOfColor(color)>>8;
219 to.green = WMGreenComponentOfColor(color)>>8;
220 to.blue = WMBlueComponentOfColor(color)>>8;
222 if (panel->image->width < 141 || panel->image->height < 91) {
223 image = RMakeTiledImage(panel->image, 141, 91);
224 } else {
225 image = RCloneImage(panel->image);
228 if (WMGetButtonSelected(panel->dirhB)) {
229 gradient = RRenderGradient(image->width, image->height, &from, &to,
230 RHorizontalGradient);
231 } else if (WMGetButtonSelected(panel->dirvB)) {
232 gradient = RRenderGradient(image->width, image->height, &from, &to,
233 RVerticalGradient);
234 } else {
235 gradient = RRenderGradient(image->width, image->height, &from, &to,
236 RDiagonalGradient);
239 RCombineImagesWithOpaqueness(image, gradient,
240 WMGetSliderValue(panel->topaS));
241 RReleaseImage(gradient);
242 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
243 image, 128);
245 WMSetLabelImage(panel->imageL, pixmap);
246 WMReleasePixmap(pixmap);
247 WMResizeWidget(panel->imageL, image->width, image->height);
248 RReleaseImage(image);
252 static void
253 updateSGradButtons(TexturePanel *panel)
255 RImage *image;
256 WMPixmap *pixmap;
257 RColor from;
258 RColor to;
259 WMColor *color;
261 color = WMGetColorWellColor(panel->tcol1W);
262 from.red = WMRedComponentOfColor(color)>>8;
263 from.green = WMGreenComponentOfColor(color)>>8;
264 from.blue = WMBlueComponentOfColor(color)>>8;
266 color = WMGetColorWellColor(panel->tcol2W);
267 to.red = WMRedComponentOfColor(color)>>8;
268 to.green = WMGreenComponentOfColor(color)>>8;
269 to.blue = WMBlueComponentOfColor(color)>>8;
271 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
272 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
273 image, 128);
274 RReleaseImage(image);
275 WMSetButtonImage(panel->dirhB, pixmap);
276 WMReleasePixmap(pixmap);
278 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
279 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
280 image, 128);
281 RReleaseImage(image);
282 WMSetButtonImage(panel->dirvB, pixmap);
283 WMReleasePixmap(pixmap);
285 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
286 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
287 image, 128);
288 RReleaseImage(image);
289 WMSetButtonImage(panel->dirdB, pixmap);
290 WMReleasePixmap(pixmap);
294 /*********** Gradient ************/
296 static void
297 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
299 RImage *image;
300 WMPixmap *pixmap;
301 WMScreen *scr = WMWidgetScreen(sPtr);
302 RColor from, to;
303 RHSVColor tmp;
305 tmp = *hsv;
306 if (saturation) {
307 tmp.saturation = 0;
308 RHSVtoRGB(&tmp, &from);
309 tmp.saturation = 255;
310 RHSVtoRGB(&tmp, &to);
311 } else {
312 tmp.value = 0;
313 RHSVtoRGB(&tmp, &from);
314 tmp.value = 255;
315 RHSVtoRGB(&tmp, &to);
317 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
318 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
319 RReleaseImage(image);
321 if (hsv->value < 128 || !saturation) {
322 WMColor *col = WMWhiteColor(scr);
324 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
325 (16 - WMFontHeight(font))/2 - 1,
326 saturation ? "Saturation" : "Brightness", 10);
327 WMReleaseColor(col);
328 } else {
329 WMColor *col = WMBlackColor(scr);
331 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
332 (16 - WMFontHeight(font))/2 - 1,
333 saturation ? "Saturation" : "Brightness", 10);
334 WMReleaseColor(col);
336 WMSetSliderImage(sPtr, pixmap);
337 WMReleasePixmap(pixmap);
341 static void
342 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
344 RColor *colors[8];
345 RImage *image;
346 WMPixmap *pixmap;
347 WMScreen *scr = WMWidgetScreen(sPtr);
348 RHSVColor thsv;
349 int i;
351 thsv = *hsv;
352 for (i = 0; i <= 6; i++) {
353 thsv.hue = (360*i)/6;
354 colors[i] = wmalloc(sizeof(RColor));
355 RHSVtoRGB(&thsv, colors[i]);
357 colors[i] = NULL;
359 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
360 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
361 RReleaseImage(image);
363 if (hsv->value < 128) {
364 WMColor *col = WMWhiteColor(scr);
366 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
367 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
368 WMReleaseColor(col);
369 } else {
370 WMColor *col = WMBlackColor(scr);
372 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
373 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
374 WMReleaseColor(col);
376 WMSetSliderImage(sPtr, pixmap);
377 WMReleasePixmap(pixmap);
379 for (i = 0; i <= 6; i++)
380 wfree(colors[i]);
385 static void
386 sliderChangeCallback(WMWidget *w, void *data)
388 TexturePanel *panel = (TexturePanel*)data;
389 RHSVColor hsv;
390 int row, rows;
391 WMListItem *item;
392 RColor **colors;
393 int i;
394 RImage *image;
395 WMScreen *scr = WMWidgetScreen(w);
397 hsv.hue = WMGetSliderValue(panel->ghueS);
398 hsv.saturation = WMGetSliderValue(panel->gsatS);
399 hsv.value = WMGetSliderValue(panel->gvalS);
401 row = WMGetListSelectedItemRow(panel->gcolL);
402 if (row >= 0) {
403 RColor *rgb;
405 item = WMGetListItem(panel->gcolL, row);
407 rgb = (RColor*)item->clientData;
409 RHSVtoRGB(&hsv, rgb);
411 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
414 if (w == panel->ghueS) {
415 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
416 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
417 } else if (w == panel->gsatS) {
418 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
419 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
420 } else {
421 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
422 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
425 rows = WMGetListNumberOfRows(panel->gcolL);
426 if (rows == 0)
427 return;
429 colors = wmalloc(sizeof(RColor*)*(rows+1));
431 for (i = 0; i < rows; i++) {
432 item = WMGetListItem(panel->gcolL, i);
434 colors[i] = (RColor*)item->clientData;
436 colors[i] = NULL;
438 if (panel->gimage != None) {
439 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
442 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
443 colors, RVerticalGradient);
444 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
445 RReleaseImage(image);
447 wfree(colors);
449 WMRedisplayWidget(panel->gcolL);
451 updateGradButtons(panel);
455 static void
456 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
457 WMRect *rect)
459 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
460 WMScreen *scr = WMWidgetScreen(lPtr);
461 int width, height, x, y;
462 Display *dpy;
463 WMColor *white = WMWhiteColor(scr);
464 WMListItem *item;
465 WMColor *black = WMBlackColor(scr);
467 dpy = WMScreenDisplay(scr);
469 width = rect->size.width;
470 height = rect->size.height;
471 x = rect->pos.x;
472 y = rect->pos.y;
474 if (state & WLDSSelected)
475 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
476 else
477 XClearArea(dpy, d, x, y, width, height, False);
479 item = WMGetListItem(lPtr, index);
481 if (panel->gimage) {
482 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
483 0, height*index, 30, height, x + 5, y);
485 WMDrawString(scr, d, WMColorGC(black), panel->listFont,
486 x + 40, y + 1, text, strlen(text));
488 WMReleaseColor(white);
489 WMReleaseColor(black);
494 static void
495 gradAddCallback(WMWidget *w, void *data)
497 TexturePanel *panel = (TexturePanel*)data;
498 WMListItem *item;
499 int row;
500 RColor *rgb;
502 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
503 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
504 rgb = wmalloc(sizeof(RColor));
505 memset(rgb, 0, sizeof(RColor));
506 item->clientData = rgb;
508 WMSelectListItem(panel->gcolL, row);
510 updateGradButtons(panel);
512 sliderChangeCallback(panel->ghueS, panel);
514 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
519 static void
520 gradClickCallback(WMWidget *w, void *data)
522 TexturePanel *panel = (TexturePanel*)data;
523 WMListItem *item;
524 int row;
525 RHSVColor hsv;
527 row = WMGetListSelectedItemRow(w);
528 if (row < 0)
529 return;
531 item = WMGetListItem(panel->gcolL, row);
532 RRGBtoHSV((RColor*)item->clientData, &hsv);
534 WMSetSliderValue(panel->ghueS, hsv.hue);
535 WMSetSliderValue(panel->gsatS, hsv.saturation);
536 WMSetSliderValue(panel->gvalS, hsv.value);
538 sliderChangeCallback(panel->ghueS, panel);
539 sliderChangeCallback(panel->gsatS, panel);
543 static void
544 gradDeleteCallback(WMWidget *w, void *data)
546 TexturePanel *panel = (TexturePanel*)data;
547 WMListItem *item;
548 int row;
550 row = WMGetListSelectedItemRow(panel->gcolL);
551 if (row < 0)
552 return;
554 item = WMGetListItem(panel->gcolL, row);
555 wfree(item->clientData);
557 WMRemoveListItem(panel->gcolL, row);
559 WMSelectListItem(panel->gcolL, row - 1);
561 updateGradButtons(panel);
563 gradClickCallback(panel->gcolL, panel);
565 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
569 /*************** Simple Gradient ***************/
571 static void
572 colorWellObserver(void *self, WMNotification *n)
574 updateSGradButtons(self);
580 static void
581 opaqChangeCallback(WMWidget *w, void *data)
583 TexturePanel *panel = (TexturePanel*)data;
585 updateTGradImage(panel);
588 /****************** Image ******************/
590 static void
591 updateImage(TexturePanel *panel, char *path)
593 WMScreen *scr = WMWidgetScreen(panel->win);
594 RImage *image;
595 WMPixmap *pixmap;
596 WMSize size;
598 if (path) {
599 image = RLoadImage(WMScreenRContext(scr), path, 0);
600 if (!image) {
601 char *message;
603 message = wstrconcat(_("Could not load the selected file: "),
604 (char*)RMessageForError(RErrorCode));
606 WMRunAlertPanel(scr, panel->win, _("Error"), message,
607 _("OK"), NULL, NULL);
609 if (!panel->image)
610 WMSetButtonEnabled(panel->okB, False);
612 wfree(message);
613 return;
616 WMSetButtonEnabled(panel->okB, True);
618 if (panel->image)
619 RReleaseImage(panel->image);
620 panel->image = image;
621 } else {
622 image = panel->image;
625 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
626 if (image) {
627 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
629 size = WMGetPixmapSize(pixmap);
630 WMSetLabelImage(panel->imageL, pixmap);
631 WMResizeWidget(panel->imageL, size.width, size.height);
633 WMReleasePixmap(pixmap);
635 } else {
636 updateTGradImage(panel);
641 static void
642 browseImageCallback(WMWidget *w, void *data)
644 TexturePanel *panel = (TexturePanel*)data;
645 WMOpenPanel *opanel;
646 WMScreen *scr = WMWidgetScreen(w);
647 static char *ipath = NULL;
649 opanel = WMGetOpenPanel(scr);
650 WMSetFilePanelCanChooseDirectories(opanel, False);
651 WMSetFilePanelCanChooseFiles(opanel, True);
653 if (!ipath)
654 ipath = wstrdup(wgethomedir());
656 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
657 _("Open Image"), NULL)) {
658 char *path, *fullpath;
659 char *tmp, *tmp2;
661 tmp = WMGetFilePanelFileName(opanel);
662 if (!tmp)
663 return;
664 fullpath = tmp;
666 wfree(ipath);
667 ipath = fullpath;
669 path = wstrdup(fullpath);
671 tmp2 = strrchr(fullpath, '/');
672 if (tmp2)
673 tmp2++;
675 tmp = wfindfileinarray(panel->pathList, tmp2);
677 if (tmp) {
678 if (strcmp(fullpath, tmp)==0) {
679 wfree(path);
680 path = tmp2;
682 wfree(tmp);
685 if (!RGetImageFileFormat(fullpath)) {
686 WMRunAlertPanel(scr, panel->win, _("Error"),
687 _("The selected file does not contain a supported image."),
688 _("OK"), NULL, NULL);
689 wfree(path);
690 } else {
691 updateImage(panel, fullpath);
692 wfree(panel->imageFile);
693 panel->imageFile = path;
695 WMSetTextFieldText(panel->imageT, path);
702 static void
703 buttonCallback(WMWidget *w, void *data)
705 TexturePanel *panel = (TexturePanel*)data;
707 if (w == panel->okB) {
708 (*panel->okAction)(panel->okData);
709 } else {
710 (*panel->cancelAction)(panel->cancelData);
716 static void
717 changeTypeCallback(WMWidget *w, void *data)
719 TexturePanel *panel = (TexturePanel*)data;
720 int newType;
721 int i;
723 newType = WMGetPopUpButtonSelectedItem(w);
724 if (newType == panel->currentType)
725 return;
727 if (panel->currentType >= 0) {
728 for (i = 0; i < MAX_SECTION_PARTS; i++) {
729 if (panel->sectionParts[panel->currentType][i] == NULL)
730 break;
731 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
735 for (i = 0; i < MAX_SECTION_PARTS; i++) {
736 if (panel->sectionParts[newType][i] == NULL)
737 break;
738 WMMapWidget(panel->sectionParts[newType][i]);
740 panel->currentType = newType;
742 switch (newType) {
743 case TYPE_SGRADIENT:
744 updateSGradButtons(panel);
745 WMSetButtonEnabled(panel->okB, True);
746 break;
747 case TYPE_GRADIENT:
748 updateGradButtons(panel);
749 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
750 break;
751 case TYPE_TGRADIENT:
752 case TYPE_PIXMAP:
753 updateImage(panel, NULL);
754 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
755 break;
756 default:
757 WMSetButtonEnabled(panel->okB, True);
758 break;
764 *--------------------------------------------------------------------------
765 * Public functions
766 *--------------------------------------------------------------------------
768 void
769 DestroyTexturePanel(TexturePanel *panel)
775 void
776 ShowTexturePanel(TexturePanel *panel)
778 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
779 Screen *scr = DefaultScreenOfDisplay(dpy);
781 WMSetWindowInitialPosition(panel->win,
782 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
783 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
784 WMMapWidget(panel->win);
788 void
789 HideTexturePanel(TexturePanel *panel)
791 WMUnmapWidget(panel->win);
795 void
796 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
798 panel->okAction = action;
799 panel->okData = clientData;
803 void
804 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
806 panel->cancelAction = action;
807 panel->cancelData = clientData;
811 void
812 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
814 WMScreen *scr = WMWidgetScreen(panel->win);
815 char *str, *type;
816 proplist_t p;
817 WMColor *color;
818 int i;
819 char buffer[64];
820 int gradient = 0;
822 WMSetTextFieldText(panel->nameT, name);
824 if (!texture)
825 return;
827 p = PLGetArrayElement(texture, 0);
828 if (!p) {
829 goto bad_texture;
831 type = PLGetString(p);
833 /*...............................................*/
834 if (strcasecmp(type, "solid")==0) {
836 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
838 p = PLGetArrayElement(texture, 1);
839 if (!p) {
840 str = "black";
841 } else {
842 str = PLGetString(p);
844 color = WMCreateNamedColor(scr, str, False);
846 WMSetColorWellColor(panel->defcW, color);
848 WMReleaseColor(color);
849 /*...............................................*/
850 } else if (strcasecmp(type, "hgradient")==0
851 || strcasecmp(type, "vgradient")==0
852 || strcasecmp(type, "dgradient")==0) {
854 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
856 p = PLGetArrayElement(texture, 1);
857 if (!p) {
858 str = "black";
859 } else {
860 str = PLGetString(p);
862 color = WMCreateNamedColor(scr, str, False);
864 WMSetColorWellColor(panel->tcol1W, color);
866 WMReleaseColor(color);
868 p = PLGetArrayElement(texture, 2);
869 if (!p) {
870 str = "black";
871 } else {
872 str = PLGetString(p);
874 color = WMCreateNamedColor(scr, str, False);
876 WMSetColorWellColor(panel->tcol2W, color);
878 WMReleaseColor(color);
880 gradient = type[0];
881 /*...............................................*/
882 } else if (strcasecmp(type, "thgradient")==0
883 || strcasecmp(type, "tvgradient")==0
884 || strcasecmp(type, "tdgradient")==0) {
885 int i;
887 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
889 gradient = type[1];
891 WMSetTextFieldText(panel->imageT,
892 PLGetString(PLGetArrayElement(texture, 1)));
893 if (panel->imageFile)
894 wfree(panel->imageFile);
895 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
898 i = 180;
899 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
900 WMSetSliderValue(panel->topaS, i);
902 p = PLGetArrayElement(texture, 3);
903 if (!p) {
904 str = "black";
905 } else {
906 str = PLGetString(p);
908 color = WMCreateNamedColor(scr, str, False);
910 WMSetColorWellColor(panel->tcol1W, color);
912 WMReleaseColor(color);
914 p = PLGetArrayElement(texture, 4);
915 if (!p) {
916 str = "black";
917 } else {
918 str = PLGetString(p);
920 color = WMCreateNamedColor(scr, str, False);
922 WMSetColorWellColor(panel->tcol2W, color);
924 WMReleaseColor(color);
926 WMSetTextFieldText(panel->imageT,
927 PLGetString(PLGetArrayElement(texture, 1)));
929 if (panel->imageFile)
930 wfree(panel->imageFile);
931 if ((panel->imageFile = wfindfileinarray(panel->pathList,
932 PLGetString(PLGetArrayElement(texture, 1)))) != NULL) {
934 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
935 updateTGradImage(panel);
937 updateSGradButtons(panel);
938 } else wwarning(_("could not load file '%s': %s"), panel->imageFile,
939 RMessageForError(RErrorCode));
941 /*...............................................*/
942 } else if (strcasecmp(type, "mhgradient")==0
943 || strcasecmp(type, "mvgradient")==0
944 || strcasecmp(type, "mdgradient")==0) {
945 WMListItem *item;
947 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
948 item = WMGetListItem(panel->gcolL, i);
949 wfree(item->clientData);
951 WMClearList(panel->gcolL);
953 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
955 p = PLGetArrayElement(texture, 1);
956 if (!p) {
957 str = "black";
958 } else {
959 str = PLGetString(p);
961 color = WMCreateNamedColor(scr, str, False);
963 WMSetColorWellColor(panel->defcW, color);
965 WMReleaseColor(color);
967 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
968 RColor *rgb;
969 XColor xcolor;
971 p = PLGetArrayElement(texture, i);
972 if (!p) {
973 str = "black";
974 } else {
975 str = PLGetString(p);
978 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
979 str, &xcolor);
981 rgb = wmalloc(sizeof(RColor));
982 rgb->red = xcolor.red >> 8;
983 rgb->green = xcolor.green >> 8;
984 rgb->blue = xcolor.blue >> 8;
985 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
987 item = WMAddListItem(panel->gcolL, buffer);
988 item->clientData = rgb;
991 sliderChangeCallback(panel->ghueS, panel);
993 gradient = type[1];
994 /*...............................................*/
995 } else if (strcasecmp(type, "cpixmap")==0
996 || strcasecmp(type, "spixmap")==0
997 || strcasecmp(type, "mpixmap")==0
998 || strcasecmp(type, "tpixmap")==0) {
1000 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1002 switch (toupper(type[0])) {
1003 case 'C':
1004 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1005 break;
1006 case 'S':
1007 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1008 break;
1009 case 'M':
1010 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1011 break;
1012 default:
1013 case 'T':
1014 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1015 break;
1018 WMSetTextFieldText(panel->imageT,
1019 PLGetString(PLGetArrayElement(texture, 1)));
1021 if (panel->imageFile)
1022 wfree(panel->imageFile);
1023 panel->imageFile = wfindfileinarray(panel->pathList,
1024 PLGetString(PLGetArrayElement(texture, 1)));
1026 color = WMCreateNamedColor(scr,
1027 PLGetString(PLGetArrayElement(texture, 2)), False);
1028 WMSetColorWellColor(panel->defcW, color);
1029 WMReleaseColor(color);
1031 updateImage(panel, panel->imageFile);
1034 changeTypeCallback(panel->typeP, panel);
1036 if (gradient > 0) {
1037 updateGradButtons(panel);
1039 switch (toupper(gradient)) {
1040 case 'H':
1041 WMPerformButtonClick(panel->dirhB);
1042 break;
1043 case 'V':
1044 WMPerformButtonClick(panel->dirvB);
1045 break;
1046 default:
1047 case 'D':
1048 WMPerformButtonClick(panel->dirdB);
1049 break;
1053 return;
1055 bad_texture:
1056 str = PLGetDescription(texture);
1057 wwarning(_("error creating texture %s"), str);
1058 wfree(str);
1064 char*
1065 GetTexturePanelTextureName(TexturePanel *panel)
1067 return WMGetTextFieldText(panel->nameT);
1073 proplist_t
1074 GetTexturePanelTexture(TexturePanel *panel)
1076 proplist_t prop = NULL;
1077 WMColor *color;
1078 char *str, *str2;
1079 char buff[32];
1080 int i;
1083 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1085 case TYPE_SOLID:
1086 color = WMGetColorWellColor(panel->defcW);
1087 str = WMGetColorRGBDescription(color);
1088 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1089 PLMakeString(str), NULL);
1090 wfree(str);
1092 break;
1094 case TYPE_PIXMAP:
1095 color = WMGetColorWellColor(panel->defcW);
1096 str = WMGetColorRGBDescription(color);
1098 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1099 case PTYPE_SCALE:
1100 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1101 PLMakeString(panel->imageFile),
1102 PLMakeString(str), NULL);
1103 break;
1104 case PTYPE_MAXIMIZE:
1105 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1106 PLMakeString(panel->imageFile),
1107 PLMakeString(str), NULL);
1108 break;
1109 case PTYPE_CENTER:
1110 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1111 PLMakeString(panel->imageFile),
1112 PLMakeString(str), NULL);
1113 break;
1114 case PTYPE_TILE:
1115 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1116 PLMakeString(panel->imageFile),
1117 PLMakeString(str), NULL);
1118 break;
1120 wfree(str);
1121 break;
1123 case TYPE_TGRADIENT:
1124 color = WMGetColorWellColor(panel->tcol1W);
1125 str = WMGetColorRGBDescription(color);
1127 color = WMGetColorWellColor(panel->tcol2W);
1128 str2 = WMGetColorRGBDescription(color);
1130 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1132 if (WMGetButtonSelected(panel->dirdB)) {
1133 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1134 PLMakeString(panel->imageFile),
1135 PLMakeString(buff),
1136 PLMakeString(str),
1137 PLMakeString(str2), NULL);
1138 } else if (WMGetButtonSelected(panel->dirvB)) {
1139 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1140 PLMakeString(panel->imageFile),
1141 PLMakeString(buff),
1142 PLMakeString(str),
1143 PLMakeString(str2), NULL);
1144 } else {
1145 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1146 PLMakeString(panel->imageFile),
1147 PLMakeString(buff),
1148 PLMakeString(str),
1149 PLMakeString(str2), NULL);
1151 wfree(str);
1152 wfree(str2);
1153 break;
1156 case TYPE_SGRADIENT:
1157 color = WMGetColorWellColor(panel->tcol1W);
1158 str = WMGetColorRGBDescription(color);
1160 color = WMGetColorWellColor(panel->tcol2W);
1161 str2 = WMGetColorRGBDescription(color);
1163 if (WMGetButtonSelected(panel->dirdB)) {
1164 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1165 PLMakeString(str),
1166 PLMakeString(str2), NULL);
1167 } else if (WMGetButtonSelected(panel->dirvB)) {
1168 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1169 PLMakeString(str),
1170 PLMakeString(str2), NULL);
1171 } else {
1172 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1173 PLMakeString(str),
1174 PLMakeString(str2), NULL);
1176 wfree(str);
1177 wfree(str2);
1178 break;
1180 case TYPE_GRADIENT:
1181 color = WMGetColorWellColor(panel->defcW);
1182 str = WMGetColorRGBDescription(color);
1184 if (WMGetButtonSelected(panel->dirdB)) {
1185 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1186 PLMakeString(str), NULL);
1187 } else if (WMGetButtonSelected(panel->dirvB)) {
1188 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1189 PLMakeString(str), NULL);
1190 } else {
1191 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1192 PLMakeString(str), NULL);
1194 wfree(str);
1196 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1197 RColor *rgb;
1198 WMListItem *item;
1200 item = WMGetListItem(panel->gcolL, i);
1202 rgb = (RColor*)item->clientData;
1204 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1206 PLAppendArrayElement(prop, PLMakeString(buff));
1208 break;
1212 return prop;
1217 void
1218 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1220 panel->pathList = array;
1225 TexturePanel*
1226 CreateTexturePanel(WMWindow *keyWindow)
1227 /*CreateTexturePanel(WMScreen *scr)*/
1229 TexturePanel *panel;
1230 WMScreen *scr = WMWidgetScreen(keyWindow);
1232 panel = wmalloc(sizeof(TexturePanel));
1233 memset(panel, 0, sizeof(TexturePanel));
1235 panel->listFont = WMSystemFontOfSize(scr, 12);
1238 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1239 WMTitledWindowMask
1240 |WMClosableWindowMask);
1242 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1243 WMTitledWindowMask
1244 |WMClosableWindowMask);
1247 WMResizeWidget(panel->win, 325, 423);
1248 WMSetWindowTitle(panel->win, _("Texture Panel"));
1249 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1252 /* texture name */
1253 panel->nameF = WMCreateFrame(panel->win);
1254 WMResizeWidget(panel->nameF, 185, 50);
1255 WMMoveWidget(panel->nameF, 15, 10);
1256 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1258 panel->nameT = WMCreateTextField(panel->nameF);
1259 WMResizeWidget(panel->nameT, 160, 20);
1260 WMMoveWidget(panel->nameT, 12, 18);
1262 WMMapSubwidgets(panel->nameF);
1264 /* texture types */
1265 panel->typeP = WMCreatePopUpButton(panel->win);
1266 WMResizeWidget(panel->typeP, 185, 20);
1267 WMMoveWidget(panel->typeP, 15, 65);
1268 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1269 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1270 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1271 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1272 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1273 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1274 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1276 /* color */
1277 panel->defcF = WMCreateFrame(panel->win);
1278 WMResizeWidget(panel->defcF, 100, 75);
1279 WMMoveWidget(panel->defcF, 210, 10);
1280 WMSetFrameTitle(panel->defcF, _("Default Color"));
1282 panel->defcW = WMCreateColorWell(panel->defcF);
1283 WMResizeWidget(panel->defcW, 60, 45);
1284 WMMoveWidget(panel->defcW, 20, 20);
1286 WMMapSubwidgets(panel->defcF);
1288 /****** Gradient ******/
1289 panel->gcolF = WMCreateFrame(panel->win);
1290 WMResizeWidget(panel->gcolF, 295, 205);
1291 WMMoveWidget(panel->gcolF, 15, 95);
1292 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1294 panel->gcolL = WMCreateList(panel->gcolF);
1295 WMResizeWidget(panel->gcolL, 130, 140);
1296 WMMoveWidget(panel->gcolL, 10, 25);
1297 WMHangData(panel->gcolL, panel);
1298 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1299 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1301 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1302 WMResizeWidget(panel->gcolaB, 64, 24);
1303 WMMoveWidget(panel->gcolaB, 10, 170);
1304 WMSetButtonText(panel->gcolaB, _("Add"));
1305 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1307 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1308 WMResizeWidget(panel->gcoldB, 64, 24);
1309 WMMoveWidget(panel->gcoldB, 75, 170);
1310 WMSetButtonText(panel->gcoldB, _("Delete"));
1311 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1313 #if 0
1314 panel->gbriS = WMCreateSlider(panel->gcolF);
1315 WMResizeWidget(panel->gbriS, 130, 16);
1316 WMMoveWidget(panel->gbriS, 150, 25);
1317 WMSetSliderKnobThickness(panel->gbriS, 8);
1318 WMSetSliderMaxValue(panel->gbriS, 100);
1319 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1321 WMPixmap *pixmap;
1322 WMColor *color;
1324 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1325 color = WMDarkGrayColor(scr);
1326 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1327 WMColorGC(color), 0, 0, 130, 16);
1328 WMReleaseColor(color);
1329 color = WMWhiteColor(color);
1330 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1331 panel->listFont, 2,
1332 (16 - WMFontHeight(panel->listFont))/2 - 1,
1333 "Brightness", 10);
1334 WMSetSliderImage(panel->gbriS, pixmap);
1335 WMReleasePixmap(pixmap);
1338 panel->gconS = WMCreateSlider(panel->gcolF);
1339 WMResizeWidget(panel->gconS, 130, 16);
1340 WMMoveWidget(panel->gconS, 150, 50);
1341 WMSetSliderKnobThickness(panel->gconS, 8);
1342 WMSetSliderMaxValue(panel->gconS, 100);
1343 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1345 WMPixmap *pixmap;
1346 WMColor *color;
1348 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1349 color = WMDarkGrayColor(scr);
1350 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1351 WMColorGC(color), 0, 0, 130, 16);
1352 WMReleaseColor(color);
1353 color = WMWhiteColor(scr);
1354 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1355 panel->listFont, 2,
1356 (16 - WMFontHeight(panel->listFont))/2 - 1,
1357 "Contrast", 8);
1358 WMSetSliderImage(panel->gconS, pixmap);
1359 WMReleasePixmap(pixmap);
1361 #endif
1362 panel->ghueS = WMCreateSlider(panel->gcolF);
1363 WMResizeWidget(panel->ghueS, 130, 16);
1364 WMMoveWidget(panel->ghueS, 150, 100);
1365 WMSetSliderKnobThickness(panel->ghueS, 8);
1366 WMSetSliderMaxValue(panel->ghueS, 359);
1367 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1369 panel->gsatS = WMCreateSlider(panel->gcolF);
1370 WMResizeWidget(panel->gsatS, 130, 16);
1371 WMMoveWidget(panel->gsatS, 150, 125);
1372 WMSetSliderKnobThickness(panel->gsatS, 8);
1373 WMSetSliderMaxValue(panel->gsatS, 255);
1374 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1376 panel->gvalS = WMCreateSlider(panel->gcolF);
1377 WMResizeWidget(panel->gvalS, 130, 16);
1378 WMMoveWidget(panel->gvalS, 150, 150);
1379 WMSetSliderKnobThickness(panel->gvalS, 8);
1380 WMSetSliderMaxValue(panel->gvalS, 255);
1381 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1384 WMMapSubwidgets(panel->gcolF);
1386 /** Direction **/
1387 panel->dirF = WMCreateFrame(panel->win);
1388 WMSetFrameTitle(panel->dirF, _("Direction"));
1389 WMResizeWidget(panel->dirF, 295, 75);
1390 WMMoveWidget(panel->dirF, 15, 305);
1392 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1393 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1394 WMResizeWidget(panel->dirvB, 90, 40);
1395 WMMoveWidget(panel->dirvB, 10, 20);
1397 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1398 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1399 WMResizeWidget(panel->dirhB, 90, 40);
1400 WMMoveWidget(panel->dirhB, 102, 20);
1402 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1403 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1404 WMResizeWidget(panel->dirdB, 90, 40);
1405 WMMoveWidget(panel->dirdB, 194, 20);
1407 WMGroupButtons(panel->dirvB, panel->dirhB);
1408 WMGroupButtons(panel->dirvB, panel->dirdB);
1410 WMMapSubwidgets(panel->dirF);
1412 /****************** Textured Gradient ******************/
1413 panel->tcolF = WMCreateFrame(panel->win);
1414 WMResizeWidget(panel->tcolF, 100, 135);
1415 WMMoveWidget(panel->tcolF, 210, 10);
1416 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1418 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1419 WMResizeWidget(panel->tcol1W, 60, 45);
1420 WMMoveWidget(panel->tcol1W, 20, 25);
1421 WMAddNotificationObserver(colorWellObserver, panel,
1422 WMColorWellDidChangeNotification, panel->tcol1W);
1424 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1425 WMResizeWidget(panel->tcol2W, 60, 45);
1426 WMMoveWidget(panel->tcol2W, 20, 75);
1427 WMAddNotificationObserver(colorWellObserver, panel,
1428 WMColorWellDidChangeNotification, panel->tcol2W);
1430 /** Opacity */
1431 panel->topaF = WMCreateFrame(panel->win);
1432 WMResizeWidget(panel->topaF, 185, 50);
1433 WMMoveWidget(panel->topaF, 15, 95);
1434 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1436 panel->topaS = WMCreateSlider(panel->topaF);
1437 WMResizeWidget(panel->topaS, 155, 18);
1438 WMMoveWidget(panel->topaS, 15, 20);
1439 WMSetSliderMaxValue(panel->topaS, 255);
1440 WMSetSliderValue(panel->topaS, 200);
1441 WMSetSliderContinuous(panel->topaS, False);
1442 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1444 WMMapSubwidgets(panel->topaF);
1447 WMPixmap *pixmap;
1448 Pixmap p;
1449 WMColor *color;
1451 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1452 p = WMGetPixmapXID(pixmap);
1454 color = WMDarkGrayColor(scr);
1455 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1456 0, 0, 155, 18);
1457 WMReleaseColor(color);
1459 color = WMWhiteColor(scr);
1460 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1461 2, 1, "0%", 2);
1462 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1463 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1464 "100%", 4);
1465 WMReleaseColor(color);
1467 WMSetSliderImage(panel->topaS, pixmap);
1468 WMReleasePixmap(pixmap);
1471 WMMapSubwidgets(panel->tcolF);
1473 /****************** Image ******************/
1474 panel->imageF = WMCreateFrame(panel->win);
1475 WMResizeWidget(panel->imageF, 295, 150);
1476 WMMoveWidget(panel->imageF, 15, 150);
1477 WMSetFrameTitle(panel->imageF, _("Image"));
1479 panel->imageL = WMCreateLabel(panel->imageF);
1480 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1482 panel->imageT = WMCreateTextField(panel->imageF);
1483 WMResizeWidget(panel->imageT, 90, 20);
1484 WMMoveWidget(panel->imageT, 190, 25);
1486 panel->imageV = WMCreateScrollView(panel->imageF);
1487 WMResizeWidget(panel->imageV, 165, 115);
1488 WMMoveWidget(panel->imageV, 15, 20);
1489 WMSetScrollViewRelief(panel->imageV, WRSunken);
1490 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1491 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1492 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1494 panel->browB = WMCreateCommandButton(panel->imageF);
1495 WMResizeWidget(panel->browB, 90, 24);
1496 WMMoveWidget(panel->browB, 190, 50);
1497 WMSetButtonText(panel->browB, _("Browse..."));
1498 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1500 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1501 WMResizeWidget(panel->dispB, 90, 24);
1502 WMMoveWidget(panel->dispB, 190, 80);
1503 WMSetButtonText(panel->dispB, _("Show"));
1506 panel->arrP = WMCreatePopUpButton(panel->imageF);
1507 WMResizeWidget(panel->arrP, 90, 20);
1508 WMMoveWidget(panel->arrP, 190, 120);
1509 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1510 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1511 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1512 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1513 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1515 WMMapSubwidgets(panel->imageF);
1517 /****/
1519 panel->okB = WMCreateCommandButton(panel->win);
1520 WMResizeWidget(panel->okB, 84, 24);
1521 WMMoveWidget(panel->okB, 225, 390);
1522 WMSetButtonText(panel->okB, _("OK"));
1523 WMSetButtonAction(panel->okB, buttonCallback, panel);
1525 panel->cancelB = WMCreateCommandButton(panel->win);
1526 WMResizeWidget(panel->cancelB, 84, 24);
1527 WMMoveWidget(panel->cancelB, 130, 390);
1528 WMSetButtonText(panel->cancelB, _("Cancel"));
1529 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1531 WMMapWidget(panel->nameF);
1532 WMMapWidget(panel->typeP);
1533 WMMapWidget(panel->okB);
1534 WMMapWidget(panel->cancelB);
1536 WMUnmapWidget(panel->arrP);
1538 WMRealizeWidget(panel->win);
1540 panel->currentType = -1;
1542 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1544 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1545 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1546 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1548 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1549 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1551 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1552 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1553 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1554 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1555 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1557 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1558 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1559 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1562 /* setup for first time */
1564 changeTypeCallback(panel->typeP, panel);
1566 sliderChangeCallback(panel->ghueS, panel);
1567 sliderChangeCallback(panel->gsatS, panel);
1569 return panel;
1575 *--------------------------------------------------------------------------
1576 * Test stuff
1577 *--------------------------------------------------------------------------
1580 #if 0
1582 char *ProgName = "test";
1584 void
1585 testOKButton(WMWidget *self, void *data)
1587 char *test;
1588 Display *dpy;
1589 Window win;
1590 Pixmap pix;
1591 RImage *image;
1593 TexturePanel *panel = (TexturePanel*)data;
1594 /* test = GetTexturePanelTextureString(panel); */
1596 wwarning(test);
1598 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1599 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1600 0, 0, 0);
1601 XMapRaised(dpy, win);
1602 XFlush(dpy);
1604 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1606 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1608 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1609 0, 0);
1611 wfree (test);
1615 void testCancelButton(WMWidget *self, void *data){
1616 wwarning("Exiting test....");
1617 exit(0);
1620 void wAbort()
1622 exit(1);
1625 int main(int argc, char **argv)
1627 TexturePanel *panel;
1629 Display *dpy = XOpenDisplay("");
1630 WMScreen *scr;
1632 /* char *test; */
1634 WMInitializeApplication("Test", &argc, argv);
1636 if (!dpy) {
1637 wfatal("could not open display");
1638 exit(1);
1641 scr = WMCreateSimpleApplicationScreen(dpy);
1643 panel = CreateTexturePanel(scr);
1645 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1646 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1648 SetTexturePanelTexture(panel, "pinky",
1649 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1651 ShowTexturePanel(panel);
1653 WMScreenMainLoop(scr);
1654 return 0;
1656 #endif