1 /* TexturePanel.c- texture editting panel
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998 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,
36 #include "TexturePanel.h"
37 #include "TexturePanel.icons"
39 typedef struct _TexturePanel
{
83 WMAction
*cancelAction
;
90 char *WMGetColorWellRGBString(WMColorWell
*cPtr
) {
95 rgbString
= wmalloc(13);
96 color
= WMGetColorWellColor(cPtr
);
99 sprintf(rgbString
,"rgb:%02x/%02x/%02x",
100 (WMRedComponentOfColor(color
) >> 8),
101 (WMGreenComponentOfColor(color
) >> 8),
102 (WMBlueComponentOfColor(color
) >> 8));
111 *--------------------------------------------------------------------------
113 *--------------------------------------------------------------------------
115 static void buttonCallback(WMWidget
*self
, void *data
);
116 static void renderTextureButtons (_TexturePanel
*panel
);
117 static void paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
*rect
);
118 static void notificationObserver(void *self
, WMNotification
*notif
);
121 notificationObserver(void *self
, WMNotification
*notif
)
123 _TexturePanel
*panel
= (_TexturePanel
*)self
;
124 void *object
= WMGetNotificationObject(notif
);
127 if (WMGetNotificationName(notif
) == WMTextDidChangeNotification
) {
128 if (object
== panel
->pimagT
) {
129 text
= WMGetTextFieldText(panel
->pimagT
);
131 WMSetButtonEnabled(panel
->okB
, True
);
133 WMSetButtonEnabled(panel
->okB
, False
);
142 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
*rect
)
145 int width
, height
, x
, y
;
149 scr
= WMWidgetScreen(lPtr
);
150 dpy
= WMScreenDisplay(scr
);
152 width
= rect
->size
.width
;
153 height
= rect
->size
.height
;
157 if (state
& WLDSSelected
)
158 XFillRectangle(dpy
, d
, WMColorGC(WMWhiteColor(scr
)), x
, y
,width
, height
);
160 XClearArea(WMScreenDisplay(scr
), d
, x
, y
, width
, height
, False
);
162 gc
= XCreateGC(dpy
, RootWindow(dpy
, 0),0,NULL
);
163 WMSetColorInGC(WMCreateNamedColor(scr
, text
, True
),gc
);
164 XFillRectangle (dpy
, d
, gc
,x
+5,y
+3,width
-8,height
-6);
170 buttonCallback(WMWidget
*self
, void *data
)
172 _TexturePanel
*panel
= (_TexturePanel
*)data
;
177 WMSetButtonEnabled(panel
->okB
, True
);
181 if (self
== panel
->okB
) {
182 if (panel
->okAction
) {
183 (*panel
->okAction
)(self
, panel
->okData
);
185 wwarning ("Texture panel OK button undefined");
187 } else if (self
== panel
->cancB
) {
188 if (panel
->cancelAction
) {
189 (*panel
->cancelAction
)(self
, panel
->cancelData
);
191 wwarning ("Texture panel CANCEL button undefined");
193 } else if (self
== panel
->tsoliB
) {
194 WMMapWidget(panel
->scolorF
);
195 WMUnmapWidget(panel
->gcolorF
);
196 WMUnmapWidget(panel
->gdirF
);
197 WMUnmapWidget(panel
->pimagF
);
198 WMUnmapWidget(panel
->pcolorF
);
199 WMUnmapWidget(panel
->pmodeF
);
200 } else if (self
== panel
->tgradB
) {
201 WMMapWidget(panel
->gcolorF
);
202 WMMapWidget(panel
->gdirF
);
203 WMUnmapWidget(panel
->scolorF
);
204 WMUnmapWidget(panel
->pimagF
);
205 WMUnmapWidget(panel
->pcolorF
);
206 WMUnmapWidget(panel
->pmodeF
);
207 } else if (self
== panel
->tpixmB
) {
208 WMMapWidget(panel
->pimagF
);
209 WMMapWidget(panel
->pcolorF
);
210 WMMapWidget(panel
->pmodeF
);
211 WMUnmapWidget(panel
->gcolorF
);
212 WMUnmapWidget(panel
->gdirF
);
213 WMUnmapWidget(panel
->scolorF
);
215 text
= WMGetTextFieldText(panel
->pimagT
);
217 WMSetButtonEnabled(panel
->okB
, False
);
221 /* Gradient Panel Buttons */
223 } else if (self
== panel
->gaddB
) {
224 color
= WMGetColorWellRGBString(panel
->gcolorW
);
225 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
226 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
228 renderTextureButtons(panel
);
230 } else if (self
== panel
->gremB
) {
231 if (WMGetListNumberOfRows(panel
->gcolorLs
) != 1) {
232 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
233 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
234 renderTextureButtons(panel
);
237 } else if (self
== panel
->gupdB
) {
238 color
= WMGetColorWellRGBString(panel
->gcolorW
);
239 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
240 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
241 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
243 renderTextureButtons(panel
);
245 /* Pixmap Panel Buttons */
247 } else if (self
== panel
->pbrowB
) {
249 op
= WMGetOpenPanel(WMWidgetScreen(panel
->pbrowB
));
250 if (WMRunModalOpenPanelForDirectory(op
, NULL
, "/usr/local", NULL
, NULL
)) {
252 path
= WMGetFilePanelFileName(op
);
253 WMSetTextFieldText(panel
->pimagT
, path
);
255 WMSetButtonEnabled(panel
->okB
, True
);
267 changePanel(WMWidget
*self
, void *data
)
269 _TexturePanel
*panel
= (_TexturePanel
*)data
;
272 WMSetButtonEnabled(panel
->okB
, True
);
273 if (self
== panel
->tsoliB
) {
274 WMMapWidget(panel
->scolorF
);
275 WMUnmapWidget(panel
->gcolorF
);
276 WMUnmapWidget(panel
->gdirF
);
277 WMUnmapWidget(panel
->pimagF
);
278 WMUnmapWidget(panel
->pcolorF
);
279 WMUnmapWidget(panel
->pmodeF
);
280 } else if (self
== panel
->tgradB
) {
281 WMMapWidget(panel
->gcolorF
);
282 WMMapWidget(panel
->gdirF
);
283 WMUnmapWidget(panel
->scolorF
);
284 WMUnmapWidget(panel
->pimagF
);
285 WMUnmapWidget(panel
->pcolorF
);
286 WMUnmapWidget(panel
->pmodeF
);
288 WMMapWidget(panel
->pimagF
);
289 WMMapWidget(panel
->pcolorF
);
290 WMMapWidget(panel
->pmodeF
);
291 WMUnmapWidget(panel
->gcolorF
);
292 WMUnmapWidget(panel
->gdirF
);
293 WMUnmapWidget(panel
->scolorF
);
295 text
= WMGetTextFieldText(panel
->pimagT
);
297 WMSetButtonEnabled(panel
->okB
, False
);
305 modifyGradientList(WMWidget
*self
, void *data
)
307 _TexturePanel
*panel
= (_TexturePanel
*)data
;
311 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
313 color
= WMGetColorWellRGBString(panel
->gcolorW
);
315 if (self
== panel
->gaddB
) {
316 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
317 } else if (self
== panel
->gremB
) {
318 if (WMGetListNumberOfRows(panel
->gcolorLs
) != 1) {
319 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
323 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
324 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
328 renderTextureButtons(panel
);
334 renderTextureButtons(_TexturePanel
*panel
)
336 RColor
**colors
= NULL
;
339 RImage
*imgh
, *imgv
, *imgd
;
344 scr
= WMWidgetScreen(panel
->gcolorLs
);
345 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
346 colors
= wmalloc(sizeof(RColor
*)*(listRows
+1));
348 for (i
=0; i
< listRows
; i
++) {
349 if (!XParseColor(WMScreenDisplay(scr
), (WMScreenRContext(scr
))->cmap
,
350 wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
),&color
)) {
351 wfatal("could not parse color \"%s\"\n", WMGetListItem(panel
->gcolorLs
, i
)->text
);
354 colors
[i
] = malloc(sizeof(RColor
));
355 colors
[i
]->red
= color
.red
>> 8;
356 colors
[i
]->green
= color
.green
>> 8;
357 colors
[i
]->blue
= color
.blue
>> 8;
362 imgh
= RRenderMultiGradient(50, 20, colors
, RGRD_HORIZONTAL
);
364 wwarning("internal error:%s", RMessageForError(RErrorCode
));
366 icon
= WMCreatePixmapFromRImage(scr
, imgh
, 120);
368 WMSetButtonImage(panel
->ghorB
, icon
);
369 WMReleasePixmap(icon
);
372 imgv
= RRenderMultiGradient(50, 20, colors
, RGRD_VERTICAL
);
374 wwarning("internal error:%s", RMessageForError(RErrorCode
));
376 icon
= WMCreatePixmapFromRImage(scr
, imgv
, 120);
378 WMSetButtonImage(panel
->gverB
, icon
);
379 WMReleasePixmap(icon
);
382 imgd
= RRenderMultiGradient(50, 20, colors
, RGRD_DIAGONAL
);
384 wwarning("internal error:%s", RMessageForError(RErrorCode
));
386 icon
= WMCreatePixmapFromRImage(scr
, imgd
, 120);
388 WMSetButtonImage(panel
->gdiaB
, icon
);
389 WMReleasePixmap(icon
);
397 *--------------------------------------------------------------------------
399 *--------------------------------------------------------------------------
402 DestroyTexturePanel(TexturePanel
*panel
)
404 WMUnmapWidget(panel
->win
);
405 WMDestroyWidget(panel
->win
);
411 ShowTexturePanel(TexturePanel
*panel
)
413 WMMapWidget(panel
->win
);
418 HideTexturePanel(TexturePanel
*panel
)
420 WMUnmapWidget(panel
->win
);
424 SetTexturePanelOkAction(TexturePanel
*panel
, WMAction
*action
, void *clientData
)
426 panel
->okAction
= action
;
427 panel
->okData
= clientData
;
432 SetTexturePanelCancelAction(TexturePanel
*panel
, WMAction
*action
, void *clientData
)
434 panel
->cancelAction
= action
;
435 panel
->cancelData
= clientData
;
439 SetTexturePanelTexture(TexturePanel
*panel
, char *texture
)
442 char *parseStringPosition
;
443 char *enclosures
= "( )";
444 char *seperators
= " ,\"";
447 WMSetButtonSelected(panel
->tsoliB
, False
);
448 WMSetButtonSelected(panel
->tgradB
, False
);
449 WMSetButtonSelected(panel
->tpixmB
, False
);
451 parseString
= wstrdup(texture
);
452 parseStringPosition
= parseString
;
454 parseStringPosition
= strtok(parseStringPosition
,seperators
);
455 wwarning ("Parsing...");
457 while (parseStringPosition
) {
459 if (!strpbrk(parseStringPosition
,enclosures
)) {
460 if (strcasecmp(parseStringPosition
,"solid") == 0) {
461 wwarning("Switch to solid");
462 WMPerformButtonClick(panel
->tsoliB
);
464 parseStringPosition
= strtok(NULL
,seperators
);
466 while (parseStringPosition
) {
467 if (!strpbrk(parseStringPosition
,enclosures
)) {
468 WMSetColorWellColor(panel
->scolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
470 parseStringPosition
= strtok(NULL
,seperators
);
473 } else if ((strstr(parseStringPosition
,"pixmap")) && (strcasecmp(strstr(parseStringPosition
,"pixmap"),"pixmap") == 0)) {
474 WMSetButtonSelected(panel
->ptileB
, False
);
475 WMSetButtonSelected(panel
->pscalB
, False
);
477 WMPerformButtonClick(panel
->tpixmB
);
479 if (tolower(*parseStringPosition
) == 't') {
480 wwarning ("Switch to Tiled Pixmap");
481 WMPerformButtonClick(panel
->ptileB
);
483 wwarning ("Switch to Scaled Pixmap");
484 WMPerformButtonClick(panel
->pscalB
);
489 parseStringPosition
= strtok(NULL
,seperators
);
491 if (filename
) filename
= wstrappend(filename
," ");
492 filename
= wstrappend(filename
,parseStringPosition
);
493 parseStringPosition
= strtok(NULL
,seperators
);
494 } while (!strstr(parseStringPosition
,"rgb:"));
496 WMSetTextFieldText(panel
->pimagT
, filename
);
499 /* parseStringPosition = strtok(NULL,seperators); */
501 WMSetColorWellColor(panel
->pcolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
503 } else if ((strstr(parseStringPosition
,"gradient")) && (strcasecmp(strstr(parseStringPosition
,"gradient"),"gradient") == 0)) {
504 WMSetButtonSelected(panel
->ghorB
, False
);
505 WMSetButtonSelected(panel
->gverB
, False
);
506 WMSetButtonSelected(panel
->gdiaB
, False
);
508 WMPerformButtonClick(panel
->tgradB
);
510 if (strstr(parseStringPosition
,"h")) {
511 WMPerformButtonClick(panel
->ghorB
);
512 } else if (strstr(parseStringPosition
,"v")) {
513 WMPerformButtonClick(panel
->gverB
);
515 WMPerformButtonClick(panel
->gdiaB
);
518 WMClearList(panel
->gcolorLs
);
520 parseStringPosition
= strtok(NULL
,seperators
);
521 while (parseStringPosition
) {
522 if (!strpbrk(parseStringPosition
,enclosures
)) {
523 WMAddListItem(panel
->gcolorLs
, parseStringPosition
);
524 WMSetColorWellColor(panel
->gcolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
526 parseStringPosition
= strtok(NULL
,seperators
);
529 wfatal("Unknown Texture Type");
532 while (parseStringPosition
) {
533 parseStringPosition
= strtok(NULL
,seperators
);
538 parseStringPosition
= strtok(NULL
,seperators
);
540 renderTextureButtons (panel
);
546 GetTexturePanelTextureString(TexturePanel
*panel
)
548 char *colorString
= NULL
;
551 char *seperator
= ", ";
555 colorString
= wstrappend(colorString
,start
);
557 if (WMGetButtonSelected(panel
->tsoliB
)) {
558 colorString
= wstrappend(colorString
,"solid");
559 colorString
= wstrappend(colorString
,seperator
);
560 colorString
= wstrappend(colorString
, quote
);
561 colorString
= wstrappend(colorString
,WMGetColorWellRGBString(panel
->scolorW
));
562 colorString
= wstrappend(colorString
, quote
);
564 } else if (WMGetButtonSelected(panel
->tgradB
)) {
565 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
568 colorString
= wstrappend(colorString
,"m");
570 if (WMGetButtonSelected(panel
->ghorB
)) {
571 colorString
= wstrappend(colorString
,"hgradient");
572 } else if (WMGetButtonSelected(panel
->gverB
)) {
573 colorString
= wstrappend(colorString
,"vgradient");
575 colorString
= wstrappend(colorString
,"dgradient");
578 for (i
=0; i
< listRows
; i
++) {
579 colorString
= wstrappend(colorString
, seperator
);
580 colorString
= wstrappend(colorString
, quote
);
581 colorString
= wstrappend(colorString
, wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
));
582 colorString
= wstrappend(colorString
, quote
);
584 } else if (WMGetButtonSelected(panel
->tpixmB
)) {
585 if (WMGetButtonSelected(panel
->pscalB
)) {
586 colorString
= wstrappend(colorString
,"spixmap");
588 colorString
= wstrappend(colorString
,"tpixmap");
590 colorString
= wstrappend(colorString
,seperator
);
591 colorString
= wstrappend(colorString
, WMGetTextFieldText(panel
->pimagT
));
592 colorString
= wstrappend(colorString
,seperator
);
593 colorString
= wstrappend(colorString
, quote
);
594 colorString
= wstrappend(colorString
, WMGetColorWellRGBString(panel
->pcolorW
));
595 colorString
= wstrappend(colorString
, quote
);
598 colorString
= wstrappend(colorString
,finish
);
605 RenderTexturePanelTexture(TexturePanel
*panel
, unsigned width
, unsigned height
)
610 RColor
**colors
= NULL
;
611 RImage
*image
=NULL
, *fileImage
;
615 int i
, listRows
, style
;
617 scr
= WMWidgetScreen(panel
->gcolorLs
);
618 ctx
= WMScreenRContext(scr
);
620 if (WMGetButtonSelected(panel
->tsoliB
)) {
622 image
= RCreateImage(width
, height
, 1);
623 wellColor
= WMGetColorWellColor(panel
->scolorW
);
625 solidColor
.red
= (WMRedComponentOfColor(wellColor
) >> 8);
626 solidColor
.green
= (WMGreenComponentOfColor(wellColor
) >> 8) ;
627 solidColor
.blue
= (WMBlueComponentOfColor(wellColor
) >> 8);
628 solidColor
.alpha
= 0xff;
630 WMReleaseColor(wellColor
);
632 RClearImage(image
, &solidColor
);
634 } else if (WMGetButtonSelected(panel
->tgradB
)) {
636 if (WMGetButtonSelected(panel
->ghorB
)) {
637 style
= RGRD_HORIZONTAL
;
638 } else if (WMGetButtonSelected(panel
->gverB
)) {
639 style
= RGRD_VERTICAL
;
641 style
= RGRD_DIAGONAL
;
644 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
645 colors
= wmalloc(sizeof(RColor
*)*(listRows
+1));
647 for (i
=0; i
< listRows
; i
++) {
648 if (!XParseColor(WMScreenDisplay(scr
), ctx
->cmap
,
649 wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
),&color
)) {
650 wfatal("could not parse color \"%s\"\n", WMGetListItem(panel
->gcolorLs
, i
)->text
);
653 colors
[i
] = malloc(sizeof(RColor
));
654 colors
[i
]->red
= color
.red
>> 8;
655 colors
[i
]->green
= color
.green
>> 8;
656 colors
[i
]->blue
= color
.blue
>> 8;
661 image
= RRenderMultiGradient(width
, height
, colors
, style
);
663 } else if (WMGetButtonSelected(panel
->tpixmB
)) {
665 if (fopen(WMGetTextFieldText(panel
->pimagT
),"r")) {
667 fileImage
= RLoadImage(ctx
, WMGetTextFieldText(panel
->pimagT
), 0);
668 if (WMGetButtonSelected(panel
->pscalB
)) {
669 image
= RScaleImage(fileImage
, width
, height
);
671 image
= RMakeTiledImage(fileImage
, width
, height
);;
674 wwarning ("Invalid File Name");
675 return RCreateImage(1,1,1);
683 CreateTexturePanel(WMScreen
*scr
)
701 panel
= wmalloc(sizeof(_TexturePanel
));
702 memset(panel
, 0, sizeof(_TexturePanel
));
703 red
= WMCreateRGBColor(scr
,100,100,100,True
);
705 panel
->win
= WMCreateWindow(scr
, "textureBuilder");
706 WMResizeWidget(panel
->win
, 275, 365);
707 WMSetWindowTitle(panel
->win
, "Texture Builder");
709 /***************** Generic stuff ****************/
711 panel
->typeF
= WMCreateFrame(panel
->win
);
712 WMResizeWidget(panel
->typeF
, 245, 80);
713 WMMoveWidget(panel
->typeF
, 15, 10);
714 WMSetFrameTitle(panel
->typeF
, "Texture Type");
716 panel
->tsoliB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
717 WMResizeWidget(panel
->tsoliB
, 48, 48);
718 WMMoveWidget(panel
->tsoliB
, 42, 20);
719 WMSetButtonImagePosition(panel
->tsoliB
, WIPImageOnly
);
720 image
= RGetImageFromXPMData(WMScreenRContext(scr
), solid_xpm
);
722 wwarning("internal error:%s", RMessageForError(RErrorCode
));
724 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
725 RDestroyImage(image
);
726 WMSetButtonImage(panel
->tsoliB
, icon
);
727 WMReleasePixmap(icon
);
729 WMSetButtonAction(panel
->tsoliB
, buttonCallback
, panel
);
731 panel
->tgradB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
732 WMGroupButtons(panel
->tsoliB
, panel
->tgradB
);
733 WMResizeWidget(panel
->tgradB
, 48, 48);
734 WMMoveWidget(panel
->tgradB
, 98, 20);
735 WMSetButtonImagePosition(panel
->tgradB
, WIPImageOnly
);
736 image
= RGetImageFromXPMData(WMScreenRContext(scr
), gradient_xpm
);
738 wwarning("internal error:%s", RMessageForError(RErrorCode
));
740 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
741 RDestroyImage(image
);
742 WMSetButtonImage(panel
->tgradB
, icon
);
743 WMReleasePixmap(icon
);
745 WMSetButtonAction(panel
->tgradB
, buttonCallback
, panel
);
747 panel
->tpixmB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
748 WMGroupButtons(panel
->tsoliB
, panel
->tpixmB
);
749 WMResizeWidget(panel
->tpixmB
, 48, 48);
750 WMMoveWidget(panel
->tpixmB
, 154, 20);
751 WMSetButtonImagePosition(panel
->tpixmB
, WIPImageOnly
);
752 image
= RGetImageFromXPMData(WMScreenRContext(scr
), pixmap_xpm
);
754 wwarning("internal error:%s", RMessageForError(RErrorCode
));
756 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
757 RDestroyImage(image
);
758 WMSetButtonImage(panel
->tpixmB
, icon
);
759 WMReleasePixmap(icon
);
761 WMSetButtonAction(panel
->tpixmB
, buttonCallback
, panel
);
763 panel
->okB
= WMCreateCommandButton(panel
->win
);
764 WMResizeWidget(panel
->okB
, 70, 28);
765 WMMoveWidget(panel
->okB
, 110, 325);
766 WMSetButtonText(panel
->okB
, "OK");
767 WMSetButtonAction(panel
->okB
,buttonCallback
,panel
);
769 panel
->cancB
= WMCreateCommandButton(panel
->win
);
770 WMResizeWidget(panel
->cancB
, 70, 28);
771 WMMoveWidget(panel
->cancB
, 190, 325);
772 WMSetButtonText(panel
->cancB
, "Cancel");
773 WMSetButtonAction(panel
->cancB
,buttonCallback
,panel
);
775 WMMapSubwidgets(panel
->typeF
);
777 /***************** Solid *****************/
778 panel
->scolorF
= WMCreateFrame(panel
->win
);
779 WMResizeWidget(panel
->scolorF
, 245, 125);
780 WMMoveWidget(panel
->scolorF
, 15, 140);
781 WMSetFrameTitle(panel
->scolorF
, "Color");
783 panel
->scolorW
= WMCreateColorWell(panel
->scolorF
);
784 WMResizeWidget(panel
->scolorW
, 60, 45);
785 WMMoveWidget(panel
->scolorW
, 95, 40);
786 WMSetColorWellColor(panel
->scolorW
,WMCreateRGBColor(scr
, 0xddff, 0xddff, 0, True
));
788 WMMapSubwidgets(panel
->scolorF
);
790 /***************** Gradient *****************/
791 panel
->gcolorF
= WMCreateFrame(panel
->win
);
792 WMResizeWidget(panel
->gcolorF
, 245, 145);
793 WMMoveWidget(panel
->gcolorF
, 15, 95);
794 WMSetFrameTitle(panel
->gcolorF
, "Colors");
796 panel
->gcolorLs
= WMCreateList(panel
->gcolorF
);
797 WMResizeWidget(panel
->gcolorLs
, 120, 84);
798 WMMoveWidget(panel
->gcolorLs
, 20, 20);
800 WMSetListUserDrawProc(panel
->gcolorLs
, paintListItem
);
802 WMAddListItem(panel
->gcolorLs
, "rgb:ff/ff/ff");
803 WMAddListItem(panel
->gcolorLs
, "rgb:00/00/ff");
805 panel
->gcolorW
= WMCreateColorWell(panel
->gcolorF
);
806 WMResizeWidget(panel
->gcolorW
, 60, 45);
807 WMMoveWidget(panel
->gcolorW
, 160, 40);
808 WMSetColorWellColor(panel
->gcolorW
,WMCreateRGBColor(scr
, 0xffff, 0, 0, True
));
810 panel
->gremB
= WMCreateCommandButton(panel
->gcolorF
);
811 WMResizeWidget(panel
->gremB
, 64, 24);
812 WMMoveWidget(panel
->gremB
, 20, 110);
813 WMSetButtonText(panel
->gremB
, "Remove");
814 WMSetButtonAction(panel
->gremB
,(WMAction
*)buttonCallback
,panel
);
816 panel
->gupdB
= WMCreateCommandButton(panel
->gcolorF
);
817 WMResizeWidget(panel
->gupdB
, 64, 24);
818 WMMoveWidget(panel
->gupdB
, 90, 110);
819 WMSetButtonText(panel
->gupdB
, "Update");
820 WMSetButtonAction(panel
->gupdB
,(WMAction
*)buttonCallback
,panel
);
822 panel
->gaddB
= WMCreateCommandButton(panel
->gcolorF
);
823 WMResizeWidget(panel
->gaddB
, 64, 24);
824 WMMoveWidget(panel
->gaddB
, 160, 110);
825 WMSetButtonText(panel
->gaddB
, "Add");
826 WMSetButtonAction(panel
->gaddB
,(WMAction
*)buttonCallback
,panel
);
827 WMMapSubwidgets(panel
->gcolorF
);
829 panel
->gdirF
= WMCreateFrame(panel
->win
);
830 WMResizeWidget(panel
->gdirF
, 245, 65);
831 WMMoveWidget(panel
->gdirF
, 15, 245);
832 WMSetFrameTitle(panel
->gdirF
, "Direction");
834 panel
->ghorB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
835 WMResizeWidget(panel
->ghorB
, 64, 34);
836 WMMoveWidget(panel
->ghorB
, 20, 20);
837 WMSetButtonImagePosition(panel
->ghorB
, WIPImageOnly
);
838 WMPerformButtonClick(panel
->ghorB
);
841 panel
->gverB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
842 WMResizeWidget(panel
->gverB
, 64, 34);
843 WMMoveWidget(panel
->gverB
, 90, 20);
844 WMSetButtonImagePosition(panel
->gverB
, WIPImageOnly
);
845 WMGroupButtons(panel
->ghorB
, panel
->gverB
);
847 panel
->gdiaB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
848 WMResizeWidget(panel
->gdiaB
, 64, 34);
849 WMMoveWidget(panel
->gdiaB
, 160, 20);
850 WMSetButtonImagePosition(panel
->gdiaB
, WIPImageOnly
);
851 WMGroupButtons(panel
->ghorB
, panel
->gdiaB
);
853 WMMapSubwidgets(panel
->gdirF
);
855 /***************** Pixmap *****************/
856 panel
->pimagF
= WMCreateFrame(panel
->win
);
857 WMResizeWidget(panel
->pimagF
, 245, 140);
858 WMMoveWidget(panel
->pimagF
, 15, 96);
859 WMSetFrameTitle(panel
->pimagF
, "Image");
861 panel
->pimagL
= WMCreateLabel(panel
->pimagF
);
862 WMResizeWidget(panel
->pimagL
, 220, 83);
863 WMMoveWidget(panel
->pimagL
, 10, 20);
864 WMSetLabelImagePosition(panel
->pimagL
, WIPImageOnly
);
866 panel
->pimagT
= WMCreateTextField(panel
->pimagF
);
867 WMResizeWidget(panel
->pimagT
, 147, 20);
868 WMMoveWidget(panel
->pimagT
, 10, 110);
870 panel
->pbrowB
= WMCreateCommandButton(panel
->pimagF
);
871 WMResizeWidget(panel
->pbrowB
, 68, 24);
872 WMMoveWidget(panel
->pbrowB
, 165, 108);
873 WMSetButtonText(panel
->pbrowB
, "Browse...");
874 WMSetButtonAction(panel
->pbrowB
,buttonCallback
,panel
);
876 WMMapSubwidgets(panel
->pimagF
);
878 panel
->pcolorF
= WMCreateFrame(panel
->win
);
879 WMResizeWidget(panel
->pcolorF
, 90, 75);
880 WMMoveWidget(panel
->pcolorF
, 15, 240);
881 WMSetFrameTitle(panel
->pcolorF
, "Color");
883 panel
->pcolorW
= WMCreateColorWell(panel
->pcolorF
);
884 WMResizeWidget(panel
->pcolorW
, 60, 45);
885 WMMoveWidget(panel
->pcolorW
, 15, 20);
886 WMSetColorWellColor(panel
->pcolorW
,WMCreateRGBColor(scr
, 0x00, 0xddff, 0xffff, True
));
889 WMMapSubwidgets(panel
->pcolorF
);
891 panel
->pmodeF
= WMCreateFrame(panel
->win
);
892 WMResizeWidget(panel
->pmodeF
, 145, 70);
893 WMMoveWidget(panel
->pmodeF
, 115, 245);
895 panel
->pscalB
= WMCreateButton(panel
->pmodeF
, WBTOnOff
);
896 WMResizeWidget(panel
->pscalB
, 54, 50);
897 WMMoveWidget(panel
->pscalB
, 10, 10);
898 WMSetButtonImagePosition(panel
->pscalB
, WIPImageOnly
);
899 WMPerformButtonClick(panel
->pscalB
);
901 image
= RGetImageFromXPMData(WMScreenRContext(scr
), scaled_xpm
);
903 wwarning("internal error:%s", RMessageForError(RErrorCode
));
905 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
906 RDestroyImage(image
);
907 WMSetButtonImage(panel
->pscalB
, icon
);
908 WMReleasePixmap(icon
);
911 panel
->ptileB
= WMCreateButton(panel
->pmodeF
, WBTOnOff
);
912 WMResizeWidget(panel
->ptileB
, 54, 50);
913 WMMoveWidget(panel
->ptileB
, 75, 10);
914 WMSetButtonImagePosition(panel
->ptileB
, WIPImageOnly
);
915 image
= RGetImageFromXPMData(WMScreenRContext(scr
), tiled_xpm
);
917 wwarning("internal error:%s", RMessageForError(RErrorCode
));
919 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
920 RDestroyImage(image
);
921 WMSetButtonImage(panel
->ptileB
, icon
);
922 WMReleasePixmap(icon
);
924 WMGroupButtons(panel
->pscalB
, panel
->ptileB
);
926 WMMapSubwidgets(panel
->pmodeF
);
928 WMRealizeWidget(panel
->win
);
929 WMMapSubwidgets(panel
->win
);
931 WMPerformButtonClick(panel
->tsoliB
);
933 WMMapWidget(panel
->win
);
935 renderTextureButtons (panel
);
938 /* register notification observers */
939 WMAddNotificationObserver(notificationObserver
, panel
,
940 WMTextDidChangeNotification
,
949 *--------------------------------------------------------------------------
951 *--------------------------------------------------------------------------
956 char *ProgName
= "test";
958 void testOKButton(WMWidget
*self
, void *data
){
965 TexturePanel
*panel
= (TexturePanel
*)data
;
966 test
= GetTexturePanelTextureString(panel
);
970 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
971 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250,
973 XMapRaised(dpy
, win
);
976 image
= RenderTexturePanelTexture(panel
, 250, 250);
978 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
980 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
, image
->height
,
983 SetTexturePanelTexture(panel
, test
);
987 void testCancelButton(WMWidget
*self
, void *data
){
988 wwarning("Exiting test....");
997 int main(int argc
, char **argv
)
1001 Display
*dpy
= XOpenDisplay("");
1006 WMInitializeApplication("Test", &argc
, argv
);
1009 wfatal("could not open display");
1013 scr
= WMCreateSimpleApplicationScreen(dpy
);
1015 panel
= CreateTexturePanel(scr
);
1017 SetTexturePanelOkAction(panel
,(WMAction
*)testOKButton
,panel
);
1018 SetTexturePanelCancelAction(panel
,(WMAction
*)testCancelButton
,panel
);
1020 ShowTexturePanel(panel
);
1022 SetTexturePanelTexture(panel
," ( tpixmap, ballot box.xpm, \"rgb:ff/de/ff\" ) ");
1024 WMScreenMainLoop(scr
);