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