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 --*/
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
);
203 updateTGradImage(TexturePanel
*panel
)
205 RImage
*image
, *gradient
;
211 color
= WMGetColorWellColor(panel
->tcol1W
);
212 from
.red
= WMRedComponentOfColor(color
)>>8;
213 from
.green
= WMGreenComponentOfColor(color
)>>8;
214 from
.blue
= WMBlueComponentOfColor(color
)>>8;
216 color
= WMGetColorWellColor(panel
->tcol2W
);
217 to
.red
= WMRedComponentOfColor(color
)>>8;
218 to
.green
= WMGreenComponentOfColor(color
)>>8;
219 to
.blue
= WMBlueComponentOfColor(color
)>>8;
221 if (WMGetButtonSelected(panel
->dirhB
)) {
222 gradient
= RRenderGradient(80, 30, &from
, &to
, RHorizontalGradient
);
223 } else if (WMGetButtonSelected(panel
->dirvB
)) {
224 gradient
= RRenderGradient(80, 30, &from
, &to
, RVerticalGradient
);
226 gradient
= RRenderGradient(80, 30, &from
, &to
, RDiagonalGradient
);
232 updateSGradButtons(TexturePanel
*panel
)
240 color
= WMGetColorWellColor(panel
->tcol1W
);
241 from
.red
= WMRedComponentOfColor(color
)>>8;
242 from
.green
= WMGreenComponentOfColor(color
)>>8;
243 from
.blue
= WMBlueComponentOfColor(color
)>>8;
245 color
= WMGetColorWellColor(panel
->tcol2W
);
246 to
.red
= WMRedComponentOfColor(color
)>>8;
247 to
.green
= WMGreenComponentOfColor(color
)>>8;
248 to
.blue
= WMBlueComponentOfColor(color
)>>8;
250 image
= RRenderGradient(80, 30, &from
, &to
, RHorizontalGradient
);
251 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
253 RDestroyImage(image
);
254 WMSetButtonImage(panel
->dirhB
, pixmap
);
255 WMReleasePixmap(pixmap
);
257 image
= RRenderGradient(80, 30, &from
, &to
, RVerticalGradient
);
258 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
260 RDestroyImage(image
);
261 WMSetButtonImage(panel
->dirvB
, pixmap
);
262 WMReleasePixmap(pixmap
);
264 image
= RRenderGradient(80, 30, &from
, &to
, RDiagonalGradient
);
265 pixmap
= WMCreatePixmapFromRImage(WMWidgetScreen(panel
->gcolL
),
267 RDestroyImage(image
);
268 WMSetButtonImage(panel
->dirdB
, pixmap
);
269 WMReleasePixmap(pixmap
);
274 changeTypeCallback(WMWidget
*w
, void *data
)
276 TexturePanel
*panel
= (TexturePanel
*)data
;
280 newType
= WMGetPopUpButtonSelectedItem(w
);
281 if (newType
== panel
->currentType
)
284 if (panel
->currentType
>= 0) {
285 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
286 if (panel
->sectionParts
[panel
->currentType
][i
] == NULL
)
288 WMUnmapWidget(panel
->sectionParts
[panel
->currentType
][i
]);
292 for (i
= 0; i
< MAX_SECTION_PARTS
; i
++) {
293 if (panel
->sectionParts
[newType
][i
] == NULL
)
295 WMMapWidget(panel
->sectionParts
[newType
][i
]);
297 panel
->currentType
= newType
;
301 updateSGradButtons(panel
);
304 updateGradButtons(panel
);
310 /*********** Gradient ************/
313 updateSVSlider(WMSlider
*sPtr
, Bool saturation
, WMFont
*font
, RHSVColor
*hsv
)
317 WMScreen
*scr
= WMWidgetScreen(sPtr
);
324 RHSVtoRGB(&tmp
, &from
);
325 tmp
.saturation
= 255;
326 RHSVtoRGB(&tmp
, &to
);
329 RHSVtoRGB(&tmp
, &from
);
331 RHSVtoRGB(&tmp
, &to
);
333 image
= RRenderGradient(130, 16, &from
, &to
, RHorizontalGradient
);
334 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
335 RDestroyImage(image
);
337 if (hsv
->value
< 128 || !saturation
) {
338 WMColor
*col
= WMWhiteColor(scr
);
340 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
341 (16 - WMFontHeight(font
))/2 - 1,
342 saturation
? "Saturation" : "Brightness", 10);
345 WMColor
*col
= WMBlackColor(scr
);
347 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
348 (16 - WMFontHeight(font
))/2 - 1,
349 saturation
? "Saturation" : "Brightness", 10);
352 WMSetSliderImage(sPtr
, pixmap
);
353 WMReleasePixmap(pixmap
);
358 updateHueSlider(WMSlider
*sPtr
, WMFont
*font
, RHSVColor
*hsv
)
363 WMScreen
*scr
= WMWidgetScreen(sPtr
);
368 for (i
= 0; i
<= 6; i
++) {
369 thsv
.hue
= (360*i
)/6;
370 colors
[i
] = wmalloc(sizeof(RColor
));
371 RHSVtoRGB(&thsv
, colors
[i
]);
375 image
= RRenderMultiGradient(130, 16, colors
, RGRD_HORIZONTAL
);
376 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
377 RDestroyImage(image
);
379 if (hsv
->value
< 128) {
380 WMColor
*col
= WMWhiteColor(scr
);
382 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
383 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
386 WMColor
*col
= WMBlackColor(scr
);
388 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(col
), font
, 2,
389 (16 - WMFontHeight(font
))/2 - 1, "Hue", 3);
392 WMSetSliderImage(sPtr
, pixmap
);
393 WMReleasePixmap(pixmap
);
395 for (i
= 0; i
<= 6; i
++)
402 sliderChangeCallback(WMWidget
*w
, void *data
)
404 TexturePanel
*panel
= (TexturePanel
*)data
;
405 RHSVColor hsv
, *hsvp
;
411 WMScreen
*scr
= WMWidgetScreen(w
);
413 hsv
.hue
= WMGetSliderValue(panel
->ghueS
);
414 hsv
.saturation
= WMGetSliderValue(panel
->gsatS
);
415 hsv
.value
= WMGetSliderValue(panel
->gvalS
);
417 row
= WMGetListSelectedItemRow(panel
->gcolL
);
421 item
= WMGetListItem(panel
->gcolL
, row
);
423 rgb
= (RColor
*)item
->clientData
;
425 RHSVtoRGB(&hsv
, rgb
);
427 sprintf(item
->text
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
430 if (w
== panel
->ghueS
) {
431 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
432 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
433 } else if (w
== panel
->gsatS
) {
434 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
435 updateSVSlider(panel
->gvalS
, False
, panel
->listFont
, &hsv
);
437 updateHueSlider(panel
->ghueS
, panel
->listFont
, &hsv
);
438 updateSVSlider(panel
->gsatS
, True
, panel
->listFont
, &hsv
);
441 rows
= WMGetListNumberOfRows(panel
->gcolL
);
445 colors
= wmalloc(sizeof(RColor
*)*(rows
+1));
447 for (i
= 0; i
< rows
; i
++) {
448 item
= WMGetListItem(panel
->gcolL
, i
);
450 colors
[i
] = (RColor
*)item
->clientData
;
454 if (panel
->gimage
!= None
) {
455 XFreePixmap(WMScreenDisplay(scr
), panel
->gimage
);
458 image
= RRenderMultiGradient(30, i
*WMGetListItemHeight(panel
->gcolL
),
459 colors
, RVerticalGradient
);
460 RConvertImage(WMScreenRContext(scr
), image
, &panel
->gimage
);
461 RDestroyImage(image
);
465 WMRedisplayWidget(panel
->gcolL
);
467 updateGradButtons(panel
);
472 paintGradListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
475 TexturePanel
*panel
= (TexturePanel
*)WMGetHangedData(lPtr
);
476 WMScreen
*scr
= WMWidgetScreen(lPtr
);
477 int width
, height
, x
, y
;
479 WMColor
*white
= WMWhiteColor(scr
);
481 WMColor
*black
= WMBlackColor(scr
);
483 dpy
= WMScreenDisplay(scr
);
485 width
= rect
->size
.width
;
486 height
= rect
->size
.height
;
490 if (state
& WLDSSelected
)
491 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
493 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
495 item
= WMGetListItem(lPtr
, index
);
498 XCopyArea(WMScreenDisplay(scr
), panel
->gimage
, d
, WMColorGC(white
),
499 0, height
*index
, 30, height
, x
+ 5, y
);
501 WMDrawString(scr
, d
, WMColorGC(black
), panel
->listFont
,
502 x
+ 40, y
+ 1, text
, strlen(text
));
504 WMReleaseColor(white
);
505 WMReleaseColor(black
);
511 gradAddCallback(WMWidget
*w
, void *data
)
513 TexturePanel
*panel
= (TexturePanel
*)data
;
518 row
= WMGetListSelectedItemRow(panel
->gcolL
) + 1;
519 item
= WMInsertListItem(panel
->gcolL
, row
, "00,00,00");
520 rgb
= wmalloc(sizeof(RColor
));
521 memset(rgb
, 0, sizeof(RColor
));
522 item
->clientData
= rgb
;
524 WMSelectListItem(panel
->gcolL
, row
);
526 updateGradButtons(panel
);
528 sliderChangeCallback(panel
->ghueS
, panel
);
534 gradClickCallback(WMWidget
*w
, void *data
)
536 TexturePanel
*panel
= (TexturePanel
*)data
;
541 row
= WMGetListSelectedItemRow(w
);
545 item
= WMGetListItem(panel
->gcolL
, row
);
546 RRGBtoHSV((RColor
*)item
->clientData
, &hsv
);
548 WMSetSliderValue(panel
->ghueS
, hsv
.hue
);
549 WMSetSliderValue(panel
->gsatS
, hsv
.saturation
);
550 WMSetSliderValue(panel
->gvalS
, hsv
.value
);
552 sliderChangeCallback(panel
->ghueS
, panel
);
553 sliderChangeCallback(panel
->gsatS
, panel
);
558 gradDeleteCallback(WMWidget
*w
, void *data
)
560 TexturePanel
*panel
= (TexturePanel
*)data
;
564 row
= WMGetListSelectedItemRow(panel
->gcolL
);
568 item
= WMGetListItem(panel
->gcolL
, row
);
569 free(item
->clientData
);
571 WMRemoveListItem(panel
->gcolL
, row
);
573 WMSelectListItem(panel
->gcolL
, row
- 1);
575 updateGradButtons(panel
);
577 gradClickCallback(panel
->gcolL
, panel
);
581 /*************** Simple Gradient ***************/
584 colorWellObserver(void *self
, WMNotification
*n
)
586 updateSGradButtons(self
);
590 /****************** Image ******************/
593 browseImageCallback(WMWidget
*w
, void *data
)
595 TexturePanel
*panel
= (TexturePanel
*)data
;
597 WMScreen
*scr
= WMWidgetScreen(w
);
599 opanel
= WMGetOpenPanel(scr
);
600 WMSetFilePanelCanChooseDirectories(opanel
, False
);
601 WMSetFilePanelCanChooseFiles(opanel
, True
);
603 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
604 "Open Image", NULL
)) {
605 char *path
, *fullpath
;
608 fullpath
= WMGetFilePanelFileName(opanel
);
611 path
= wstrdup(fullpath
);
613 tmp2
= strrchr(fullpath
, '/');
617 tmp
= wfindfileinarray(panel
->pathList
, tmp2
);
620 if (strcmp(fullpath
, tmp
)==0) {
627 if (!RGetImageFileFormat(fullpath
)) {
628 WMRunAlertPanel(scr
, panel
->win
, _("Error"),
629 _("The selected file does not contain a supported image."),
630 _("OK"), NULL
, NULL
);
634 RImage
*image
, *scaled
;
638 image
= RLoadImage(WMScreenRContext(scr
), fullpath
, 0);
642 message
= wstrappend(_("Could not load the selected file: "),
643 (char*)RMessageForError(RErrorCode
));
645 WMRunAlertPanel(scr
, panel
->win
, _("Error"), message
,
646 _("OK"), NULL
, NULL
);
654 RDestroyImage(panel
->image
);
655 panel
->image
= image
;
657 if (WMGetPopUpButtonSelectedItem(panel
->typeP
) == TYPE_PIXMAP
) {
658 pixmap
= WMCreatePixmapFromRImage(scr
, image
, 128);
660 size
= WMGetPixmapSize(pixmap
);
661 WMSetLabelImage(panel
->imageL
, pixmap
);
662 WMResizeWidget(panel
->imageL
, size
.width
, size
.height
);
664 WMReleasePixmap(pixmap
);
666 updateTGradImage(panel
);
668 panel
->imageFile
= path
;
670 WMSetTextFieldText(panel
->imageT
, path
);
680 buttonCallback(WMWidget
*w
, void *data
)
682 TexturePanel
*panel
= (TexturePanel
*)data
;
684 if (w
== panel
->okB
) {
685 (*panel
->okAction
)(panel
->okData
);
687 (*panel
->cancelAction
)(panel
->cancelData
);
693 *--------------------------------------------------------------------------
695 *--------------------------------------------------------------------------
698 DestroyTexturePanel(TexturePanel
*panel
)
705 ShowTexturePanel(TexturePanel
*panel
)
707 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
709 WMSetWindowUPosition(panel
->win
,
710 WidthOfScreen(DefaultScreenOfDisplay(dpy
)),
711 HeightOfScreen(DefaultScreenOfDisplay(dpy
)));
712 WMMapWidget(panel
->win
);
717 HideTexturePanel(TexturePanel
*panel
)
719 WMUnmapWidget(panel
->win
);
724 SetTexturePanelOkAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
726 panel
->okAction
= action
;
727 panel
->okData
= clientData
;
732 SetTexturePanelCancelAction(TexturePanel
*panel
, WMCallback
*action
, void *clientData
)
734 panel
->cancelAction
= action
;
735 panel
->cancelData
= clientData
;
740 SetTexturePanelTexture(TexturePanel
*panel
, char *name
, proplist_t texture
)
742 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
750 WMSetTextFieldText(panel
->nameT
, name
);
755 p
= PLGetArrayElement(texture
, 0);
759 type
= PLGetString(p
);
761 /*...............................................*/
762 if (strcasecmp(type
, "solid")==0) {
764 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SOLID
);
766 p
= PLGetArrayElement(texture
, 1);
770 str
= PLGetString(p
);
772 color
= WMCreateNamedColor(scr
, str
, False
);
774 WMSetColorWellColor(panel
->defcW
, color
);
776 WMReleaseColor(color
);
777 /*...............................................*/
778 } else if (strcasecmp(type
, "hgradient")==0
779 || strcasecmp(type
, "vgradient")==0
780 || strcasecmp(type
, "dgradient")==0) {
782 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_SGRADIENT
);
784 p
= PLGetArrayElement(texture
, 1);
788 str
= PLGetString(p
);
790 color
= WMCreateNamedColor(scr
, str
, False
);
792 WMSetColorWellColor(panel
->tcol1W
, color
);
794 WMReleaseColor(color
);
796 p
= PLGetArrayElement(texture
, 2);
800 str
= PLGetString(p
);
802 color
= WMCreateNamedColor(scr
, str
, False
);
804 WMSetColorWellColor(panel
->tcol2W
, color
);
806 WMReleaseColor(color
);
809 /*...............................................*/
810 } else if (strcasecmp(type
, "thgradient")==0
811 || strcasecmp(type
, "tvgradient")==0
812 || strcasecmp(type
, "tdgradient")==0) {
815 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_TGRADIENT
);
819 WMSetTextFieldText(panel
->imageT
,
820 PLGetString(PLGetArrayElement(texture
, 1)));
823 sscanf(PLGetString(PLGetArrayElement(texture
, 2)), "%i", &i
);
824 WMSetSliderValue(panel
->topaS
, i
);
826 p
= PLGetArrayElement(texture
, 3);
830 str
= PLGetString(p
);
832 color
= WMCreateNamedColor(scr
, str
, False
);
834 WMSetColorWellColor(panel
->tcol1W
, color
);
836 WMReleaseColor(color
);
838 p
= PLGetArrayElement(texture
, 4);
842 str
= PLGetString(p
);
844 color
= WMCreateNamedColor(scr
, str
, False
);
846 WMSetColorWellColor(panel
->tcol2W
, color
);
848 WMReleaseColor(color
);
850 /*...............................................*/
851 } else if (strcasecmp(type
, "mhgradient")==0
852 || strcasecmp(type
, "mvgradient")==0
853 || strcasecmp(type
, "mdgradient")==0) {
856 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
857 item
= WMGetListItem(panel
->gcolL
, i
);
858 free(item
->clientData
);
860 WMClearList(panel
->gcolL
);
862 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_GRADIENT
);
864 p
= PLGetArrayElement(texture
, 1);
868 str
= PLGetString(p
);
870 color
= WMCreateNamedColor(scr
, str
, False
);
872 WMSetColorWellColor(panel
->defcW
, color
);
874 WMReleaseColor(color
);
876 for (i
= 2; i
< PLGetNumberOfElements(texture
); i
++) {
880 p
= PLGetArrayElement(texture
, i
);
884 str
= PLGetString(p
);
887 XParseColor(WMScreenDisplay(scr
), WMScreenRContext(scr
)->cmap
,
890 rgb
= wmalloc(sizeof(RColor
));
891 rgb
->red
= xcolor
.red
>> 8;
892 rgb
->green
= xcolor
.green
>> 8;
893 rgb
->blue
= xcolor
.blue
>> 8;
894 sprintf(buffer
, "%02x,%02x,%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
896 item
= WMAddListItem(panel
->gcolL
, buffer
);
897 item
->clientData
= rgb
;
900 sliderChangeCallback(panel
->ghueS
, panel
);
903 /*...............................................*/
904 } else if (strcasecmp(type
, "cpixmap")==0
905 || strcasecmp(type
, "spixmap")==0
906 || strcasecmp(type
, "mpixmap")==0
907 || strcasecmp(type
, "tpixmap")==0) {
909 WMSetPopUpButtonSelectedItem(panel
->typeP
, TYPE_PIXMAP
);
911 switch (toupper(type
[0])) {
913 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_CENTER
);
916 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_SCALE
);
919 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_MAXIMIZE
);
923 WMSetPopUpButtonSelectedItem(panel
->arrP
, PTYPE_TILE
);
927 WMSetTextFieldText(panel
->imageT
,
928 PLGetString(PLGetArrayElement(texture
, 1)));
931 changeTypeCallback(panel
->typeP
, panel
);
934 updateGradButtons(panel
);
936 switch (toupper(gradient
)) {
938 WMPerformButtonClick(panel
->dirhB
);
941 WMPerformButtonClick(panel
->dirvB
);
945 WMPerformButtonClick(panel
->dirdB
);
953 str
= PLGetDescription(texture
);
954 wwarning("error creating texture %s", str
);
962 GetTexturePanelTextureName(TexturePanel
*panel
)
964 return WMGetTextFieldText(panel
->nameT
);
971 GetTexturePanelTexture(TexturePanel
*panel
)
973 proplist_t prop
= NULL
;
980 switch (WMGetPopUpButtonSelectedItem(panel
->typeP
)) {
983 color
= WMGetColorWellColor(panel
->defcW
);
984 str
= WMGetColorRGBDescription(color
);
985 prop
= PLMakeArrayFromElements(PLMakeString("solid"),
986 PLMakeString(str
), NULL
);
992 color
= WMGetColorWellColor(panel
->defcW
);
993 str
= WMGetColorRGBDescription(color
);
995 switch (WMGetPopUpButtonSelectedItem(panel
->arrP
)) {
997 prop
= PLMakeArrayFromElements(PLMakeString("spixmap"),
998 PLMakeString(panel
->imageFile
),
999 PLMakeString(str
), NULL
);
1001 case PTYPE_MAXIMIZE
:
1002 prop
= PLMakeArrayFromElements(PLMakeString("mpixmap"),
1003 PLMakeString(panel
->imageFile
),
1004 PLMakeString(str
), NULL
);
1007 prop
= PLMakeArrayFromElements(PLMakeString("cpixmap"),
1008 PLMakeString(panel
->imageFile
),
1009 PLMakeString(str
), NULL
);
1012 prop
= PLMakeArrayFromElements(PLMakeString("tpixmap"),
1013 PLMakeString(panel
->imageFile
),
1014 PLMakeString(str
), NULL
);
1020 case TYPE_SGRADIENT
:
1021 color
= WMGetColorWellColor(panel
->tcol1W
);
1022 str
= WMGetColorRGBDescription(color
);
1024 color
= WMGetColorWellColor(panel
->tcol2W
);
1025 str2
= WMGetColorRGBDescription(color
);
1027 if (WMGetButtonSelected(panel
->dirdB
)) {
1028 prop
= PLMakeArrayFromElements(PLMakeString("dgradient"),
1030 PLMakeString(str2
), NULL
);
1031 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1032 prop
= PLMakeArrayFromElements(PLMakeString("vgradient"),
1034 PLMakeString(str2
), NULL
);
1036 prop
= PLMakeArrayFromElements(PLMakeString("hgradient"),
1038 PLMakeString(str2
), NULL
);
1045 color
= WMGetColorWellColor(panel
->defcW
);
1046 str
= WMGetColorRGBDescription(color
);
1048 if (WMGetButtonSelected(panel
->dirdB
)) {
1049 prop
= PLMakeArrayFromElements(PLMakeString("mdgradient"),
1050 PLMakeString(str
), NULL
);
1051 } else if (WMGetButtonSelected(panel
->dirvB
)) {
1052 prop
= PLMakeArrayFromElements(PLMakeString("mvgradient"),
1053 PLMakeString(str
), NULL
);
1055 prop
= PLMakeArrayFromElements(PLMakeString("mhgradient"),
1056 PLMakeString(str
), NULL
);
1060 for (i
= 0; i
< WMGetListNumberOfRows(panel
->gcolL
); i
++) {
1064 item
= WMGetListItem(panel
->gcolL
, i
);
1066 rgb
= (RColor
*)item
->clientData
;
1068 sprintf(buff
, "#%02x%02x%02x", rgb
->red
, rgb
->green
, rgb
->blue
);
1070 PLAppendArrayElement(prop
, PLMakeString(buff
));
1082 SetTexturePanelPixmapPath(TexturePanel
*panel
, proplist_t array
)
1084 panel
->pathList
= array
;
1090 CreateTexturePanel(WMWindow
*keyWindow
)
1091 /*CreateTexturePanel(WMScreen *scr)*/
1093 TexturePanel
*panel
;
1094 WMScreen
*scr
= WMWidgetScreen(keyWindow
);
1096 panel
= wmalloc(sizeof(TexturePanel
));
1097 memset(panel
, 0, sizeof(TexturePanel
));
1099 panel
->listFont
= WMSystemFontOfSize(scr
, 12);
1102 panel
->win
= WMCreatePanelWithStyleForWindow(keyWindow
, "texturePanel",
1104 |WMClosableWindowMask
);
1106 panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
1108 |WMClosableWindowMask);
1111 WMResizeWidget(panel
->win
, 325, 423);
1112 WMSetWindowTitle(panel
->win
, _("Texture Panel"));
1116 panel
->nameF
= WMCreateFrame(panel
->win
);
1117 WMResizeWidget(panel
->nameF
, 185, 50);
1118 WMMoveWidget(panel
->nameF
, 15, 10);
1119 WMSetFrameTitle(panel
->nameF
, _("Texture Name"));
1121 panel
->nameT
= WMCreateTextField(panel
->nameF
);
1122 WMResizeWidget(panel
->nameT
, 160, 20);
1123 WMMoveWidget(panel
->nameT
, 12, 18);
1125 WMMapSubwidgets(panel
->nameF
);
1128 panel
->typeP
= WMCreatePopUpButton(panel
->win
);
1129 WMResizeWidget(panel
->typeP
, 185, 20);
1130 WMMoveWidget(panel
->typeP
, 15, 65);
1131 WMAddPopUpButtonItem(panel
->typeP
, _("Solid Color"));
1132 WMAddPopUpButtonItem(panel
->typeP
, _("Gradient Texture"));
1133 WMAddPopUpButtonItem(panel
->typeP
, _("Simple Gradient Texture"));
1134 WMAddPopUpButtonItem(panel
->typeP
, _("Textured Gradient"));
1135 WMAddPopUpButtonItem(panel
->typeP
, _("Image Texture"));
1136 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
1137 WMSetPopUpButtonAction(panel
->typeP
, changeTypeCallback
, panel
);
1140 panel
->defcF
= WMCreateFrame(panel
->win
);
1141 WMResizeWidget(panel
->defcF
, 100, 75);
1142 WMMoveWidget(panel
->defcF
, 210, 10);
1143 WMSetFrameTitle(panel
->defcF
, _("Default Color"));
1145 panel
->defcW
= WMCreateColorWell(panel
->defcF
);
1146 WMResizeWidget(panel
->defcW
, 60, 45);
1147 WMMoveWidget(panel
->defcW
, 20, 20);
1149 WMMapSubwidgets(panel
->defcF
);
1151 /****** Gradient ******/
1152 panel
->gcolF
= WMCreateFrame(panel
->win
);
1153 WMResizeWidget(panel
->gcolF
, 295, 205);
1154 WMMoveWidget(panel
->gcolF
, 15, 95);
1155 WMSetFrameTitle(panel
->gcolF
, _("Gradient Colors"));
1157 panel
->gcolL
= WMCreateList(panel
->gcolF
);
1158 WMResizeWidget(panel
->gcolL
, 130, 140);
1159 WMMoveWidget(panel
->gcolL
, 10, 25);
1160 WMHangData(panel
->gcolL
, panel
);
1161 WMSetListUserDrawProc(panel
->gcolL
, paintGradListItem
);
1162 WMSetListAction(panel
->gcolL
, gradClickCallback
, panel
);
1164 panel
->gcolaB
= WMCreateCommandButton(panel
->gcolF
);
1165 WMResizeWidget(panel
->gcolaB
, 64, 24);
1166 WMMoveWidget(panel
->gcolaB
, 10, 170);
1167 WMSetButtonText(panel
->gcolaB
, _("Add"));
1168 WMSetButtonAction(panel
->gcolaB
, gradAddCallback
, panel
);
1170 panel
->gcoldB
= WMCreateCommandButton(panel
->gcolF
);
1171 WMResizeWidget(panel
->gcoldB
, 64, 24);
1172 WMMoveWidget(panel
->gcoldB
, 75, 170);
1173 WMSetButtonText(panel
->gcoldB
, _("Delete"));
1174 WMSetButtonAction(panel
->gcoldB
, gradDeleteCallback
, panel
);
1177 panel
->gbriS
= WMCreateSlider(panel
->gcolF
);
1178 WMResizeWidget(panel
->gbriS
, 130, 16);
1179 WMMoveWidget(panel
->gbriS
, 150, 25);
1180 WMSetSliderKnobThickness(panel
->gbriS
, 8);
1181 WMSetSliderMaxValue(panel
->gbriS
, 100);
1182 WMSetSliderAction(panel
->gbriS
, sliderChangeCallback
, panel
);
1187 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1188 color
= WMDarkGrayColor(scr
);
1189 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1190 WMColorGC(color
), 0, 0, 130, 16);
1191 WMReleaseColor(color
);
1192 color
= WMWhiteColor(color
);
1193 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1195 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1197 WMSetSliderImage(panel
->gbriS
, pixmap
);
1198 WMReleasePixmap(pixmap
);
1201 panel
->gconS
= WMCreateSlider(panel
->gcolF
);
1202 WMResizeWidget(panel
->gconS
, 130, 16);
1203 WMMoveWidget(panel
->gconS
, 150, 50);
1204 WMSetSliderKnobThickness(panel
->gconS
, 8);
1205 WMSetSliderMaxValue(panel
->gconS
, 100);
1206 WMSetSliderAction(panel
->gconS
, sliderChangeCallback
, panel
);
1211 pixmap
= WMCreatePixmap(scr
, 130, 16, WMScreenDepth(scr
), False
);
1212 color
= WMDarkGrayColor(scr
);
1213 XFillRectangle(WMScreenDisplay(scr
), WMGetPixmapXID(pixmap
),
1214 WMColorGC(color
), 0, 0, 130, 16);
1215 WMReleaseColor(color
);
1216 color
= WMWhiteColor(scr
);
1217 WMDrawString(scr
, WMGetPixmapXID(pixmap
), WMColorGC(color
),
1219 (16 - WMFontHeight(panel
->listFont
))/2 - 1,
1221 WMSetSliderImage(panel
->gconS
, pixmap
);
1222 WMReleasePixmap(pixmap
);
1225 panel
->ghueS
= WMCreateSlider(panel
->gcolF
);
1226 WMResizeWidget(panel
->ghueS
, 130, 16);
1227 WMMoveWidget(panel
->ghueS
, 150, 100);
1228 WMSetSliderKnobThickness(panel
->ghueS
, 8);
1229 WMSetSliderMaxValue(panel
->ghueS
, 359);
1230 WMSetSliderAction(panel
->ghueS
, sliderChangeCallback
, panel
);
1232 panel
->gsatS
= WMCreateSlider(panel
->gcolF
);
1233 WMResizeWidget(panel
->gsatS
, 130, 16);
1234 WMMoveWidget(panel
->gsatS
, 150, 125);
1235 WMSetSliderKnobThickness(panel
->gsatS
, 8);
1236 WMSetSliderMaxValue(panel
->gsatS
, 255);
1237 WMSetSliderAction(panel
->gsatS
, sliderChangeCallback
, panel
);
1239 panel
->gvalS
= WMCreateSlider(panel
->gcolF
);
1240 WMResizeWidget(panel
->gvalS
, 130, 16);
1241 WMMoveWidget(panel
->gvalS
, 150, 150);
1242 WMSetSliderKnobThickness(panel
->gvalS
, 8);
1243 WMSetSliderMaxValue(panel
->gvalS
, 255);
1244 WMSetSliderAction(panel
->gvalS
, sliderChangeCallback
, panel
);
1247 WMMapSubwidgets(panel
->gcolF
);
1250 panel
->dirF
= WMCreateFrame(panel
->win
);
1251 WMSetFrameTitle(panel
->dirF
, _("Direction"));
1252 WMResizeWidget(panel
->dirF
, 295, 75);
1253 WMMoveWidget(panel
->dirF
, 15, 305);
1255 panel
->dirvB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1256 WMSetButtonImagePosition(panel
->dirvB
, WIPImageOnly
);
1257 WMResizeWidget(panel
->dirvB
, 90, 40);
1258 WMMoveWidget(panel
->dirvB
, 10, 20);
1260 panel
->dirhB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1261 WMSetButtonImagePosition(panel
->dirhB
, WIPImageOnly
);
1262 WMResizeWidget(panel
->dirhB
, 90, 40);
1263 WMMoveWidget(panel
->dirhB
, 102, 20);
1265 panel
->dirdB
= WMCreateButton(panel
->dirF
, WBTOnOff
);
1266 WMSetButtonImagePosition(panel
->dirdB
, WIPImageOnly
);
1267 WMResizeWidget(panel
->dirdB
, 90, 40);
1268 WMMoveWidget(panel
->dirdB
, 194, 20);
1270 WMGroupButtons(panel
->dirvB
, panel
->dirhB
);
1271 WMGroupButtons(panel
->dirvB
, panel
->dirdB
);
1273 WMMapSubwidgets(panel
->dirF
);
1275 /****************** Textured Gradient ******************/
1276 panel
->tcolF
= WMCreateFrame(panel
->win
);
1277 WMResizeWidget(panel
->tcolF
, 100, 135);
1278 WMMoveWidget(panel
->tcolF
, 210, 10);
1279 WMSetFrameTitle(panel
->tcolF
, _("Gradient"));
1281 panel
->tcol1W
= WMCreateColorWell(panel
->tcolF
);
1282 WMResizeWidget(panel
->tcol1W
, 60, 45);
1283 WMMoveWidget(panel
->tcol1W
, 20, 25);
1284 WMAddNotificationObserver(colorWellObserver
, panel
,
1285 WMColorWellDidChangeNotification
, panel
->tcol1W
);
1287 panel
->tcol2W
= WMCreateColorWell(panel
->tcolF
);
1288 WMResizeWidget(panel
->tcol2W
, 60, 45);
1289 WMMoveWidget(panel
->tcol2W
, 20, 75);
1290 WMAddNotificationObserver(colorWellObserver
, panel
,
1291 WMColorWellDidChangeNotification
, panel
->tcol2W
);
1294 panel
->topaF
= WMCreateFrame(panel
->win
);
1295 WMResizeWidget(panel
->topaF
, 185, 50);
1296 WMMoveWidget(panel
->topaF
, 15, 95);
1297 WMSetFrameTitle(panel
->topaF
, _("Gradient Opacity"));
1299 panel
->topaS
= WMCreateSlider(panel
->topaF
);
1300 WMResizeWidget(panel
->topaS
, 155, 18);
1301 WMMoveWidget(panel
->topaS
, 15, 20);
1302 WMSetSliderMaxValue(panel
->topaS
, 255);
1303 WMSetSliderValue(panel
->topaS
, 200);
1304 WMMapSubwidgets(panel
->topaF
);
1311 pixmap
= WMCreatePixmap(scr
, 155, 18, WMScreenDepth(scr
), False
);
1312 p
= WMGetPixmapXID(pixmap
);
1314 color
= WMDarkGrayColor(scr
);
1315 XFillRectangle(WMScreenDisplay(scr
), p
, WMColorGC(color
),
1317 WMReleaseColor(color
);
1319 color
= WMWhiteColor(scr
);
1320 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1322 WMDrawString(scr
, p
, WMColorGC(color
), panel
->listFont
,
1323 153 - WMWidthOfString(panel
->listFont
, "100%", 4), 1,
1325 WMReleaseColor(color
);
1327 WMSetSliderImage(panel
->topaS
, pixmap
);
1328 WMReleasePixmap(pixmap
);
1331 WMMapSubwidgets(panel
->tcolF
);
1333 /****************** Image ******************/
1334 panel
->imageF
= WMCreateFrame(panel
->win
);
1335 WMResizeWidget(panel
->imageF
, 295, 150);
1336 WMMoveWidget(panel
->imageF
, 15, 150);
1337 WMSetFrameTitle(panel
->imageF
, _("Image"));
1339 panel
->imageL
= WMCreateLabel(panel
->imageF
);
1340 WMSetLabelImagePosition(panel
->imageL
, WIPImageOnly
);
1342 panel
->imageT
= WMCreateTextField(panel
->imageF
);
1343 WMResizeWidget(panel
->imageT
, 90, 20);
1344 WMMoveWidget(panel
->imageT
, 190, 25);
1346 panel
->imageV
= WMCreateScrollView(panel
->imageF
);
1347 WMResizeWidget(panel
->imageV
, 165, 115);
1348 WMMoveWidget(panel
->imageV
, 15, 20);
1349 WMSetScrollViewRelief(panel
->imageV
, WRSunken
);
1350 WMSetScrollViewHasHorizontalScroller(panel
->imageV
, True
);
1351 WMSetScrollViewHasVerticalScroller(panel
->imageV
, True
);
1352 WMSetScrollViewContentView(panel
->imageV
, WMWidgetView(panel
->imageL
));
1354 panel
->browB
= WMCreateCommandButton(panel
->imageF
);
1355 WMResizeWidget(panel
->browB
, 90, 24);
1356 WMMoveWidget(panel
->browB
, 190, 50);
1357 WMSetButtonText(panel
->browB
, _("Browse..."));
1358 WMSetButtonAction(panel
->browB
, browseImageCallback
, panel
);
1360 panel
->dispB
= WMCreateCommandButton(panel
->imageF
);
1361 WMResizeWidget(panel
->dispB
, 90, 24);
1362 WMMoveWidget(panel
->dispB
, 190, 80);
1363 WMSetButtonText(panel
->dispB
, _("Show"));
1365 panel
->arrP
= WMCreatePopUpButton(panel
->imageF
);
1366 WMResizeWidget(panel
->arrP
, 90, 20);
1367 WMMoveWidget(panel
->arrP
, 190, 120);
1368 WMAddPopUpButtonItem(panel
->arrP
, _("Tile"));
1369 WMAddPopUpButtonItem(panel
->arrP
, _("Scale"));
1370 WMAddPopUpButtonItem(panel
->arrP
, _("Center"));
1371 WMAddPopUpButtonItem(panel
->arrP
, _("Maximize"));
1372 WMSetPopUpButtonSelectedItem(panel
->arrP
, 0);
1374 WMMapSubwidgets(panel
->imageF
);
1378 panel
->okB
= WMCreateCommandButton(panel
->win
);
1379 WMResizeWidget(panel
->okB
, 84, 24);
1380 WMMoveWidget(panel
->okB
, 225, 390);
1381 WMSetButtonText(panel
->okB
, _("OK"));
1382 WMSetButtonAction(panel
->okB
, buttonCallback
, panel
);
1384 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
1385 WMResizeWidget(panel
->cancelB
, 84, 24);
1386 WMMoveWidget(panel
->cancelB
, 130, 390);
1387 WMSetButtonText(panel
->cancelB
, _("Cancel"));
1388 WMSetButtonAction(panel
->cancelB
, buttonCallback
, panel
);
1390 WMMapWidget(panel
->nameF
);
1391 WMMapWidget(panel
->typeP
);
1392 WMMapWidget(panel
->okB
);
1393 WMMapWidget(panel
->cancelB
);
1395 WMUnmapWidget(panel
->arrP
);
1397 WMRealizeWidget(panel
->win
);
1399 panel
->currentType
= -1;
1401 panel
->sectionParts
[TYPE_SOLID
][0] = panel
->defcF
;
1403 panel
->sectionParts
[TYPE_GRADIENT
][0] = panel
->defcF
;
1404 panel
->sectionParts
[TYPE_GRADIENT
][1] = panel
->gcolF
;
1405 panel
->sectionParts
[TYPE_GRADIENT
][2] = panel
->dirF
;
1407 panel
->sectionParts
[TYPE_SGRADIENT
][0] = panel
->tcolF
;
1408 panel
->sectionParts
[TYPE_SGRADIENT
][1] = panel
->dirF
;
1410 panel
->sectionParts
[TYPE_TGRADIENT
][0] = panel
->tcolF
;
1411 panel
->sectionParts
[TYPE_TGRADIENT
][1] = panel
->dirF
;
1412 panel
->sectionParts
[TYPE_TGRADIENT
][2] = panel
->imageF
;
1413 panel
->sectionParts
[TYPE_TGRADIENT
][3] = panel
->topaF
;
1414 panel
->sectionParts
[TYPE_TGRADIENT
][4] = panel
->arrP
;
1416 panel
->sectionParts
[TYPE_PIXMAP
][0] = panel
->defcF
;
1417 panel
->sectionParts
[TYPE_PIXMAP
][1] = panel
->imageF
;
1418 panel
->sectionParts
[TYPE_PIXMAP
][2] = panel
->arrP
;
1421 /* setup for first time */
1423 changeTypeCallback(panel
->typeP
, panel
);
1425 sliderChangeCallback(panel
->ghueS
, panel
);
1426 sliderChangeCallback(panel
->gsatS
, panel
);
1434 *--------------------------------------------------------------------------
1436 *--------------------------------------------------------------------------
1441 char *ProgName
= "test";
1444 testOKButton(WMWidget
*self
, void *data
)
1452 TexturePanel
*panel
= (TexturePanel
*)data
;
1453 // test = GetTexturePanelTextureString(panel);
1457 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
1458 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250,
1460 XMapRaised(dpy
, win
);
1463 // image = RenderTexturePanelTexture(panel, 250, 250);
1465 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
1467 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
, image
->height
,
1474 void testCancelButton(WMWidget
*self
, void *data
){
1475 wwarning("Exiting test....");
1484 int main(int argc
, char **argv
)
1486 TexturePanel
*panel
;
1488 Display
*dpy
= XOpenDisplay("");
1493 WMInitializeApplication("Test", &argc
, argv
);
1496 wfatal("could not open display");
1500 scr
= WMCreateSimpleApplicationScreen(dpy
);
1502 panel
= CreateTexturePanel(scr
);
1504 SetTexturePanelOkAction(panel
,(WMAction
*)testOKButton
,panel
);
1505 SetTexturePanelCancelAction(panel
,(WMAction
*)testCancelButton
,panel
);
1507 SetTexturePanelTexture(panel
, "pinky",
1508 PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
1510 ShowTexturePanel(panel
);
1512 WMScreenMainLoop(scr
);