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"
42 #define MAX_SECTION_PARTS 4
44 typedef struct _TexturePanel
{
76 /* direction (common) */
82 /*-- Simple Gradient --*/
85 /*-- Textured Gradient --*/
111 WMCallback
*okAction
;
114 WMCallback
*cancelAction
;
118 WMWidget
*sectionParts
[5][MAX_SECTION_PARTS
];
130 #define TYPE_GRADIENT 1
131 #define TYPE_SGRADIENT 2
132 #define TYPE_TGRADIENT 3
133 #define TYPE_PIXMAP 4
137 #define PTYPE_SCALE 1
138 #define PTYPE_CENTER 2
139 #define PTYPE_MAXIMIZE 3
144 *--------------------------------------------------------------------------
146 *--------------------------------------------------------------------------
152 updateGradButtons(TexturePanel
*panel
)
159 colorn
= WMGetListNumberOfRows(panel
->gcolL
);
166 colors
= wmalloc(sizeof(RColor
*)*(colorn
+1));
168 for (i
= 0; i
< colorn
; i
++) {
169 item
= WMGetListItem(panel
->gcolL
, i
);
170 colors
[i
] = (RColor
*)item
->clientData
;
174 image
= RRenderMultiGradient(80, 30, colors
, RHorizontalGradient
);
175 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
177 RDestroyImage(image
);
178 WMSetButtonImage(panel
->dirhB
, pixmap
);
179 WMReleasePixmap(pixmap
);
181 image
= RRenderMultiGradient(80, 30, colors
, RVerticalGradient
);
182 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
184 RDestroyImage(image
);
185 WMSetButtonImage(panel
->dirvB
, pixmap
);
186 WMReleasePixmap(pixmap
);
188 image
= RRenderMultiGradient(80, 30, colors
, RDiagonalGradient
);
189 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
191 RDestroyImage(image
);
192 WMSetButtonImage(panel
->dirdB
, pixmap
);
193 WMReleasePixmap(pixmap
);
201 updateSGradButtons(TexturePanel
*panel
)
209 color
= WMGetColorWellColor(panel
->tcol1W
);
210 from
.red
= WMRedComponentOfColor(color
)>>8;
211 from
.green
= WMGreenComponentOfColor(color
)>>8;
212 from
.blue
= WMBlueComponentOfColor(color
)>>8;
214 color
= WMGetColorWellColor(panel
->tcol2W
);
215 to
.red
= WMRedComponentOfColor(color
)>>8;
216 to
.green
= WMGreenComponentOfColor(color
)>>8;
217 to
.blue
= WMBlueComponentOfColor(color
)>>8;
219 image
= RRenderGradient(80, 30, &from
, &to
, RHorizontalGradient
);
220 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
222 RDestroyImage(image
);
223 WMSetButtonImage(panel
->dirhB
, pixmap
);
224 WMReleasePixmap(pixmap
);
226 image
= RRenderGradient(80, 30, &from
, &to
, RVerticalGradient
);
227 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
229 RDestroyImage(image
);
230 WMSetButtonImage(panel
->dirvB
, pixmap
);
231 WMReleasePixmap(pixmap
);
233 image
= RRenderGradient(80, 30, &from
, &to
, RDiagonalGradient
);
234 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
236 RDestroyImage(image
);
237 WMSetButtonImage(panel
->dirdB
, pixmap
);
238 WMReleasePixmap(pixmap
);
243 changeTypeCallback(WMWidget
*w
, void *data
)
245 TexturePanel
*panel
= (TexturePanel
*)data
;
249 newType
= WMGetPopUpButtonSelectedItem(w
);
250 if (newType
== panel
->currentType
)
253 if (panel
->currentType
>= 0) {
254 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
255 if (panel
->sectionParts
[panel
->currentType
][i
] == NULL
)
257 WMUnmapWidget(panel
->sectionParts
[panel
->currentType
][i
]);
261 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
262 if (panel
->sectionParts
[newType
][i
] == NULL
)
264 WMMapWidget(panel
->sectionParts
[newType
][i
]);
266 panel
->currentType
= newType
;
270 updateSGradButtons(panel
);
273 updateGradButtons(panel
);
279 /*********** Gradient ************/
282 updateSVSlider(WMSlider
*sPtr
, Bool saturation
, WMFont
*font
, RHSVColor
*hsv
)
286 WMScreen
*scr
= WMWidgetScreen(sPtr
);
293 RHSVtoRGB(&tmp
, &from
);
294 tmp
.saturation
= 255;
295 RHSVtoRGB(&tmp
, &to
);
298 RHSVtoRGB(&tmp
, &from
);
300 RHSVtoRGB(&tmp
, &to
);
302 image
= RRenderGradient(130, 16, &from
, &to
, RHorizontalGradient
);
303 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
304 RDestroyImage(image
);
306 if (hsv
->value
< 128 || !saturation
) {
307 WMColor
*col
= WMWhiteColor(scr
);
309 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
310 (16 - WMFontHeight(font
))/2 - 1,
311 saturation
? "Saturation" : "Brightness", 10);
314 WMColor
*col
= WMBlackColor(scr
);
316 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
317 (16 - WMFontHeight(font
))/2 - 1,
318 saturation
? "Saturation" : "Brightness", 10);
321 WMSetSliderImage(sPtr
, pixmap
);
322 WMReleasePixmap(pixmap
);
327 updateHueSlider(WMSlider
*sPtr
, WMFont
*font
, RHSVColor
*hsv
)
332 WMScreen
*scr
= WMWidgetScreen(sPtr
);
337 for (i
= 0; i
<= 6; i
++) {
338 thsv
.hue
= (360*i
)/6;
339 colors
[i
] = wmalloc(sizeof(RColor
));
340 RHSVtoRGB(&thsv
, colors
[i
]);
344 image
= RRenderMultiGradient(130, 16, colors
, RGRD_HORIZONTAL
);
345 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
346 RDestroyImage(image
);
348 if (hsv
->value
< 128) {
349 WMColor
*col
= WMWhiteColor(scr
);
351 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
352 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
355 WMColor
*col
= WMBlackColor(scr
);
357 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
358 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
361 WMSetSliderImage(sPtr
, pixmap
);
362 WMReleasePixmap(pixmap
);
364 for (i
= 0; i
<= 6; i
++)
371 sliderChangeCallback(WMWidget
*w
, void *data
)
373 TexturePanel
*panel
= (TexturePanel
*)data
;
374 RHSVColor hsv
, *hsvp
;
380 WMScreen
*scr
= WMWidgetScreen(w
);
382 hsv
.hue
= WMGetSliderValue(panel
->ghueS
);
383 hsv
.saturation
= WMGetSliderValue(panel
->gsatS
);
384 hsv
.value
= WMGetSliderValue(panel
->gvalS
);
386 row
= WMGetListSelectedItemRow(panel
->gcolL
);
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 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
401 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
402 } else if (w
== panel
->gsatS
) {
403 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
404 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
406 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
407 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
410 rows
= WMGetListNumberOfRows(panel
->gcolL
);
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
);
427 image
= RRenderMultiGradient(30, i
*WMGetListItemHeight(panel
->gcolL
),
428 colors
, RVerticalGradient
);
429 RConvertImage(WMScreenRContext(scr
), image
, &panel
->gimage
);
430 RDestroyImage(image
);
434 WMRedisplayWidget(panel
->gcolL
);
436 updateGradButtons(panel
);
441 paintGradListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
444 TexturePanel
*panel
= (TexturePanel
*)WMGetHangedData(lPtr
);
445 WMScreen
*scr
= WMWidgetScreen(lPtr
);
446 int width
, height
, x
, y
;
448 WMColor
*white
= WMWhiteColor(scr
);
450 WMColor
*black
= WMBlackColor(scr
);
452 dpy
= WMScreenDisplay(scr
);
454 width
= rect
->size
.width
;
455 height
= rect
->size
.height
;
459 if (state
& WLDSSelected
)
460 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
462 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
464 item
= WMGetListItem(lPtr
, index
);
467 XCopyArea(WMScreenDisplay(scr
), panel
->gimage
, d
, WMColorGC(white
),
468 0, height
*index
, 30, height
, x
+ 5, y
);
470 WMDrawString(scr
, d
, WMColorGC(black
), panel
->listFont
,
471 x
+ 40, y
+ 1, text
, strlen(text
));
473 WMReleaseColor(white
);
474 WMReleaseColor(black
);
480 gradAddCallback(WMWidget
*w
, void *data
)
482 TexturePanel
*panel
= (TexturePanel
*)data
;
487 row
= WMGetListSelectedItemRow(panel
->gcolL
) + 1;
488 item
= WMInsertListItem(panel
->gcolL
, row
, "00,00,00");
489 rgb
= wmalloc(sizeof(RColor
));
490 memset(rgb
, 0, sizeof(RColor
));
491 item
->clientData
= rgb
;
493 WMSelectListItem(panel
->gcolL
, row
);
495 updateGradButtons(panel
);
497 sliderChangeCallback(panel
->ghueS
, panel
);
503 gradClickCallback(WMWidget
*w
, void *data
)
505 TexturePanel
*panel
= (TexturePanel
*)data
;
510 row
= WMGetListSelectedItemRow(w
);
514 item
= WMGetListItem(panel
->gcolL
, row
);
515 RRGBtoHSV((RColor
*)item
->clientData
, &hsv
);
517 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
518 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
519 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
521 sliderChangeCallback(panel
->ghueS
, panel
);
522 sliderChangeCallback(panel
->gsatS
, panel
);
527 gradDeleteCallback(WMWidget
*w
, void *data
)
529 TexturePanel
*panel
= (TexturePanel
*)data
;
533 row
= WMGetListSelectedItemRow(panel
->gcolL
);
537 item
= WMGetListItem(panel
->gcolL
, row
);
538 free(item
->clientData
);
540 WMRemoveListItem(panel
->gcolL
, row
);
542 WMSelectListItem(panel
->gcolL
, row
- 1);
544 updateGradButtons(panel
);
546 gradClickCallback(panel
->gcolL
, panel
);
550 /*************** Simple Gradient ***************/
553 colorWellObserver(void *self
, WMNotification
*n
)
555 updateSGradButtons(self
);
559 /****************** Image ******************/
562 browseImageCallback(WMWidget
*w
, void *data
)
564 TexturePanel
*panel
= (TexturePanel
*)data
;
566 WMScreen
*scr
= WMWidgetScreen(w
);
568 opanel
= WMGetOpenPanel(scr
);
569 WMSetFilePanelCanChooseDirectories(opanel
, False
);
570 WMSetFilePanelCanChooseFiles(opanel
, True
);
572 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
573 "Open Image", NULL
)) {
574 char *path
, *fullpath
;
577 fullpath
= WMGetFilePanelFileName(opanel
);
580 path
= wstrdup(fullpath
);
582 tmp2
= strrchr(fullpath
, '/');
586 tmp
= wfindfileinarray(panel
->pathList
, tmp2
);
589 if (strcmp(fullpath
, tmp
)==0) {
596 if (!RGetImageFileFormat(fullpath
)) {
597 WMRunAlertPanel(scr
, panel
->win
, _("Error"),
598 _("The selected file does not contain a supported image."),
599 _("OK"), NULL
, NULL
);
603 RImage
*image
, *scaled
;
607 image
= RLoadImage(WMScreenRContext(scr
), fullpath
, 0);
611 message
= wstrappend(_("Could not load the selected file: "),
612 (char*)RMessageForError(RErrorCode
));
614 WMRunAlertPanel(scr
, panel
->win
, _("Error"), message
,
615 _("OK"), NULL
, NULL
);
622 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
623 RDestroyImage(image
);
625 size
= WMGetPixmapSize(pixmap
);
626 WMSetLabelImage(panel
->imageL
, pixmap
);
627 WMResizeWidget(panel
->imageL
, size
.width
, size
.height
);
629 WMReleasePixmap(pixmap
);
631 panel
->imageFile
= path
;
633 WMSetTextFieldText(panel
->imageT
, path
);
643 buttonCallback(WMWidget
*w
, void *data
)
645 TexturePanel
*panel
= (TexturePanel
*)data
;
647 if (w
== panel
->okB
) {
648 (*panel
->okAction
)(panel
->okData
);
650 (*panel
->cancelAction
)(panel
->cancelData
);
656 *--------------------------------------------------------------------------
658 *--------------------------------------------------------------------------
661 DestroyTexturePanel(TexturePanel
*panel
)
668 ShowTexturePanel(TexturePanel
*panel
)
670 WMMapWidget(panel
->win
);
675 HideTexturePanel(TexturePanel
*panel
)
677 WMUnmapWidget(panel
->win
);
682 SetTexturePanelOkAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
684 panel
->okAction
= action
;
685 panel
->okData
= clientData
;
690 SetTexturePanelCancelAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
692 panel
->cancelAction
= action
;
693 panel
->cancelData
= clientData
;
698 SetTexturePanelTexture(TexturePanel
*panel
, char *name
, proplist_t texture
)
700 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
708 WMSetTextFieldText(panel
->nameT
, name
);
713 p
= PLGetArrayElement(texture
, 0);
717 type
= PLGetString(p
);
719 /*...............................................*/
720 if (strcasecmp(type
, "solid")==0) {
722 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SOLID
);
724 p
= PLGetArrayElement(texture
, 1);
729 str
= PLGetString(p
);
730 color
= WMCreateNamedColor(scr
, str
, False
);
732 WMSetColorWellColor(panel
->defcW
, color
);
734 WMReleaseColor(color
);
735 /*...............................................*/
736 } else if (strcasecmp(type
, "hgradient")==0
737 || strcasecmp(type
, "vgradient")==0
738 || strcasecmp(type
, "dgradient")==0) {
740 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SGRADIENT
);
742 p
= PLGetArrayElement(texture
, 1);
746 str
= PLGetString(p
);
747 color
= WMCreateNamedColor(scr
, str
, False
);
749 WMSetColorWellColor(panel
->tcol1W
, color
);
751 WMReleaseColor(color
);
753 p
= PLGetArrayElement(texture
, 2);
757 str
= PLGetString(p
);
758 color
= WMCreateNamedColor(scr
, str
, False
);
760 WMSetColorWellColor(panel
->tcol2W
, color
);
762 WMReleaseColor(color
);
765 /*...............................................*/
766 } else if (strcasecmp(type
, "thgradient")==0
767 || strcasecmp(type
, "tvgradient")==0
768 || strcasecmp(type
, "tdgradient")==0) {
770 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_TGRADIENT
);
772 /****** TODO: setador de textura apartir desse */
774 /*...............................................*/
775 } else if (strcasecmp(type
, "mhgradient")==0
776 || strcasecmp(type
, "mvgradient")==0
777 || strcasecmp(type
, "mdgradient")==0) {
780 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
781 item
= WMGetListItem(panel
->gcolL
, i
);
782 free(item
->clientData
);
784 WMClearList(panel
->gcolL
);
786 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_GRADIENT
);
788 p
= PLGetArrayElement(texture
, 1);
793 str
= PLGetString(p
);
794 color
= WMCreateNamedColor(scr
, str
, False
);
796 WMSetColorWellColor(panel
->defcW
, color
);
798 WMReleaseColor(color
);
800 for (i
= 2; i
< PLGetNumberOfElements(texture
); i
++) {
804 p
= PLGetArrayElement(texture
, i
);
808 str
= PLGetString(p
);
810 XParseColor(WMScreenDisplay(scr
), WMScreenRContext(scr
)->cmap
,
813 rgb
= wmalloc(sizeof(RColor
));
814 rgb
->red
= xcolor
.red
>> 8;
815 rgb
->green
= xcolor
.green
>> 8;
816 rgb
->blue
= xcolor
.blue
>> 8;
817 sprintf(buffer
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
819 item
= WMAddListItem(panel
->gcolL
, buffer
);
820 item
->clientData
= rgb
;
823 sliderChangeCallback(panel
->ghueS
, panel
);
826 /*...............................................*/
827 } else if (strcasecmp(type
, "cpixmap")==0
828 || strcasecmp(type
, "spixmap")==0
829 || strcasecmp(type
, "mpixmap")==0
830 || strcasecmp(type
, "tpixmap")==0) {
832 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_PIXMAP
);
834 switch (toupper(type
[0])) {
836 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_CENTER
);
839 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_SCALE
);
842 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_MAXIMIZE
);
846 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_TILE
);
850 WMSetTextFieldText(panel
->imageT
,
851 PLGetString(PLGetArrayElement(texture
, 1)));
854 changeTypeCallback(panel
->typeP
, panel
);
857 updateGradButtons(panel
);
859 switch (toupper(gradient
)) {
861 WMPerformButtonClick(panel
->dirhB
);
864 WMPerformButtonClick(panel
->dirvB
);
868 WMPerformButtonClick(panel
->dirdB
);
876 str
= PLGetDescription(texture
);
877 wwarning("error creating texture %s", str
);
885 GetTexturePanelTextureName(TexturePanel
*panel
)
887 return WMGetTextFieldText(panel
->nameT
);
894 GetTexturePanelTexture(TexturePanel
*panel
)
896 proplist_t prop
= NULL
;
903 switch (WMGetPopUpButtonSelectedItem(panel
->typeP
)) {
906 color
= WMGetColorWellColor(panel
->defcW
);
907 str
= WMGetColorRGBDescription(color
);
908 prop
= PLMakeArrayFromElements(PLMakeString("solid"),
909 PLMakeString(str
), NULL
);
915 color
= WMGetColorWellColor(panel
->defcW
);
916 str
= WMGetColorRGBDescription(color
);
918 switch (WMGetPopUpButtonSelectedItem(panel
->arrP
)) {
920 prop
= PLMakeArrayFromElements(PLMakeString("spixmap"),
921 PLMakeString(panel
->imageFile
),
922 PLMakeString(str
), NULL
);
925 prop
= PLMakeArrayFromElements(PLMakeString("mpixmap"),
926 PLMakeString(panel
->imageFile
),
927 PLMakeString(str
), NULL
);
930 prop
= PLMakeArrayFromElements(PLMakeString("cpixmap"),
931 PLMakeString(panel
->imageFile
),
932 PLMakeString(str
), NULL
);
935 prop
= PLMakeArrayFromElements(PLMakeString("tpixmap"),
936 PLMakeString(panel
->imageFile
),
937 PLMakeString(str
), NULL
);
944 color
= WMGetColorWellColor(panel
->tcol1W
);
945 str
= WMGetColorRGBDescription(color
);
947 color
= WMGetColorWellColor(panel
->tcol2W
);
948 str2
= WMGetColorRGBDescription(color
);
950 if (WMGetButtonSelected(panel
->dirdB
)) {
951 prop
= PLMakeArrayFromElements(PLMakeString("dgradient"),
953 PLMakeString(str2
), NULL
);
954 } else if (WMGetButtonSelected(panel
->dirvB
)) {
955 prop
= PLMakeArrayFromElements(PLMakeString("vgradient"),
957 PLMakeString(str2
), NULL
);
959 prop
= PLMakeArrayFromElements(PLMakeString("hgradient"),
961 PLMakeString(str2
), NULL
);
968 color
= WMGetColorWellColor(panel
->defcW
);
969 str
= WMGetColorRGBDescription(color
);
971 if (WMGetButtonSelected(panel
->dirdB
)) {
972 prop
= PLMakeArrayFromElements(PLMakeString("mdgradient"),
973 PLMakeString(str
), NULL
);
974 } else if (WMGetButtonSelected(panel
->dirvB
)) {
975 prop
= PLMakeArrayFromElements(PLMakeString("mvgradient"),
976 PLMakeString(str
), NULL
);
978 prop
= PLMakeArrayFromElements(PLMakeString("mhgradient"),
979 PLMakeString(str
), NULL
);
983 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
987 item
= WMGetListItem(panel
->gcolL
, i
);
989 rgb
= (RColor
*)item
->clientData
;
991 sprintf(buff
, "#%02x%02x%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
993 PLAppendArrayElement(prop
, PLMakeString(buff
));
1005 SetTexturePanelPixmapPath(TexturePanel
*panel
, proplist_t array
)
1007 panel
->pathList
= array
;
1013 CreateTexturePanel(WMWindow
*keyWindow
)
1014 /*CreateTexturePanel(WMScreen *scr)*/
1016 TexturePanel
*panel
;
1017 WMScreen
*scr
= WMWidgetScreen(keyWindow
);
1019 panel
= wmalloc(sizeof(TexturePanel
));
1020 memset(panel
, 0, sizeof(TexturePanel
));
1022 panel
->listFont
= WMSystemFontOfSize(scr
, 12);
1025 panel
->win
= WMCreatePanelWithStyleForWindow(keyWindow
, "texturePanel",
1027 |WMClosableWindowMask
);
1029 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1031 |WMClosableWindowMask);
1034 WMResizeWidget(panel
->win
, 325, 423);
1035 WMSetWindowTitle(panel
->win
, _("Texture Panel"));
1039 panel
->nameF
= WMCreateFrame(panel
->win
);
1040 WMResizeWidget(panel
->nameF
, 185, 50);
1041 WMMoveWidget(panel
->nameF
, 15, 10);
1042 WMSetFrameTitle(panel
->nameF
, _("Texture Name"));
1044 panel
->nameT
= WMCreateTextField(panel
->nameF
);
1045 WMResizeWidget(panel
->nameT
, 160, 20);
1046 WMMoveWidget(panel
->nameT
, 12, 18);
1048 WMMapSubwidgets(panel
->nameF
);
1051 panel
->typeP
= WMCreatePopUpButton(panel
->win
);
1052 WMResizeWidget(panel
->typeP
, 185, 20);
1053 WMMoveWidget(panel
->typeP
, 15, 65);
1054 WMAddPopUpButtonItem(panel
->typeP
, _("Solid Color"));
1055 WMAddPopUpButtonItem(panel
->typeP
, _("Gradient Texture"));
1056 WMAddPopUpButtonItem(panel
->typeP
, _("Simple Gradient Texture"));
1057 WMAddPopUpButtonItem(panel
->typeP
, _("Textured Gradient"));
1058 WMAddPopUpButtonItem(panel
->typeP
, _("Image Texture"));
1059 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
1060 WMSetPopUpButtonAction(panel
->typeP
, changeTypeCallback
, panel
);
1062 WMSetPopUpButtonItemEnabled(panel
->typeP
, TYPE_TGRADIENT
, False
);
1065 panel
->defcF
= WMCreateFrame(panel
->win
);
1066 WMResizeWidget(panel
->defcF
, 100, 75);
1067 WMMoveWidget(panel
->defcF
, 210, 10);
1068 WMSetFrameTitle(panel
->defcF
, _("Default Color"));
1070 panel
->defcW
= WMCreateColorWell(panel
->defcF
);
1071 WMResizeWidget(panel
->defcW
, 60, 45);
1072 WMMoveWidget(panel
->defcW
, 20, 20);
1074 WMMapSubwidgets(panel
->defcF
);
1076 /****** Gradient ******/
1077 panel
->gcolF
= WMCreateFrame(panel
->win
);
1078 WMResizeWidget(panel
->gcolF
, 295, 205);
1079 WMMoveWidget(panel
->gcolF
, 15, 95);
1080 WMSetFrameTitle(panel
->gcolF
, _("Gradient Colors"));
1082 panel
->gcolL
= WMCreateList(panel
->gcolF
);
1083 WMResizeWidget(panel
->gcolL
, 130, 140);
1084 WMMoveWidget(panel
->gcolL
, 10, 25);
1085 WMHangData(panel
->gcolL
, panel
);
1086 WMSetListUserDrawProc(panel
->gcolL
, paintGradListItem
);
1087 WMSetListAction(panel
->gcolL
, gradClickCallback
, panel
);
1089 panel
->gcolaB
= WMCreateCommandButton(panel
->gcolF
);
1090 WMResizeWidget(panel
->gcolaB
, 64, 24);
1091 WMMoveWidget(panel
->gcolaB
, 10, 170);
1092 WMSetButtonText(panel
->gcolaB
, _("Add"));
1093 WMSetButtonAction(panel
->gcolaB
, gradAddCallback
, panel
);
1095 panel
->gcoldB
= WMCreateCommandButton(panel
->gcolF
);
1096 WMResizeWidget(panel
->gcoldB
, 64, 24);
1097 WMMoveWidget(panel
->gcoldB
, 75, 170);
1098 WMSetButtonText(panel
->gcoldB
, _("Delete"));
1099 WMSetButtonAction(panel
->gcoldB
, gradDeleteCallback
, panel
);
1102 panel
->gbriS
= WMCreateSlider(panel
->gcolF
);
1103 WMResizeWidget(panel
->gbriS
, 130, 16);
1104 WMMoveWidget(panel
->gbriS
, 150, 25);
1105 WMSetSliderKnobThickness(panel
->gbriS
, 8);
1106 WMSetSliderMaxValue(panel
->gbriS
, 100);
1107 WMSetSliderAction(panel
->gbriS
, sliderChangeCallback
, panel
);
1112 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1113 color
= WMDarkGrayColor(scr
);
1114 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1115 WMColorGC(color
), 0, 0, 130, 16);
1116 WMReleaseColor(color
);
1117 color
= WMWhiteColor(color
);
1118 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1120 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1122 WMSetSliderImage(panel
->gbriS
, pixmap
);
1123 WMReleasePixmap(pixmap
);
1126 panel
->gconS
= WMCreateSlider(panel
->gcolF
);
1127 WMResizeWidget(panel
->gconS
, 130, 16);
1128 WMMoveWidget(panel
->gconS
, 150, 50);
1129 WMSetSliderKnobThickness(panel
->gconS
, 8);
1130 WMSetSliderMaxValue(panel
->gconS
, 100);
1131 WMSetSliderAction(panel
->gconS
, sliderChangeCallback
, panel
);
1136 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1137 color
= WMDarkGrayColor(scr
);
1138 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1139 WMColorGC(color
), 0, 0, 130, 16);
1140 WMReleaseColor(color
);
1141 color
= WMWhiteColor(scr
);
1142 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1144 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1146 WMSetSliderImage(panel
->gconS
, pixmap
);
1147 WMReleasePixmap(pixmap
);
1150 panel
->ghueS
= WMCreateSlider(panel
->gcolF
);
1151 WMResizeWidget(panel
->ghueS
, 130, 16);
1152 WMMoveWidget(panel
->ghueS
, 150, 100);
1153 WMSetSliderKnobThickness(panel
->ghueS
, 8);
1154 WMSetSliderMaxValue(panel
->ghueS
, 359);
1155 WMSetSliderAction(panel
->ghueS
, sliderChangeCallback
, panel
);
1157 panel
->gsatS
= WMCreateSlider(panel
->gcolF
);
1158 WMResizeWidget(panel
->gsatS
, 130, 16);
1159 WMMoveWidget(panel
->gsatS
, 150, 125);
1160 WMSetSliderKnobThickness(panel
->gsatS
, 8);
1161 WMSetSliderMaxValue(panel
->gsatS
, 255);
1162 WMSetSliderAction(panel
->gsatS
, sliderChangeCallback
, panel
);
1164 panel
->gvalS
= WMCreateSlider(panel
->gcolF
);
1165 WMResizeWidget(panel
->gvalS
, 130, 16);
1166 WMMoveWidget(panel
->gvalS
, 150, 150);
1167 WMSetSliderKnobThickness(panel
->gvalS
, 8);
1168 WMSetSliderMaxValue(panel
->gvalS
, 255);
1169 WMSetSliderAction(panel
->gvalS
, sliderChangeCallback
, panel
);
1172 WMMapSubwidgets(panel
->gcolF
);
1175 panel
->dirF
= WMCreateFrame(panel
->win
);
1176 WMSetFrameTitle(panel
->dirF
, _("Direction"));
1177 WMResizeWidget(panel
->dirF
, 295, 75);
1178 WMMoveWidget(panel
->dirF
, 15, 305);
1180 panel
->dirvB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1181 WMSetButtonImagePosition(panel
->dirvB
, WIPImageOnly
);
1182 WMResizeWidget(panel
->dirvB
, 90, 40);
1183 WMMoveWidget(panel
->dirvB
, 10, 20);
1185 panel
->dirhB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1186 WMSetButtonImagePosition(panel
->dirhB
, WIPImageOnly
);
1187 WMResizeWidget(panel
->dirhB
, 90, 40);
1188 WMMoveWidget(panel
->dirhB
, 102, 20);
1190 panel
->dirdB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1191 WMSetButtonImagePosition(panel
->dirdB
, WIPImageOnly
);
1192 WMResizeWidget(panel
->dirdB
, 90, 40);
1193 WMMoveWidget(panel
->dirdB
, 194, 20);
1195 WMGroupButtons(panel
->dirvB
, panel
->dirhB
);
1196 WMGroupButtons(panel
->dirvB
, panel
->dirdB
);
1198 WMMapSubwidgets(panel
->dirF
);
1200 /****************** Textured Gradient ******************/
1201 panel
->tcolF
= WMCreateFrame(panel
->win
);
1202 WMResizeWidget(panel
->tcolF
, 100, 135);
1203 WMMoveWidget(panel
->tcolF
, 210, 10);
1204 WMSetFrameTitle(panel
->tcolF
, _("Gradient"));
1206 panel
->tcol1W
= WMCreateColorWell(panel
->tcolF
);
1207 WMResizeWidget(panel
->tcol1W
, 60, 45);
1208 WMMoveWidget(panel
->tcol1W
, 20, 25);
1209 WMAddNotificationObserver(colorWellObserver
, panel
,
1210 WMColorWellDidChangeNotification
, panel
->tcol1W
);
1212 panel
->tcol2W
= WMCreateColorWell(panel
->tcolF
);
1213 WMResizeWidget(panel
->tcol2W
, 60, 45);
1214 WMMoveWidget(panel
->tcol2W
, 20, 75);
1215 WMAddNotificationObserver(colorWellObserver
, panel
,
1216 WMColorWellDidChangeNotification
, panel
->tcol2W
);
1219 panel
->topaF
= WMCreateFrame(panel
->win
);
1220 WMResizeWidget(panel
->topaF
, 185, 50);
1221 WMMoveWidget(panel
->topaF
, 15, 95);
1222 WMSetFrameTitle(panel
->topaF
, _("Gradient Opacity"));
1224 panel
->topaS
= WMCreateSlider(panel
->topaF
);
1225 WMResizeWidget(panel
->topaS
, 155, 18);
1226 WMMoveWidget(panel
->topaS
, 15, 20);
1227 WMSetSliderMaxValue(panel
->topaS
, 255);
1228 WMSetSliderValue(panel
->topaS
, 200);
1229 WMMapSubwidgets(panel
->topaF
);
1236 pixmap
= WMCreatePixmap(scr
, 155, 18, WMScreenDepth(scr
), False
);
1237 p
= WMGetPixmapXID(pixmap
);
1239 color
= WMDarkGrayColor(scr
);
1240 XFillRectangle(WMScreenDisplay(scr
), p
, WMColorGC(color
),
1242 WMReleaseColor(color
);
1244 color
= WMWhiteColor(scr
);
1245 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1247 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1248 153 - WMWidthOfString(panel
->listFont
, "100%", 4), 1,
1250 WMReleaseColor(color
);
1252 WMSetSliderImage(panel
->topaS
, pixmap
);
1253 WMReleasePixmap(pixmap
);
1256 WMMapSubwidgets(panel
->tcolF
);
1258 /****************** Image ******************/
1259 panel
->imageF
= WMCreateFrame(panel
->win
);
1260 WMResizeWidget(panel
->imageF
, 295, 150);
1261 WMMoveWidget(panel
->imageF
, 15, 150);
1262 WMSetFrameTitle(panel
->imageF
, _("Image"));
1264 panel
->imageL
= WMCreateLabel(panel
->imageF
);
1265 WMSetLabelImagePosition(panel
->imageL
, WIPImageOnly
);
1267 panel
->imageT
= WMCreateTextField(panel
->imageF
);
1268 WMResizeWidget(panel
->imageT
, 90, 20);
1269 WMMoveWidget(panel
->imageT
, 190, 25);
1271 panel
->imageV
= WMCreateScrollView(panel
->imageF
);
1272 WMResizeWidget(panel
->imageV
, 165, 115);
1273 WMMoveWidget(panel
->imageV
, 15, 20);
1274 WMSetScrollViewRelief(panel
->imageV
, WRSunken
);
1275 WMSetScrollViewHasHorizontalScroller(panel
->imageV
, True
);
1276 WMSetScrollViewHasVerticalScroller(panel
->imageV
, True
);
1277 WMSetScrollViewContentView(panel
->imageV
, WMWidgetView(panel
->imageL
));
1279 panel
->browB
= WMCreateCommandButton(panel
->imageF
);
1280 WMResizeWidget(panel
->browB
, 90, 24);
1281 WMMoveWidget(panel
->browB
, 190, 50);
1282 WMSetButtonText(panel
->browB
, _("Browse..."));
1283 WMSetButtonAction(panel
->browB
, browseImageCallback
, panel
);
1285 panel
->dispB
= WMCreateCommandButton(panel
->imageF
);
1286 WMResizeWidget(panel
->dispB
, 90, 24);
1287 WMMoveWidget(panel
->dispB
, 190, 80);
1288 WMSetButtonText(panel
->dispB
, _("Show"));
1290 panel
->arrP
= WMCreatePopUpButton(panel
->imageF
);
1291 WMResizeWidget(panel
->arrP
, 90, 20);
1292 WMMoveWidget(panel
->arrP
, 190, 120);
1293 WMAddPopUpButtonItem(panel
->arrP
, _("Tile"));
1294 WMAddPopUpButtonItem(panel
->arrP
, _("Scale"));
1295 WMAddPopUpButtonItem(panel
->arrP
, _("Center"));
1296 WMAddPopUpButtonItem(panel
->arrP
, _("Maximize"));
1297 WMSetPopUpButtonSelectedItem(panel
->arrP
, 0);
1299 WMMapSubwidgets(panel
->imageF
);
1303 panel
->okB
= WMCreateCommandButton(panel
->win
);
1304 WMResizeWidget(panel
->okB
, 84, 24);
1305 WMMoveWidget(panel
->okB
, 225, 390);
1306 WMSetButtonText(panel
->okB
, _("OK"));
1307 WMSetButtonAction(panel
->okB
, buttonCallback
, panel
);
1309 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
1310 WMResizeWidget(panel
->cancelB
, 84, 24);
1311 WMMoveWidget(panel
->cancelB
, 130, 390);
1312 WMSetButtonText(panel
->cancelB
, _("Cancel"));
1313 WMSetButtonAction(panel
->cancelB
, buttonCallback
, panel
);
1315 WMMapWidget(panel
->nameF
);
1316 WMMapWidget(panel
->typeP
);
1317 WMMapWidget(panel
->okB
);
1318 WMMapWidget(panel
->cancelB
);
1320 WMUnmapWidget(panel
->arrP
);
1322 WMRealizeWidget(panel
->win
);
1324 panel
->currentType
= -1;
1326 panel
->sectionParts
[TYPE_SOLID
][0] = panel
->defcF
;
1328 panel
->sectionParts
[TYPE_GRADIENT
][0] = panel
->defcF
;
1329 panel
->sectionParts
[TYPE_GRADIENT
][1] = panel
->gcolF
;
1330 panel
->sectionParts
[TYPE_GRADIENT
][2] = panel
->dirF
;
1332 panel
->sectionParts
[TYPE_SGRADIENT
][0] = panel
->tcolF
;
1333 panel
->sectionParts
[TYPE_SGRADIENT
][1] = panel
->dirF
;
1335 panel
->sectionParts
[TYPE_TGRADIENT
][0] = panel
->tcolF
;
1336 panel
->sectionParts
[TYPE_TGRADIENT
][1] = panel
->dirF
;
1337 panel
->sectionParts
[TYPE_TGRADIENT
][2] = panel
->imageF
;
1338 panel
->sectionParts
[TYPE_TGRADIENT
][3] = panel
->topaF
;
1339 panel
->sectionParts
[TYPE_TGRADIENT
][4] = panel
->arrP
;
1341 panel
->sectionParts
[TYPE_PIXMAP
][0] = panel
->defcF
;
1342 panel
->sectionParts
[TYPE_PIXMAP
][1] = panel
->imageF
;
1343 panel
->sectionParts
[TYPE_PIXMAP
][2] = panel
->arrP
;
1346 /* setup for first time */
1348 changeTypeCallback(panel
->typeP
, panel
);
1350 sliderChangeCallback(panel
->ghueS
, panel
);
1351 sliderChangeCallback(panel
->gsatS
, panel
);
1359 *--------------------------------------------------------------------------
1361 *--------------------------------------------------------------------------
1366 char *ProgName
= "test";
1369 testOKButton(WMWidget
*self
, void *data
)
1377 TexturePanel
*panel
= (TexturePanel
*)data
;
1378 // test = GetTexturePanelTextureString(panel);
1382 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
1383 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250,
1385 XMapRaised(dpy
, win
);
1388 // image = RenderTexturePanelTexture(panel, 250, 250);
1390 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
1392 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
, image
->height
,
1399 void testCancelButton(WMWidget
*self
, void *data
){
1400 wwarning("Exiting test....");
1409 int main(int argc
, char **argv
)
1411 TexturePanel
*panel
;
1413 Display
*dpy
= XOpenDisplay("");
1418 WMInitializeApplication("Test", &argc
, argv
);
1421 wfatal("could not open display");
1425 scr
= WMCreateSimpleApplicationScreen(dpy
);
1427 panel
= CreateTexturePanel(scr
);
1429 SetTexturePanelOkAction(panel
,(WMAction
*)testOKButton
,panel
);
1430 SetTexturePanelCancelAction(panel
,(WMAction
*)testCancelButton
,panel
);
1432 SetTexturePanelTexture(panel
, "pinky",
1433 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1435 ShowTexturePanel(panel
);
1437 WMScreenMainLoop(scr
);