Applied patch from Largo to update sound related stuff and documentation
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blob035ff03b19ce1c82a443003d372a259f9d2daa9c
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.h>
35 #include <WUtil.h>
37 #include "WPrefs.h"
39 #include "TexturePanel.h"
41 #define MAX_SECTION_PARTS 5
43 typedef struct _TexturePanel {
44 WMWindow *win;
46 /* texture name */
47 WMFrame *nameF;
48 WMTextField *nameT;
50 /* texture type */
51 WMPopUpButton *typeP;
53 /* default color */
54 WMFrame *defcF;
55 WMColorWell *defcW;
57 WMFont *listFont;
59 /*-- Gradient --*/
61 Pixmap gimage;
63 /* colors */
64 WMFrame *gcolF;
65 WMList *gcolL;
66 WMButton *gcolaB;
67 WMButton *gcoldB;
68 WMSlider *ghueS;
69 WMSlider *gsatS;
70 WMSlider *gvalS;
72 WMSlider *gbriS;
73 WMSlider *gconS;
75 /* direction (common) */
76 WMFrame *dirF;
77 WMButton *dirhB;
78 WMButton *dirvB;
79 WMButton *dirdB;
81 /*-- Simple Gradient --*/
84 /*-- Textured Gradient --*/
86 WMFrame *tcolF;
87 WMColorWell *tcol1W;
88 WMColorWell *tcol2W;
90 WMFrame *topaF;
91 WMSlider *topaS;
93 /*-- Image --*/
94 WMFrame *imageF;
95 WMScrollView *imageV;
96 WMTextField *imageT;
97 WMLabel *imageL;
98 WMButton *browB;
99 WMButton *dispB;
100 WMPopUpButton *arrP;
102 RImage *image;
103 char *imageFile;
105 /*****/
107 WMButton *okB;
108 WMButton *cancelB;
111 WMCallback *okAction;
112 void *okData;
114 WMCallback *cancelAction;
115 void *cancelData;
117 /****/
118 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
120 int currentType;
123 proplist_t pathList;
125 } _TexturePanel;
129 #define TYPE_SOLID 0
130 #define TYPE_GRADIENT 1
131 #define TYPE_SGRADIENT 2
132 #define TYPE_TGRADIENT 3
133 #define TYPE_PIXMAP 4
136 #define PTYPE_TILE 0
137 #define PTYPE_SCALE 1
138 #define PTYPE_CENTER 2
139 #define PTYPE_MAXIMIZE 3
144 *--------------------------------------------------------------------------
145 * Private Functions
146 *--------------------------------------------------------------------------
149 /************/
151 static void
152 updateGradButtons(TexturePanel *panel)
154 RImage *image;
155 WMPixmap *pixmap;
156 int colorn;
157 RColor **colors;
159 colorn = WMGetListNumberOfRows(panel->gcolL);
160 if (colorn < 1) {
161 pixmap = NULL;
162 } else {
163 int i;
164 WMListItem *item;
166 colors = wmalloc(sizeof(RColor*)*(colorn+1));
168 for (i = 0; i < colorn; i++) {
169 item = WMGetListItem(panel->gcolL, i);
170 colors[i] = (RColor*)item->clientData;
172 colors[i] = NULL;
174 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
175 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
176 image, 128);
177 RDestroyImage(image);
178 WMSetButtonImage(panel->dirhB, pixmap);
179 WMReleasePixmap(pixmap);
181 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
182 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
183 image, 128);
184 RDestroyImage(image);
185 WMSetButtonImage(panel->dirvB, pixmap);
186 WMReleasePixmap(pixmap);
188 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
189 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
190 image, 128);
191 RDestroyImage(image);
192 WMSetButtonImage(panel->dirdB, pixmap);
193 WMReleasePixmap(pixmap);
195 wfree(colors);
201 static void
202 updateTGradImage(TexturePanel *panel)
204 RImage *image, *gradient;
205 WMPixmap *pixmap;
206 RColor from;
207 RColor to;
208 WMColor *color;
210 if (!panel->image)
211 return;
213 color = WMGetColorWellColor(panel->tcol1W);
214 from.red = WMRedComponentOfColor(color)>>8;
215 from.green = WMGreenComponentOfColor(color)>>8;
216 from.blue = WMBlueComponentOfColor(color)>>8;
218 color = WMGetColorWellColor(panel->tcol2W);
219 to.red = WMRedComponentOfColor(color)>>8;
220 to.green = WMGreenComponentOfColor(color)>>8;
221 to.blue = WMBlueComponentOfColor(color)>>8;
223 if (panel->image->width < 141 || panel->image->height < 91) {
224 image = RMakeTiledImage(panel->image, 141, 91);
225 } else {
226 image = RCloneImage(panel->image);
229 if (WMGetButtonSelected(panel->dirhB)) {
230 gradient = RRenderGradient(image->width, image->height, &from, &to,
231 RHorizontalGradient);
232 } else if (WMGetButtonSelected(panel->dirvB)) {
233 gradient = RRenderGradient(image->width, image->height, &from, &to,
234 RVerticalGradient);
235 } else {
236 gradient = RRenderGradient(image->width, image->height, &from, &to,
237 RDiagonalGradient);
240 RCombineImagesWithOpaqueness(image, gradient,
241 WMGetSliderValue(panel->topaS));
242 RDestroyImage(gradient);
243 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
244 image, 128);
246 WMSetLabelImage(panel->imageL, pixmap);
247 WMReleasePixmap(pixmap);
248 WMResizeWidget(panel->imageL, image->width, image->height);
249 RDestroyImage(image);
253 static void
254 updateSGradButtons(TexturePanel *panel)
256 RImage *image;
257 WMPixmap *pixmap;
258 RColor from;
259 RColor to;
260 WMColor *color;
262 color = WMGetColorWellColor(panel->tcol1W);
263 from.red = WMRedComponentOfColor(color)>>8;
264 from.green = WMGreenComponentOfColor(color)>>8;
265 from.blue = WMBlueComponentOfColor(color)>>8;
267 color = WMGetColorWellColor(panel->tcol2W);
268 to.red = WMRedComponentOfColor(color)>>8;
269 to.green = WMGreenComponentOfColor(color)>>8;
270 to.blue = WMBlueComponentOfColor(color)>>8;
272 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
273 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
274 image, 128);
275 RDestroyImage(image);
276 WMSetButtonImage(panel->dirhB, pixmap);
277 WMReleasePixmap(pixmap);
279 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
280 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
281 image, 128);
282 RDestroyImage(image);
283 WMSetButtonImage(panel->dirvB, pixmap);
284 WMReleasePixmap(pixmap);
286 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
287 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
288 image, 128);
289 RDestroyImage(image);
290 WMSetButtonImage(panel->dirdB, pixmap);
291 WMReleasePixmap(pixmap);
295 /*********** Gradient ************/
297 static void
298 updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
300 RImage *image;
301 WMPixmap *pixmap;
302 WMScreen *scr = WMWidgetScreen(sPtr);
303 RColor from, to;
304 RHSVColor tmp;
306 tmp = *hsv;
307 if (saturation) {
308 tmp.saturation = 0;
309 RHSVtoRGB(&tmp, &from);
310 tmp.saturation = 255;
311 RHSVtoRGB(&tmp, &to);
312 } else {
313 tmp.value = 0;
314 RHSVtoRGB(&tmp, &from);
315 tmp.value = 255;
316 RHSVtoRGB(&tmp, &to);
318 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
319 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
320 RDestroyImage(image);
322 if (hsv->value < 128 || !saturation) {
323 WMColor *col = WMWhiteColor(scr);
325 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
326 (16 - WMFontHeight(font))/2 - 1,
327 saturation ? "Saturation" : "Brightness", 10);
328 WMReleaseColor(col);
329 } else {
330 WMColor *col = WMBlackColor(scr);
332 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
333 (16 - WMFontHeight(font))/2 - 1,
334 saturation ? "Saturation" : "Brightness", 10);
335 WMReleaseColor(col);
337 WMSetSliderImage(sPtr, pixmap);
338 WMReleasePixmap(pixmap);
342 static void
343 updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
345 RColor *colors[8];
346 RImage *image;
347 WMPixmap *pixmap;
348 WMScreen *scr = WMWidgetScreen(sPtr);
349 RHSVColor thsv;
350 int i;
352 thsv = *hsv;
353 for (i = 0; i <= 6; i++) {
354 thsv.hue = (360*i)/6;
355 colors[i] = wmalloc(sizeof(RColor));
356 RHSVtoRGB(&thsv, colors[i]);
358 colors[i] = NULL;
360 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
361 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
362 RDestroyImage(image);
364 if (hsv->value < 128) {
365 WMColor *col = WMWhiteColor(scr);
367 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
368 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
369 WMReleaseColor(col);
370 } else {
371 WMColor *col = WMBlackColor(scr);
373 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
374 (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
375 WMReleaseColor(col);
377 WMSetSliderImage(sPtr, pixmap);
378 WMReleasePixmap(pixmap);
380 for (i = 0; i <= 6; i++)
381 wfree(colors[i]);
386 static void
387 sliderChangeCallback(WMWidget *w, void *data)
389 TexturePanel *panel = (TexturePanel*)data;
390 RHSVColor hsv;
391 int row, rows;
392 WMListItem *item;
393 RColor **colors;
394 int i;
395 RImage *image;
396 WMScreen *scr = WMWidgetScreen(w);
398 hsv.hue = WMGetSliderValue(panel->ghueS);
399 hsv.saturation = WMGetSliderValue(panel->gsatS);
400 hsv.value = WMGetSliderValue(panel->gvalS);
402 row = WMGetListSelectedItemRow(panel->gcolL);
403 if (row >= 0) {
404 RColor *rgb;
406 item = WMGetListItem(panel->gcolL, row);
408 rgb = (RColor*)item->clientData;
410 RHSVtoRGB(&hsv, rgb);
412 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
415 if (w == panel->ghueS) {
416 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
417 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
418 } else if (w == panel->gsatS) {
419 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
420 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
421 } else {
422 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
423 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
426 rows = WMGetListNumberOfRows(panel->gcolL);
427 if (rows == 0)
428 return;
430 colors = wmalloc(sizeof(RColor*)*(rows+1));
432 for (i = 0; i < rows; i++) {
433 item = WMGetListItem(panel->gcolL, i);
435 colors[i] = (RColor*)item->clientData;
437 colors[i] = NULL;
439 if (panel->gimage != None) {
440 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
443 image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL),
444 colors, RVerticalGradient);
445 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
446 RDestroyImage(image);
448 wfree(colors);
450 WMRedisplayWidget(panel->gcolL);
452 updateGradButtons(panel);
456 static void
457 paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
458 WMRect *rect)
460 TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
461 WMScreen *scr = WMWidgetScreen(lPtr);
462 int width, height, x, y;
463 Display *dpy;
464 WMColor *white = WMWhiteColor(scr);
465 WMListItem *item;
466 WMColor *black = WMBlackColor(scr);
468 dpy = WMScreenDisplay(scr);
470 width = rect->size.width;
471 height = rect->size.height;
472 x = rect->pos.x;
473 y = rect->pos.y;
475 if (state & WLDSSelected)
476 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
477 else
478 XClearArea(dpy, d, x, y, width, height, False);
480 item = WMGetListItem(lPtr, index);
482 if (panel->gimage) {
483 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
484 0, height*index, 30, height, x + 5, y);
486 WMDrawString(scr, d, WMColorGC(black), panel->listFont,
487 x + 40, y + 1, text, strlen(text));
489 WMReleaseColor(white);
490 WMReleaseColor(black);
495 static void
496 gradAddCallback(WMWidget *w, void *data)
498 TexturePanel *panel = (TexturePanel*)data;
499 WMListItem *item;
500 int row;
501 RColor *rgb;
503 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
504 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
505 rgb = wmalloc(sizeof(RColor));
506 memset(rgb, 0, sizeof(RColor));
507 item->clientData = rgb;
509 WMSelectListItem(panel->gcolL, row);
511 updateGradButtons(panel);
513 sliderChangeCallback(panel->ghueS, panel);
515 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
520 static void
521 gradClickCallback(WMWidget *w, void *data)
523 TexturePanel *panel = (TexturePanel*)data;
524 WMListItem *item;
525 int row;
526 RHSVColor hsv;
528 row = WMGetListSelectedItemRow(w);
529 if (row < 0)
530 return;
532 item = WMGetListItem(panel->gcolL, row);
533 RRGBtoHSV((RColor*)item->clientData, &hsv);
535 WMSetSliderValue(panel->ghueS, hsv.hue);
536 WMSetSliderValue(panel->gsatS, hsv.saturation);
537 WMSetSliderValue(panel->gvalS, hsv.value);
539 sliderChangeCallback(panel->ghueS, panel);
540 sliderChangeCallback(panel->gsatS, panel);
544 static void
545 gradDeleteCallback(WMWidget *w, void *data)
547 TexturePanel *panel = (TexturePanel*)data;
548 WMListItem *item;
549 int row;
551 row = WMGetListSelectedItemRow(panel->gcolL);
552 if (row < 0)
553 return;
555 item = WMGetListItem(panel->gcolL, row);
556 wfree(item->clientData);
558 WMRemoveListItem(panel->gcolL, row);
560 WMSelectListItem(panel->gcolL, row - 1);
562 updateGradButtons(panel);
564 gradClickCallback(panel->gcolL, panel);
566 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
570 /*************** Simple Gradient ***************/
572 static void
573 colorWellObserver(void *self, WMNotification *n)
575 updateSGradButtons(self);
581 static void
582 opaqChangeCallback(WMWidget *w, void *data)
584 TexturePanel *panel = (TexturePanel*)data;
586 updateTGradImage(panel);
589 /****************** Image ******************/
591 static void
592 updateImage(TexturePanel *panel, char *path)
594 WMScreen *scr = WMWidgetScreen(panel->win);
595 RImage *image;
596 WMPixmap *pixmap;
597 WMSize size;
599 if (path) {
600 image = RLoadImage(WMScreenRContext(scr), path, 0);
601 if (!image) {
602 char *message;
604 message = wstrconcat(_("Could not load the selected file: "),
605 (char*)RMessageForError(RErrorCode));
607 WMRunAlertPanel(scr, panel->win, _("Error"), message,
608 _("OK"), NULL, NULL);
610 if (!panel->image)
611 WMSetButtonEnabled(panel->okB, False);
613 wfree(message);
614 return;
617 WMSetButtonEnabled(panel->okB, True);
619 if (panel->image)
620 RDestroyImage(panel->image);
621 panel->image = image;
622 } else {
623 image = panel->image;
626 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
627 if (image) {
628 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
630 size = WMGetPixmapSize(pixmap);
631 WMSetLabelImage(panel->imageL, pixmap);
632 WMResizeWidget(panel->imageL, size.width, size.height);
634 WMReleasePixmap(pixmap);
636 } else {
637 updateTGradImage(panel);
642 static void
643 browseImageCallback(WMWidget *w, void *data)
645 TexturePanel *panel = (TexturePanel*)data;
646 WMOpenPanel *opanel;
647 WMScreen *scr = WMWidgetScreen(w);
648 static char *ipath = NULL;
650 opanel = WMGetOpenPanel(scr);
651 WMSetFilePanelCanChooseDirectories(opanel, False);
652 WMSetFilePanelCanChooseFiles(opanel, True);
654 if (!ipath)
655 ipath = wstrdup(wgethomedir());
657 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
658 "Open Image", NULL)) {
659 char *path, *fullpath;
660 char *tmp, *tmp2;
662 tmp = WMGetFilePanelFileName(opanel);
663 if (!tmp)
664 return;
665 fullpath = tmp;
667 wfree(ipath);
668 ipath = fullpath;
670 path = wstrdup(fullpath);
672 tmp2 = strrchr(fullpath, '/');
673 if (tmp2)
674 tmp2++;
676 tmp = wfindfileinarray(panel->pathList, tmp2);
678 if (tmp) {
679 if (strcmp(fullpath, tmp)==0) {
680 wfree(path);
681 path = tmp2;
683 wfree(tmp);
686 if (!RGetImageFileFormat(fullpath)) {
687 WMRunAlertPanel(scr, panel->win, _("Error"),
688 _("The selected file does not contain a supported image."),
689 _("OK"), NULL, NULL);
690 wfree(path);
691 } else {
692 updateImage(panel, fullpath);
693 wfree(panel->imageFile);
694 panel->imageFile = path;
696 WMSetTextFieldText(panel->imageT, path);
703 static void
704 buttonCallback(WMWidget *w, void *data)
706 TexturePanel *panel = (TexturePanel*)data;
708 if (w == panel->okB) {
709 (*panel->okAction)(panel->okData);
710 } else {
711 (*panel->cancelAction)(panel->cancelData);
717 static void
718 changeTypeCallback(WMWidget *w, void *data)
720 TexturePanel *panel = (TexturePanel*)data;
721 int newType;
722 int i;
724 newType = WMGetPopUpButtonSelectedItem(w);
725 if (newType == panel->currentType)
726 return;
728 if (panel->currentType >= 0) {
729 for (i = 0; i < MAX_SECTION_PARTS; i++) {
730 if (panel->sectionParts[panel->currentType][i] == NULL)
731 break;
732 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
736 for (i = 0; i < MAX_SECTION_PARTS; i++) {
737 if (panel->sectionParts[newType][i] == NULL)
738 break;
739 WMMapWidget(panel->sectionParts[newType][i]);
741 panel->currentType = newType;
743 switch (newType) {
744 case TYPE_SGRADIENT:
745 updateSGradButtons(panel);
746 WMSetButtonEnabled(panel->okB, True);
747 break;
748 case TYPE_GRADIENT:
749 updateGradButtons(panel);
750 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
751 break;
752 case TYPE_TGRADIENT:
753 case TYPE_PIXMAP:
754 updateImage(panel, NULL);
755 WMSetButtonEnabled(panel->okB, panel->image!=NULL);
756 break;
757 default:
758 WMSetButtonEnabled(panel->okB, True);
759 break;
765 *--------------------------------------------------------------------------
766 * Public functions
767 *--------------------------------------------------------------------------
769 void
770 DestroyTexturePanel(TexturePanel *panel)
776 void
777 ShowTexturePanel(TexturePanel *panel)
779 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
780 Screen *scr = DefaultScreenOfDisplay(dpy);
782 WMSetWindowInitialPosition(panel->win,
783 (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
784 (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
785 WMMapWidget(panel->win);
789 void
790 HideTexturePanel(TexturePanel *panel)
792 WMUnmapWidget(panel->win);
796 void
797 SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
799 panel->okAction = action;
800 panel->okData = clientData;
804 void
805 SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
807 panel->cancelAction = action;
808 panel->cancelData = clientData;
812 void
813 SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
815 WMScreen *scr = WMWidgetScreen(panel->win);
816 char *str, *type;
817 proplist_t p;
818 WMColor *color;
819 int i;
820 char buffer[64];
821 int gradient = 0;
823 WMSetTextFieldText(panel->nameT, name);
825 if (!texture)
826 return;
828 p = PLGetArrayElement(texture, 0);
829 if (!p) {
830 goto bad_texture;
832 type = PLGetString(p);
834 /*...............................................*/
835 if (strcasecmp(type, "solid")==0) {
837 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
839 p = PLGetArrayElement(texture, 1);
840 if (!p) {
841 str = "black";
842 } else {
843 str = PLGetString(p);
845 color = WMCreateNamedColor(scr, str, False);
847 WMSetColorWellColor(panel->defcW, color);
849 WMReleaseColor(color);
850 /*...............................................*/
851 } else if (strcasecmp(type, "hgradient")==0
852 || strcasecmp(type, "vgradient")==0
853 || strcasecmp(type, "dgradient")==0) {
855 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
857 p = PLGetArrayElement(texture, 1);
858 if (!p) {
859 str = "black";
860 } else {
861 str = PLGetString(p);
863 color = WMCreateNamedColor(scr, str, False);
865 WMSetColorWellColor(panel->tcol1W, color);
867 WMReleaseColor(color);
869 p = PLGetArrayElement(texture, 2);
870 if (!p) {
871 str = "black";
872 } else {
873 str = PLGetString(p);
875 color = WMCreateNamedColor(scr, str, False);
877 WMSetColorWellColor(panel->tcol2W, color);
879 WMReleaseColor(color);
881 gradient = type[0];
882 /*...............................................*/
883 } else if (strcasecmp(type, "thgradient")==0
884 || strcasecmp(type, "tvgradient")==0
885 || strcasecmp(type, "tdgradient")==0) {
886 int i;
888 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
890 gradient = type[1];
892 WMSetTextFieldText(panel->imageT,
893 PLGetString(PLGetArrayElement(texture, 1)));
894 if (panel->imageFile)
895 wfree(panel->imageFile);
896 panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
899 i = 180;
900 sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
901 WMSetSliderValue(panel->topaS, i);
903 p = PLGetArrayElement(texture, 3);
904 if (!p) {
905 str = "black";
906 } else {
907 str = PLGetString(p);
909 color = WMCreateNamedColor(scr, str, False);
911 WMSetColorWellColor(panel->tcol1W, color);
913 WMReleaseColor(color);
915 p = PLGetArrayElement(texture, 4);
916 if (!p) {
917 str = "black";
918 } else {
919 str = PLGetString(p);
921 color = WMCreateNamedColor(scr, str, False);
923 WMSetColorWellColor(panel->tcol2W, color);
925 WMReleaseColor(color);
927 WMSetTextFieldText(panel->imageT,
928 PLGetString(PLGetArrayElement(texture, 1)));
930 if (panel->imageFile)
931 wfree(panel->imageFile);
932 if ((panel->imageFile = wfindfileinarray(panel->pathList,
933 PLGetString(PLGetArrayElement(texture, 1)))) != NULL) {
935 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
936 updateTGradImage(panel);
938 updateSGradButtons(panel);
939 } else wwarning("could not load file '%s': %s", panel->imageFile,
940 RMessageForError(RErrorCode));
942 /*...............................................*/
943 } else if (strcasecmp(type, "mhgradient")==0
944 || strcasecmp(type, "mvgradient")==0
945 || strcasecmp(type, "mdgradient")==0) {
946 WMListItem *item;
948 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
949 item = WMGetListItem(panel->gcolL, i);
950 wfree(item->clientData);
952 WMClearList(panel->gcolL);
954 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
956 p = PLGetArrayElement(texture, 1);
957 if (!p) {
958 str = "black";
959 } else {
960 str = PLGetString(p);
962 color = WMCreateNamedColor(scr, str, False);
964 WMSetColorWellColor(panel->defcW, color);
966 WMReleaseColor(color);
968 for (i = 2; i < PLGetNumberOfElements(texture); i++) {
969 RColor *rgb;
970 XColor xcolor;
972 p = PLGetArrayElement(texture, i);
973 if (!p) {
974 str = "black";
975 } else {
976 str = PLGetString(p);
979 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
980 str, &xcolor);
982 rgb = wmalloc(sizeof(RColor));
983 rgb->red = xcolor.red >> 8;
984 rgb->green = xcolor.green >> 8;
985 rgb->blue = xcolor.blue >> 8;
986 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
988 item = WMAddListItem(panel->gcolL, buffer);
989 item->clientData = rgb;
992 sliderChangeCallback(panel->ghueS, panel);
994 gradient = type[1];
995 /*...............................................*/
996 } else if (strcasecmp(type, "cpixmap")==0
997 || strcasecmp(type, "spixmap")==0
998 || strcasecmp(type, "mpixmap")==0
999 || strcasecmp(type, "tpixmap")==0) {
1001 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
1003 switch (toupper(type[0])) {
1004 case 'C':
1005 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
1006 break;
1007 case 'S':
1008 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
1009 break;
1010 case 'M':
1011 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
1012 break;
1013 default:
1014 case 'T':
1015 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
1016 break;
1019 WMSetTextFieldText(panel->imageT,
1020 PLGetString(PLGetArrayElement(texture, 1)));
1022 if (panel->imageFile)
1023 wfree(panel->imageFile);
1024 panel->imageFile = wfindfileinarray(panel->pathList,
1025 PLGetString(PLGetArrayElement(texture, 1)));
1027 color = WMCreateNamedColor(scr,
1028 PLGetString(PLGetArrayElement(texture, 2)), False);
1029 WMSetColorWellColor(panel->defcW, color);
1030 WMReleaseColor(color);
1032 updateImage(panel, panel->imageFile);
1035 changeTypeCallback(panel->typeP, panel);
1037 if (gradient > 0) {
1038 updateGradButtons(panel);
1040 switch (toupper(gradient)) {
1041 case 'H':
1042 WMPerformButtonClick(panel->dirhB);
1043 break;
1044 case 'V':
1045 WMPerformButtonClick(panel->dirvB);
1046 break;
1047 default:
1048 case 'D':
1049 WMPerformButtonClick(panel->dirdB);
1050 break;
1054 return;
1056 bad_texture:
1057 str = PLGetDescription(texture);
1058 wwarning("error creating texture %s", str);
1059 wfree(str);
1065 char*
1066 GetTexturePanelTextureName(TexturePanel *panel)
1068 return WMGetTextFieldText(panel->nameT);
1074 proplist_t
1075 GetTexturePanelTexture(TexturePanel *panel)
1077 proplist_t prop = NULL;
1078 WMColor *color;
1079 char *str, *str2;
1080 char buff[32];
1081 int i;
1084 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
1086 case TYPE_SOLID:
1087 color = WMGetColorWellColor(panel->defcW);
1088 str = WMGetColorRGBDescription(color);
1089 prop = PLMakeArrayFromElements(PLMakeString("solid"),
1090 PLMakeString(str), NULL);
1091 wfree(str);
1093 break;
1095 case TYPE_PIXMAP:
1096 color = WMGetColorWellColor(panel->defcW);
1097 str = WMGetColorRGBDescription(color);
1099 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1100 case PTYPE_SCALE:
1101 prop = PLMakeArrayFromElements(PLMakeString("spixmap"),
1102 PLMakeString(panel->imageFile),
1103 PLMakeString(str), NULL);
1104 break;
1105 case PTYPE_MAXIMIZE:
1106 prop = PLMakeArrayFromElements(PLMakeString("mpixmap"),
1107 PLMakeString(panel->imageFile),
1108 PLMakeString(str), NULL);
1109 break;
1110 case PTYPE_CENTER:
1111 prop = PLMakeArrayFromElements(PLMakeString("cpixmap"),
1112 PLMakeString(panel->imageFile),
1113 PLMakeString(str), NULL);
1114 break;
1115 case PTYPE_TILE:
1116 prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
1117 PLMakeString(panel->imageFile),
1118 PLMakeString(str), NULL);
1119 break;
1121 wfree(str);
1122 break;
1124 case TYPE_TGRADIENT:
1125 color = WMGetColorWellColor(panel->tcol1W);
1126 str = WMGetColorRGBDescription(color);
1128 color = WMGetColorWellColor(panel->tcol2W);
1129 str2 = WMGetColorRGBDescription(color);
1131 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1133 if (WMGetButtonSelected(panel->dirdB)) {
1134 prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
1135 PLMakeString(panel->imageFile),
1136 PLMakeString(buff),
1137 PLMakeString(str),
1138 PLMakeString(str2), NULL);
1139 } else if (WMGetButtonSelected(panel->dirvB)) {
1140 prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
1141 PLMakeString(panel->imageFile),
1142 PLMakeString(buff),
1143 PLMakeString(str),
1144 PLMakeString(str2), NULL);
1145 } else {
1146 prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
1147 PLMakeString(panel->imageFile),
1148 PLMakeString(buff),
1149 PLMakeString(str),
1150 PLMakeString(str2), NULL);
1152 wfree(str);
1153 wfree(str2);
1154 break;
1157 case TYPE_SGRADIENT:
1158 color = WMGetColorWellColor(panel->tcol1W);
1159 str = WMGetColorRGBDescription(color);
1161 color = WMGetColorWellColor(panel->tcol2W);
1162 str2 = WMGetColorRGBDescription(color);
1164 if (WMGetButtonSelected(panel->dirdB)) {
1165 prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
1166 PLMakeString(str),
1167 PLMakeString(str2), NULL);
1168 } else if (WMGetButtonSelected(panel->dirvB)) {
1169 prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
1170 PLMakeString(str),
1171 PLMakeString(str2), NULL);
1172 } else {
1173 prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
1174 PLMakeString(str),
1175 PLMakeString(str2), NULL);
1177 wfree(str);
1178 wfree(str2);
1179 break;
1181 case TYPE_GRADIENT:
1182 color = WMGetColorWellColor(panel->defcW);
1183 str = WMGetColorRGBDescription(color);
1185 if (WMGetButtonSelected(panel->dirdB)) {
1186 prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
1187 PLMakeString(str), NULL);
1188 } else if (WMGetButtonSelected(panel->dirvB)) {
1189 prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
1190 PLMakeString(str), NULL);
1191 } else {
1192 prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
1193 PLMakeString(str), NULL);
1195 wfree(str);
1197 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1198 RColor *rgb;
1199 WMListItem *item;
1201 item = WMGetListItem(panel->gcolL, i);
1203 rgb = (RColor*)item->clientData;
1205 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1207 PLAppendArrayElement(prop, PLMakeString(buff));
1209 break;
1213 return prop;
1218 void
1219 SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
1221 panel->pathList = array;
1226 TexturePanel*
1227 CreateTexturePanel(WMWindow *keyWindow)
1228 /*CreateTexturePanel(WMScreen *scr)*/
1230 TexturePanel *panel;
1231 WMScreen *scr = WMWidgetScreen(keyWindow);
1233 panel = wmalloc(sizeof(TexturePanel));
1234 memset(panel, 0, sizeof(TexturePanel));
1236 panel->listFont = WMSystemFontOfSize(scr, 12);
1239 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1240 WMTitledWindowMask
1241 |WMClosableWindowMask);
1243 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1244 WMTitledWindowMask
1245 |WMClosableWindowMask);
1248 WMResizeWidget(panel->win, 325, 423);
1249 WMSetWindowTitle(panel->win, _("Texture Panel"));
1250 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1253 /* texture name */
1254 panel->nameF = WMCreateFrame(panel->win);
1255 WMResizeWidget(panel->nameF, 185, 50);
1256 WMMoveWidget(panel->nameF, 15, 10);
1257 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1259 panel->nameT = WMCreateTextField(panel->nameF);
1260 WMResizeWidget(panel->nameT, 160, 20);
1261 WMMoveWidget(panel->nameT, 12, 18);
1263 WMMapSubwidgets(panel->nameF);
1265 /* texture types */
1266 panel->typeP = WMCreatePopUpButton(panel->win);
1267 WMResizeWidget(panel->typeP, 185, 20);
1268 WMMoveWidget(panel->typeP, 15, 65);
1269 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1270 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1271 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1272 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1273 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1274 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1275 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1277 /* color */
1278 panel->defcF = WMCreateFrame(panel->win);
1279 WMResizeWidget(panel->defcF, 100, 75);
1280 WMMoveWidget(panel->defcF, 210, 10);
1281 WMSetFrameTitle(panel->defcF, _("Default Color"));
1283 panel->defcW = WMCreateColorWell(panel->defcF);
1284 WMResizeWidget(panel->defcW, 60, 45);
1285 WMMoveWidget(panel->defcW, 20, 20);
1287 WMMapSubwidgets(panel->defcF);
1289 /****** Gradient ******/
1290 panel->gcolF = WMCreateFrame(panel->win);
1291 WMResizeWidget(panel->gcolF, 295, 205);
1292 WMMoveWidget(panel->gcolF, 15, 95);
1293 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1295 panel->gcolL = WMCreateList(panel->gcolF);
1296 WMResizeWidget(panel->gcolL, 130, 140);
1297 WMMoveWidget(panel->gcolL, 10, 25);
1298 WMHangData(panel->gcolL, panel);
1299 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1300 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1302 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1303 WMResizeWidget(panel->gcolaB, 64, 24);
1304 WMMoveWidget(panel->gcolaB, 10, 170);
1305 WMSetButtonText(panel->gcolaB, _("Add"));
1306 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1308 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1309 WMResizeWidget(panel->gcoldB, 64, 24);
1310 WMMoveWidget(panel->gcoldB, 75, 170);
1311 WMSetButtonText(panel->gcoldB, _("Delete"));
1312 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1314 #if 0
1315 panel->gbriS = WMCreateSlider(panel->gcolF);
1316 WMResizeWidget(panel->gbriS, 130, 16);
1317 WMMoveWidget(panel->gbriS, 150, 25);
1318 WMSetSliderKnobThickness(panel->gbriS, 8);
1319 WMSetSliderMaxValue(panel->gbriS, 100);
1320 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1322 WMPixmap *pixmap;
1323 WMColor *color;
1325 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1326 color = WMDarkGrayColor(scr);
1327 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1328 WMColorGC(color), 0, 0, 130, 16);
1329 WMReleaseColor(color);
1330 color = WMWhiteColor(color);
1331 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1332 panel->listFont, 2,
1333 (16 - WMFontHeight(panel->listFont))/2 - 1,
1334 "Brightness", 10);
1335 WMSetSliderImage(panel->gbriS, pixmap);
1336 WMReleasePixmap(pixmap);
1339 panel->gconS = WMCreateSlider(panel->gcolF);
1340 WMResizeWidget(panel->gconS, 130, 16);
1341 WMMoveWidget(panel->gconS, 150, 50);
1342 WMSetSliderKnobThickness(panel->gconS, 8);
1343 WMSetSliderMaxValue(panel->gconS, 100);
1344 WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
1346 WMPixmap *pixmap;
1347 WMColor *color;
1349 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1350 color = WMDarkGrayColor(scr);
1351 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
1352 WMColorGC(color), 0, 0, 130, 16);
1353 WMReleaseColor(color);
1354 color = WMWhiteColor(scr);
1355 WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
1356 panel->listFont, 2,
1357 (16 - WMFontHeight(panel->listFont))/2 - 1,
1358 "Contrast", 8);
1359 WMSetSliderImage(panel->gconS, pixmap);
1360 WMReleasePixmap(pixmap);
1362 #endif
1363 panel->ghueS = WMCreateSlider(panel->gcolF);
1364 WMResizeWidget(panel->ghueS, 130, 16);
1365 WMMoveWidget(panel->ghueS, 150, 100);
1366 WMSetSliderKnobThickness(panel->ghueS, 8);
1367 WMSetSliderMaxValue(panel->ghueS, 359);
1368 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1370 panel->gsatS = WMCreateSlider(panel->gcolF);
1371 WMResizeWidget(panel->gsatS, 130, 16);
1372 WMMoveWidget(panel->gsatS, 150, 125);
1373 WMSetSliderKnobThickness(panel->gsatS, 8);
1374 WMSetSliderMaxValue(panel->gsatS, 255);
1375 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1377 panel->gvalS = WMCreateSlider(panel->gcolF);
1378 WMResizeWidget(panel->gvalS, 130, 16);
1379 WMMoveWidget(panel->gvalS, 150, 150);
1380 WMSetSliderKnobThickness(panel->gvalS, 8);
1381 WMSetSliderMaxValue(panel->gvalS, 255);
1382 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1385 WMMapSubwidgets(panel->gcolF);
1387 /** Direction **/
1388 panel->dirF = WMCreateFrame(panel->win);
1389 WMSetFrameTitle(panel->dirF, _("Direction"));
1390 WMResizeWidget(panel->dirF, 295, 75);
1391 WMMoveWidget(panel->dirF, 15, 305);
1393 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1394 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1395 WMResizeWidget(panel->dirvB, 90, 40);
1396 WMMoveWidget(panel->dirvB, 10, 20);
1398 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1399 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1400 WMResizeWidget(panel->dirhB, 90, 40);
1401 WMMoveWidget(panel->dirhB, 102, 20);
1403 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1404 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1405 WMResizeWidget(panel->dirdB, 90, 40);
1406 WMMoveWidget(panel->dirdB, 194, 20);
1408 WMGroupButtons(panel->dirvB, panel->dirhB);
1409 WMGroupButtons(panel->dirvB, panel->dirdB);
1411 WMMapSubwidgets(panel->dirF);
1413 /****************** Textured Gradient ******************/
1414 panel->tcolF = WMCreateFrame(panel->win);
1415 WMResizeWidget(panel->tcolF, 100, 135);
1416 WMMoveWidget(panel->tcolF, 210, 10);
1417 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1419 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1420 WMResizeWidget(panel->tcol1W, 60, 45);
1421 WMMoveWidget(panel->tcol1W, 20, 25);
1422 WMAddNotificationObserver(colorWellObserver, panel,
1423 WMColorWellDidChangeNotification, panel->tcol1W);
1425 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1426 WMResizeWidget(panel->tcol2W, 60, 45);
1427 WMMoveWidget(panel->tcol2W, 20, 75);
1428 WMAddNotificationObserver(colorWellObserver, panel,
1429 WMColorWellDidChangeNotification, panel->tcol2W);
1431 /** Opacity */
1432 panel->topaF = WMCreateFrame(panel->win);
1433 WMResizeWidget(panel->topaF, 185, 50);
1434 WMMoveWidget(panel->topaF, 15, 95);
1435 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1437 panel->topaS = WMCreateSlider(panel->topaF);
1438 WMResizeWidget(panel->topaS, 155, 18);
1439 WMMoveWidget(panel->topaS, 15, 20);
1440 WMSetSliderMaxValue(panel->topaS, 255);
1441 WMSetSliderValue(panel->topaS, 200);
1442 WMSetSliderContinuous(panel->topaS, False);
1443 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1445 WMMapSubwidgets(panel->topaF);
1448 WMPixmap *pixmap;
1449 Pixmap p;
1450 WMColor *color;
1452 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1453 p = WMGetPixmapXID(pixmap);
1455 color = WMDarkGrayColor(scr);
1456 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
1457 0, 0, 155, 18);
1458 WMReleaseColor(color);
1460 color = WMWhiteColor(scr);
1461 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1462 2, 1, "0%", 2);
1463 WMDrawString(scr, p, WMColorGC(color), panel->listFont,
1464 153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
1465 "100%", 4);
1466 WMReleaseColor(color);
1468 WMSetSliderImage(panel->topaS, pixmap);
1469 WMReleasePixmap(pixmap);
1472 WMMapSubwidgets(panel->tcolF);
1474 /****************** Image ******************/
1475 panel->imageF = WMCreateFrame(panel->win);
1476 WMResizeWidget(panel->imageF, 295, 150);
1477 WMMoveWidget(panel->imageF, 15, 150);
1478 WMSetFrameTitle(panel->imageF, _("Image"));
1480 panel->imageL = WMCreateLabel(panel->imageF);
1481 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1483 panel->imageT = WMCreateTextField(panel->imageF);
1484 WMResizeWidget(panel->imageT, 90, 20);
1485 WMMoveWidget(panel->imageT, 190, 25);
1487 panel->imageV = WMCreateScrollView(panel->imageF);
1488 WMResizeWidget(panel->imageV, 165, 115);
1489 WMMoveWidget(panel->imageV, 15, 20);
1490 WMSetScrollViewRelief(panel->imageV, WRSunken);
1491 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1492 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1493 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1495 panel->browB = WMCreateCommandButton(panel->imageF);
1496 WMResizeWidget(panel->browB, 90, 24);
1497 WMMoveWidget(panel->browB, 190, 50);
1498 WMSetButtonText(panel->browB, _("Browse..."));
1499 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1501 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1502 WMResizeWidget(panel->dispB, 90, 24);
1503 WMMoveWidget(panel->dispB, 190, 80);
1504 WMSetButtonText(panel->dispB, _("Show"));
1507 panel->arrP = WMCreatePopUpButton(panel->imageF);
1508 WMResizeWidget(panel->arrP, 90, 20);
1509 WMMoveWidget(panel->arrP, 190, 120);
1510 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1511 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1512 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1513 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1514 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1516 WMMapSubwidgets(panel->imageF);
1518 /****/
1520 panel->okB = WMCreateCommandButton(panel->win);
1521 WMResizeWidget(panel->okB, 84, 24);
1522 WMMoveWidget(panel->okB, 225, 390);
1523 WMSetButtonText(panel->okB, _("OK"));
1524 WMSetButtonAction(panel->okB, buttonCallback, panel);
1526 panel->cancelB = WMCreateCommandButton(panel->win);
1527 WMResizeWidget(panel->cancelB, 84, 24);
1528 WMMoveWidget(panel->cancelB, 130, 390);
1529 WMSetButtonText(panel->cancelB, _("Cancel"));
1530 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1532 WMMapWidget(panel->nameF);
1533 WMMapWidget(panel->typeP);
1534 WMMapWidget(panel->okB);
1535 WMMapWidget(panel->cancelB);
1537 WMUnmapWidget(panel->arrP);
1539 WMRealizeWidget(panel->win);
1541 panel->currentType = -1;
1543 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1545 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1546 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1547 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1549 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1550 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1552 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1553 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1554 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1555 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1556 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1558 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1559 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1560 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1563 /* setup for first time */
1565 changeTypeCallback(panel->typeP, panel);
1567 sliderChangeCallback(panel->ghueS, panel);
1568 sliderChangeCallback(panel->gsatS, panel);
1570 return panel;
1576 *--------------------------------------------------------------------------
1577 * Test stuff
1578 *--------------------------------------------------------------------------
1581 #if 0
1583 char *ProgName = "test";
1585 void
1586 testOKButton(WMWidget *self, void *data)
1588 char *test;
1589 Display *dpy;
1590 Window win;
1591 Pixmap pix;
1592 RImage *image;
1594 TexturePanel *panel = (TexturePanel*)data;
1595 /* test = GetTexturePanelTextureString(panel); */
1597 wwarning(test);
1599 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1600 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
1601 0, 0, 0);
1602 XMapRaised(dpy, win);
1603 XFlush(dpy);
1605 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1607 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1609 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height,
1610 0, 0);
1612 wfree (test);
1616 void testCancelButton(WMWidget *self, void *data){
1617 wwarning("Exiting test....");
1618 exit(0);
1621 void wAbort()
1623 exit(1);
1626 int main(int argc, char **argv)
1628 TexturePanel *panel;
1630 Display *dpy = XOpenDisplay("");
1631 WMScreen *scr;
1633 /* char *test; */
1635 WMInitializeApplication("Test", &argc, argv);
1637 if (!dpy) {
1638 wfatal("could not open display");
1639 exit(1);
1642 scr = WMCreateSimpleApplicationScreen(dpy);
1644 panel = CreateTexturePanel(scr);
1646 SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
1647 SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
1649 SetTexturePanelTexture(panel, "pinky",
1650 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1652 ShowTexturePanel(panel);
1654 WMScreenMainLoop(scr);
1655 return 0;
1657 #endif