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.
31 #include <WINGs/WINGs.h>
35 #include "TexturePanel.h"
37 #define MAX_SECTION_PARTS 5
39 typedef struct _TexturePanel
{
71 /* direction (common) */
77 /*-- Simple Gradient --*/
79 /*-- Textured Gradient --*/
105 WMCallback
*okAction
;
108 WMCallback
*cancelAction
;
112 WMWidget
*sectionParts
[5][MAX_SECTION_PARTS
];
116 WMPropList
*pathList
;
121 #define TYPE_GRADIENT 1
122 #define TYPE_SGRADIENT 2
123 #define TYPE_TGRADIENT 3
124 #define TYPE_PIXMAP 4
127 #define PTYPE_SCALE 1
128 #define PTYPE_CENTER 2
129 #define PTYPE_MAXIMIZE 3
132 *--------------------------------------------------------------------------
134 *--------------------------------------------------------------------------
139 static void updateGradButtons(TexturePanel
* panel
)
146 colorn
= WMGetListNumberOfRows(panel
->gcolL
);
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
;
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
);
183 static void updateTGradImage(TexturePanel
* panel
)
185 RImage
*image
, *gradient
;
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);
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
);
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
)
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
)
271 WMScreen
*scr
= WMWidgetScreen(sPtr
);
279 RHSVtoRGB(&tmp
, &from
);
280 tmp
.saturation
= 255;
281 RHSVtoRGB(&tmp
, &to
);
284 RHSVtoRGB(&tmp
, &from
);
286 RHSVtoRGB(&tmp
, &to
);
288 image
= RRenderGradient(130, 16, &from
, &to
, RHorizontalGradient
);
289 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
290 RReleaseImage(image
);
293 buffer
= wstrdup(_("Saturation"));
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
));
304 WMColor
*col
= WMBlackColor(scr
);
306 WMDrawString(scr
, WMGetPixmapXID(pixmap
), col
, font
, 2,
307 (16 - WMFontHeight(font
)) / 2 - 1, buffer
, strlen(buffer
));
311 WMSetSliderImage(sPtr
, pixmap
);
312 WMReleasePixmap(pixmap
);
315 static void updateHueSlider(WMSlider
* sPtr
, WMFont
* font
, RHSVColor
* hsv
)
320 WMScreen
*scr
= WMWidgetScreen(sPtr
);
325 for (i
= 0; i
<= 6; i
++) {
326 thsv
.hue
= (360 * i
) / 6;
327 colors
[i
] = wmalloc(sizeof(RColor
));
328 RHSVtoRGB(&thsv
, colors
[i
]);
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")));
343 WMColor
*col
= WMBlackColor(scr
);
345 WMDrawString(scr
, WMGetPixmapXID(pixmap
), col
, font
, 2,
346 (16 - WMFontHeight(font
)) / 2 - 1, _("Hue"), strlen(_("Hue")));
349 WMSetSliderImage(sPtr
, pixmap
);
350 WMReleasePixmap(pixmap
);
352 for (i
= 0; i
<= 6; i
++)
356 static void sliderChangeCallback(WMWidget
* w
, void *data
)
358 TexturePanel
*panel
= (TexturePanel
*) data
;
364 WMScreen
*scr
= WMWidgetScreen(w
);
366 hsv
.hue
= WMGetSliderValue(panel
->ghueS
);
367 hsv
.saturation
= WMGetSliderValue(panel
->gsatS
);
368 hsv
.value
= WMGetSliderValue(panel
->gvalS
);
370 rows
= WMGetListNumberOfRows(panel
->gcolL
);
371 row
= WMGetListSelectedItemRow(panel
->gcolL
);
373 if (row
< 0 && rows
> 0) {
375 WMSelectListItem(panel
->gcolL
, row
);
376 item
= WMGetListItem(panel
->gcolL
, row
);
377 RRGBtoHSV((RColor
*) item
->clientData
, &hsv
);
379 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
380 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
381 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
387 item
= WMGetListItem(panel
->gcolL
, row
);
389 rgb
= (RColor
*) item
->clientData
;
391 RHSVtoRGB(&hsv
, rgb
);
393 sprintf(item
->text
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
396 if (w
== panel
->ghueS
) {
397 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
398 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
399 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
400 } else if (w
== panel
->gsatS
) {
401 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
402 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
404 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
405 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
411 colors
= wmalloc(sizeof(RColor
*) * (rows
+ 1));
413 for (i
= 0; i
< rows
; i
++) {
414 item
= WMGetListItem(panel
->gcolL
, i
);
416 colors
[i
] = (RColor
*) item
->clientData
;
420 if (panel
->gimage
!= None
) {
421 XFreePixmap(WMScreenDisplay(scr
), panel
->gimage
);
424 image
= RRenderMultiGradient(30, i
* WMGetListItemHeight(panel
->gcolL
), colors
, RVerticalGradient
);
425 RConvertImage(WMScreenRContext(scr
), image
, &panel
->gimage
);
426 RReleaseImage(image
);
430 WMRedisplayWidget(panel
->gcolL
);
432 updateGradButtons(panel
);
435 static void paintGradListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
437 TexturePanel
*panel
= (TexturePanel
*) WMGetHangedData(lPtr
);
438 WMScreen
*scr
= WMWidgetScreen(lPtr
);
439 WMColor
*white
= WMWhiteColor(scr
);
440 WMColor
*black
= WMBlackColor(scr
);
441 WMColor
*gray
= WMGrayColor(scr
);
442 int width
, height
, x
, y
;
445 dpy
= WMScreenDisplay(scr
);
447 width
= rect
->size
.width
;
448 height
= rect
->size
.height
;
452 if (state
& WLDSSelected
)
453 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
455 XFillRectangle(dpy
, d
, WMColorGC(gray
), x
, y
, width
, height
);
458 XCopyArea(WMScreenDisplay(scr
), panel
->gimage
, d
, WMColorGC(white
),
459 0, height
* index
, 30, height
, x
+ 5, y
);
461 WMDrawString(scr
, d
, black
, panel
->listFont
, x
+ 40, y
+ 1, text
, strlen(text
));
463 WMReleaseColor(white
);
464 WMReleaseColor(black
);
465 WMReleaseColor(gray
);
468 static void gradAddCallback(WMWidget
* w
, void *data
)
470 TexturePanel
*panel
= (TexturePanel
*) data
;
475 /* Parameter not used, but tell the compiler that it is ok */
478 row
= WMGetListSelectedItemRow(panel
->gcolL
) + 1;
479 item
= WMInsertListItem(panel
->gcolL
, row
, "00,00,00");
480 rgb
= wmalloc(sizeof(RColor
));
481 item
->clientData
= rgb
;
483 WMSelectListItem(panel
->gcolL
, row
);
485 updateGradButtons(panel
);
487 sliderChangeCallback(panel
->ghueS
, panel
);
489 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
492 static void gradClickCallback(WMWidget
* w
, void *data
)
494 TexturePanel
*panel
= (TexturePanel
*) data
;
499 row
= WMGetListSelectedItemRow(w
);
503 item
= WMGetListItem(panel
->gcolL
, row
);
504 RRGBtoHSV((RColor
*) item
->clientData
, &hsv
);
506 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
507 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
508 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
510 sliderChangeCallback(panel
->ghueS
, panel
);
511 sliderChangeCallback(panel
->gsatS
, panel
);
514 static void gradDeleteCallback(WMWidget
* w
, void *data
)
516 TexturePanel
*panel
= (TexturePanel
*) data
;
520 /* Parameter not used, but tell the compiler that it is ok */
523 row
= WMGetListSelectedItemRow(panel
->gcolL
);
527 item
= WMGetListItem(panel
->gcolL
, row
);
528 wfree(item
->clientData
);
530 WMRemoveListItem(panel
->gcolL
, row
);
532 WMSelectListItem(panel
->gcolL
, row
- 1);
534 rows
= WMGetListNumberOfRows(panel
->gcolL
);
536 WMSelectListItem(panel
->gcolL
, 0);
539 updateGradButtons(panel
);
541 gradClickCallback(panel
->gcolL
, panel
);
543 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
546 /*************** Simple Gradient ***************/
548 static void colorWellObserver(void *self
, WMNotification
* n
)
550 /* Parameter not used, but tell the compiler that it is ok */
553 updateSGradButtons(self
);
556 static void opaqChangeCallback(WMWidget
* w
, void *data
)
558 TexturePanel
*panel
= (TexturePanel
*) data
;
560 /* Parameter not used, but tell the compiler that it is ok */
563 updateTGradImage(panel
);
566 /****************** Image ******************/
568 static void updateImage(TexturePanel
* panel
, const char *path
)
570 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
576 image
= RLoadImage(WMScreenRContext(scr
), path
, 0);
580 message
= wstrconcat(_("Could not load the selected file: "),
581 (char *)RMessageForError(RErrorCode
));
583 WMRunAlertPanel(scr
, panel
->win
, _("Error"), message
, _("OK"), NULL
, NULL
);
586 WMSetButtonEnabled(panel
->okB
, False
);
592 WMSetButtonEnabled(panel
->okB
, True
);
595 RReleaseImage(panel
->image
);
596 panel
->image
= image
;
598 image
= panel
->image
;
601 if (WMGetPopUpButtonSelectedItem(panel
->typeP
) == TYPE_PIXMAP
) {
603 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
605 size
= WMGetPixmapSize(pixmap
);
606 WMSetLabelImage(panel
->imageL
, pixmap
);
607 WMResizeWidget(panel
->imageL
, size
.width
, size
.height
);
609 WMReleasePixmap(pixmap
);
612 updateTGradImage(panel
);
616 static void browseImageCallback(WMWidget
* w
, void *data
)
618 TexturePanel
*panel
= (TexturePanel
*) data
;
620 WMScreen
*scr
= WMWidgetScreen(w
);
621 static char *ipath
= NULL
;
623 opanel
= WMGetOpenPanel(scr
);
624 WMSetFilePanelCanChooseDirectories(opanel
, False
);
625 WMSetFilePanelCanChooseFiles(opanel
, True
);
628 ipath
= wstrdup(wgethomedir());
630 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, ipath
, _("Open Image"), NULL
)) {
631 char *path
, *fullpath
;
634 tmp
= WMGetFilePanelFileName(opanel
);
642 path
= wstrdup(fullpath
);
644 tmp2
= strrchr(fullpath
, '/');
648 tmp
= wfindfileinarray(panel
->pathList
, tmp2
);
651 if (strcmp(fullpath
, tmp
) == 0) {
658 if (!RGetImageFileFormat(fullpath
)) {
659 WMRunAlertPanel(scr
, panel
->win
, _("Error"),
660 _("The selected file does not contain a supported image."),
661 _("OK"), NULL
, NULL
);
664 updateImage(panel
, fullpath
);
665 wfree(panel
->imageFile
);
666 panel
->imageFile
= path
;
668 WMSetTextFieldText(panel
->imageT
, path
);
673 static void buttonCallback(WMWidget
* w
, void *data
)
675 TexturePanel
*panel
= (TexturePanel
*) data
;
677 if (w
== panel
->okB
) {
678 (*panel
->okAction
) (panel
->okData
);
680 (*panel
->cancelAction
) (panel
->cancelData
);
684 static void changeTypeCallback(WMWidget
* w
, void *data
)
686 TexturePanel
*panel
= (TexturePanel
*) data
;
690 newType
= WMGetPopUpButtonSelectedItem(w
);
691 if (newType
== panel
->currentType
)
694 if (panel
->currentType
>= 0) {
695 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
696 if (panel
->sectionParts
[panel
->currentType
][i
] == NULL
)
698 WMUnmapWidget(panel
->sectionParts
[panel
->currentType
][i
]);
702 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
703 if (panel
->sectionParts
[newType
][i
] == NULL
)
705 WMMapWidget(panel
->sectionParts
[newType
][i
]);
707 panel
->currentType
= newType
;
711 updateSGradButtons(panel
);
712 WMSetButtonEnabled(panel
->okB
, True
);
715 updateGradButtons(panel
);
716 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
720 updateImage(panel
, NULL
);
721 WMSetButtonEnabled(panel
->okB
, panel
->image
!= NULL
);
724 WMSetButtonEnabled(panel
->okB
, True
);
730 *--------------------------------------------------------------------------
732 *--------------------------------------------------------------------------
734 void ShowTexturePanel(TexturePanel
* panel
)
736 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
737 Screen
*scr
= DefaultScreenOfDisplay(dpy
);
739 WMSetWindowInitialPosition(panel
->win
,
740 (WidthOfScreen(scr
) - WMWidgetWidth(panel
->win
)) / 2,
741 (HeightOfScreen(scr
) - WMWidgetHeight(panel
->win
)) / 2);
742 WMMapWidget(panel
->win
);
745 void HideTexturePanel(TexturePanel
* panel
)
747 WMUnmapWidget(panel
->win
);
750 void SetTexturePanelOkAction(TexturePanel
* panel
, WMCallback
* action
, void *clientData
)
752 panel
->okAction
= action
;
753 panel
->okData
= clientData
;
756 void SetTexturePanelCancelAction(TexturePanel
* panel
, WMCallback
* action
, void *clientData
)
758 panel
->cancelAction
= action
;
759 panel
->cancelData
= clientData
;
762 void SetTexturePanelTexture(TexturePanel
* panel
, const char *name
, WMPropList
* texture
)
764 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
772 WMSetTextFieldText(panel
->nameT
, name
);
777 p
= WMGetFromPLArray(texture
, 0);
781 type
= WMGetFromPLString(p
);
783 /*............................................... */
784 if (strcasecmp(type
, "solid") == 0) {
786 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SOLID
);
788 p
= WMGetFromPLArray(texture
, 1);
792 str
= WMGetFromPLString(p
);
794 color
= WMCreateNamedColor(scr
, str
, False
);
796 WMSetColorWellColor(panel
->defcW
, color
);
798 WMReleaseColor(color
);
799 /*............................................... */
800 } else if (strcasecmp(type
, "hgradient") == 0
801 || strcasecmp(type
, "vgradient") == 0 || strcasecmp(type
, "dgradient") == 0) {
803 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SGRADIENT
);
805 p
= WMGetFromPLArray(texture
, 1);
809 str
= WMGetFromPLString(p
);
811 color
= WMCreateNamedColor(scr
, str
, False
);
813 WMSetColorWellColor(panel
->tcol1W
, color
);
815 WMReleaseColor(color
);
817 p
= WMGetFromPLArray(texture
, 2);
821 str
= WMGetFromPLString(p
);
823 color
= WMCreateNamedColor(scr
, str
, False
);
825 WMSetColorWellColor(panel
->tcol2W
, color
);
827 WMReleaseColor(color
);
830 /*............................................... */
831 } else if (strcasecmp(type
, "thgradient") == 0
832 || strcasecmp(type
, "tvgradient") == 0 || strcasecmp(type
, "tdgradient") == 0) {
835 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_TGRADIENT
);
839 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
840 if (panel
->imageFile
)
841 wfree(panel
->imageFile
);
842 panel
->imageFile
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
844 if (sscanf(WMGetFromPLString(WMGetFromPLArray(texture
, 2)), "%i", &i
) != 1)
846 WMSetSliderValue(panel
->topaS
, i
);
848 p
= WMGetFromPLArray(texture
, 3);
852 str
= WMGetFromPLString(p
);
854 color
= WMCreateNamedColor(scr
, str
, False
);
856 WMSetColorWellColor(panel
->tcol1W
, color
);
858 WMReleaseColor(color
);
860 p
= WMGetFromPLArray(texture
, 4);
864 str
= WMGetFromPLString(p
);
866 color
= WMCreateNamedColor(scr
, str
, False
);
868 WMSetColorWellColor(panel
->tcol2W
, color
);
870 WMReleaseColor(color
);
872 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
874 if (panel
->imageFile
)
875 wfree(panel
->imageFile
);
876 if ((panel
->imageFile
= wfindfileinarray(panel
->pathList
,
877 WMGetFromPLString(WMGetFromPLArray(texture
, 1)))) !=
880 panel
->image
= RLoadImage(WMScreenRContext(scr
), panel
->imageFile
, 0);
881 updateTGradImage(panel
);
883 updateSGradButtons(panel
);
885 wwarning(_("could not load file '%s': %s"), panel
->imageFile
,
886 RMessageForError(RErrorCode
));
888 /*............................................... */
889 } else if (strcasecmp(type
, "mhgradient") == 0
890 || strcasecmp(type
, "mvgradient") == 0 || strcasecmp(type
, "mdgradient") == 0) {
893 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
894 item
= WMGetListItem(panel
->gcolL
, i
);
895 wfree(item
->clientData
);
897 WMClearList(panel
->gcolL
);
899 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_GRADIENT
);
901 p
= WMGetFromPLArray(texture
, 1);
905 str
= WMGetFromPLString(p
);
907 color
= WMCreateNamedColor(scr
, str
, False
);
909 WMSetColorWellColor(panel
->defcW
, color
);
911 WMReleaseColor(color
);
913 for (i
= 2; i
< WMGetPropListItemCount(texture
); i
++) {
917 p
= WMGetFromPLArray(texture
, i
);
921 str
= WMGetFromPLString(p
);
924 XParseColor(WMScreenDisplay(scr
), WMScreenRContext(scr
)->cmap
, str
, &xcolor
);
926 rgb
= wmalloc(sizeof(RColor
));
927 rgb
->red
= xcolor
.red
>> 8;
928 rgb
->green
= xcolor
.green
>> 8;
929 rgb
->blue
= xcolor
.blue
>> 8;
930 sprintf(buffer
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
932 item
= WMAddListItem(panel
->gcolL
, buffer
);
933 item
->clientData
= rgb
;
936 sliderChangeCallback(panel
->ghueS
, panel
);
939 /*............................................... */
940 } else if (strcasecmp(type
, "cpixmap") == 0
941 || strcasecmp(type
, "spixmap") == 0
942 || strcasecmp(type
, "mpixmap") == 0 || strcasecmp(type
, "tpixmap") == 0) {
944 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_PIXMAP
);
946 switch (toupper(type
[0])) {
948 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_CENTER
);
951 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_SCALE
);
954 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_MAXIMIZE
);
958 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_TILE
);
962 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
964 if (panel
->imageFile
)
965 wfree(panel
->imageFile
);
966 panel
->imageFile
= wfindfileinarray(panel
->pathList
,
967 WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
969 color
= WMCreateNamedColor(scr
, WMGetFromPLString(WMGetFromPLArray(texture
, 2)), False
);
970 WMSetColorWellColor(panel
->defcW
, color
);
971 WMReleaseColor(color
);
973 updateImage(panel
, panel
->imageFile
);
976 changeTypeCallback(panel
->typeP
, panel
);
979 updateGradButtons(panel
);
981 switch (toupper(gradient
)) {
983 WMPerformButtonClick(panel
->dirhB
);
986 WMPerformButtonClick(panel
->dirvB
);
990 WMPerformButtonClick(panel
->dirdB
);
998 str
= WMGetPropListDescription(texture
, False
);
999 wwarning(_("error creating texture %s"), str
);
1004 char *GetTexturePanelTextureName(TexturePanel
* panel
)
1006 return WMGetTextFieldText(panel
->nameT
);
1010 WMPropList
*GetTexturePanelTexture(TexturePanel
* panel
)
1012 WMPropList
*prop
= NULL
;
1018 switch (WMGetPopUpButtonSelectedItem(panel
->typeP
)) {
1021 color
= WMGetColorWellColor(panel
->defcW
);
1022 str
= WMGetColorRGBDescription(color
);
1023 prop
= WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str
), NULL
);
1029 color
= WMGetColorWellColor(panel
->defcW
);
1030 str
= WMGetColorRGBDescription(color
);
1032 switch (WMGetPopUpButtonSelectedItem(panel
->arrP
)) {
1034 prop
= WMCreatePLArray(WMCreatePLString("spixmap"),
1035 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1037 case PTYPE_MAXIMIZE
:
1038 prop
= WMCreatePLArray(WMCreatePLString("mpixmap"),
1039 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1042 prop
= WMCreatePLArray(WMCreatePLString("cpixmap"),
1043 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1046 prop
= WMCreatePLArray(WMCreatePLString("tpixmap"),
1047 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1053 case TYPE_TGRADIENT
:
1054 color
= WMGetColorWellColor(panel
->tcol1W
);
1055 str
= WMGetColorRGBDescription(color
);
1057 color
= WMGetColorWellColor(panel
->tcol2W
);
1058 str2
= WMGetColorRGBDescription(color
);
1060 sprintf(buff
, "%i", WMGetSliderValue(panel
->topaS
));
1062 if (WMGetButtonSelected(panel
->dirdB
)) {
1063 prop
= WMCreatePLArray(WMCreatePLString("tdgradient"),
1064 WMCreatePLString(panel
->imageFile
),
1065 WMCreatePLString(buff
),
1066 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1067 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1068 prop
= WMCreatePLArray(WMCreatePLString("tvgradient"),
1069 WMCreatePLString(panel
->imageFile
),
1070 WMCreatePLString(buff
),
1071 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1073 prop
= WMCreatePLArray(WMCreatePLString("thgradient"),
1074 WMCreatePLString(panel
->imageFile
),
1075 WMCreatePLString(buff
),
1076 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1082 case TYPE_SGRADIENT
:
1083 color
= WMGetColorWellColor(panel
->tcol1W
);
1084 str
= WMGetColorRGBDescription(color
);
1086 color
= WMGetColorWellColor(panel
->tcol2W
);
1087 str2
= WMGetColorRGBDescription(color
);
1089 if (WMGetButtonSelected(panel
->dirdB
)) {
1090 prop
= WMCreatePLArray(WMCreatePLString("dgradient"),
1091 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1092 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1093 prop
= WMCreatePLArray(WMCreatePLString("vgradient"),
1094 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1096 prop
= WMCreatePLArray(WMCreatePLString("hgradient"),
1097 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1104 color
= WMGetColorWellColor(panel
->defcW
);
1105 str
= WMGetColorRGBDescription(color
);
1107 if (WMGetButtonSelected(panel
->dirdB
)) {
1108 prop
= WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str
), NULL
);
1109 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1110 prop
= WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str
), NULL
);
1112 prop
= WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str
), NULL
);
1116 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
1120 item
= WMGetListItem(panel
->gcolL
, i
);
1122 rgb
= (RColor
*) item
->clientData
;
1124 sprintf(buff
, "#%02x%02x%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
1126 WMAddToPLArray(prop
, WMCreatePLString(buff
));
1134 void SetTexturePanelPixmapPath(TexturePanel
* panel
, WMPropList
* array
)
1136 panel
->pathList
= array
;
1139 TexturePanel
*CreateTexturePanel(WMWindow
* keyWindow
)
1140 /*CreateTexturePanel(WMScreen *scr)*/
1142 TexturePanel
*panel
;
1143 WMScreen
*scr
= WMWidgetScreen(keyWindow
);
1145 panel
= wmalloc(sizeof(TexturePanel
));
1147 panel
->listFont
= WMSystemFontOfSize(scr
, 12);
1149 panel
->win
= WMCreatePanelWithStyleForWindow(keyWindow
, "texturePanel",
1150 WMTitledWindowMask
| WMClosableWindowMask
);
1152 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1154 |WMClosableWindowMask);
1157 WMResizeWidget(panel
->win
, 325, 423);
1158 WMSetWindowTitle(panel
->win
, _("Texture Panel"));
1159 WMSetWindowCloseAction(panel
->win
, buttonCallback
, panel
);
1162 panel
->nameF
= WMCreateFrame(panel
->win
);
1163 WMResizeWidget(panel
->nameF
, 185, 50);
1164 WMMoveWidget(panel
->nameF
, 15, 10);
1165 WMSetFrameTitle(panel
->nameF
, _("Texture Name"));
1167 panel
->nameT
= WMCreateTextField(panel
->nameF
);
1168 WMResizeWidget(panel
->nameT
, 160, 20);
1169 WMMoveWidget(panel
->nameT
, 12, 18);
1171 WMMapSubwidgets(panel
->nameF
);
1174 panel
->typeP
= WMCreatePopUpButton(panel
->win
);
1175 WMResizeWidget(panel
->typeP
, 185, 20);
1176 WMMoveWidget(panel
->typeP
, 15, 65);
1177 WMAddPopUpButtonItem(panel
->typeP
, _("Solid Color"));
1178 WMAddPopUpButtonItem(panel
->typeP
, _("Gradient Texture"));
1179 WMAddPopUpButtonItem(panel
->typeP
, _("Simple Gradient Texture"));
1180 WMAddPopUpButtonItem(panel
->typeP
, _("Textured Gradient"));
1181 WMAddPopUpButtonItem(panel
->typeP
, _("Image Texture"));
1182 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
1183 WMSetPopUpButtonAction(panel
->typeP
, changeTypeCallback
, panel
);
1186 panel
->defcF
= WMCreateFrame(panel
->win
);
1187 WMResizeWidget(panel
->defcF
, 100, 75);
1188 WMMoveWidget(panel
->defcF
, 210, 10);
1189 WMSetFrameTitle(panel
->defcF
, _("Default Color"));
1191 panel
->defcW
= WMCreateColorWell(panel
->defcF
);
1192 WMResizeWidget(panel
->defcW
, 60, 45);
1193 WMMoveWidget(panel
->defcW
, 20, 20);
1195 WMMapSubwidgets(panel
->defcF
);
1197 /****** Gradient ******/
1198 panel
->gcolF
= WMCreateFrame(panel
->win
);
1199 WMResizeWidget(panel
->gcolF
, 295, 205);
1200 WMMoveWidget(panel
->gcolF
, 15, 95);
1201 WMSetFrameTitle(panel
->gcolF
, _("Gradient Colors"));
1203 panel
->gcolL
= WMCreateList(panel
->gcolF
);
1204 WMResizeWidget(panel
->gcolL
, 130, 140);
1205 WMMoveWidget(panel
->gcolL
, 10, 25);
1206 WMHangData(panel
->gcolL
, panel
);
1207 WMSetListUserDrawProc(panel
->gcolL
, paintGradListItem
);
1208 WMSetListAction(panel
->gcolL
, gradClickCallback
, panel
);
1210 panel
->gcolaB
= WMCreateCommandButton(panel
->gcolF
);
1211 WMResizeWidget(panel
->gcolaB
, 64, 24);
1212 WMMoveWidget(panel
->gcolaB
, 10, 170);
1213 WMSetButtonText(panel
->gcolaB
, _("Add"));
1214 WMSetButtonAction(panel
->gcolaB
, gradAddCallback
, panel
);
1216 panel
->gcoldB
= WMCreateCommandButton(panel
->gcolF
);
1217 WMResizeWidget(panel
->gcoldB
, 64, 24);
1218 WMMoveWidget(panel
->gcoldB
, 75, 170);
1219 WMSetButtonText(panel
->gcoldB
, _("Delete"));
1220 WMSetButtonAction(panel
->gcoldB
, gradDeleteCallback
, panel
);
1223 panel
->gbriS
= WMCreateSlider(panel
->gcolF
);
1224 WMResizeWidget(panel
->gbriS
, 130, 16);
1225 WMMoveWidget(panel
->gbriS
, 150, 25);
1226 WMSetSliderKnobThickness(panel
->gbriS
, 8);
1227 WMSetSliderMaxValue(panel
->gbriS
, 100);
1228 WMSetSliderAction(panel
->gbriS
, sliderChangeCallback
, panel
);
1233 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1234 color
= WMDarkGrayColor(scr
);
1235 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
), WMColorGC(color
), 0, 0, 130, 16);
1236 WMReleaseColor(color
);
1237 color
= WMWhiteColor(color
);
1238 WMDrawString(scr
, WMGetPixmapXID(pixmap
), color
,
1239 panel
->listFont
, 2, (16 - WMFontHeight(panel
->listFont
)) / 2 - 1, "Brightness", 10);
1240 WMSetSliderImage(panel
->gbriS
, pixmap
);
1241 WMReleasePixmap(pixmap
);
1244 panel
->gconS
= WMCreateSlider(panel
->gcolF
);
1245 WMResizeWidget(panel
->gconS
, 130, 16);
1246 WMMoveWidget(panel
->gconS
, 150, 50);
1247 WMSetSliderKnobThickness(panel
->gconS
, 8);
1248 WMSetSliderMaxValue(panel
->gconS
, 100);
1249 WMSetSliderAction(panel
->gconS
, sliderChangeCallback
, panel
);
1254 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1255 color
= WMDarkGrayColor(scr
);
1256 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
), WMColorGC(color
), 0, 0, 130, 16);
1257 WMReleaseColor(color
);
1258 color
= WMWhiteColor(scr
);
1259 WMDrawString(scr
, WMGetPixmapXID(pixmap
), color
,
1260 panel
->listFont
, 2, (16 - WMFontHeight(panel
->listFont
)) / 2 - 1, "Contrast", 8);
1261 WMSetSliderImage(panel
->gconS
, pixmap
);
1262 WMReleasePixmap(pixmap
);
1265 panel
->ghueS
= WMCreateSlider(panel
->gcolF
);
1266 WMResizeWidget(panel
->ghueS
, 130, 16);
1267 WMMoveWidget(panel
->ghueS
, 150, 100);
1268 WMSetSliderKnobThickness(panel
->ghueS
, 8);
1269 WMSetSliderMaxValue(panel
->ghueS
, 359);
1270 WMSetSliderAction(panel
->ghueS
, sliderChangeCallback
, panel
);
1272 panel
->gsatS
= WMCreateSlider(panel
->gcolF
);
1273 WMResizeWidget(panel
->gsatS
, 130, 16);
1274 WMMoveWidget(panel
->gsatS
, 150, 125);
1275 WMSetSliderKnobThickness(panel
->gsatS
, 8);
1276 WMSetSliderMaxValue(panel
->gsatS
, 255);
1277 WMSetSliderAction(panel
->gsatS
, sliderChangeCallback
, panel
);
1279 panel
->gvalS
= WMCreateSlider(panel
->gcolF
);
1280 WMResizeWidget(panel
->gvalS
, 130, 16);
1281 WMMoveWidget(panel
->gvalS
, 150, 150);
1282 WMSetSliderKnobThickness(panel
->gvalS
, 8);
1283 WMSetSliderMaxValue(panel
->gvalS
, 255);
1284 WMSetSliderAction(panel
->gvalS
, sliderChangeCallback
, panel
);
1286 WMMapSubwidgets(panel
->gcolF
);
1289 panel
->dirF
= WMCreateFrame(panel
->win
);
1290 WMSetFrameTitle(panel
->dirF
, _("Direction"));
1291 WMResizeWidget(panel
->dirF
, 295, 75);
1292 WMMoveWidget(panel
->dirF
, 15, 305);
1294 panel
->dirvB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1295 WMSetButtonImagePosition(panel
->dirvB
, WIPImageOnly
);
1296 WMResizeWidget(panel
->dirvB
, 90, 40);
1297 WMMoveWidget(panel
->dirvB
, 10, 20);
1299 panel
->dirhB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1300 WMSetButtonImagePosition(panel
->dirhB
, WIPImageOnly
);
1301 WMResizeWidget(panel
->dirhB
, 90, 40);
1302 WMMoveWidget(panel
->dirhB
, 102, 20);
1304 panel
->dirdB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1305 WMSetButtonImagePosition(panel
->dirdB
, WIPImageOnly
);
1306 WMResizeWidget(panel
->dirdB
, 90, 40);
1307 WMMoveWidget(panel
->dirdB
, 194, 20);
1309 WMGroupButtons(panel
->dirvB
, panel
->dirhB
);
1310 WMGroupButtons(panel
->dirvB
, panel
->dirdB
);
1312 WMMapSubwidgets(panel
->dirF
);
1314 /****************** Textured Gradient ******************/
1315 panel
->tcolF
= WMCreateFrame(panel
->win
);
1316 WMResizeWidget(panel
->tcolF
, 100, 135);
1317 WMMoveWidget(panel
->tcolF
, 210, 10);
1318 WMSetFrameTitle(panel
->tcolF
, _("Gradient"));
1320 panel
->tcol1W
= WMCreateColorWell(panel
->tcolF
);
1321 WMResizeWidget(panel
->tcol1W
, 60, 45);
1322 WMMoveWidget(panel
->tcol1W
, 20, 25);
1323 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->tcol1W
);
1325 panel
->tcol2W
= WMCreateColorWell(panel
->tcolF
);
1326 WMResizeWidget(panel
->tcol2W
, 60, 45);
1327 WMMoveWidget(panel
->tcol2W
, 20, 75);
1328 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->tcol2W
);
1331 panel
->topaF
= WMCreateFrame(panel
->win
);
1332 WMResizeWidget(panel
->topaF
, 185, 50);
1333 WMMoveWidget(panel
->topaF
, 15, 95);
1334 WMSetFrameTitle(panel
->topaF
, _("Gradient Opacity"));
1336 panel
->topaS
= WMCreateSlider(panel
->topaF
);
1337 WMResizeWidget(panel
->topaS
, 155, 18);
1338 WMMoveWidget(panel
->topaS
, 15, 20);
1339 WMSetSliderMaxValue(panel
->topaS
, 255);
1340 WMSetSliderValue(panel
->topaS
, 200);
1341 WMSetSliderContinuous(panel
->topaS
, False
);
1342 WMSetSliderAction(panel
->topaS
, opaqChangeCallback
, panel
);
1344 WMMapSubwidgets(panel
->topaF
);
1351 pixmap
= WMCreatePixmap(scr
, 155, 18, WMScreenDepth(scr
), False
);
1352 p
= WMGetPixmapXID(pixmap
);
1354 color
= WMDarkGrayColor(scr
);
1355 XFillRectangle(WMScreenDisplay(scr
), p
, WMColorGC(color
), 0, 0, 155, 18);
1356 WMReleaseColor(color
);
1358 color
= WMWhiteColor(scr
);
1359 WMDrawString(scr
, p
, color
, panel
->listFont
, 2, 1, "0%", 2);
1360 WMDrawString(scr
, p
, color
, panel
->listFont
,
1361 153 - WMWidthOfString(panel
->listFont
, "100%", 4), 1, "100%", 4);
1362 WMReleaseColor(color
);
1364 WMSetSliderImage(panel
->topaS
, pixmap
);
1365 WMReleasePixmap(pixmap
);
1368 WMMapSubwidgets(panel
->tcolF
);
1370 /****************** Image ******************/
1371 panel
->imageF
= WMCreateFrame(panel
->win
);
1372 WMResizeWidget(panel
->imageF
, 295, 150);
1373 WMMoveWidget(panel
->imageF
, 15, 150);
1374 WMSetFrameTitle(panel
->imageF
, _("Image"));
1376 panel
->imageL
= WMCreateLabel(panel
->imageF
);
1377 WMSetLabelImagePosition(panel
->imageL
, WIPImageOnly
);
1379 panel
->imageT
= WMCreateTextField(panel
->imageF
);
1380 WMResizeWidget(panel
->imageT
, 90, 20);
1381 WMMoveWidget(panel
->imageT
, 190, 25);
1383 panel
->imageV
= WMCreateScrollView(panel
->imageF
);
1384 WMResizeWidget(panel
->imageV
, 165, 115);
1385 WMMoveWidget(panel
->imageV
, 15, 20);
1386 WMSetScrollViewRelief(panel
->imageV
, WRSunken
);
1387 WMSetScrollViewHasHorizontalScroller(panel
->imageV
, True
);
1388 WMSetScrollViewHasVerticalScroller(panel
->imageV
, True
);
1389 WMSetScrollViewContentView(panel
->imageV
, WMWidgetView(panel
->imageL
));
1391 panel
->browB
= WMCreateCommandButton(panel
->imageF
);
1392 WMResizeWidget(panel
->browB
, 90, 24);
1393 WMMoveWidget(panel
->browB
, 190, 50);
1394 WMSetButtonText(panel
->browB
, _("Browse..."));
1395 WMSetButtonAction(panel
->browB
, browseImageCallback
, panel
);
1397 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1398 WMResizeWidget(panel->dispB, 90, 24);
1399 WMMoveWidget(panel->dispB, 190, 80);
1400 WMSetButtonText(panel->dispB, _("Show"));
1403 panel
->arrP
= WMCreatePopUpButton(panel
->imageF
);
1404 WMResizeWidget(panel
->arrP
, 90, 20);
1405 WMMoveWidget(panel
->arrP
, 190, 120);
1406 WMAddPopUpButtonItem(panel
->arrP
, _("Tile"));
1407 WMAddPopUpButtonItem(panel
->arrP
, _("Scale"));
1408 WMAddPopUpButtonItem(panel
->arrP
, _("Center"));
1409 WMAddPopUpButtonItem(panel
->arrP
, _("Maximize"));
1410 WMSetPopUpButtonSelectedItem(panel
->arrP
, 0);
1412 WMMapSubwidgets(panel
->imageF
);
1416 panel
->okB
= WMCreateCommandButton(panel
->win
);
1417 WMResizeWidget(panel
->okB
, 84, 24);
1418 WMMoveWidget(panel
->okB
, 225, 390);
1419 WMSetButtonText(panel
->okB
, _("OK"));
1420 WMSetButtonAction(panel
->okB
, buttonCallback
, panel
);
1422 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
1423 WMResizeWidget(panel
->cancelB
, 84, 24);
1424 WMMoveWidget(panel
->cancelB
, 130, 390);
1425 WMSetButtonText(panel
->cancelB
, _("Cancel"));
1426 WMSetButtonAction(panel
->cancelB
, buttonCallback
, panel
);
1428 WMMapWidget(panel
->nameF
);
1429 WMMapWidget(panel
->typeP
);
1430 WMMapWidget(panel
->okB
);
1431 WMMapWidget(panel
->cancelB
);
1433 WMUnmapWidget(panel
->arrP
);
1435 WMRealizeWidget(panel
->win
);
1437 panel
->currentType
= -1;
1439 panel
->sectionParts
[TYPE_SOLID
][0] = panel
->defcF
;
1441 panel
->sectionParts
[TYPE_GRADIENT
][0] = panel
->defcF
;
1442 panel
->sectionParts
[TYPE_GRADIENT
][1] = panel
->gcolF
;
1443 panel
->sectionParts
[TYPE_GRADIENT
][2] = panel
->dirF
;
1445 panel
->sectionParts
[TYPE_SGRADIENT
][0] = panel
->tcolF
;
1446 panel
->sectionParts
[TYPE_SGRADIENT
][1] = panel
->dirF
;
1448 panel
->sectionParts
[TYPE_TGRADIENT
][0] = panel
->tcolF
;
1449 panel
->sectionParts
[TYPE_TGRADIENT
][1] = panel
->dirF
;
1450 panel
->sectionParts
[TYPE_TGRADIENT
][2] = panel
->imageF
;
1451 panel
->sectionParts
[TYPE_TGRADIENT
][3] = panel
->topaF
;
1452 panel
->sectionParts
[TYPE_TGRADIENT
][4] = panel
->arrP
;
1454 panel
->sectionParts
[TYPE_PIXMAP
][0] = panel
->defcF
;
1455 panel
->sectionParts
[TYPE_PIXMAP
][1] = panel
->imageF
;
1456 panel
->sectionParts
[TYPE_PIXMAP
][2] = panel
->arrP
;
1458 /* setup for first time */
1460 changeTypeCallback(panel
->typeP
, panel
);
1462 sliderChangeCallback(panel
->ghueS
, panel
);
1463 sliderChangeCallback(panel
->gsatS
, panel
);
1469 *--------------------------------------------------------------------------
1471 *--------------------------------------------------------------------------
1476 char *ProgName
= "test";
1478 void testOKButton(WMWidget
* self
, void *data
)
1486 TexturePanel
*panel
= (TexturePanel
*) data
;
1487 /* test = GetTexturePanelTextureString(panel); */
1491 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
1492 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250, 0, 0, 0);
1493 XMapRaised(dpy
, win
);
1496 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1498 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
1500 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
,
1501 image
->height
, 0, 0);
1507 void testCancelButton(WMWidget
* self
, void *data
)
1509 wwarning("Exiting test....");
1518 int main(int argc
, char **argv
)
1520 TexturePanel
*panel
;
1522 Display
*dpy
= XOpenDisplay("");
1527 WMInitializeApplication("Test", &argc
, argv
);
1530 wfatal("could not open display");
1534 scr
= WMCreateSimpleApplicationScreen(dpy
);
1536 panel
= CreateTexturePanel(scr
);
1538 SetTexturePanelOkAction(panel
, (WMAction
*) testOKButton
, panel
);
1539 SetTexturePanelCancelAction(panel
, (WMAction
*) testCancelButton
, panel
);
1541 SetTexturePanelTexture(panel
, "pinky",
1542 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1544 ShowTexturePanel(panel
);
1546 WMScreenMainLoop(scr
);