1 /* TexturePanel.c- texture editting panel
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998, 1999 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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
39 //#include "TexturePanel.h"
41 typedef struct _TexturePanel TexturePanel
;
43 #define MAX_SECTION_PARTS 4
45 typedef struct _TexturePanel
{
77 /* direction (common) */
83 /*-- Simple Gradient --*/
86 /*-- Textured Gradient --*/
112 WMCallback
*okAction
;
115 WMCallback
*cancelAction
;
119 WMWidget
*sectionParts
[5][MAX_SECTION_PARTS
];
131 #define TYPE_GRADIENT 1
132 #define TYPE_SGRADIENT 2
133 #define TYPE_TGRADIENT 3
134 #define TYPE_PIXMAP 4
138 #define PTYPE_SCALE 1
139 #define PTYPE_CENTER 2
140 #define PTYPE_MAXIMIZE 3
145 *--------------------------------------------------------------------------
147 *--------------------------------------------------------------------------
153 updateGradButtons(TexturePanel
*panel
)
160 colorn
= WMGetListNumberOfRows(panel
->gcolL
);
167 colors
= wmalloc(sizeof(RColor
*)*(colorn
+1));
169 for (i
= 0; i
< colorn
; i
++) {
170 item
= WMGetListItem(panel
->gcolL
, i
);
171 colors
[i
] = (RColor
*)item
->clientData
;
175 image
= RRenderMultiGradient(80, 30, colors
, RHorizontalGradient
);
176 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
178 RDestroyImage(image
);
179 WMSetButtonImage(panel
->dirhB
, pixmap
);
180 WMReleasePixmap(pixmap
);
182 image
= RRenderMultiGradient(80, 30, colors
, RVerticalGradient
);
183 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
185 RDestroyImage(image
);
186 WMSetButtonImage(panel
->dirvB
, pixmap
);
187 WMReleasePixmap(pixmap
);
189 image
= RRenderMultiGradient(80, 30, colors
, RDiagonalGradient
);
190 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
192 RDestroyImage(image
);
193 WMSetButtonImage(panel
->dirdB
, pixmap
);
194 WMReleasePixmap(pixmap
);
202 updateSGradButtons(TexturePanel
*panel
)
210 color
= WMGetColorWellColor(panel
->tcol1W
);
211 from
.red
= WMRedComponentOfColor(color
)>>8;
212 from
.green
= WMGreenComponentOfColor(color
)>>8;
213 from
.blue
= WMBlueComponentOfColor(color
)>>8;
215 color
= WMGetColorWellColor(panel
->tcol2W
);
216 to
.red
= WMRedComponentOfColor(color
)>>8;
217 to
.green
= WMGreenComponentOfColor(color
)>>8;
218 to
.blue
= WMBlueComponentOfColor(color
)>>8;
220 image
= RRenderGradient(80, 30, &from
, &to
, RHorizontalGradient
);
221 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
223 RDestroyImage(image
);
224 WMSetButtonImage(panel
->dirhB
, pixmap
);
225 WMReleasePixmap(pixmap
);
227 image
= RRenderGradient(80, 30, &from
, &to
, RVerticalGradient
);
228 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
230 RDestroyImage(image
);
231 WMSetButtonImage(panel
->dirvB
, pixmap
);
232 WMReleasePixmap(pixmap
);
234 image
= RRenderGradient(80, 30, &from
, &to
, RDiagonalGradient
);
235 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
237 RDestroyImage(image
);
238 WMSetButtonImage(panel
->dirdB
, pixmap
);
239 WMReleasePixmap(pixmap
);
244 changeTypeCallback(WMWidget
*w
, void *data
)
246 TexturePanel
*panel
= (TexturePanel
*)data
;
250 newType
= WMGetPopUpButtonSelectedItem(w
);
251 if (newType
== panel
->currentType
)
254 if (panel
->currentType
>= 0) {
255 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
256 if (panel
->sectionParts
[panel
->currentType
][i
] == NULL
)
258 WMUnmapWidget(panel
->sectionParts
[panel
->currentType
][i
]);
262 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
263 if (panel
->sectionParts
[newType
][i
] == NULL
)
265 WMMapWidget(panel
->sectionParts
[newType
][i
]);
267 panel
->currentType
= newType
;
271 updateSGradButtons(panel
);
274 updateGradButtons(panel
);
280 /*********** Gradient ************/
283 updateSVSlider(WMSlider
*sPtr
, Bool saturation
, WMFont
*font
, RHSVColor
*hsv
)
287 WMScreen
*scr
= WMWidgetScreen(sPtr
);
294 RHSVtoRGB(&tmp
, &from
);
295 tmp
.saturation
= 255;
296 RHSVtoRGB(&tmp
, &to
);
299 RHSVtoRGB(&tmp
, &from
);
301 RHSVtoRGB(&tmp
, &to
);
303 image
= RRenderGradient(130, 16, &from
, &to
, RHorizontalGradient
);
304 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
305 RDestroyImage(image
);
307 if (hsv
->value
< 128 || !saturation
) {
308 WMColor
*col
= WMWhiteColor(scr
);
310 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
311 (16 - WMFontHeight(font
))/2 - 1,
312 saturation
? "Saturation" : "Brightness", 10);
315 WMColor
*col
= WMBlackColor(scr
);
317 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
318 (16 - WMFontHeight(font
))/2 - 1,
319 saturation
? "Saturation" : "Brightness", 10);
322 WMSetSliderImage(sPtr
, pixmap
);
323 WMReleasePixmap(pixmap
);
328 updateHueSlider(WMSlider
*sPtr
, WMFont
*font
, RHSVColor
*hsv
)
333 WMScreen
*scr
= WMWidgetScreen(sPtr
);
338 for (i
= 0; i
<= 6; i
++) {
339 thsv
.hue
= (360*i
)/6;
340 colors
[i
] = wmalloc(sizeof(RColor
));
341 RHSVtoRGB(&thsv
, colors
[i
]);
345 image
= RRenderMultiGradient(130, 16, colors
, RGRD_HORIZONTAL
);
346 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
347 RDestroyImage(image
);
349 if (hsv
->value
< 128) {
350 WMColor
*col
= WMWhiteColor(scr
);
352 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
353 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
356 WMColor
*col
= WMBlackColor(scr
);
358 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
359 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
362 WMSetSliderImage(sPtr
, pixmap
);
363 WMReleasePixmap(pixmap
);
365 for (i
= 0; i
<= 6; i
++)
372 sliderChangeCallback(WMWidget
*w
, void *data
)
374 TexturePanel
*panel
= (TexturePanel
*)data
;
375 RHSVColor hsv
, *hsvp
;
381 WMScreen
*scr
= WMWidgetScreen(w
);
383 hsv
.hue
= WMGetSliderValue(panel
->ghueS
);
384 hsv
.saturation
= WMGetSliderValue(panel
->gsatS
);
385 hsv
.value
= WMGetSliderValue(panel
->gvalS
);
387 row
= WMGetListSelectedItemRow(panel
->gcolL
);
391 item
= WMGetListItem(panel
->gcolL
, row
);
393 rgb
= (RColor
*)item
->clientData
;
395 RHSVtoRGB(&hsv
, rgb
);
397 sprintf(item
->text
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
400 if (w
== panel
->ghueS
) {
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
);
411 rows
= WMGetListNumberOfRows(panel
->gcolL
);
415 colors
= wmalloc(sizeof(RColor
*)*(rows
+1));
417 for (i
= 0; i
< rows
; i
++) {
418 item
= WMGetListItem(panel
->gcolL
, i
);
420 colors
[i
] = (RColor
*)item
->clientData
;
424 if (panel
->gimage
!= None
) {
425 XFreePixmap(WMScreenDisplay(scr
), panel
->gimage
);
428 image
= RRenderMultiGradient(30, i
*WMGetListItemHeight(panel
->gcolL
),
429 colors
, RVerticalGradient
);
430 RConvertImage(WMScreenRContext(scr
), image
, &panel
->gimage
);
431 RDestroyImage(image
);
435 WMRedisplayWidget(panel
->gcolL
);
437 updateGradButtons(panel
);
442 paintGradListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
445 TexturePanel
*panel
= (TexturePanel
*)WMGetHangedData(lPtr
);
446 WMScreen
*scr
= WMWidgetScreen(lPtr
);
447 int width
, height
, x
, y
;
449 WMColor
*white
= WMWhiteColor(scr
);
451 WMColor
*black
= WMBlackColor(scr
);
453 dpy
= WMScreenDisplay(scr
);
455 width
= rect
->size
.width
;
456 height
= rect
->size
.height
;
460 if (state
& WLDSSelected
)
461 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
463 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
465 item
= WMGetListItem(lPtr
, index
);
468 XCopyArea(WMScreenDisplay(scr
), panel
->gimage
, d
, WMColorGC(white
),
469 0, height
*index
, 30, height
, x
+ 5, y
);
471 WMDrawString(scr
, d
, WMColorGC(black
), panel
->listFont
,
472 x
+ 40, y
+ 1, text
, strlen(text
));
474 WMReleaseColor(white
);
475 WMReleaseColor(black
);
481 gradAddCallback(WMWidget
*w
, void *data
)
483 TexturePanel
*panel
= (TexturePanel
*)data
;
488 row
= WMGetListSelectedItemRow(panel
->gcolL
) + 1;
489 item
= WMInsertListItem(panel
->gcolL
, row
, "00,00,00");
490 rgb
= wmalloc(sizeof(RColor
));
491 memset(rgb
, 0, sizeof(RColor
));
492 item
->clientData
= rgb
;
494 WMSelectListItem(panel
->gcolL
, row
);
496 updateGradButtons(panel
);
498 sliderChangeCallback(panel
->ghueS
, panel
);
504 gradClickCallback(WMWidget
*w
, void *data
)
506 TexturePanel
*panel
= (TexturePanel
*)data
;
511 row
= WMGetListSelectedItemRow(w
);
515 item
= WMGetListItem(panel
->gcolL
, row
);
516 RRGBtoHSV((RColor
*)item
->clientData
, &hsv
);
518 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
519 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
520 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
522 sliderChangeCallback(panel
->ghueS
, panel
);
523 sliderChangeCallback(panel
->gsatS
, panel
);
528 gradDeleteCallback(WMWidget
*w
, void *data
)
530 TexturePanel
*panel
= (TexturePanel
*)data
;
534 row
= WMGetListSelectedItemRow(panel
->gcolL
);
538 item
= WMGetListItem(panel
->gcolL
, row
);
539 free(item
->clientData
);
541 WMRemoveListItem(panel
->gcolL
, row
);
543 WMSelectListItem(panel
->gcolL
, row
- 1);
545 updateGradButtons(panel
);
547 gradClickCallback(panel
->gcolL
, panel
);
551 /*************** Simple Gradient ***************/
554 colorWellObserver(void *self
, WMNotification
*n
)
556 updateSGradButtons(self
);
560 /****************** Image ******************/
563 browseImageCallback(WMWidget
*w
, void *data
)
565 TexturePanel
*panel
= (TexturePanel
*)data
;
567 WMScreen
*scr
= WMWidgetScreen(w
);
569 opanel
= WMGetOpenPanel(scr
);
570 WMSetFilePanelCanChooseDirectories(opanel
, False
);
571 WMSetFilePanelCanChooseFiles(opanel
, True
);
573 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
574 "Open Image", NULL
)) {
575 char *path
, *fullpath
;
578 fullpath
= WMGetFilePanelFileName(opanel
);
581 path
= wstrdup(fullpath
);
583 tmp2
= strrchr(fullpath
, '/');
587 tmp
= wfindfileinarray(panel
->pathList
, tmp2
);
590 if (strcmp(fullpath
, tmp
)==0) {
597 if (!RGetImageFileFormat(fullpath
)) {
598 WMRunAlertPanel(scr
, panel
->win
, _("Error"),
599 _("The selected file does not contain a supported image."),
600 _("OK"), NULL
, NULL
);
604 RImage
*image
, *scaled
;
608 image
= RLoadImage(WMScreenRContext(scr
), fullpath
, 0);
612 message
= wstrappend(_("Could not load the selected file: "),
613 (char*)RMessageForError(RErrorCode
));
615 WMRunAlertPanel(scr
, panel
->win
, _("Error"), message
,
616 _("OK"), NULL
, NULL
);
623 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
624 RDestroyImage(image
);
626 size
= WMGetPixmapSize(pixmap
);
627 WMSetLabelImage(panel
->imageL
, pixmap
);
628 WMResizeWidget(panel
->imageL
, size
.width
, size
.height
);
630 WMReleasePixmap(pixmap
);
632 panel
->imageFile
= path
;
634 WMSetTextFieldText(panel
->imageT
, path
);
644 buttonCallback(WMWidget
*w
, void *data
)
646 TexturePanel
*panel
= (TexturePanel
*)data
;
648 if (w
== panel
->okB
) {
649 (*panel
->okAction
)(panel
->okData
);
651 (*panel
->cancelAction
)(panel
->cancelData
);
657 *--------------------------------------------------------------------------
659 *--------------------------------------------------------------------------
662 DestroyTexturePanel(TexturePanel
*panel
)
669 ShowTexturePanel(TexturePanel
*panel
)
671 WMMapWidget(panel
->win
);
676 HideTexturePanel(TexturePanel
*panel
)
678 WMUnmapWidget(panel
->win
);
683 SetTexturePanelOkAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
685 panel
->okAction
= action
;
686 panel
->okData
= clientData
;
691 SetTexturePanelCancelAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
693 panel
->cancelAction
= action
;
694 panel
->cancelData
= clientData
;
699 SetTexturePanelTexture(TexturePanel
*panel
, char *name
, proplist_t texture
)
701 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
709 WMSetTextFieldText(panel
->nameT
, name
);
714 p
= PLGetArrayElement(texture
, 0);
718 type
= PLGetString(p
);
720 /*...............................................*/
721 if (strcasecmp(type
, "solid")==0) {
723 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SOLID
);
725 p
= PLGetArrayElement(texture
, 1);
730 str
= PLGetString(p
);
731 color
= WMCreateNamedColor(scr
, str
, False
);
733 WMSetColorWellColor(panel
->defcW
, color
);
735 WMReleaseColor(color
);
736 /*...............................................*/
737 } else if (strcasecmp(type
, "hgradient")==0
738 || strcasecmp(type
, "vgradient")==0
739 || strcasecmp(type
, "dgradient")==0) {
741 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SGRADIENT
);
743 p
= PLGetArrayElement(texture
, 1);
747 str
= PLGetString(p
);
748 color
= WMCreateNamedColor(scr
, str
, False
);
750 WMSetColorWellColor(panel
->tcol1W
, color
);
752 WMReleaseColor(color
);
754 p
= PLGetArrayElement(texture
, 2);
758 str
= PLGetString(p
);
759 color
= WMCreateNamedColor(scr
, str
, False
);
761 WMSetColorWellColor(panel
->tcol2W
, color
);
763 WMReleaseColor(color
);
766 /*...............................................*/
767 } else if (strcasecmp(type
, "thgradient")==0
768 || strcasecmp(type
, "tvgradient")==0
769 || strcasecmp(type
, "tdgradient")==0) {
771 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_TGRADIENT
);
773 /****** TODO: setador de textura apartir desse */
775 /*...............................................*/
776 } else if (strcasecmp(type
, "mhgradient")==0
777 || strcasecmp(type
, "mvgradient")==0
778 || strcasecmp(type
, "mdgradient")==0) {
781 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
782 item
= WMGetListItem(panel
->gcolL
, i
);
783 free(item
->clientData
);
785 WMClearList(panel
->gcolL
);
787 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_GRADIENT
);
789 p
= PLGetArrayElement(texture
, 1);
794 str
= PLGetString(p
);
795 color
= WMCreateNamedColor(scr
, str
, False
);
797 WMSetColorWellColor(panel
->defcW
, color
);
799 WMReleaseColor(color
);
801 for (i
= 2; i
< PLGetNumberOfElements(texture
); i
++) {
805 p
= PLGetArrayElement(texture
, i
);
809 str
= PLGetString(p
);
811 XParseColor(WMScreenDisplay(scr
), WMScreenRContext(scr
)->cmap
,
814 rgb
= wmalloc(sizeof(RColor
));
815 rgb
->red
= xcolor
.red
>> 8;
816 rgb
->green
= xcolor
.green
>> 8;
817 rgb
->blue
= xcolor
.blue
>> 8;
818 sprintf(buffer
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
820 item
= WMAddListItem(panel
->gcolL
, buffer
);
821 item
->clientData
= rgb
;
824 sliderChangeCallback(panel
->ghueS
, panel
);
827 /*...............................................*/
828 } else if (strcasecmp(type
, "cpixmap")==0
829 || strcasecmp(type
, "spixmap")==0
830 || strcasecmp(type
, "mpixmap")==0
831 || strcasecmp(type
, "tpixmap")==0) {
833 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_PIXMAP
);
835 switch (toupper(type
[0])) {
837 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_CENTER
);
840 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_SCALE
);
843 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_MAXIMIZE
);
847 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_TILE
);
851 WMSetTextFieldText(panel
->imageT
,
852 PLGetString(PLGetArrayElement(texture
, 1)));
855 changeTypeCallback(panel
->typeP
, panel
);
858 updateGradButtons(panel
);
860 switch (toupper(gradient
)) {
862 WMPerformButtonClick(panel
->dirhB
);
865 WMPerformButtonClick(panel
->dirvB
);
869 WMPerformButtonClick(panel
->dirdB
);
877 str
= PLGetDescription(texture
);
878 wwarning("error creating texture %s", str
);
886 GetTexturePanelTextureName(TexturePanel
*panel
)
888 return WMGetTextFieldText(panel
->nameT
);
895 GetTexturePanelTexture(TexturePanel
*panel
)
897 proplist_t prop
= NULL
;
904 switch (WMGetPopUpButtonSelectedItem(panel
->typeP
)) {
907 color
= WMGetColorWellColor(panel
->defcW
);
908 str
= WMGetColorRGBDescription(color
);
909 prop
= PLMakeArrayFromElements(PLMakeString("solid"),
910 PLMakeString(str
), NULL
);
916 color
= WMGetColorWellColor(panel
->defcW
);
917 str
= WMGetColorRGBDescription(color
);
919 switch (WMGetPopUpButtonSelectedItem(panel
->arrP
)) {
921 prop
= PLMakeArrayFromElements(PLMakeString("spixmap"),
922 PLMakeString(panel
->imageFile
),
923 PLMakeString(str
), NULL
);
926 prop
= PLMakeArrayFromElements(PLMakeString("mpixmap"),
927 PLMakeString(panel
->imageFile
),
928 PLMakeString(str
), NULL
);
931 prop
= PLMakeArrayFromElements(PLMakeString("cpixmap"),
932 PLMakeString(panel
->imageFile
),
933 PLMakeString(str
), NULL
);
936 prop
= PLMakeArrayFromElements(PLMakeString("tpixmap"),
937 PLMakeString(panel
->imageFile
),
938 PLMakeString(str
), NULL
);
945 color
= WMGetColorWellColor(panel
->tcol1W
);
946 str
= WMGetColorRGBDescription(color
);
948 color
= WMGetColorWellColor(panel
->tcol2W
);
949 str2
= WMGetColorRGBDescription(color
);
951 if (WMGetButtonSelected(panel
->dirdB
)) {
952 prop
= PLMakeArrayFromElements(PLMakeString("dgradient"),
954 PLMakeString(str2
), NULL
);
955 } else if (WMGetButtonSelected(panel
->dirvB
)) {
956 prop
= PLMakeArrayFromElements(PLMakeString("vgradient"),
958 PLMakeString(str2
), NULL
);
960 prop
= PLMakeArrayFromElements(PLMakeString("hgradient"),
962 PLMakeString(str2
), NULL
);
969 color
= WMGetColorWellColor(panel
->defcW
);
970 str
= WMGetColorRGBDescription(color
);
972 if (WMGetButtonSelected(panel
->dirdB
)) {
973 prop
= PLMakeArrayFromElements(PLMakeString("mdgradient"),
974 PLMakeString(str
), NULL
);
975 } else if (WMGetButtonSelected(panel
->dirvB
)) {
976 prop
= PLMakeArrayFromElements(PLMakeString("mvgradient"),
977 PLMakeString(str
), NULL
);
979 prop
= PLMakeArrayFromElements(PLMakeString("mhgradient"),
980 PLMakeString(str
), NULL
);
984 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
988 item
= WMGetListItem(panel
->gcolL
, i
);
990 rgb
= (RColor
*)item
->clientData
;
992 sprintf(buff
, "#%02x%02x%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
994 PLAppendArrayElement(prop
, PLMakeString(buff
));
1006 SetTexturePanelPixmapPath(TexturePanel
*panel
, proplist_t array
)
1008 panel
->pathList
= array
;
1014 CreateTexturePanel(WMWindow
*keyWindow
)
1015 //CreateTexturePanel(WMScreen *scr)
1017 TexturePanel
*panel
;
1018 WMScreen
*scr
= WMWidgetScreen(keyWindow
);
1020 panel
= wmalloc(sizeof(TexturePanel
));
1021 memset(panel
, 0, sizeof(TexturePanel
));
1023 panel
->listFont
= WMSystemFontOfSize(scr
, 12);
1026 panel
->win
= WMCreatePanelWithStyleForWindow(keyWindow
, "texturePanel",
1028 |WMClosableWindowMask
);
1030 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1032 |WMClosableWindowMask);
1035 WMResizeWidget(panel
->win
, 325, 423);
1036 WMSetWindowTitle(panel
->win
, _("Texture Panel"));
1040 panel
->nameF
= WMCreateFrame(panel
->win
);
1041 WMResizeWidget(panel
->nameF
, 185, 50);
1042 WMMoveWidget(panel
->nameF
, 15, 10);
1043 WMSetFrameTitle(panel
->nameF
, _("Texture Name"));
1045 panel
->nameT
= WMCreateTextField(panel
->nameF
);
1046 WMResizeWidget(panel
->nameT
, 160, 20);
1047 WMMoveWidget(panel
->nameT
, 12, 18);
1049 WMMapSubwidgets(panel
->nameF
);
1052 panel
->typeP
= WMCreatePopUpButton(panel
->win
);
1053 WMResizeWidget(panel
->typeP
, 185, 20);
1054 WMMoveWidget(panel
->typeP
, 15, 65);
1055 WMAddPopUpButtonItem(panel
->typeP
, _("Solid Color"));
1056 WMAddPopUpButtonItem(panel
->typeP
, _("Gradient Texture"));
1057 WMAddPopUpButtonItem(panel
->typeP
, _("Simple Gradient Texture"));
1058 WMAddPopUpButtonItem(panel
->typeP
, _("Textured Gradient"));
1059 WMAddPopUpButtonItem(panel
->typeP
, _("Image Texture"));
1060 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
1061 WMSetPopUpButtonAction(panel
->typeP
, changeTypeCallback
, panel
);
1063 WMSetPopUpButtonItemEnabled(panel
->typeP
, TYPE_TGRADIENT
, False
);
1066 panel
->defcF
= WMCreateFrame(panel
->win
);
1067 WMResizeWidget(panel
->defcF
, 100, 75);
1068 WMMoveWidget(panel
->defcF
, 210, 10);
1069 WMSetFrameTitle(panel
->defcF
, _("Default Color"));
1071 panel
->defcW
= WMCreateColorWell(panel
->defcF
);
1072 WMResizeWidget(panel
->defcW
, 60, 45);
1073 WMMoveWidget(panel
->defcW
, 20, 20);
1075 WMMapSubwidgets(panel
->defcF
);
1077 /****** Gradient ******/
1078 panel
->gcolF
= WMCreateFrame(panel
->win
);
1079 WMResizeWidget(panel
->gcolF
, 295, 205);
1080 WMMoveWidget(panel
->gcolF
, 15, 95);
1081 WMSetFrameTitle(panel
->gcolF
, _("Gradient Colors"));
1083 panel
->gcolL
= WMCreateList(panel
->gcolF
);
1084 WMResizeWidget(panel
->gcolL
, 130, 140);
1085 WMMoveWidget(panel
->gcolL
, 10, 25);
1086 WMHangData(panel
->gcolL
, panel
);
1087 WMSetListUserDrawProc(panel
->gcolL
, paintGradListItem
);
1088 WMSetListAction(panel
->gcolL
, gradClickCallback
, panel
);
1090 panel
->gcolaB
= WMCreateCommandButton(panel
->gcolF
);
1091 WMResizeWidget(panel
->gcolaB
, 64, 24);
1092 WMMoveWidget(panel
->gcolaB
, 10, 170);
1093 WMSetButtonText(panel
->gcolaB
, _("Add"));
1094 WMSetButtonAction(panel
->gcolaB
, gradAddCallback
, panel
);
1096 panel
->gcoldB
= WMCreateCommandButton(panel
->gcolF
);
1097 WMResizeWidget(panel
->gcoldB
, 64, 24);
1098 WMMoveWidget(panel
->gcoldB
, 75, 170);
1099 WMSetButtonText(panel
->gcoldB
, _("Delete"));
1100 WMSetButtonAction(panel
->gcoldB
, gradDeleteCallback
, panel
);
1103 panel
->gbriS
= WMCreateSlider(panel
->gcolF
);
1104 WMResizeWidget(panel
->gbriS
, 130, 16);
1105 WMMoveWidget(panel
->gbriS
, 150, 25);
1106 WMSetSliderKnobThickness(panel
->gbriS
, 8);
1107 WMSetSliderMaxValue(panel
->gbriS
, 100);
1108 WMSetSliderAction(panel
->gbriS
, sliderChangeCallback
, panel
);
1113 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1114 color
= WMDarkGrayColor(scr
);
1115 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1116 WMColorGC(color
), 0, 0, 130, 16);
1117 WMReleaseColor(color
);
1118 color
= WMWhiteColor(color
);
1119 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1121 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1123 WMSetSliderImage(panel
->gbriS
, pixmap
);
1124 WMReleasePixmap(pixmap
);
1127 panel
->gconS
= WMCreateSlider(panel
->gcolF
);
1128 WMResizeWidget(panel
->gconS
, 130, 16);
1129 WMMoveWidget(panel
->gconS
, 150, 50);
1130 WMSetSliderKnobThickness(panel
->gconS
, 8);
1131 WMSetSliderMaxValue(panel
->gconS
, 100);
1132 WMSetSliderAction(panel
->gconS
, sliderChangeCallback
, panel
);
1137 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1138 color
= WMDarkGrayColor(scr
);
1139 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1140 WMColorGC(color
), 0, 0, 130, 16);
1141 WMReleaseColor(color
);
1142 color
= WMWhiteColor(scr
);
1143 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1145 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1147 WMSetSliderImage(panel
->gconS
, pixmap
);
1148 WMReleasePixmap(pixmap
);
1151 panel
->ghueS
= WMCreateSlider(panel
->gcolF
);
1152 WMResizeWidget(panel
->ghueS
, 130, 16);
1153 WMMoveWidget(panel
->ghueS
, 150, 100);
1154 WMSetSliderKnobThickness(panel
->ghueS
, 8);
1155 WMSetSliderMaxValue(panel
->ghueS
, 359);
1156 WMSetSliderAction(panel
->ghueS
, sliderChangeCallback
, panel
);
1158 panel
->gsatS
= WMCreateSlider(panel
->gcolF
);
1159 WMResizeWidget(panel
->gsatS
, 130, 16);
1160 WMMoveWidget(panel
->gsatS
, 150, 125);
1161 WMSetSliderKnobThickness(panel
->gsatS
, 8);
1162 WMSetSliderMaxValue(panel
->gsatS
, 255);
1163 WMSetSliderAction(panel
->gsatS
, sliderChangeCallback
, panel
);
1165 panel
->gvalS
= WMCreateSlider(panel
->gcolF
);
1166 WMResizeWidget(panel
->gvalS
, 130, 16);
1167 WMMoveWidget(panel
->gvalS
, 150, 150);
1168 WMSetSliderKnobThickness(panel
->gvalS
, 8);
1169 WMSetSliderMaxValue(panel
->gvalS
, 255);
1170 WMSetSliderAction(panel
->gvalS
, sliderChangeCallback
, panel
);
1173 WMMapSubwidgets(panel
->gcolF
);
1176 panel
->dirF
= WMCreateFrame(panel
->win
);
1177 WMSetFrameTitle(panel
->dirF
, _("Direction"));
1178 WMResizeWidget(panel
->dirF
, 295, 75);
1179 WMMoveWidget(panel
->dirF
, 15, 305);
1181 panel
->dirvB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1182 WMSetButtonImagePosition(panel
->dirvB
, WIPImageOnly
);
1183 WMResizeWidget(panel
->dirvB
, 90, 40);
1184 WMMoveWidget(panel
->dirvB
, 10, 20);
1186 panel
->dirhB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1187 WMSetButtonImagePosition(panel
->dirhB
, WIPImageOnly
);
1188 WMResizeWidget(panel
->dirhB
, 90, 40);
1189 WMMoveWidget(panel
->dirhB
, 102, 20);
1191 panel
->dirdB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1192 WMSetButtonImagePosition(panel
->dirdB
, WIPImageOnly
);
1193 WMResizeWidget(panel
->dirdB
, 90, 40);
1194 WMMoveWidget(panel
->dirdB
, 194, 20);
1196 WMGroupButtons(panel
->dirvB
, panel
->dirhB
);
1197 WMGroupButtons(panel
->dirvB
, panel
->dirdB
);
1199 WMMapSubwidgets(panel
->dirF
);
1201 /****************** Textured Gradient ******************/
1202 panel
->tcolF
= WMCreateFrame(panel
->win
);
1203 WMResizeWidget(panel
->tcolF
, 100, 135);
1204 WMMoveWidget(panel
->tcolF
, 210, 10);
1205 WMSetFrameTitle(panel
->tcolF
, _("Gradient"));
1207 panel
->tcol1W
= WMCreateColorWell(panel
->tcolF
);
1208 WMResizeWidget(panel
->tcol1W
, 60, 45);
1209 WMMoveWidget(panel
->tcol1W
, 20, 25);
1210 WMAddNotificationObserver(colorWellObserver
, panel
,
1211 WMColorWellDidChangeNotification
, panel
->tcol1W
);
1213 panel
->tcol2W
= WMCreateColorWell(panel
->tcolF
);
1214 WMResizeWidget(panel
->tcol2W
, 60, 45);
1215 WMMoveWidget(panel
->tcol2W
, 20, 75);
1216 WMAddNotificationObserver(colorWellObserver
, panel
,
1217 WMColorWellDidChangeNotification
, panel
->tcol2W
);
1220 panel
->topaF
= WMCreateFrame(panel
->win
);
1221 WMResizeWidget(panel
->topaF
, 185, 50);
1222 WMMoveWidget(panel
->topaF
, 15, 95);
1223 WMSetFrameTitle(panel
->topaF
, _("Gradient Opacity"));
1225 panel
->topaS
= WMCreateSlider(panel
->topaF
);
1226 WMResizeWidget(panel
->topaS
, 155, 18);
1227 WMMoveWidget(panel
->topaS
, 15, 20);
1228 WMSetSliderMaxValue(panel
->topaS
, 255);
1229 WMSetSliderValue(panel
->topaS
, 200);
1230 WMMapSubwidgets(panel
->topaF
);
1237 pixmap
= WMCreatePixmap(scr
, 155, 18, WMScreenDepth(scr
), False
);
1238 p
= WMGetPixmapXID(pixmap
);
1240 color
= WMDarkGrayColor(scr
);
1241 XFillRectangle(WMScreenDisplay(scr
), p
, WMColorGC(color
),
1243 WMReleaseColor(color
);
1245 color
= WMWhiteColor(scr
);
1246 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1248 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1249 153 - WMWidthOfString(panel
->listFont
, "100%", 4), 1,
1251 WMReleaseColor(color
);
1253 WMSetSliderImage(panel
->topaS
, pixmap
);
1254 WMReleasePixmap(pixmap
);
1257 WMMapSubwidgets(panel
->tcolF
);
1259 /****************** Image ******************/
1260 panel
->imageF
= WMCreateFrame(panel
->win
);
1261 WMResizeWidget(panel
->imageF
, 295, 150);
1262 WMMoveWidget(panel
->imageF
, 15, 150);
1263 WMSetFrameTitle(panel
->imageF
, _("Image"));
1265 panel
->imageL
= WMCreateLabel(panel
->imageF
);
1266 WMSetLabelImagePosition(panel
->imageL
, WIPImageOnly
);
1268 panel
->imageT
= WMCreateTextField(panel
->imageF
);
1269 WMResizeWidget(panel
->imageT
, 90, 20);
1270 WMMoveWidget(panel
->imageT
, 190, 25);
1272 panel
->imageV
= WMCreateScrollView(panel
->imageF
);
1273 WMResizeWidget(panel
->imageV
, 165, 115);
1274 WMMoveWidget(panel
->imageV
, 15, 20);
1275 WMSetScrollViewRelief(panel
->imageV
, WRSunken
);
1276 WMSetScrollViewHasHorizontalScroller(panel
->imageV
, True
);
1277 WMSetScrollViewHasVerticalScroller(panel
->imageV
, True
);
1278 WMSetScrollViewContentView(panel
->imageV
, WMWidgetView(panel
->imageL
));
1280 panel
->browB
= WMCreateCommandButton(panel
->imageF
);
1281 WMResizeWidget(panel
->browB
, 90, 24);
1282 WMMoveWidget(panel
->browB
, 190, 50);
1283 WMSetButtonText(panel
->browB
, _("Browse..."));
1284 WMSetButtonAction(panel
->browB
, browseImageCallback
, panel
);
1286 panel
->dispB
= WMCreateCommandButton(panel
->imageF
);
1287 WMResizeWidget(panel
->dispB
, 90, 24);
1288 WMMoveWidget(panel
->dispB
, 190, 80);
1289 WMSetButtonText(panel
->dispB
, _("Show"));
1291 panel
->arrP
= WMCreatePopUpButton(panel
->imageF
);
1292 WMResizeWidget(panel
->arrP
, 90, 20);
1293 WMMoveWidget(panel
->arrP
, 190, 120);
1294 WMAddPopUpButtonItem(panel
->arrP
, _("Tile"));
1295 WMAddPopUpButtonItem(panel
->arrP
, _("Scale"));
1296 WMAddPopUpButtonItem(panel
->arrP
, _("Center"));
1297 WMAddPopUpButtonItem(panel
->arrP
, _("Maximize"));
1298 WMSetPopUpButtonSelectedItem(panel
->arrP
, 0);
1300 WMMapSubwidgets(panel
->imageF
);
1304 panel
->okB
= WMCreateCommandButton(panel
->win
);
1305 WMResizeWidget(panel
->okB
, 84, 24);
1306 WMMoveWidget(panel
->okB
, 225, 390);
1307 WMSetButtonText(panel
->okB
, _("OK"));
1308 WMSetButtonAction(panel
->okB
, buttonCallback
, panel
);
1310 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
1311 WMResizeWidget(panel
->cancelB
, 84, 24);
1312 WMMoveWidget(panel
->cancelB
, 130, 390);
1313 WMSetButtonText(panel
->cancelB
, _("Cancel"));
1314 WMSetButtonAction(panel
->cancelB
, buttonCallback
, panel
);
1316 WMMapWidget(panel
->nameF
);
1317 WMMapWidget(panel
->typeP
);
1318 WMMapWidget(panel
->okB
);
1319 WMMapWidget(panel
->cancelB
);
1321 WMUnmapWidget(panel
->arrP
);
1323 WMRealizeWidget(panel
->win
);
1325 panel
->currentType
= -1;
1327 panel
->sectionParts
[TYPE_SOLID
][0] = panel
->defcF
;
1329 panel
->sectionParts
[TYPE_GRADIENT
][0] = panel
->defcF
;
1330 panel
->sectionParts
[TYPE_GRADIENT
][1] = panel
->gcolF
;
1331 panel
->sectionParts
[TYPE_GRADIENT
][2] = panel
->dirF
;
1333 panel
->sectionParts
[TYPE_SGRADIENT
][0] = panel
->tcolF
;
1334 panel
->sectionParts
[TYPE_SGRADIENT
][1] = panel
->dirF
;
1336 panel
->sectionParts
[TYPE_TGRADIENT
][0] = panel
->tcolF
;
1337 panel
->sectionParts
[TYPE_TGRADIENT
][1] = panel
->dirF
;
1338 panel
->sectionParts
[TYPE_TGRADIENT
][2] = panel
->imageF
;
1339 panel
->sectionParts
[TYPE_TGRADIENT
][3] = panel
->topaF
;
1340 panel
->sectionParts
[TYPE_TGRADIENT
][4] = panel
->arrP
;
1342 panel
->sectionParts
[TYPE_PIXMAP
][0] = panel
->defcF
;
1343 panel
->sectionParts
[TYPE_PIXMAP
][1] = panel
->imageF
;
1344 panel
->sectionParts
[TYPE_PIXMAP
][2] = panel
->arrP
;
1347 /* setup for first time */
1349 changeTypeCallback(panel
->typeP
, panel
);
1351 sliderChangeCallback(panel
->ghueS
, panel
);
1352 sliderChangeCallback(panel
->gsatS
, panel
);
1360 *--------------------------------------------------------------------------
1362 *--------------------------------------------------------------------------
1367 char *ProgName
= "test";
1370 testOKButton(WMWidget
*self
, void *data
)
1378 TexturePanel
*panel
= (TexturePanel
*)data
;
1379 // test = GetTexturePanelTextureString(panel);
1383 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
1384 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250,
1386 XMapRaised(dpy
, win
);
1389 // image = RenderTexturePanelTexture(panel, 250, 250);
1391 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
1393 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
, image
->height
,
1400 void testCancelButton(WMWidget
*self
, void *data
){
1401 wwarning("Exiting test....");
1410 int main(int argc
, char **argv
)
1412 TexturePanel
*panel
;
1414 Display
*dpy
= XOpenDisplay("");
1419 WMInitializeApplication("Test", &argc
, argv
);
1422 wfatal("could not open display");
1426 scr
= WMCreateSimpleApplicationScreen(dpy
);
1428 panel
= CreateTexturePanel(scr
);
1430 SetTexturePanelOkAction(panel
,(WMAction
*)testOKButton
,panel
);
1431 SetTexturePanelCancelAction(panel
,(WMAction
*)testCancelButton
,panel
);
1433 SetTexturePanelTexture(panel
, "pinky",
1434 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1436 ShowTexturePanel(panel
);
1438 WMScreenMainLoop(scr
);