Get rid of cropline(), use wtrimspace() instead
[wmaker-crm.git] / WPrefs.app / TexturePanel.c
blobae3ee64bb174042bad10bc1e86fb9ef082120789
1 /* TexturePanel.c- texture editting panel
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * Copyright (c) 1998 James Thompson
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <ctype.h>
29 #include <X11/Xlib.h>
31 #include <WINGs/WINGs.h>
33 #include "WPrefs.h"
35 #include "TexturePanel.h"
37 #define MAX_SECTION_PARTS 5
39 typedef struct _TexturePanel {
40 WMWindow *win;
42 /* texture name */
43 WMFrame *nameF;
44 WMTextField *nameT;
46 /* texture type */
47 WMPopUpButton *typeP;
49 /* default color */
50 WMFrame *defcF;
51 WMColorWell *defcW;
53 WMFont *listFont;
55 /*-- Gradient --*/
57 Pixmap gimage;
59 /* colors */
60 WMFrame *gcolF;
61 WMList *gcolL;
62 WMButton *gcolaB;
63 WMButton *gcoldB;
64 WMSlider *ghueS;
65 WMSlider *gsatS;
66 WMSlider *gvalS;
68 WMSlider *gbriS;
69 WMSlider *gconS;
71 /* direction (common) */
72 WMFrame *dirF;
73 WMButton *dirhB;
74 WMButton *dirvB;
75 WMButton *dirdB;
77 /*-- Simple Gradient --*/
79 /*-- Textured Gradient --*/
81 WMFrame *tcolF;
82 WMColorWell *tcol1W;
83 WMColorWell *tcol2W;
85 WMFrame *topaF;
86 WMSlider *topaS;
88 /*-- Image --*/
89 WMFrame *imageF;
90 WMScrollView *imageV;
91 WMTextField *imageT;
92 WMLabel *imageL;
93 WMButton *browB;
94 WMButton *dispB;
95 WMPopUpButton *arrP;
97 RImage *image;
98 char *imageFile;
100 /*****/
102 WMButton *okB;
103 WMButton *cancelB;
105 WMCallback *okAction;
106 void *okData;
108 WMCallback *cancelAction;
109 void *cancelData;
111 /****/
112 WMWidget *sectionParts[5][MAX_SECTION_PARTS];
114 int currentType;
116 WMPropList *pathList;
118 } _TexturePanel;
120 #define TYPE_SOLID 0
121 #define TYPE_GRADIENT 1
122 #define TYPE_SGRADIENT 2
123 #define TYPE_TGRADIENT 3
124 #define TYPE_PIXMAP 4
126 #define PTYPE_TILE 0
127 #define PTYPE_SCALE 1
128 #define PTYPE_CENTER 2
129 #define PTYPE_MAXIMIZE 3
132 *--------------------------------------------------------------------------
133 * Private Functions
134 *--------------------------------------------------------------------------
137 /************/
139 static void updateGradButtons(TexturePanel * panel)
141 RImage *image;
142 WMPixmap *pixmap;
143 int colorn;
144 RColor **colors;
146 colorn = WMGetListNumberOfRows(panel->gcolL);
147 if (colorn < 1) {
148 pixmap = NULL;
149 } else {
150 int i;
151 WMListItem *item;
153 colors = wmalloc(sizeof(RColor *) * (colorn + 1));
155 for (i = 0; i < colorn; i++) {
156 item = WMGetListItem(panel->gcolL, i);
157 colors[i] = (RColor *) item->clientData;
159 colors[i] = NULL;
161 image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
162 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
163 RReleaseImage(image);
164 WMSetButtonImage(panel->dirhB, pixmap);
165 WMReleasePixmap(pixmap);
167 image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
168 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
169 RReleaseImage(image);
170 WMSetButtonImage(panel->dirvB, pixmap);
171 WMReleasePixmap(pixmap);
173 image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
174 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
175 RReleaseImage(image);
176 WMSetButtonImage(panel->dirdB, pixmap);
177 WMReleasePixmap(pixmap);
179 wfree(colors);
183 static void updateTGradImage(TexturePanel * panel)
185 RImage *image, *gradient;
186 WMPixmap *pixmap;
187 RColor from;
188 RColor to;
189 WMColor *color;
191 if (!panel->image)
192 return;
194 color = WMGetColorWellColor(panel->tcol1W);
195 from.red = WMRedComponentOfColor(color) >> 8;
196 from.green = WMGreenComponentOfColor(color) >> 8;
197 from.blue = WMBlueComponentOfColor(color) >> 8;
199 color = WMGetColorWellColor(panel->tcol2W);
200 to.red = WMRedComponentOfColor(color) >> 8;
201 to.green = WMGreenComponentOfColor(color) >> 8;
202 to.blue = WMBlueComponentOfColor(color) >> 8;
204 if (panel->image->width < 141 || panel->image->height < 91) {
205 image = RMakeTiledImage(panel->image, 141, 91);
206 } else {
207 image = RCloneImage(panel->image);
210 if (WMGetButtonSelected(panel->dirhB)) {
211 gradient = RRenderGradient(image->width, image->height, &from, &to, RHorizontalGradient);
212 } else if (WMGetButtonSelected(panel->dirvB)) {
213 gradient = RRenderGradient(image->width, image->height, &from, &to, RVerticalGradient);
214 } else {
215 gradient = RRenderGradient(image->width, image->height, &from, &to, RDiagonalGradient);
218 RCombineImagesWithOpaqueness(image, gradient, WMGetSliderValue(panel->topaS));
219 RReleaseImage(gradient);
220 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win), image, 128);
222 WMSetLabelImage(panel->imageL, pixmap);
223 WMReleasePixmap(pixmap);
224 WMResizeWidget(panel->imageL, image->width, image->height);
225 RReleaseImage(image);
228 static void updateSGradButtons(TexturePanel * panel)
230 RImage *image;
231 WMPixmap *pixmap;
232 RColor from;
233 RColor to;
234 WMColor *color;
236 color = WMGetColorWellColor(panel->tcol1W);
237 from.red = WMRedComponentOfColor(color) >> 8;
238 from.green = WMGreenComponentOfColor(color) >> 8;
239 from.blue = WMBlueComponentOfColor(color) >> 8;
241 color = WMGetColorWellColor(panel->tcol2W);
242 to.red = WMRedComponentOfColor(color) >> 8;
243 to.green = WMGreenComponentOfColor(color) >> 8;
244 to.blue = WMBlueComponentOfColor(color) >> 8;
246 image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
247 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
248 RReleaseImage(image);
249 WMSetButtonImage(panel->dirhB, pixmap);
250 WMReleasePixmap(pixmap);
252 image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
253 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
254 RReleaseImage(image);
255 WMSetButtonImage(panel->dirvB, pixmap);
256 WMReleasePixmap(pixmap);
258 image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
259 pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL), image, 128);
260 RReleaseImage(image);
261 WMSetButtonImage(panel->dirdB, pixmap);
262 WMReleasePixmap(pixmap);
265 /*********** Gradient ************/
267 static void updateSVSlider(WMSlider * sPtr, Bool saturation, WMFont * font, RHSVColor * hsv)
269 RImage *image;
270 WMPixmap *pixmap;
271 WMScreen *scr = WMWidgetScreen(sPtr);
272 RColor from, to;
273 RHSVColor tmp;
274 char *buffer;
276 tmp = *hsv;
277 if (saturation) {
278 tmp.saturation = 0;
279 RHSVtoRGB(&tmp, &from);
280 tmp.saturation = 255;
281 RHSVtoRGB(&tmp, &to);
282 } else {
283 tmp.value = 0;
284 RHSVtoRGB(&tmp, &from);
285 tmp.value = 255;
286 RHSVtoRGB(&tmp, &to);
288 image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
289 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
290 RReleaseImage(image);
292 if (saturation)
293 buffer = wstrdup(_("Saturation"));
294 else
295 buffer = wstrdup(_("Brightness"));
297 if (hsv->value < 128 || !saturation) {
298 WMColor *col = WMWhiteColor(scr);
300 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
301 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
302 WMReleaseColor(col);
303 } else {
304 WMColor *col = WMBlackColor(scr);
306 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
307 (16 - WMFontHeight(font)) / 2 - 1, buffer, strlen(buffer));
308 WMReleaseColor(col);
310 wfree(buffer);
311 WMSetSliderImage(sPtr, pixmap);
312 WMReleasePixmap(pixmap);
315 static void updateHueSlider(WMSlider * sPtr, WMFont * font, RHSVColor * hsv)
317 RColor *colors[8];
318 RImage *image;
319 WMPixmap *pixmap;
320 WMScreen *scr = WMWidgetScreen(sPtr);
321 RHSVColor thsv;
322 int i;
324 thsv = *hsv;
325 for (i = 0; i <= 6; i++) {
326 thsv.hue = (360 * i) / 6;
327 colors[i] = wmalloc(sizeof(RColor));
328 RHSVtoRGB(&thsv, colors[i]);
330 colors[i] = NULL;
332 image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
333 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
334 RReleaseImage(image);
336 if (hsv->value < 128) {
337 WMColor *col = WMWhiteColor(scr);
339 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
340 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
341 WMReleaseColor(col);
342 } else {
343 WMColor *col = WMBlackColor(scr);
345 WMDrawString(scr, WMGetPixmapXID(pixmap), col, font, 2,
346 (16 - WMFontHeight(font)) / 2 - 1, _("Hue"), strlen(_("Hue")));
347 WMReleaseColor(col);
349 WMSetSliderImage(sPtr, pixmap);
350 WMReleasePixmap(pixmap);
352 for (i = 0; i <= 6; i++)
353 wfree(colors[i]);
356 static void sliderChangeCallback(WMWidget * w, void *data)
358 TexturePanel *panel = (TexturePanel *) data;
359 RHSVColor hsv;
360 int row, rows;
361 WMListItem *item;
362 RColor **colors;
363 int i;
364 RImage *image;
365 WMScreen *scr = WMWidgetScreen(w);
367 hsv.hue = WMGetSliderValue(panel->ghueS);
368 hsv.saturation = WMGetSliderValue(panel->gsatS);
369 hsv.value = WMGetSliderValue(panel->gvalS);
371 row = WMGetListSelectedItemRow(panel->gcolL);
372 if (row >= 0) {
373 RColor *rgb;
375 item = WMGetListItem(panel->gcolL, row);
377 rgb = (RColor *) item->clientData;
379 RHSVtoRGB(&hsv, rgb);
381 sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
384 if (w == panel->ghueS) {
385 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
386 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
387 } else if (w == panel->gsatS) {
388 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
389 updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
390 } else {
391 updateHueSlider(panel->ghueS, panel->listFont, &hsv);
392 updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
395 rows = WMGetListNumberOfRows(panel->gcolL);
396 if (rows == 0)
397 return;
399 colors = wmalloc(sizeof(RColor *) * (rows + 1));
401 for (i = 0; i < rows; i++) {
402 item = WMGetListItem(panel->gcolL, i);
404 colors[i] = (RColor *) item->clientData;
406 colors[i] = NULL;
408 if (panel->gimage != None) {
409 XFreePixmap(WMScreenDisplay(scr), panel->gimage);
412 image = RRenderMultiGradient(30, i * WMGetListItemHeight(panel->gcolL), colors, RVerticalGradient);
413 RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
414 RReleaseImage(image);
416 wfree(colors);
418 WMRedisplayWidget(panel->gcolL);
420 updateGradButtons(panel);
423 static void paintGradListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
425 TexturePanel *panel = (TexturePanel *) WMGetHangedData(lPtr);
426 WMScreen *scr = WMWidgetScreen(lPtr);
427 WMColor *white = WMWhiteColor(scr);
428 WMColor *black = WMBlackColor(scr);
429 WMColor *gray = WMGrayColor(scr);
430 int width, height, x, y;
431 Display *dpy;
433 dpy = WMScreenDisplay(scr);
435 width = rect->size.width;
436 height = rect->size.height;
437 x = rect->pos.x;
438 y = rect->pos.y;
440 if (state & WLDSSelected)
441 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
442 else
443 XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height);
445 if (panel->gimage) {
446 XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
447 0, height * index, 30, height, x + 5, y);
449 WMDrawString(scr, d, black, panel->listFont, x + 40, y + 1, text, strlen(text));
451 WMReleaseColor(white);
452 WMReleaseColor(black);
453 WMReleaseColor(gray);
456 static void gradAddCallback(WMWidget * w, void *data)
458 TexturePanel *panel = (TexturePanel *) data;
459 WMListItem *item;
460 int row;
461 RColor *rgb;
463 row = WMGetListSelectedItemRow(panel->gcolL) + 1;
464 item = WMInsertListItem(panel->gcolL, row, "00,00,00");
465 rgb = wmalloc(sizeof(RColor));
466 memset(rgb, 0, sizeof(RColor));
467 item->clientData = rgb;
469 WMSelectListItem(panel->gcolL, row);
471 updateGradButtons(panel);
473 sliderChangeCallback(panel->ghueS, panel);
475 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
478 static void gradClickCallback(WMWidget * w, void *data)
480 TexturePanel *panel = (TexturePanel *) data;
481 WMListItem *item;
482 int row;
483 RHSVColor hsv;
485 row = WMGetListSelectedItemRow(w);
486 if (row < 0)
487 return;
489 item = WMGetListItem(panel->gcolL, row);
490 RRGBtoHSV((RColor *) item->clientData, &hsv);
492 WMSetSliderValue(panel->ghueS, hsv.hue);
493 WMSetSliderValue(panel->gsatS, hsv.saturation);
494 WMSetSliderValue(panel->gvalS, hsv.value);
496 sliderChangeCallback(panel->ghueS, panel);
497 sliderChangeCallback(panel->gsatS, panel);
500 static void gradDeleteCallback(WMWidget * w, void *data)
502 TexturePanel *panel = (TexturePanel *) data;
503 WMListItem *item;
504 int row;
506 row = WMGetListSelectedItemRow(panel->gcolL);
507 if (row < 0)
508 return;
510 item = WMGetListItem(panel->gcolL, row);
511 wfree(item->clientData);
513 WMRemoveListItem(panel->gcolL, row);
515 WMSelectListItem(panel->gcolL, row - 1);
517 updateGradButtons(panel);
519 gradClickCallback(panel->gcolL, panel);
521 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
524 /*************** Simple Gradient ***************/
526 static void colorWellObserver(void *self, WMNotification * n)
528 updateSGradButtons(self);
531 static void opaqChangeCallback(WMWidget * w, void *data)
533 TexturePanel *panel = (TexturePanel *) data;
535 updateTGradImage(panel);
538 /****************** Image ******************/
540 static void updateImage(TexturePanel * panel, char *path)
542 WMScreen *scr = WMWidgetScreen(panel->win);
543 RImage *image;
544 WMPixmap *pixmap;
545 WMSize size;
547 if (path) {
548 image = RLoadImage(WMScreenRContext(scr), path, 0);
549 if (!image) {
550 char *message;
552 message = wstrconcat(_("Could not load the selected file: "),
553 (char *)RMessageForError(RErrorCode));
555 WMRunAlertPanel(scr, panel->win, _("Error"), message, _("OK"), NULL, NULL);
557 if (!panel->image)
558 WMSetButtonEnabled(panel->okB, False);
560 wfree(message);
561 return;
564 WMSetButtonEnabled(panel->okB, True);
566 if (panel->image)
567 RReleaseImage(panel->image);
568 panel->image = image;
569 } else {
570 image = panel->image;
573 if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
574 if (image) {
575 pixmap = WMCreatePixmapFromRImage(scr, image, 128);
577 size = WMGetPixmapSize(pixmap);
578 WMSetLabelImage(panel->imageL, pixmap);
579 WMResizeWidget(panel->imageL, size.width, size.height);
581 WMReleasePixmap(pixmap);
583 } else {
584 updateTGradImage(panel);
588 static void browseImageCallback(WMWidget * w, void *data)
590 TexturePanel *panel = (TexturePanel *) data;
591 WMOpenPanel *opanel;
592 WMScreen *scr = WMWidgetScreen(w);
593 static char *ipath = NULL;
595 opanel = WMGetOpenPanel(scr);
596 WMSetFilePanelCanChooseDirectories(opanel, False);
597 WMSetFilePanelCanChooseFiles(opanel, True);
599 if (!ipath)
600 ipath = wstrdup(wgethomedir());
602 if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
603 char *path, *fullpath;
604 char *tmp, *tmp2;
606 tmp = WMGetFilePanelFileName(opanel);
607 if (!tmp)
608 return;
609 fullpath = tmp;
611 wfree(ipath);
612 ipath = fullpath;
614 path = wstrdup(fullpath);
616 tmp2 = strrchr(fullpath, '/');
617 if (tmp2)
618 tmp2++;
620 tmp = wfindfileinarray(panel->pathList, tmp2);
622 if (tmp) {
623 if (strcmp(fullpath, tmp) == 0) {
624 wfree(path);
625 path = tmp2;
627 wfree(tmp);
630 if (!RGetImageFileFormat(fullpath)) {
631 WMRunAlertPanel(scr, panel->win, _("Error"),
632 _("The selected file does not contain a supported image."),
633 _("OK"), NULL, NULL);
634 wfree(path);
635 } else {
636 updateImage(panel, fullpath);
637 wfree(panel->imageFile);
638 panel->imageFile = path;
640 WMSetTextFieldText(panel->imageT, path);
645 static void buttonCallback(WMWidget * w, void *data)
647 TexturePanel *panel = (TexturePanel *) data;
649 if (w == panel->okB) {
650 (*panel->okAction) (panel->okData);
651 } else {
652 (*panel->cancelAction) (panel->cancelData);
656 static void changeTypeCallback(WMWidget * w, void *data)
658 TexturePanel *panel = (TexturePanel *) data;
659 int newType;
660 int i;
662 newType = WMGetPopUpButtonSelectedItem(w);
663 if (newType == panel->currentType)
664 return;
666 if (panel->currentType >= 0) {
667 for (i = 0; i < MAX_SECTION_PARTS; i++) {
668 if (panel->sectionParts[panel->currentType][i] == NULL)
669 break;
670 WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
674 for (i = 0; i < MAX_SECTION_PARTS; i++) {
675 if (panel->sectionParts[newType][i] == NULL)
676 break;
677 WMMapWidget(panel->sectionParts[newType][i]);
679 panel->currentType = newType;
681 switch (newType) {
682 case TYPE_SGRADIENT:
683 updateSGradButtons(panel);
684 WMSetButtonEnabled(panel->okB, True);
685 break;
686 case TYPE_GRADIENT:
687 updateGradButtons(panel);
688 WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
689 break;
690 case TYPE_TGRADIENT:
691 case TYPE_PIXMAP:
692 updateImage(panel, NULL);
693 WMSetButtonEnabled(panel->okB, panel->image != NULL);
694 break;
695 default:
696 WMSetButtonEnabled(panel->okB, True);
697 break;
702 *--------------------------------------------------------------------------
703 * Public functions
704 *--------------------------------------------------------------------------
706 void DestroyTexturePanel(TexturePanel * panel)
711 void ShowTexturePanel(TexturePanel * panel)
713 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
714 Screen *scr = DefaultScreenOfDisplay(dpy);
716 WMSetWindowInitialPosition(panel->win,
717 (WidthOfScreen(scr) - WMWidgetWidth(panel->win)) / 2,
718 (HeightOfScreen(scr) - WMWidgetHeight(panel->win)) / 2);
719 WMMapWidget(panel->win);
722 void HideTexturePanel(TexturePanel * panel)
724 WMUnmapWidget(panel->win);
727 void SetTexturePanelOkAction(TexturePanel * panel, WMCallback * action, void *clientData)
729 panel->okAction = action;
730 panel->okData = clientData;
733 void SetTexturePanelCancelAction(TexturePanel * panel, WMCallback * action, void *clientData)
735 panel->cancelAction = action;
736 panel->cancelData = clientData;
739 void SetTexturePanelTexture(TexturePanel * panel, char *name, WMPropList * texture)
741 WMScreen *scr = WMWidgetScreen(panel->win);
742 char *str, *type;
743 WMPropList *p;
744 WMColor *color;
745 int i;
746 char buffer[64];
747 int gradient = 0;
749 WMSetTextFieldText(panel->nameT, name);
751 if (!texture)
752 return;
754 p = WMGetFromPLArray(texture, 0);
755 if (!p) {
756 goto bad_texture;
758 type = WMGetFromPLString(p);
760 /*............................................... */
761 if (strcasecmp(type, "solid") == 0) {
763 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
765 p = WMGetFromPLArray(texture, 1);
766 if (!p) {
767 str = "black";
768 } else {
769 str = WMGetFromPLString(p);
771 color = WMCreateNamedColor(scr, str, False);
773 WMSetColorWellColor(panel->defcW, color);
775 WMReleaseColor(color);
776 /*............................................... */
777 } else if (strcasecmp(type, "hgradient") == 0
778 || strcasecmp(type, "vgradient") == 0 || strcasecmp(type, "dgradient") == 0) {
780 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
782 p = WMGetFromPLArray(texture, 1);
783 if (!p) {
784 str = "black";
785 } else {
786 str = WMGetFromPLString(p);
788 color = WMCreateNamedColor(scr, str, False);
790 WMSetColorWellColor(panel->tcol1W, color);
792 WMReleaseColor(color);
794 p = WMGetFromPLArray(texture, 2);
795 if (!p) {
796 str = "black";
797 } else {
798 str = WMGetFromPLString(p);
800 color = WMCreateNamedColor(scr, str, False);
802 WMSetColorWellColor(panel->tcol2W, color);
804 WMReleaseColor(color);
806 gradient = type[0];
807 /*............................................... */
808 } else if (strcasecmp(type, "thgradient") == 0
809 || strcasecmp(type, "tvgradient") == 0 || strcasecmp(type, "tdgradient") == 0) {
810 int i;
812 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
814 gradient = type[1];
816 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
817 if (panel->imageFile)
818 wfree(panel->imageFile);
819 panel->imageFile = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 1)));
821 i = 180;
822 sscanf(WMGetFromPLString(WMGetFromPLArray(texture, 2)), "%i", &i);
823 WMSetSliderValue(panel->topaS, i);
825 p = WMGetFromPLArray(texture, 3);
826 if (!p) {
827 str = "black";
828 } else {
829 str = WMGetFromPLString(p);
831 color = WMCreateNamedColor(scr, str, False);
833 WMSetColorWellColor(panel->tcol1W, color);
835 WMReleaseColor(color);
837 p = WMGetFromPLArray(texture, 4);
838 if (!p) {
839 str = "black";
840 } else {
841 str = WMGetFromPLString(p);
843 color = WMCreateNamedColor(scr, str, False);
845 WMSetColorWellColor(panel->tcol2W, color);
847 WMReleaseColor(color);
849 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
851 if (panel->imageFile)
852 wfree(panel->imageFile);
853 if ((panel->imageFile = wfindfileinarray(panel->pathList,
854 WMGetFromPLString(WMGetFromPLArray(texture, 1)))) !=
855 NULL) {
857 panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
858 updateTGradImage(panel);
860 updateSGradButtons(panel);
861 } else
862 wwarning(_("could not load file '%s': %s"), panel->imageFile,
863 RMessageForError(RErrorCode));
865 /*............................................... */
866 } else if (strcasecmp(type, "mhgradient") == 0
867 || strcasecmp(type, "mvgradient") == 0 || strcasecmp(type, "mdgradient") == 0) {
868 WMListItem *item;
870 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
871 item = WMGetListItem(panel->gcolL, i);
872 wfree(item->clientData);
874 WMClearList(panel->gcolL);
876 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
878 p = WMGetFromPLArray(texture, 1);
879 if (!p) {
880 str = "black";
881 } else {
882 str = WMGetFromPLString(p);
884 color = WMCreateNamedColor(scr, str, False);
886 WMSetColorWellColor(panel->defcW, color);
888 WMReleaseColor(color);
890 for (i = 2; i < WMGetPropListItemCount(texture); i++) {
891 RColor *rgb;
892 XColor xcolor;
894 p = WMGetFromPLArray(texture, i);
895 if (!p) {
896 str = "black";
897 } else {
898 str = WMGetFromPLString(p);
901 XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap, str, &xcolor);
903 rgb = wmalloc(sizeof(RColor));
904 rgb->red = xcolor.red >> 8;
905 rgb->green = xcolor.green >> 8;
906 rgb->blue = xcolor.blue >> 8;
907 sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
909 item = WMAddListItem(panel->gcolL, buffer);
910 item->clientData = rgb;
913 sliderChangeCallback(panel->ghueS, panel);
915 gradient = type[1];
916 /*............................................... */
917 } else if (strcasecmp(type, "cpixmap") == 0
918 || strcasecmp(type, "spixmap") == 0
919 || strcasecmp(type, "mpixmap") == 0 || strcasecmp(type, "tpixmap") == 0) {
921 WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
923 switch (toupper(type[0])) {
924 case 'C':
925 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
926 break;
927 case 'S':
928 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
929 break;
930 case 'M':
931 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
932 break;
933 default:
934 case 'T':
935 WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
936 break;
939 WMSetTextFieldText(panel->imageT, WMGetFromPLString(WMGetFromPLArray(texture, 1)));
941 if (panel->imageFile)
942 wfree(panel->imageFile);
943 panel->imageFile = wfindfileinarray(panel->pathList,
944 WMGetFromPLString(WMGetFromPLArray(texture, 1)));
946 color = WMCreateNamedColor(scr, WMGetFromPLString(WMGetFromPLArray(texture, 2)), False);
947 WMSetColorWellColor(panel->defcW, color);
948 WMReleaseColor(color);
950 updateImage(panel, panel->imageFile);
953 changeTypeCallback(panel->typeP, panel);
955 if (gradient > 0) {
956 updateGradButtons(panel);
958 switch (toupper(gradient)) {
959 case 'H':
960 WMPerformButtonClick(panel->dirhB);
961 break;
962 case 'V':
963 WMPerformButtonClick(panel->dirvB);
964 break;
965 default:
966 case 'D':
967 WMPerformButtonClick(panel->dirdB);
968 break;
972 return;
974 bad_texture:
975 str = WMGetPropListDescription(texture, False);
976 wwarning(_("error creating texture %s"), str);
977 wfree(str);
981 char *GetTexturePanelTextureName(TexturePanel * panel)
983 return WMGetTextFieldText(panel->nameT);
987 WMPropList *GetTexturePanelTexture(TexturePanel * panel)
989 WMPropList *prop = NULL;
990 WMColor *color;
991 char *str, *str2;
992 char buff[32];
993 int i;
995 switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
997 case TYPE_SOLID:
998 color = WMGetColorWellColor(panel->defcW);
999 str = WMGetColorRGBDescription(color);
1000 prop = WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str), NULL);
1001 wfree(str);
1003 break;
1005 case TYPE_PIXMAP:
1006 color = WMGetColorWellColor(panel->defcW);
1007 str = WMGetColorRGBDescription(color);
1009 switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
1010 case PTYPE_SCALE:
1011 prop = WMCreatePLArray(WMCreatePLString("spixmap"),
1012 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1013 break;
1014 case PTYPE_MAXIMIZE:
1015 prop = WMCreatePLArray(WMCreatePLString("mpixmap"),
1016 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1017 break;
1018 case PTYPE_CENTER:
1019 prop = WMCreatePLArray(WMCreatePLString("cpixmap"),
1020 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1021 break;
1022 case PTYPE_TILE:
1023 prop = WMCreatePLArray(WMCreatePLString("tpixmap"),
1024 WMCreatePLString(panel->imageFile), WMCreatePLString(str), NULL);
1025 break;
1027 wfree(str);
1028 break;
1030 case TYPE_TGRADIENT:
1031 color = WMGetColorWellColor(panel->tcol1W);
1032 str = WMGetColorRGBDescription(color);
1034 color = WMGetColorWellColor(panel->tcol2W);
1035 str2 = WMGetColorRGBDescription(color);
1037 sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
1039 if (WMGetButtonSelected(panel->dirdB)) {
1040 prop = WMCreatePLArray(WMCreatePLString("tdgradient"),
1041 WMCreatePLString(panel->imageFile),
1042 WMCreatePLString(buff),
1043 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1044 } else if (WMGetButtonSelected(panel->dirvB)) {
1045 prop = WMCreatePLArray(WMCreatePLString("tvgradient"),
1046 WMCreatePLString(panel->imageFile),
1047 WMCreatePLString(buff),
1048 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1049 } else {
1050 prop = WMCreatePLArray(WMCreatePLString("thgradient"),
1051 WMCreatePLString(panel->imageFile),
1052 WMCreatePLString(buff),
1053 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1055 wfree(str);
1056 wfree(str2);
1057 break;
1059 case TYPE_SGRADIENT:
1060 color = WMGetColorWellColor(panel->tcol1W);
1061 str = WMGetColorRGBDescription(color);
1063 color = WMGetColorWellColor(panel->tcol2W);
1064 str2 = WMGetColorRGBDescription(color);
1066 if (WMGetButtonSelected(panel->dirdB)) {
1067 prop = WMCreatePLArray(WMCreatePLString("dgradient"),
1068 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1069 } else if (WMGetButtonSelected(panel->dirvB)) {
1070 prop = WMCreatePLArray(WMCreatePLString("vgradient"),
1071 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1072 } else {
1073 prop = WMCreatePLArray(WMCreatePLString("hgradient"),
1074 WMCreatePLString(str), WMCreatePLString(str2), NULL);
1076 wfree(str);
1077 wfree(str2);
1078 break;
1080 case TYPE_GRADIENT:
1081 color = WMGetColorWellColor(panel->defcW);
1082 str = WMGetColorRGBDescription(color);
1084 if (WMGetButtonSelected(panel->dirdB)) {
1085 prop = WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str), NULL);
1086 } else if (WMGetButtonSelected(panel->dirvB)) {
1087 prop = WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str), NULL);
1088 } else {
1089 prop = WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str), NULL);
1091 wfree(str);
1093 for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
1094 RColor *rgb;
1095 WMListItem *item;
1097 item = WMGetListItem(panel->gcolL, i);
1099 rgb = (RColor *) item->clientData;
1101 sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
1103 WMAddToPLArray(prop, WMCreatePLString(buff));
1105 break;
1108 return prop;
1111 void SetTexturePanelPixmapPath(TexturePanel * panel, WMPropList * array)
1113 panel->pathList = array;
1116 TexturePanel *CreateTexturePanel(WMWindow * keyWindow)
1117 /*CreateTexturePanel(WMScreen *scr)*/
1119 TexturePanel *panel;
1120 WMScreen *scr = WMWidgetScreen(keyWindow);
1122 panel = wmalloc(sizeof(TexturePanel));
1123 memset(panel, 0, sizeof(TexturePanel));
1125 panel->listFont = WMSystemFontOfSize(scr, 12);
1127 panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
1128 WMTitledWindowMask | WMClosableWindowMask);
1130 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1131 WMTitledWindowMask
1132 |WMClosableWindowMask);
1135 WMResizeWidget(panel->win, 325, 423);
1136 WMSetWindowTitle(panel->win, _("Texture Panel"));
1137 WMSetWindowCloseAction(panel->win, buttonCallback, panel);
1139 /* texture name */
1140 panel->nameF = WMCreateFrame(panel->win);
1141 WMResizeWidget(panel->nameF, 185, 50);
1142 WMMoveWidget(panel->nameF, 15, 10);
1143 WMSetFrameTitle(panel->nameF, _("Texture Name"));
1145 panel->nameT = WMCreateTextField(panel->nameF);
1146 WMResizeWidget(panel->nameT, 160, 20);
1147 WMMoveWidget(panel->nameT, 12, 18);
1149 WMMapSubwidgets(panel->nameF);
1151 /* texture types */
1152 panel->typeP = WMCreatePopUpButton(panel->win);
1153 WMResizeWidget(panel->typeP, 185, 20);
1154 WMMoveWidget(panel->typeP, 15, 65);
1155 WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
1156 WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
1157 WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
1158 WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
1159 WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
1160 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
1161 WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
1163 /* color */
1164 panel->defcF = WMCreateFrame(panel->win);
1165 WMResizeWidget(panel->defcF, 100, 75);
1166 WMMoveWidget(panel->defcF, 210, 10);
1167 WMSetFrameTitle(panel->defcF, _("Default Color"));
1169 panel->defcW = WMCreateColorWell(panel->defcF);
1170 WMResizeWidget(panel->defcW, 60, 45);
1171 WMMoveWidget(panel->defcW, 20, 20);
1173 WMMapSubwidgets(panel->defcF);
1175 /****** Gradient ******/
1176 panel->gcolF = WMCreateFrame(panel->win);
1177 WMResizeWidget(panel->gcolF, 295, 205);
1178 WMMoveWidget(panel->gcolF, 15, 95);
1179 WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
1181 panel->gcolL = WMCreateList(panel->gcolF);
1182 WMResizeWidget(panel->gcolL, 130, 140);
1183 WMMoveWidget(panel->gcolL, 10, 25);
1184 WMHangData(panel->gcolL, panel);
1185 WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
1186 WMSetListAction(panel->gcolL, gradClickCallback, panel);
1188 panel->gcolaB = WMCreateCommandButton(panel->gcolF);
1189 WMResizeWidget(panel->gcolaB, 64, 24);
1190 WMMoveWidget(panel->gcolaB, 10, 170);
1191 WMSetButtonText(panel->gcolaB, _("Add"));
1192 WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
1194 panel->gcoldB = WMCreateCommandButton(panel->gcolF);
1195 WMResizeWidget(panel->gcoldB, 64, 24);
1196 WMMoveWidget(panel->gcoldB, 75, 170);
1197 WMSetButtonText(panel->gcoldB, _("Delete"));
1198 WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
1200 #if 0
1201 panel->gbriS = WMCreateSlider(panel->gcolF);
1202 WMResizeWidget(panel->gbriS, 130, 16);
1203 WMMoveWidget(panel->gbriS, 150, 25);
1204 WMSetSliderKnobThickness(panel->gbriS, 8);
1205 WMSetSliderMaxValue(panel->gbriS, 100);
1206 WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
1208 WMPixmap *pixmap;
1209 WMColor *color;
1211 pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
1212 color = WMDarkGrayColor(scr);
1213 XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap), WMColorGC(color), 0, 0, 130, 16);
1214 WMReleaseColor(color);
1215 color = WMWhiteColor(color);
1216 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1217 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Brightness", 10);
1218 WMSetSliderImage(panel->gbriS, pixmap);
1219 WMReleasePixmap(pixmap);
1222 panel->gconS = WMCreateSlider(panel->gcolF);
1223 WMResizeWidget(panel->gconS, 130, 16);
1224 WMMoveWidget(panel->gconS, 150, 50);
1225 WMSetSliderKnobThickness(panel->gconS, 8);
1226 WMSetSliderMaxValue(panel->gconS, 100);
1227 WMSetSliderAction(panel->gconS, 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(scr);
1237 WMDrawString(scr, WMGetPixmapXID(pixmap), color,
1238 panel->listFont, 2, (16 - WMFontHeight(panel->listFont)) / 2 - 1, "Contrast", 8);
1239 WMSetSliderImage(panel->gconS, pixmap);
1240 WMReleasePixmap(pixmap);
1242 #endif
1243 panel->ghueS = WMCreateSlider(panel->gcolF);
1244 WMResizeWidget(panel->ghueS, 130, 16);
1245 WMMoveWidget(panel->ghueS, 150, 100);
1246 WMSetSliderKnobThickness(panel->ghueS, 8);
1247 WMSetSliderMaxValue(panel->ghueS, 359);
1248 WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
1250 panel->gsatS = WMCreateSlider(panel->gcolF);
1251 WMResizeWidget(panel->gsatS, 130, 16);
1252 WMMoveWidget(panel->gsatS, 150, 125);
1253 WMSetSliderKnobThickness(panel->gsatS, 8);
1254 WMSetSliderMaxValue(panel->gsatS, 255);
1255 WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
1257 panel->gvalS = WMCreateSlider(panel->gcolF);
1258 WMResizeWidget(panel->gvalS, 130, 16);
1259 WMMoveWidget(panel->gvalS, 150, 150);
1260 WMSetSliderKnobThickness(panel->gvalS, 8);
1261 WMSetSliderMaxValue(panel->gvalS, 255);
1262 WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
1264 WMMapSubwidgets(panel->gcolF);
1266 /** Direction **/
1267 panel->dirF = WMCreateFrame(panel->win);
1268 WMSetFrameTitle(panel->dirF, _("Direction"));
1269 WMResizeWidget(panel->dirF, 295, 75);
1270 WMMoveWidget(panel->dirF, 15, 305);
1272 panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
1273 WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
1274 WMResizeWidget(panel->dirvB, 90, 40);
1275 WMMoveWidget(panel->dirvB, 10, 20);
1277 panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
1278 WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
1279 WMResizeWidget(panel->dirhB, 90, 40);
1280 WMMoveWidget(panel->dirhB, 102, 20);
1282 panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
1283 WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
1284 WMResizeWidget(panel->dirdB, 90, 40);
1285 WMMoveWidget(panel->dirdB, 194, 20);
1287 WMGroupButtons(panel->dirvB, panel->dirhB);
1288 WMGroupButtons(panel->dirvB, panel->dirdB);
1290 WMMapSubwidgets(panel->dirF);
1292 /****************** Textured Gradient ******************/
1293 panel->tcolF = WMCreateFrame(panel->win);
1294 WMResizeWidget(panel->tcolF, 100, 135);
1295 WMMoveWidget(panel->tcolF, 210, 10);
1296 WMSetFrameTitle(panel->tcolF, _("Gradient"));
1298 panel->tcol1W = WMCreateColorWell(panel->tcolF);
1299 WMResizeWidget(panel->tcol1W, 60, 45);
1300 WMMoveWidget(panel->tcol1W, 20, 25);
1301 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol1W);
1303 panel->tcol2W = WMCreateColorWell(panel->tcolF);
1304 WMResizeWidget(panel->tcol2W, 60, 45);
1305 WMMoveWidget(panel->tcol2W, 20, 75);
1306 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->tcol2W);
1308 /** Opacity */
1309 panel->topaF = WMCreateFrame(panel->win);
1310 WMResizeWidget(panel->topaF, 185, 50);
1311 WMMoveWidget(panel->topaF, 15, 95);
1312 WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
1314 panel->topaS = WMCreateSlider(panel->topaF);
1315 WMResizeWidget(panel->topaS, 155, 18);
1316 WMMoveWidget(panel->topaS, 15, 20);
1317 WMSetSliderMaxValue(panel->topaS, 255);
1318 WMSetSliderValue(panel->topaS, 200);
1319 WMSetSliderContinuous(panel->topaS, False);
1320 WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
1322 WMMapSubwidgets(panel->topaF);
1325 WMPixmap *pixmap;
1326 Pixmap p;
1327 WMColor *color;
1329 pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
1330 p = WMGetPixmapXID(pixmap);
1332 color = WMDarkGrayColor(scr);
1333 XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color), 0, 0, 155, 18);
1334 WMReleaseColor(color);
1336 color = WMWhiteColor(scr);
1337 WMDrawString(scr, p, color, panel->listFont, 2, 1, "0%", 2);
1338 WMDrawString(scr, p, color, panel->listFont,
1339 153 - WMWidthOfString(panel->listFont, "100%", 4), 1, "100%", 4);
1340 WMReleaseColor(color);
1342 WMSetSliderImage(panel->topaS, pixmap);
1343 WMReleasePixmap(pixmap);
1346 WMMapSubwidgets(panel->tcolF);
1348 /****************** Image ******************/
1349 panel->imageF = WMCreateFrame(panel->win);
1350 WMResizeWidget(panel->imageF, 295, 150);
1351 WMMoveWidget(panel->imageF, 15, 150);
1352 WMSetFrameTitle(panel->imageF, _("Image"));
1354 panel->imageL = WMCreateLabel(panel->imageF);
1355 WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
1357 panel->imageT = WMCreateTextField(panel->imageF);
1358 WMResizeWidget(panel->imageT, 90, 20);
1359 WMMoveWidget(panel->imageT, 190, 25);
1361 panel->imageV = WMCreateScrollView(panel->imageF);
1362 WMResizeWidget(panel->imageV, 165, 115);
1363 WMMoveWidget(panel->imageV, 15, 20);
1364 WMSetScrollViewRelief(panel->imageV, WRSunken);
1365 WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
1366 WMSetScrollViewHasVerticalScroller(panel->imageV, True);
1367 WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
1369 panel->browB = WMCreateCommandButton(panel->imageF);
1370 WMResizeWidget(panel->browB, 90, 24);
1371 WMMoveWidget(panel->browB, 190, 50);
1372 WMSetButtonText(panel->browB, _("Browse..."));
1373 WMSetButtonAction(panel->browB, browseImageCallback, panel);
1375 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1376 WMResizeWidget(panel->dispB, 90, 24);
1377 WMMoveWidget(panel->dispB, 190, 80);
1378 WMSetButtonText(panel->dispB, _("Show"));
1381 panel->arrP = WMCreatePopUpButton(panel->imageF);
1382 WMResizeWidget(panel->arrP, 90, 20);
1383 WMMoveWidget(panel->arrP, 190, 120);
1384 WMAddPopUpButtonItem(panel->arrP, _("Tile"));
1385 WMAddPopUpButtonItem(panel->arrP, _("Scale"));
1386 WMAddPopUpButtonItem(panel->arrP, _("Center"));
1387 WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
1388 WMSetPopUpButtonSelectedItem(panel->arrP, 0);
1390 WMMapSubwidgets(panel->imageF);
1392 /****/
1394 panel->okB = WMCreateCommandButton(panel->win);
1395 WMResizeWidget(panel->okB, 84, 24);
1396 WMMoveWidget(panel->okB, 225, 390);
1397 WMSetButtonText(panel->okB, _("OK"));
1398 WMSetButtonAction(panel->okB, buttonCallback, panel);
1400 panel->cancelB = WMCreateCommandButton(panel->win);
1401 WMResizeWidget(panel->cancelB, 84, 24);
1402 WMMoveWidget(panel->cancelB, 130, 390);
1403 WMSetButtonText(panel->cancelB, _("Cancel"));
1404 WMSetButtonAction(panel->cancelB, buttonCallback, panel);
1406 WMMapWidget(panel->nameF);
1407 WMMapWidget(panel->typeP);
1408 WMMapWidget(panel->okB);
1409 WMMapWidget(panel->cancelB);
1411 WMUnmapWidget(panel->arrP);
1413 WMRealizeWidget(panel->win);
1415 panel->currentType = -1;
1417 panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
1419 panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
1420 panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
1421 panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
1423 panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
1424 panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
1426 panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
1427 panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
1428 panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
1429 panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
1430 panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
1432 panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
1433 panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
1434 panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
1436 /* setup for first time */
1438 changeTypeCallback(panel->typeP, panel);
1440 sliderChangeCallback(panel->ghueS, panel);
1441 sliderChangeCallback(panel->gsatS, panel);
1443 return panel;
1447 *--------------------------------------------------------------------------
1448 * Test stuff
1449 *--------------------------------------------------------------------------
1452 #if 0
1454 char *ProgName = "test";
1456 void testOKButton(WMWidget * self, void *data)
1458 char *test;
1459 Display *dpy;
1460 Window win;
1461 Pixmap pix;
1462 RImage *image;
1464 TexturePanel *panel = (TexturePanel *) data;
1465 /* test = GetTexturePanelTextureString(panel); */
1467 wwarning(test);
1469 dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
1470 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250, 0, 0, 0);
1471 XMapRaised(dpy, win);
1472 XFlush(dpy);
1474 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1476 RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
1478 XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width,
1479 image->height, 0, 0);
1481 wfree(test);
1485 void testCancelButton(WMWidget * self, void *data)
1487 wwarning("Exiting test....");
1488 exit(0);
1491 void wAbort()
1493 exit(1);
1496 int main(int argc, char **argv)
1498 TexturePanel *panel;
1500 Display *dpy = XOpenDisplay("");
1501 WMScreen *scr;
1503 /* char *test; */
1505 WMInitializeApplication("Test", &argc, argv);
1507 if (!dpy) {
1508 wfatal("could not open display");
1509 exit(1);
1512 scr = WMCreateSimpleApplicationScreen(dpy);
1514 panel = CreateTexturePanel(scr);
1516 SetTexturePanelOkAction(panel, (WMAction *) testOKButton, panel);
1517 SetTexturePanelCancelAction(panel, (WMAction *) testCancelButton, panel);
1519 SetTexturePanelTexture(panel, "pinky",
1520 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1522 ShowTexturePanel(panel);
1524 WMScreenMainLoop(scr);
1525 return 0;
1527 #endif