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
;
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
);
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
);
391 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
392 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
395 rows
= WMGetListNumberOfRows(panel
->gcolL
);
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
;
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
);
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
;
433 dpy
= WMScreenDisplay(scr
);
435 width
= rect
->size
.width
;
436 height
= rect
->size
.height
;
440 if (state
& WLDSSelected
)
441 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
443 XFillRectangle(dpy
, d
, WMColorGC(gray
), x
, y
, width
, height
);
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
;
463 /* Parameter not used, but tell the compiler that it is ok */
466 row
= WMGetListSelectedItemRow(panel
->gcolL
) + 1;
467 item
= WMInsertListItem(panel
->gcolL
, row
, "00,00,00");
468 rgb
= wmalloc(sizeof(RColor
));
469 item
->clientData
= rgb
;
471 WMSelectListItem(panel
->gcolL
, row
);
473 updateGradButtons(panel
);
475 sliderChangeCallback(panel
->ghueS
, panel
);
477 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
480 static void gradClickCallback(WMWidget
* w
, void *data
)
482 TexturePanel
*panel
= (TexturePanel
*) data
;
487 row
= WMGetListSelectedItemRow(w
);
491 item
= WMGetListItem(panel
->gcolL
, row
);
492 RRGBtoHSV((RColor
*) item
->clientData
, &hsv
);
494 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
495 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
496 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
498 sliderChangeCallback(panel
->ghueS
, panel
);
499 sliderChangeCallback(panel
->gsatS
, panel
);
502 static void gradDeleteCallback(WMWidget
* w
, void *data
)
504 TexturePanel
*panel
= (TexturePanel
*) data
;
508 /* Parameter not used, but tell the compiler that it is ok */
511 row
= WMGetListSelectedItemRow(panel
->gcolL
);
515 item
= WMGetListItem(panel
->gcolL
, row
);
516 wfree(item
->clientData
);
518 WMRemoveListItem(panel
->gcolL
, row
);
520 WMSelectListItem(panel
->gcolL
, row
- 1);
522 updateGradButtons(panel
);
524 gradClickCallback(panel
->gcolL
, panel
);
526 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
529 /*************** Simple Gradient ***************/
531 static void colorWellObserver(void *self
, WMNotification
* n
)
533 /* Parameter not used, but tell the compiler that it is ok */
536 updateSGradButtons(self
);
539 static void opaqChangeCallback(WMWidget
* w
, void *data
)
541 TexturePanel
*panel
= (TexturePanel
*) data
;
543 /* Parameter not used, but tell the compiler that it is ok */
546 updateTGradImage(panel
);
549 /****************** Image ******************/
551 static void updateImage(TexturePanel
* panel
, const char *path
)
553 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
559 image
= RLoadImage(WMScreenRContext(scr
), path
, 0);
563 message
= wstrconcat(_("Could not load the selected file: "),
564 (char *)RMessageForError(RErrorCode
));
566 WMRunAlertPanel(scr
, panel
->win
, _("Error"), message
, _("OK"), NULL
, NULL
);
569 WMSetButtonEnabled(panel
->okB
, False
);
575 WMSetButtonEnabled(panel
->okB
, True
);
578 RReleaseImage(panel
->image
);
579 panel
->image
= image
;
581 image
= panel
->image
;
584 if (WMGetPopUpButtonSelectedItem(panel
->typeP
) == TYPE_PIXMAP
) {
586 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
588 size
= WMGetPixmapSize(pixmap
);
589 WMSetLabelImage(panel
->imageL
, pixmap
);
590 WMResizeWidget(panel
->imageL
, size
.width
, size
.height
);
592 WMReleasePixmap(pixmap
);
595 updateTGradImage(panel
);
599 static void browseImageCallback(WMWidget
* w
, void *data
)
601 TexturePanel
*panel
= (TexturePanel
*) data
;
603 WMScreen
*scr
= WMWidgetScreen(w
);
604 static char *ipath
= NULL
;
606 opanel
= WMGetOpenPanel(scr
);
607 WMSetFilePanelCanChooseDirectories(opanel
, False
);
608 WMSetFilePanelCanChooseFiles(opanel
, True
);
611 ipath
= wstrdup(wgethomedir());
613 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, ipath
, _("Open Image"), NULL
)) {
614 char *path
, *fullpath
;
617 tmp
= WMGetFilePanelFileName(opanel
);
625 path
= wstrdup(fullpath
);
627 tmp2
= strrchr(fullpath
, '/');
631 tmp
= wfindfileinarray(panel
->pathList
, tmp2
);
634 if (strcmp(fullpath
, tmp
) == 0) {
641 if (!RGetImageFileFormat(fullpath
)) {
642 WMRunAlertPanel(scr
, panel
->win
, _("Error"),
643 _("The selected file does not contain a supported image."),
644 _("OK"), NULL
, NULL
);
647 updateImage(panel
, fullpath
);
648 wfree(panel
->imageFile
);
649 panel
->imageFile
= path
;
651 WMSetTextFieldText(panel
->imageT
, path
);
656 static void buttonCallback(WMWidget
* w
, void *data
)
658 TexturePanel
*panel
= (TexturePanel
*) data
;
660 if (w
== panel
->okB
) {
661 (*panel
->okAction
) (panel
->okData
);
663 (*panel
->cancelAction
) (panel
->cancelData
);
667 static void changeTypeCallback(WMWidget
* w
, void *data
)
669 TexturePanel
*panel
= (TexturePanel
*) data
;
673 newType
= WMGetPopUpButtonSelectedItem(w
);
674 if (newType
== panel
->currentType
)
677 if (panel
->currentType
>= 0) {
678 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
679 if (panel
->sectionParts
[panel
->currentType
][i
] == NULL
)
681 WMUnmapWidget(panel
->sectionParts
[panel
->currentType
][i
]);
685 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
686 if (panel
->sectionParts
[newType
][i
] == NULL
)
688 WMMapWidget(panel
->sectionParts
[newType
][i
]);
690 panel
->currentType
= newType
;
694 updateSGradButtons(panel
);
695 WMSetButtonEnabled(panel
->okB
, True
);
698 updateGradButtons(panel
);
699 WMSetButtonEnabled(panel
->okB
, WMGetListNumberOfRows(panel
->gcolL
) > 1);
703 updateImage(panel
, NULL
);
704 WMSetButtonEnabled(panel
->okB
, panel
->image
!= NULL
);
707 WMSetButtonEnabled(panel
->okB
, True
);
713 *--------------------------------------------------------------------------
715 *--------------------------------------------------------------------------
717 void ShowTexturePanel(TexturePanel
* panel
)
719 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
720 Screen
*scr
= DefaultScreenOfDisplay(dpy
);
722 WMSetWindowInitialPosition(panel
->win
,
723 (WidthOfScreen(scr
) - WMWidgetWidth(panel
->win
)) / 2,
724 (HeightOfScreen(scr
) - WMWidgetHeight(panel
->win
)) / 2);
725 WMMapWidget(panel
->win
);
728 void HideTexturePanel(TexturePanel
* panel
)
730 WMUnmapWidget(panel
->win
);
733 void SetTexturePanelOkAction(TexturePanel
* panel
, WMCallback
* action
, void *clientData
)
735 panel
->okAction
= action
;
736 panel
->okData
= clientData
;
739 void SetTexturePanelCancelAction(TexturePanel
* panel
, WMCallback
* action
, void *clientData
)
741 panel
->cancelAction
= action
;
742 panel
->cancelData
= clientData
;
745 void SetTexturePanelTexture(TexturePanel
* panel
, const char *name
, WMPropList
* texture
)
747 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
755 WMSetTextFieldText(panel
->nameT
, name
);
760 p
= WMGetFromPLArray(texture
, 0);
764 type
= WMGetFromPLString(p
);
766 /*............................................... */
767 if (strcasecmp(type
, "solid") == 0) {
769 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SOLID
);
771 p
= WMGetFromPLArray(texture
, 1);
775 str
= WMGetFromPLString(p
);
777 color
= WMCreateNamedColor(scr
, str
, False
);
779 WMSetColorWellColor(panel
->defcW
, color
);
781 WMReleaseColor(color
);
782 /*............................................... */
783 } else if (strcasecmp(type
, "hgradient") == 0
784 || strcasecmp(type
, "vgradient") == 0 || strcasecmp(type
, "dgradient") == 0) {
786 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SGRADIENT
);
788 p
= WMGetFromPLArray(texture
, 1);
792 str
= WMGetFromPLString(p
);
794 color
= WMCreateNamedColor(scr
, str
, False
);
796 WMSetColorWellColor(panel
->tcol1W
, color
);
798 WMReleaseColor(color
);
800 p
= WMGetFromPLArray(texture
, 2);
804 str
= WMGetFromPLString(p
);
806 color
= WMCreateNamedColor(scr
, str
, False
);
808 WMSetColorWellColor(panel
->tcol2W
, color
);
810 WMReleaseColor(color
);
813 /*............................................... */
814 } else if (strcasecmp(type
, "thgradient") == 0
815 || strcasecmp(type
, "tvgradient") == 0 || strcasecmp(type
, "tdgradient") == 0) {
818 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_TGRADIENT
);
822 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
823 if (panel
->imageFile
)
824 wfree(panel
->imageFile
);
825 panel
->imageFile
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
827 if (sscanf(WMGetFromPLString(WMGetFromPLArray(texture
, 2)), "%i", &i
) != 1)
829 WMSetSliderValue(panel
->topaS
, i
);
831 p
= WMGetFromPLArray(texture
, 3);
835 str
= WMGetFromPLString(p
);
837 color
= WMCreateNamedColor(scr
, str
, False
);
839 WMSetColorWellColor(panel
->tcol1W
, color
);
841 WMReleaseColor(color
);
843 p
= WMGetFromPLArray(texture
, 4);
847 str
= WMGetFromPLString(p
);
849 color
= WMCreateNamedColor(scr
, str
, False
);
851 WMSetColorWellColor(panel
->tcol2W
, color
);
853 WMReleaseColor(color
);
855 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
857 if (panel
->imageFile
)
858 wfree(panel
->imageFile
);
859 if ((panel
->imageFile
= wfindfileinarray(panel
->pathList
,
860 WMGetFromPLString(WMGetFromPLArray(texture
, 1)))) !=
863 panel
->image
= RLoadImage(WMScreenRContext(scr
), panel
->imageFile
, 0);
864 updateTGradImage(panel
);
866 updateSGradButtons(panel
);
868 wwarning(_("could not load file '%s': %s"), panel
->imageFile
,
869 RMessageForError(RErrorCode
));
871 /*............................................... */
872 } else if (strcasecmp(type
, "mhgradient") == 0
873 || strcasecmp(type
, "mvgradient") == 0 || strcasecmp(type
, "mdgradient") == 0) {
876 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
877 item
= WMGetListItem(panel
->gcolL
, i
);
878 wfree(item
->clientData
);
880 WMClearList(panel
->gcolL
);
882 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_GRADIENT
);
884 p
= WMGetFromPLArray(texture
, 1);
888 str
= WMGetFromPLString(p
);
890 color
= WMCreateNamedColor(scr
, str
, False
);
892 WMSetColorWellColor(panel
->defcW
, color
);
894 WMReleaseColor(color
);
896 for (i
= 2; i
< WMGetPropListItemCount(texture
); i
++) {
900 p
= WMGetFromPLArray(texture
, i
);
904 str
= WMGetFromPLString(p
);
907 XParseColor(WMScreenDisplay(scr
), WMScreenRContext(scr
)->cmap
, str
, &xcolor
);
909 rgb
= wmalloc(sizeof(RColor
));
910 rgb
->red
= xcolor
.red
>> 8;
911 rgb
->green
= xcolor
.green
>> 8;
912 rgb
->blue
= xcolor
.blue
>> 8;
913 sprintf(buffer
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
915 item
= WMAddListItem(panel
->gcolL
, buffer
);
916 item
->clientData
= rgb
;
919 sliderChangeCallback(panel
->ghueS
, panel
);
922 /*............................................... */
923 } else if (strcasecmp(type
, "cpixmap") == 0
924 || strcasecmp(type
, "spixmap") == 0
925 || strcasecmp(type
, "mpixmap") == 0 || strcasecmp(type
, "tpixmap") == 0) {
927 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_PIXMAP
);
929 switch (toupper(type
[0])) {
931 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_CENTER
);
934 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_SCALE
);
937 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_MAXIMIZE
);
941 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_TILE
);
945 WMSetTextFieldText(panel
->imageT
, WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
947 if (panel
->imageFile
)
948 wfree(panel
->imageFile
);
949 panel
->imageFile
= wfindfileinarray(panel
->pathList
,
950 WMGetFromPLString(WMGetFromPLArray(texture
, 1)));
952 color
= WMCreateNamedColor(scr
, WMGetFromPLString(WMGetFromPLArray(texture
, 2)), False
);
953 WMSetColorWellColor(panel
->defcW
, color
);
954 WMReleaseColor(color
);
956 updateImage(panel
, panel
->imageFile
);
959 changeTypeCallback(panel
->typeP
, panel
);
962 updateGradButtons(panel
);
964 switch (toupper(gradient
)) {
966 WMPerformButtonClick(panel
->dirhB
);
969 WMPerformButtonClick(panel
->dirvB
);
973 WMPerformButtonClick(panel
->dirdB
);
981 str
= WMGetPropListDescription(texture
, False
);
982 wwarning(_("error creating texture %s"), str
);
987 char *GetTexturePanelTextureName(TexturePanel
* panel
)
989 return WMGetTextFieldText(panel
->nameT
);
993 WMPropList
*GetTexturePanelTexture(TexturePanel
* panel
)
995 WMPropList
*prop
= NULL
;
1001 switch (WMGetPopUpButtonSelectedItem(panel
->typeP
)) {
1004 color
= WMGetColorWellColor(panel
->defcW
);
1005 str
= WMGetColorRGBDescription(color
);
1006 prop
= WMCreatePLArray(WMCreatePLString("solid"), WMCreatePLString(str
), NULL
);
1012 color
= WMGetColorWellColor(panel
->defcW
);
1013 str
= WMGetColorRGBDescription(color
);
1015 switch (WMGetPopUpButtonSelectedItem(panel
->arrP
)) {
1017 prop
= WMCreatePLArray(WMCreatePLString("spixmap"),
1018 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1020 case PTYPE_MAXIMIZE
:
1021 prop
= WMCreatePLArray(WMCreatePLString("mpixmap"),
1022 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1025 prop
= WMCreatePLArray(WMCreatePLString("cpixmap"),
1026 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1029 prop
= WMCreatePLArray(WMCreatePLString("tpixmap"),
1030 WMCreatePLString(panel
->imageFile
), WMCreatePLString(str
), NULL
);
1036 case TYPE_TGRADIENT
:
1037 color
= WMGetColorWellColor(panel
->tcol1W
);
1038 str
= WMGetColorRGBDescription(color
);
1040 color
= WMGetColorWellColor(panel
->tcol2W
);
1041 str2
= WMGetColorRGBDescription(color
);
1043 sprintf(buff
, "%i", WMGetSliderValue(panel
->topaS
));
1045 if (WMGetButtonSelected(panel
->dirdB
)) {
1046 prop
= WMCreatePLArray(WMCreatePLString("tdgradient"),
1047 WMCreatePLString(panel
->imageFile
),
1048 WMCreatePLString(buff
),
1049 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1050 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1051 prop
= WMCreatePLArray(WMCreatePLString("tvgradient"),
1052 WMCreatePLString(panel
->imageFile
),
1053 WMCreatePLString(buff
),
1054 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1056 prop
= WMCreatePLArray(WMCreatePLString("thgradient"),
1057 WMCreatePLString(panel
->imageFile
),
1058 WMCreatePLString(buff
),
1059 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1065 case TYPE_SGRADIENT
:
1066 color
= WMGetColorWellColor(panel
->tcol1W
);
1067 str
= WMGetColorRGBDescription(color
);
1069 color
= WMGetColorWellColor(panel
->tcol2W
);
1070 str2
= WMGetColorRGBDescription(color
);
1072 if (WMGetButtonSelected(panel
->dirdB
)) {
1073 prop
= WMCreatePLArray(WMCreatePLString("dgradient"),
1074 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1075 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1076 prop
= WMCreatePLArray(WMCreatePLString("vgradient"),
1077 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1079 prop
= WMCreatePLArray(WMCreatePLString("hgradient"),
1080 WMCreatePLString(str
), WMCreatePLString(str2
), NULL
);
1087 color
= WMGetColorWellColor(panel
->defcW
);
1088 str
= WMGetColorRGBDescription(color
);
1090 if (WMGetButtonSelected(panel
->dirdB
)) {
1091 prop
= WMCreatePLArray(WMCreatePLString("mdgradient"), WMCreatePLString(str
), NULL
);
1092 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1093 prop
= WMCreatePLArray(WMCreatePLString("mvgradient"), WMCreatePLString(str
), NULL
);
1095 prop
= WMCreatePLArray(WMCreatePLString("mhgradient"), WMCreatePLString(str
), NULL
);
1099 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
1103 item
= WMGetListItem(panel
->gcolL
, i
);
1105 rgb
= (RColor
*) item
->clientData
;
1107 sprintf(buff
, "#%02x%02x%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
1109 WMAddToPLArray(prop
, WMCreatePLString(buff
));
1117 void SetTexturePanelPixmapPath(TexturePanel
* panel
, WMPropList
* array
)
1119 panel
->pathList
= array
;
1122 TexturePanel
*CreateTexturePanel(WMWindow
* keyWindow
)
1123 /*CreateTexturePanel(WMScreen *scr)*/
1125 TexturePanel
*panel
;
1126 WMScreen
*scr
= WMWidgetScreen(keyWindow
);
1128 panel
= wmalloc(sizeof(TexturePanel
));
1130 panel
->listFont
= WMSystemFontOfSize(scr
, 12);
1132 panel
->win
= WMCreatePanelWithStyleForWindow(keyWindow
, "texturePanel",
1133 WMTitledWindowMask
| WMClosableWindowMask
);
1135 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1137 |WMClosableWindowMask);
1140 WMResizeWidget(panel
->win
, 325, 423);
1141 WMSetWindowTitle(panel
->win
, _("Texture Panel"));
1142 WMSetWindowCloseAction(panel
->win
, buttonCallback
, panel
);
1145 panel
->nameF
= WMCreateFrame(panel
->win
);
1146 WMResizeWidget(panel
->nameF
, 185, 50);
1147 WMMoveWidget(panel
->nameF
, 15, 10);
1148 WMSetFrameTitle(panel
->nameF
, _("Texture Name"));
1150 panel
->nameT
= WMCreateTextField(panel
->nameF
);
1151 WMResizeWidget(panel
->nameT
, 160, 20);
1152 WMMoveWidget(panel
->nameT
, 12, 18);
1154 WMMapSubwidgets(panel
->nameF
);
1157 panel
->typeP
= WMCreatePopUpButton(panel
->win
);
1158 WMResizeWidget(panel
->typeP
, 185, 20);
1159 WMMoveWidget(panel
->typeP
, 15, 65);
1160 WMAddPopUpButtonItem(panel
->typeP
, _("Solid Color"));
1161 WMAddPopUpButtonItem(panel
->typeP
, _("Gradient Texture"));
1162 WMAddPopUpButtonItem(panel
->typeP
, _("Simple Gradient Texture"));
1163 WMAddPopUpButtonItem(panel
->typeP
, _("Textured Gradient"));
1164 WMAddPopUpButtonItem(panel
->typeP
, _("Image Texture"));
1165 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
1166 WMSetPopUpButtonAction(panel
->typeP
, changeTypeCallback
, panel
);
1169 panel
->defcF
= WMCreateFrame(panel
->win
);
1170 WMResizeWidget(panel
->defcF
, 100, 75);
1171 WMMoveWidget(panel
->defcF
, 210, 10);
1172 WMSetFrameTitle(panel
->defcF
, _("Default Color"));
1174 panel
->defcW
= WMCreateColorWell(panel
->defcF
);
1175 WMResizeWidget(panel
->defcW
, 60, 45);
1176 WMMoveWidget(panel
->defcW
, 20, 20);
1178 WMMapSubwidgets(panel
->defcF
);
1180 /****** Gradient ******/
1181 panel
->gcolF
= WMCreateFrame(panel
->win
);
1182 WMResizeWidget(panel
->gcolF
, 295, 205);
1183 WMMoveWidget(panel
->gcolF
, 15, 95);
1184 WMSetFrameTitle(panel
->gcolF
, _("Gradient Colors"));
1186 panel
->gcolL
= WMCreateList(panel
->gcolF
);
1187 WMResizeWidget(panel
->gcolL
, 130, 140);
1188 WMMoveWidget(panel
->gcolL
, 10, 25);
1189 WMHangData(panel
->gcolL
, panel
);
1190 WMSetListUserDrawProc(panel
->gcolL
, paintGradListItem
);
1191 WMSetListAction(panel
->gcolL
, gradClickCallback
, panel
);
1193 panel
->gcolaB
= WMCreateCommandButton(panel
->gcolF
);
1194 WMResizeWidget(panel
->gcolaB
, 64, 24);
1195 WMMoveWidget(panel
->gcolaB
, 10, 170);
1196 WMSetButtonText(panel
->gcolaB
, _("Add"));
1197 WMSetButtonAction(panel
->gcolaB
, gradAddCallback
, panel
);
1199 panel
->gcoldB
= WMCreateCommandButton(panel
->gcolF
);
1200 WMResizeWidget(panel
->gcoldB
, 64, 24);
1201 WMMoveWidget(panel
->gcoldB
, 75, 170);
1202 WMSetButtonText(panel
->gcoldB
, _("Delete"));
1203 WMSetButtonAction(panel
->gcoldB
, gradDeleteCallback
, panel
);
1206 panel
->gbriS
= WMCreateSlider(panel
->gcolF
);
1207 WMResizeWidget(panel
->gbriS
, 130, 16);
1208 WMMoveWidget(panel
->gbriS
, 150, 25);
1209 WMSetSliderKnobThickness(panel
->gbriS
, 8);
1210 WMSetSliderMaxValue(panel
->gbriS
, 100);
1211 WMSetSliderAction(panel
->gbriS
, sliderChangeCallback
, panel
);
1216 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1217 color
= WMDarkGrayColor(scr
);
1218 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
), WMColorGC(color
), 0, 0, 130, 16);
1219 WMReleaseColor(color
);
1220 color
= WMWhiteColor(color
);
1221 WMDrawString(scr
, WMGetPixmapXID(pixmap
), color
,
1222 panel
->listFont
, 2, (16 - WMFontHeight(panel
->listFont
)) / 2 - 1, "Brightness", 10);
1223 WMSetSliderImage(panel
->gbriS
, pixmap
);
1224 WMReleasePixmap(pixmap
);
1227 panel
->gconS
= WMCreateSlider(panel
->gcolF
);
1228 WMResizeWidget(panel
->gconS
, 130, 16);
1229 WMMoveWidget(panel
->gconS
, 150, 50);
1230 WMSetSliderKnobThickness(panel
->gconS
, 8);
1231 WMSetSliderMaxValue(panel
->gconS
, 100);
1232 WMSetSliderAction(panel
->gconS
, sliderChangeCallback
, panel
);
1237 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1238 color
= WMDarkGrayColor(scr
);
1239 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
), WMColorGC(color
), 0, 0, 130, 16);
1240 WMReleaseColor(color
);
1241 color
= WMWhiteColor(scr
);
1242 WMDrawString(scr
, WMGetPixmapXID(pixmap
), color
,
1243 panel
->listFont
, 2, (16 - WMFontHeight(panel
->listFont
)) / 2 - 1, "Contrast", 8);
1244 WMSetSliderImage(panel
->gconS
, pixmap
);
1245 WMReleasePixmap(pixmap
);
1248 panel
->ghueS
= WMCreateSlider(panel
->gcolF
);
1249 WMResizeWidget(panel
->ghueS
, 130, 16);
1250 WMMoveWidget(panel
->ghueS
, 150, 100);
1251 WMSetSliderKnobThickness(panel
->ghueS
, 8);
1252 WMSetSliderMaxValue(panel
->ghueS
, 359);
1253 WMSetSliderAction(panel
->ghueS
, sliderChangeCallback
, panel
);
1255 panel
->gsatS
= WMCreateSlider(panel
->gcolF
);
1256 WMResizeWidget(panel
->gsatS
, 130, 16);
1257 WMMoveWidget(panel
->gsatS
, 150, 125);
1258 WMSetSliderKnobThickness(panel
->gsatS
, 8);
1259 WMSetSliderMaxValue(panel
->gsatS
, 255);
1260 WMSetSliderAction(panel
->gsatS
, sliderChangeCallback
, panel
);
1262 panel
->gvalS
= WMCreateSlider(panel
->gcolF
);
1263 WMResizeWidget(panel
->gvalS
, 130, 16);
1264 WMMoveWidget(panel
->gvalS
, 150, 150);
1265 WMSetSliderKnobThickness(panel
->gvalS
, 8);
1266 WMSetSliderMaxValue(panel
->gvalS
, 255);
1267 WMSetSliderAction(panel
->gvalS
, sliderChangeCallback
, panel
);
1269 WMMapSubwidgets(panel
->gcolF
);
1272 panel
->dirF
= WMCreateFrame(panel
->win
);
1273 WMSetFrameTitle(panel
->dirF
, _("Direction"));
1274 WMResizeWidget(panel
->dirF
, 295, 75);
1275 WMMoveWidget(panel
->dirF
, 15, 305);
1277 panel
->dirvB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1278 WMSetButtonImagePosition(panel
->dirvB
, WIPImageOnly
);
1279 WMResizeWidget(panel
->dirvB
, 90, 40);
1280 WMMoveWidget(panel
->dirvB
, 10, 20);
1282 panel
->dirhB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1283 WMSetButtonImagePosition(panel
->dirhB
, WIPImageOnly
);
1284 WMResizeWidget(panel
->dirhB
, 90, 40);
1285 WMMoveWidget(panel
->dirhB
, 102, 20);
1287 panel
->dirdB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1288 WMSetButtonImagePosition(panel
->dirdB
, WIPImageOnly
);
1289 WMResizeWidget(panel
->dirdB
, 90, 40);
1290 WMMoveWidget(panel
->dirdB
, 194, 20);
1292 WMGroupButtons(panel
->dirvB
, panel
->dirhB
);
1293 WMGroupButtons(panel
->dirvB
, panel
->dirdB
);
1295 WMMapSubwidgets(panel
->dirF
);
1297 /****************** Textured Gradient ******************/
1298 panel
->tcolF
= WMCreateFrame(panel
->win
);
1299 WMResizeWidget(panel
->tcolF
, 100, 135);
1300 WMMoveWidget(panel
->tcolF
, 210, 10);
1301 WMSetFrameTitle(panel
->tcolF
, _("Gradient"));
1303 panel
->tcol1W
= WMCreateColorWell(panel
->tcolF
);
1304 WMResizeWidget(panel
->tcol1W
, 60, 45);
1305 WMMoveWidget(panel
->tcol1W
, 20, 25);
1306 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->tcol1W
);
1308 panel
->tcol2W
= WMCreateColorWell(panel
->tcolF
);
1309 WMResizeWidget(panel
->tcol2W
, 60, 45);
1310 WMMoveWidget(panel
->tcol2W
, 20, 75);
1311 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->tcol2W
);
1314 panel
->topaF
= WMCreateFrame(panel
->win
);
1315 WMResizeWidget(panel
->topaF
, 185, 50);
1316 WMMoveWidget(panel
->topaF
, 15, 95);
1317 WMSetFrameTitle(panel
->topaF
, _("Gradient Opacity"));
1319 panel
->topaS
= WMCreateSlider(panel
->topaF
);
1320 WMResizeWidget(panel
->topaS
, 155, 18);
1321 WMMoveWidget(panel
->topaS
, 15, 20);
1322 WMSetSliderMaxValue(panel
->topaS
, 255);
1323 WMSetSliderValue(panel
->topaS
, 200);
1324 WMSetSliderContinuous(panel
->topaS
, False
);
1325 WMSetSliderAction(panel
->topaS
, opaqChangeCallback
, panel
);
1327 WMMapSubwidgets(panel
->topaF
);
1334 pixmap
= WMCreatePixmap(scr
, 155, 18, WMScreenDepth(scr
), False
);
1335 p
= WMGetPixmapXID(pixmap
);
1337 color
= WMDarkGrayColor(scr
);
1338 XFillRectangle(WMScreenDisplay(scr
), p
, WMColorGC(color
), 0, 0, 155, 18);
1339 WMReleaseColor(color
);
1341 color
= WMWhiteColor(scr
);
1342 WMDrawString(scr
, p
, color
, panel
->listFont
, 2, 1, "0%", 2);
1343 WMDrawString(scr
, p
, color
, panel
->listFont
,
1344 153 - WMWidthOfString(panel
->listFont
, "100%", 4), 1, "100%", 4);
1345 WMReleaseColor(color
);
1347 WMSetSliderImage(panel
->topaS
, pixmap
);
1348 WMReleasePixmap(pixmap
);
1351 WMMapSubwidgets(panel
->tcolF
);
1353 /****************** Image ******************/
1354 panel
->imageF
= WMCreateFrame(panel
->win
);
1355 WMResizeWidget(panel
->imageF
, 295, 150);
1356 WMMoveWidget(panel
->imageF
, 15, 150);
1357 WMSetFrameTitle(panel
->imageF
, _("Image"));
1359 panel
->imageL
= WMCreateLabel(panel
->imageF
);
1360 WMSetLabelImagePosition(panel
->imageL
, WIPImageOnly
);
1362 panel
->imageT
= WMCreateTextField(panel
->imageF
);
1363 WMResizeWidget(panel
->imageT
, 90, 20);
1364 WMMoveWidget(panel
->imageT
, 190, 25);
1366 panel
->imageV
= WMCreateScrollView(panel
->imageF
);
1367 WMResizeWidget(panel
->imageV
, 165, 115);
1368 WMMoveWidget(panel
->imageV
, 15, 20);
1369 WMSetScrollViewRelief(panel
->imageV
, WRSunken
);
1370 WMSetScrollViewHasHorizontalScroller(panel
->imageV
, True
);
1371 WMSetScrollViewHasVerticalScroller(panel
->imageV
, True
);
1372 WMSetScrollViewContentView(panel
->imageV
, WMWidgetView(panel
->imageL
));
1374 panel
->browB
= WMCreateCommandButton(panel
->imageF
);
1375 WMResizeWidget(panel
->browB
, 90, 24);
1376 WMMoveWidget(panel
->browB
, 190, 50);
1377 WMSetButtonText(panel
->browB
, _("Browse..."));
1378 WMSetButtonAction(panel
->browB
, browseImageCallback
, panel
);
1380 /* panel->dispB = WMCreateCommandButton(panel->imageF);
1381 WMResizeWidget(panel->dispB, 90, 24);
1382 WMMoveWidget(panel->dispB, 190, 80);
1383 WMSetButtonText(panel->dispB, _("Show"));
1386 panel
->arrP
= WMCreatePopUpButton(panel
->imageF
);
1387 WMResizeWidget(panel
->arrP
, 90, 20);
1388 WMMoveWidget(panel
->arrP
, 190, 120);
1389 WMAddPopUpButtonItem(panel
->arrP
, _("Tile"));
1390 WMAddPopUpButtonItem(panel
->arrP
, _("Scale"));
1391 WMAddPopUpButtonItem(panel
->arrP
, _("Center"));
1392 WMAddPopUpButtonItem(panel
->arrP
, _("Maximize"));
1393 WMSetPopUpButtonSelectedItem(panel
->arrP
, 0);
1395 WMMapSubwidgets(panel
->imageF
);
1399 panel
->okB
= WMCreateCommandButton(panel
->win
);
1400 WMResizeWidget(panel
->okB
, 84, 24);
1401 WMMoveWidget(panel
->okB
, 225, 390);
1402 WMSetButtonText(panel
->okB
, _("OK"));
1403 WMSetButtonAction(panel
->okB
, buttonCallback
, panel
);
1405 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
1406 WMResizeWidget(panel
->cancelB
, 84, 24);
1407 WMMoveWidget(panel
->cancelB
, 130, 390);
1408 WMSetButtonText(panel
->cancelB
, _("Cancel"));
1409 WMSetButtonAction(panel
->cancelB
, buttonCallback
, panel
);
1411 WMMapWidget(panel
->nameF
);
1412 WMMapWidget(panel
->typeP
);
1413 WMMapWidget(panel
->okB
);
1414 WMMapWidget(panel
->cancelB
);
1416 WMUnmapWidget(panel
->arrP
);
1418 WMRealizeWidget(panel
->win
);
1420 panel
->currentType
= -1;
1422 panel
->sectionParts
[TYPE_SOLID
][0] = panel
->defcF
;
1424 panel
->sectionParts
[TYPE_GRADIENT
][0] = panel
->defcF
;
1425 panel
->sectionParts
[TYPE_GRADIENT
][1] = panel
->gcolF
;
1426 panel
->sectionParts
[TYPE_GRADIENT
][2] = panel
->dirF
;
1428 panel
->sectionParts
[TYPE_SGRADIENT
][0] = panel
->tcolF
;
1429 panel
->sectionParts
[TYPE_SGRADIENT
][1] = panel
->dirF
;
1431 panel
->sectionParts
[TYPE_TGRADIENT
][0] = panel
->tcolF
;
1432 panel
->sectionParts
[TYPE_TGRADIENT
][1] = panel
->dirF
;
1433 panel
->sectionParts
[TYPE_TGRADIENT
][2] = panel
->imageF
;
1434 panel
->sectionParts
[TYPE_TGRADIENT
][3] = panel
->topaF
;
1435 panel
->sectionParts
[TYPE_TGRADIENT
][4] = panel
->arrP
;
1437 panel
->sectionParts
[TYPE_PIXMAP
][0] = panel
->defcF
;
1438 panel
->sectionParts
[TYPE_PIXMAP
][1] = panel
->imageF
;
1439 panel
->sectionParts
[TYPE_PIXMAP
][2] = panel
->arrP
;
1441 /* setup for first time */
1443 changeTypeCallback(panel
->typeP
, panel
);
1445 sliderChangeCallback(panel
->ghueS
, panel
);
1446 sliderChangeCallback(panel
->gsatS
, panel
);
1452 *--------------------------------------------------------------------------
1454 *--------------------------------------------------------------------------
1459 char *ProgName
= "test";
1461 void testOKButton(WMWidget
* self
, void *data
)
1469 TexturePanel
*panel
= (TexturePanel
*) data
;
1470 /* test = GetTexturePanelTextureString(panel); */
1474 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
1475 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250, 0, 0, 0);
1476 XMapRaised(dpy
, win
);
1479 /* image = RenderTexturePanelTexture(panel, 250, 250); */
1481 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
1483 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
,
1484 image
->height
, 0, 0);
1490 void testCancelButton(WMWidget
* self
, void *data
)
1492 wwarning("Exiting test....");
1501 int main(int argc
, char **argv
)
1503 TexturePanel
*panel
;
1505 Display
*dpy
= XOpenDisplay("");
1510 WMInitializeApplication("Test", &argc
, argv
);
1513 wfatal("could not open display");
1517 scr
= WMCreateSimpleApplicationScreen(dpy
);
1519 panel
= CreateTexturePanel(scr
);
1521 SetTexturePanelOkAction(panel
, (WMAction
*) testOKButton
, panel
);
1522 SetTexturePanelCancelAction(panel
, (WMAction
*) testCancelButton
, panel
);
1524 SetTexturePanelTexture(panel
, "pinky",
1525 WMCreatePropListFromDescription("(mdgradient, pink, red, blue, yellow)"));
1527 ShowTexturePanel(panel
);
1529 WMScreenMainLoop(scr
);