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,
36 #include "TexturePanel.h"
37 #include "TexturePanel.icons"
39 typedef struct _TexturePanel
{
83 WMAction
*cancelAction
;
91 WMGetColorWellRGBString(WMColorWell
*cPtr
)
97 rgbString
= wmalloc(13);
98 color
= WMGetColorWellColor(cPtr
);
101 sprintf(rgbString
,"rgb:%02x/%02x/%02x",
102 (WMRedComponentOfColor(color
) >> 8),
103 (WMGreenComponentOfColor(color
) >> 8),
104 (WMBlueComponentOfColor(color
) >> 8));
113 *--------------------------------------------------------------------------
115 *--------------------------------------------------------------------------
117 static void buttonCallback(WMWidget
*self
, void *data
);
118 static void renderTextureButtons (_TexturePanel
*panel
);
119 static void paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
*rect
);
120 static void notificationObserver(void *self
, WMNotification
*notif
);
123 notificationObserver(void *self
, WMNotification
*notif
)
125 _TexturePanel
*panel
= (_TexturePanel
*)self
;
126 void *object
= WMGetNotificationObject(notif
);
129 if (WMGetNotificationName(notif
) == WMTextDidChangeNotification
) {
130 if (object
== panel
->pimagT
) {
131 text
= WMGetTextFieldText(panel
->pimagT
);
133 WMSetButtonEnabled(panel
->okB
, True
);
135 WMSetButtonEnabled(panel
->okB
, False
);
144 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
*rect
)
147 int width
, height
, x
, y
;
151 scr
= WMWidgetScreen(lPtr
);
152 dpy
= WMScreenDisplay(scr
);
154 width
= rect
->size
.width
;
155 height
= rect
->size
.height
;
159 if (state
& WLDSSelected
)
160 XFillRectangle(dpy
, d
, WMColorGC(WMWhiteColor(scr
)), x
, y
,width
, height
);
162 XClearArea(WMScreenDisplay(scr
), d
, x
, y
, width
, height
, False
);
164 gc
= XCreateGC(dpy
, RootWindow(dpy
, 0),0,NULL
);
165 WMSetColorInGC(WMCreateNamedColor(scr
, text
, True
),gc
);
166 XFillRectangle (dpy
, d
, gc
,x
+5,y
+3,width
-8,height
-6);
172 buttonCallback(WMWidget
*self
, void *data
)
174 _TexturePanel
*panel
= (_TexturePanel
*)data
;
179 WMSetButtonEnabled(panel
->okB
, True
);
183 if (self
== panel
->okB
) {
184 if (panel
->okAction
) {
185 (*panel
->okAction
)(self
, panel
->okData
);
187 wwarning ("Texture panel OK button undefined");
189 } else if (self
== panel
->cancB
) {
190 if (panel
->cancelAction
) {
191 (*panel
->cancelAction
)(self
, panel
->cancelData
);
193 wwarning ("Texture panel CANCEL button undefined");
195 } else if (self
== panel
->tsoliB
) {
196 WMMapWidget(panel
->scolorF
);
197 WMUnmapWidget(panel
->gcolorF
);
198 WMUnmapWidget(panel
->gdirF
);
199 WMUnmapWidget(panel
->pimagF
);
200 WMUnmapWidget(panel
->pcolorF
);
201 WMUnmapWidget(panel
->pmodeF
);
202 } else if (self
== panel
->tgradB
) {
203 WMMapWidget(panel
->gcolorF
);
204 WMMapWidget(panel
->gdirF
);
205 WMUnmapWidget(panel
->scolorF
);
206 WMUnmapWidget(panel
->pimagF
);
207 WMUnmapWidget(panel
->pcolorF
);
208 WMUnmapWidget(panel
->pmodeF
);
209 } else if (self
== panel
->tpixmB
) {
210 WMMapWidget(panel
->pimagF
);
211 WMMapWidget(panel
->pcolorF
);
212 WMMapWidget(panel
->pmodeF
);
213 WMUnmapWidget(panel
->gcolorF
);
214 WMUnmapWidget(panel
->gdirF
);
215 WMUnmapWidget(panel
->scolorF
);
217 text
= WMGetTextFieldText(panel
->pimagT
);
219 WMSetButtonEnabled(panel
->okB
, False
);
223 /* Gradient Panel Buttons */
225 } else if (self
== panel
->gaddB
) {
226 color
= WMGetColorWellRGBString(panel
->gcolorW
);
227 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
228 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
230 renderTextureButtons(panel
);
232 } else if (self
== panel
->gremB
) {
233 if (WMGetListNumberOfRows(panel
->gcolorLs
) != 1) {
234 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
235 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
236 renderTextureButtons(panel
);
239 } else if (self
== panel
->gupdB
) {
240 color
= WMGetColorWellRGBString(panel
->gcolorW
);
241 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
242 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
243 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
245 renderTextureButtons(panel
);
247 /* Pixmap Panel Buttons */
249 } else if (self
== panel
->pbrowB
) {
250 op
= WMGetOpenPanel(WMWidgetScreen(panel
->pbrowB
));
251 if (WMRunModalFilePanelForDirectory(op
, NULL
, "/usr/local", NULL
, NULL
)) {
253 path
= WMGetFilePanelFileName(op
);
254 WMSetTextFieldText(panel
->pimagT
, path
);
256 WMSetButtonEnabled(panel
->okB
, True
);
268 changePanel(WMWidget
*self
, void *data
)
270 _TexturePanel
*panel
= (_TexturePanel
*)data
;
273 WMSetButtonEnabled(panel
->okB
, True
);
274 if (self
== panel
->tsoliB
) {
275 WMMapWidget(panel
->scolorF
);
276 WMUnmapWidget(panel
->gcolorF
);
277 WMUnmapWidget(panel
->gdirF
);
278 WMUnmapWidget(panel
->pimagF
);
279 WMUnmapWidget(panel
->pcolorF
);
280 WMUnmapWidget(panel
->pmodeF
);
281 } else if (self
== panel
->tgradB
) {
282 WMMapWidget(panel
->gcolorF
);
283 WMMapWidget(panel
->gdirF
);
284 WMUnmapWidget(panel
->scolorF
);
285 WMUnmapWidget(panel
->pimagF
);
286 WMUnmapWidget(panel
->pcolorF
);
287 WMUnmapWidget(panel
->pmodeF
);
289 WMMapWidget(panel
->pimagF
);
290 WMMapWidget(panel
->pcolorF
);
291 WMMapWidget(panel
->pmodeF
);
292 WMUnmapWidget(panel
->gcolorF
);
293 WMUnmapWidget(panel
->gdirF
);
294 WMUnmapWidget(panel
->scolorF
);
296 text
= WMGetTextFieldText(panel
->pimagT
);
298 WMSetButtonEnabled(panel
->okB
, False
);
306 modifyGradientList(WMWidget
*self
, void *data
)
308 _TexturePanel
*panel
= (_TexturePanel
*)data
;
312 itemRow
= WMGetListSelectedItemRow(panel
->gcolorLs
);
314 color
= WMGetColorWellRGBString(panel
->gcolorW
);
316 if (self
== panel
->gaddB
) {
317 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
318 } else if (self
== panel
->gremB
) {
319 if (WMGetListNumberOfRows(panel
->gcolorLs
) != 1) {
320 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
324 WMRemoveListItem(panel
->gcolorLs
,itemRow
);
325 WMInsertListItem(panel
->gcolorLs
,itemRow
, color
);
329 renderTextureButtons(panel
);
335 renderTextureButtons(_TexturePanel
*panel
)
337 RColor
**colors
= NULL
;
340 RImage
*imgh
, *imgv
, *imgd
;
345 scr
= WMWidgetScreen(panel
->gcolorLs
);
346 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
347 colors
= wmalloc(sizeof(RColor
*)*(listRows
+1));
349 for (i
=0; i
< listRows
; i
++) {
350 if (!XParseColor(WMScreenDisplay(scr
), (WMScreenRContext(scr
))->cmap
,
351 wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
),&color
)) {
352 wfatal("could not parse color \"%s\"\n", WMGetListItem(panel
->gcolorLs
, i
)->text
);
355 colors
[i
] = malloc(sizeof(RColor
));
356 colors
[i
]->red
= color
.red
>> 8;
357 colors
[i
]->green
= color
.green
>> 8;
358 colors
[i
]->blue
= color
.blue
>> 8;
363 imgh
= RRenderMultiGradient(50, 20, colors
, RGRD_HORIZONTAL
);
365 wwarning("internal error:%s", RMessageForError(RErrorCode
));
367 icon
= WMCreatePixmapFromRImage(scr
, imgh
, 120);
369 WMSetButtonImage(panel
->ghorB
, icon
);
370 WMReleasePixmap(icon
);
373 imgv
= RRenderMultiGradient(50, 20, colors
, RGRD_VERTICAL
);
375 wwarning("internal error:%s", RMessageForError(RErrorCode
));
377 icon
= WMCreatePixmapFromRImage(scr
, imgv
, 120);
379 WMSetButtonImage(panel
->gverB
, icon
);
380 WMReleasePixmap(icon
);
383 imgd
= RRenderMultiGradient(50, 20, colors
, RGRD_DIAGONAL
);
385 wwarning("internal error:%s", RMessageForError(RErrorCode
));
387 icon
= WMCreatePixmapFromRImage(scr
, imgd
, 120);
389 WMSetButtonImage(panel
->gdiaB
, icon
);
390 WMReleasePixmap(icon
);
398 *--------------------------------------------------------------------------
400 *--------------------------------------------------------------------------
403 DestroyTexturePanel(TexturePanel
*panel
)
405 WMUnmapWidget(panel
->win
);
406 WMDestroyWidget(panel
->win
);
412 ShowTexturePanel(TexturePanel
*panel
)
414 WMMapWidget(panel
->win
);
419 HideTexturePanel(TexturePanel
*panel
)
421 WMUnmapWidget(panel
->win
);
425 SetTexturePanelOkAction(TexturePanel
*panel
, WMAction
*action
, void *clientData
)
427 panel
->okAction
= action
;
428 panel
->okData
= clientData
;
433 SetTexturePanelCancelAction(TexturePanel
*panel
, WMAction
*action
, void *clientData
)
435 panel
->cancelAction
= action
;
436 panel
->cancelData
= clientData
;
440 SetTexturePanelTexture(TexturePanel
*panel
, char *texture
)
443 char *parseStringPosition
;
444 char *enclosures
= "( )";
445 char *seperators
= " ,\"";
448 WMSetButtonSelected(panel
->tsoliB
, False
);
449 WMSetButtonSelected(panel
->tgradB
, False
);
450 WMSetButtonSelected(panel
->tpixmB
, False
);
452 parseString
= wstrdup(texture
);
453 parseStringPosition
= parseString
;
455 parseStringPosition
= strtok(parseStringPosition
,seperators
);
456 wwarning ("Parsing...");
458 while (parseStringPosition
) {
460 if (!strpbrk(parseStringPosition
,enclosures
)) {
461 if (strcasecmp(parseStringPosition
,"solid") == 0) {
462 wwarning("Switch to solid");
463 WMPerformButtonClick(panel
->tsoliB
);
465 parseStringPosition
= strtok(NULL
,seperators
);
467 while (parseStringPosition
) {
468 if (!strpbrk(parseStringPosition
,enclosures
)) {
469 WMSetColorWellColor(panel
->scolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
471 parseStringPosition
= strtok(NULL
,seperators
);
474 } else if ((strstr(parseStringPosition
,"pixmap")) && (strcasecmp(strstr(parseStringPosition
,"pixmap"),"pixmap") == 0)) {
475 WMSetButtonSelected(panel
->ptileB
, False
);
476 WMSetButtonSelected(panel
->pscalB
, False
);
478 WMPerformButtonClick(panel
->tpixmB
);
480 if (tolower(*parseStringPosition
) == 't') {
481 wwarning ("Switch to Tiled Pixmap");
482 WMPerformButtonClick(panel
->ptileB
);
484 wwarning ("Switch to Scaled Pixmap");
485 WMPerformButtonClick(panel
->pscalB
);
490 parseStringPosition
= strtok(NULL
,seperators
);
492 if (filename
) filename
= wstrappend(filename
," ");
493 filename
= wstrappend(filename
,parseStringPosition
);
494 parseStringPosition
= strtok(NULL
,seperators
);
495 } while (!strstr(parseStringPosition
,"rgb:"));
497 WMSetTextFieldText(panel
->pimagT
, filename
);
500 /* parseStringPosition = strtok(NULL,seperators); */
502 WMSetColorWellColor(panel
->pcolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
504 } else if ((strstr(parseStringPosition
,"gradient")) && (strcasecmp(strstr(parseStringPosition
,"gradient"),"gradient") == 0)) {
505 WMSetButtonSelected(panel
->ghorB
, False
);
506 WMSetButtonSelected(panel
->gverB
, False
);
507 WMSetButtonSelected(panel
->gdiaB
, False
);
509 WMPerformButtonClick(panel
->tgradB
);
511 if (strstr(parseStringPosition
,"h")) {
512 WMPerformButtonClick(panel
->ghorB
);
513 } else if (strstr(parseStringPosition
,"v")) {
514 WMPerformButtonClick(panel
->gverB
);
516 WMPerformButtonClick(panel
->gdiaB
);
519 WMClearList(panel
->gcolorLs
);
521 parseStringPosition
= strtok(NULL
,seperators
);
522 while (parseStringPosition
) {
523 if (!strpbrk(parseStringPosition
,enclosures
)) {
524 WMAddListItem(panel
->gcolorLs
, parseStringPosition
);
525 WMSetColorWellColor(panel
->gcolorW
,WMCreateNamedColor(WMWidgetScreen(panel
->scolorW
), parseStringPosition
, True
));
527 parseStringPosition
= strtok(NULL
,seperators
);
530 wfatal("Unknown Texture Type");
533 while (parseStringPosition
) {
534 parseStringPosition
= strtok(NULL
,seperators
);
539 parseStringPosition
= strtok(NULL
,seperators
);
541 renderTextureButtons (panel
);
547 GetTexturePanelTextureString(TexturePanel
*panel
)
549 char *colorString
= NULL
;
552 char *seperator
= ", ";
556 colorString
= wstrappend(colorString
,start
);
558 if (WMGetButtonSelected(panel
->tsoliB
)) {
559 colorString
= wstrappend(colorString
,"solid");
560 colorString
= wstrappend(colorString
,seperator
);
561 colorString
= wstrappend(colorString
, quote
);
562 colorString
= wstrappend(colorString
,WMGetColorWellRGBString(panel
->scolorW
));
563 colorString
= wstrappend(colorString
, quote
);
565 } else if (WMGetButtonSelected(panel
->tgradB
)) {
566 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
569 colorString
= wstrappend(colorString
,"m");
571 if (WMGetButtonSelected(panel
->ghorB
)) {
572 colorString
= wstrappend(colorString
,"hgradient");
573 } else if (WMGetButtonSelected(panel
->gverB
)) {
574 colorString
= wstrappend(colorString
,"vgradient");
576 colorString
= wstrappend(colorString
,"dgradient");
579 for (i
=0; i
< listRows
; i
++) {
580 colorString
= wstrappend(colorString
, seperator
);
581 colorString
= wstrappend(colorString
, quote
);
582 colorString
= wstrappend(colorString
, wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
));
583 colorString
= wstrappend(colorString
, quote
);
585 } else if (WMGetButtonSelected(panel
->tpixmB
)) {
586 if (WMGetButtonSelected(panel
->pscalB
)) {
587 colorString
= wstrappend(colorString
,"spixmap");
589 colorString
= wstrappend(colorString
,"tpixmap");
591 colorString
= wstrappend(colorString
,seperator
);
592 colorString
= wstrappend(colorString
, WMGetTextFieldText(panel
->pimagT
));
593 colorString
= wstrappend(colorString
,seperator
);
594 colorString
= wstrappend(colorString
, quote
);
595 colorString
= wstrappend(colorString
, WMGetColorWellRGBString(panel
->pcolorW
));
596 colorString
= wstrappend(colorString
, quote
);
599 colorString
= wstrappend(colorString
,finish
);
606 RenderTexturePanelTexture(TexturePanel
*panel
, unsigned width
, unsigned height
)
611 RColor
**colors
= NULL
;
612 RImage
*image
=NULL
, *fileImage
;
616 int i
, listRows
, style
;
618 scr
= WMWidgetScreen(panel
->gcolorLs
);
619 ctx
= WMScreenRContext(scr
);
621 if (WMGetButtonSelected(panel
->tsoliB
)) {
623 image
= RCreateImage(width
, height
, 1);
624 wellColor
= WMGetColorWellColor(panel
->scolorW
);
626 solidColor
.red
= (WMRedComponentOfColor(wellColor
) >> 8);
627 solidColor
.green
= (WMGreenComponentOfColor(wellColor
) >> 8) ;
628 solidColor
.blue
= (WMBlueComponentOfColor(wellColor
) >> 8);
629 solidColor
.alpha
= 0xff;
631 WMReleaseColor(wellColor
);
633 RClearImage(image
, &solidColor
);
635 } else if (WMGetButtonSelected(panel
->tgradB
)) {
637 if (WMGetButtonSelected(panel
->ghorB
)) {
638 style
= RGRD_HORIZONTAL
;
639 } else if (WMGetButtonSelected(panel
->gverB
)) {
640 style
= RGRD_VERTICAL
;
642 style
= RGRD_DIAGONAL
;
645 listRows
= WMGetListNumberOfRows(panel
->gcolorLs
);
646 colors
= wmalloc(sizeof(RColor
*)*(listRows
+1));
648 for (i
=0; i
< listRows
; i
++) {
649 if (!XParseColor(WMScreenDisplay(scr
), ctx
->cmap
,
650 wstrdup(WMGetListItem(panel
->gcolorLs
, i
)->text
),&color
)) {
651 wfatal("could not parse color \"%s\"\n", WMGetListItem(panel
->gcolorLs
, i
)->text
);
654 colors
[i
] = malloc(sizeof(RColor
));
655 colors
[i
]->red
= color
.red
>> 8;
656 colors
[i
]->green
= color
.green
>> 8;
657 colors
[i
]->blue
= color
.blue
>> 8;
662 image
= RRenderMultiGradient(width
, height
, colors
, style
);
664 } else if (WMGetButtonSelected(panel
->tpixmB
)) {
666 if (fopen(WMGetTextFieldText(panel
->pimagT
),"r")) {
668 fileImage
= RLoadImage(ctx
, WMGetTextFieldText(panel
->pimagT
), 0);
669 if (WMGetButtonSelected(panel
->pscalB
)) {
670 image
= RScaleImage(fileImage
, width
, height
);
672 image
= RMakeTiledImage(fileImage
, width
, height
);;
675 wwarning ("Invalid File Name");
676 return RCreateImage(1,1,1);
684 CreateTexturePanel(WMScreen
*scr
)
702 panel
= wmalloc(sizeof(_TexturePanel
));
703 memset(panel
, 0, sizeof(_TexturePanel
));
704 red
= WMCreateRGBColor(scr
,100,100,100,True
);
706 panel
->win
= WMCreateWindow(scr
, "textureBuilder");
707 WMResizeWidget(panel
->win
, 275, 365);
708 WMSetWindowTitle(panel
->win
, "Texture Builder");
710 /***************** Generic stuff ****************/
712 panel
->typeF
= WMCreateFrame(panel
->win
);
713 WMResizeWidget(panel
->typeF
, 245, 80);
714 WMMoveWidget(panel
->typeF
, 15, 10);
715 WMSetFrameTitle(panel
->typeF
, "Texture Type");
717 panel
->tsoliB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
718 WMResizeWidget(panel
->tsoliB
, 48, 48);
719 WMMoveWidget(panel
->tsoliB
, 42, 20);
720 WMSetButtonImagePosition(panel
->tsoliB
, WIPImageOnly
);
721 image
= RGetImageFromXPMData(WMScreenRContext(scr
), solid_xpm
);
723 wwarning("internal error:%s", RMessageForError(RErrorCode
));
725 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
726 RDestroyImage(image
);
727 WMSetButtonImage(panel
->tsoliB
, icon
);
728 WMReleasePixmap(icon
);
730 WMSetButtonAction(panel
->tsoliB
, buttonCallback
, panel
);
732 panel
->tgradB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
733 WMGroupButtons(panel
->tsoliB
, panel
->tgradB
);
734 WMResizeWidget(panel
->tgradB
, 48, 48);
735 WMMoveWidget(panel
->tgradB
, 98, 20);
736 WMSetButtonImagePosition(panel
->tgradB
, WIPImageOnly
);
737 image
= RGetImageFromXPMData(WMScreenRContext(scr
), gradient_xpm
);
739 wwarning("internal error:%s", RMessageForError(RErrorCode
));
741 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
742 RDestroyImage(image
);
743 WMSetButtonImage(panel
->tgradB
, icon
);
744 WMReleasePixmap(icon
);
746 WMSetButtonAction(panel
->tgradB
, buttonCallback
, panel
);
748 panel
->tpixmB
= WMCreateButton(panel
->typeF
, WBTOnOff
);
749 WMGroupButtons(panel
->tsoliB
, panel
->tpixmB
);
750 WMResizeWidget(panel
->tpixmB
, 48, 48);
751 WMMoveWidget(panel
->tpixmB
, 154, 20);
752 WMSetButtonImagePosition(panel
->tpixmB
, WIPImageOnly
);
753 image
= RGetImageFromXPMData(WMScreenRContext(scr
), pixmap_xpm
);
755 wwarning("internal error:%s", RMessageForError(RErrorCode
));
757 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
758 RDestroyImage(image
);
759 WMSetButtonImage(panel
->tpixmB
, icon
);
760 WMReleasePixmap(icon
);
762 WMSetButtonAction(panel
->tpixmB
, buttonCallback
, panel
);
764 panel
->okB
= WMCreateCommandButton(panel
->win
);
765 WMResizeWidget(panel
->okB
, 70, 28);
766 WMMoveWidget(panel
->okB
, 110, 325);
767 WMSetButtonText(panel
->okB
, "OK");
768 WMSetButtonAction(panel
->okB
,buttonCallback
,panel
);
770 panel
->cancB
= WMCreateCommandButton(panel
->win
);
771 WMResizeWidget(panel
->cancB
, 70, 28);
772 WMMoveWidget(panel
->cancB
, 190, 325);
773 WMSetButtonText(panel
->cancB
, "Cancel");
774 WMSetButtonAction(panel
->cancB
,buttonCallback
,panel
);
776 WMMapSubwidgets(panel
->typeF
);
778 /***************** Solid *****************/
779 panel
->scolorF
= WMCreateFrame(panel
->win
);
780 WMResizeWidget(panel
->scolorF
, 245, 125);
781 WMMoveWidget(panel
->scolorF
, 15, 140);
782 WMSetFrameTitle(panel
->scolorF
, "Color");
784 panel
->scolorW
= WMCreateColorWell(panel
->scolorF
);
785 WMResizeWidget(panel
->scolorW
, 60, 45);
786 WMMoveWidget(panel
->scolorW
, 95, 40);
787 WMSetColorWellColor(panel
->scolorW
,WMCreateRGBColor(scr
, 0xddff, 0xddff, 0, True
));
789 WMMapSubwidgets(panel
->scolorF
);
791 /***************** Gradient *****************/
792 panel
->gcolorF
= WMCreateFrame(panel
->win
);
793 WMResizeWidget(panel
->gcolorF
, 245, 145);
794 WMMoveWidget(panel
->gcolorF
, 15, 95);
795 WMSetFrameTitle(panel
->gcolorF
, "Colors");
797 panel
->gcolorLs
= WMCreateList(panel
->gcolorF
);
798 WMResizeWidget(panel
->gcolorLs
, 120, 84);
799 WMMoveWidget(panel
->gcolorLs
, 20, 20);
801 WMSetListUserDrawProc(panel
->gcolorLs
, paintListItem
);
803 WMAddListItem(panel
->gcolorLs
, "rgb:ff/ff/ff");
804 WMAddListItem(panel
->gcolorLs
, "rgb:00/00/ff");
806 panel
->gcolorW
= WMCreateColorWell(panel
->gcolorF
);
807 WMResizeWidget(panel
->gcolorW
, 60, 45);
808 WMMoveWidget(panel
->gcolorW
, 160, 40);
809 WMSetColorWellColor(panel
->gcolorW
,WMCreateRGBColor(scr
, 0xffff, 0, 0, True
));
811 panel
->gremB
= WMCreateCommandButton(panel
->gcolorF
);
812 WMResizeWidget(panel
->gremB
, 64, 24);
813 WMMoveWidget(panel
->gremB
, 20, 110);
814 WMSetButtonText(panel
->gremB
, "Remove");
815 WMSetButtonAction(panel
->gremB
,(WMAction
*)buttonCallback
,panel
);
817 panel
->gupdB
= WMCreateCommandButton(panel
->gcolorF
);
818 WMResizeWidget(panel
->gupdB
, 64, 24);
819 WMMoveWidget(panel
->gupdB
, 90, 110);
820 WMSetButtonText(panel
->gupdB
, "Update");
821 WMSetButtonAction(panel
->gupdB
,(WMAction
*)buttonCallback
,panel
);
823 panel
->gaddB
= WMCreateCommandButton(panel
->gcolorF
);
824 WMResizeWidget(panel
->gaddB
, 64, 24);
825 WMMoveWidget(panel
->gaddB
, 160, 110);
826 WMSetButtonText(panel
->gaddB
, "Add");
827 WMSetButtonAction(panel
->gaddB
,(WMAction
*)buttonCallback
,panel
);
828 WMMapSubwidgets(panel
->gcolorF
);
830 panel
->gdirF
= WMCreateFrame(panel
->win
);
831 WMResizeWidget(panel
->gdirF
, 245, 65);
832 WMMoveWidget(panel
->gdirF
, 15, 245);
833 WMSetFrameTitle(panel
->gdirF
, "Direction");
835 panel
->ghorB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
836 WMResizeWidget(panel
->ghorB
, 64, 34);
837 WMMoveWidget(panel
->ghorB
, 20, 20);
838 WMSetButtonImagePosition(panel
->ghorB
, WIPImageOnly
);
839 WMPerformButtonClick(panel
->ghorB
);
842 panel
->gverB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
843 WMResizeWidget(panel
->gverB
, 64, 34);
844 WMMoveWidget(panel
->gverB
, 90, 20);
845 WMSetButtonImagePosition(panel
->gverB
, WIPImageOnly
);
846 WMGroupButtons(panel
->ghorB
, panel
->gverB
);
848 panel
->gdiaB
= WMCreateButton(panel
->gdirF
, WBTOnOff
);
849 WMResizeWidget(panel
->gdiaB
, 64, 34);
850 WMMoveWidget(panel
->gdiaB
, 160, 20);
851 WMSetButtonImagePosition(panel
->gdiaB
, WIPImageOnly
);
852 WMGroupButtons(panel
->ghorB
, panel
->gdiaB
);
854 WMMapSubwidgets(panel
->gdirF
);
856 /***************** Pixmap *****************/
857 panel
->pimagF
= WMCreateFrame(panel
->win
);
858 WMResizeWidget(panel
->pimagF
, 245, 140);
859 WMMoveWidget(panel
->pimagF
, 15, 96);
860 WMSetFrameTitle(panel
->pimagF
, "Image");
862 panel
->pimagL
= WMCreateLabel(panel
->pimagF
);
863 WMResizeWidget(panel
->pimagL
, 220, 83);
864 WMMoveWidget(panel
->pimagL
, 10, 20);
865 WMSetLabelImagePosition(panel
->pimagL
, WIPImageOnly
);
867 panel
->pimagT
= WMCreateTextField(panel
->pimagF
);
868 WMResizeWidget(panel
->pimagT
, 147, 20);
869 WMMoveWidget(panel
->pimagT
, 10, 110);
871 panel
->pbrowB
= WMCreateCommandButton(panel
->pimagF
);
872 WMResizeWidget(panel
->pbrowB
, 68, 24);
873 WMMoveWidget(panel
->pbrowB
, 165, 108);
874 WMSetButtonText(panel
->pbrowB
, "Browse...");
875 WMSetButtonAction(panel
->pbrowB
,buttonCallback
,panel
);
877 WMMapSubwidgets(panel
->pimagF
);
879 panel
->pcolorF
= WMCreateFrame(panel
->win
);
880 WMResizeWidget(panel
->pcolorF
, 90, 75);
881 WMMoveWidget(panel
->pcolorF
, 15, 240);
882 WMSetFrameTitle(panel
->pcolorF
, "Color");
884 panel
->pcolorW
= WMCreateColorWell(panel
->pcolorF
);
885 WMResizeWidget(panel
->pcolorW
, 60, 45);
886 WMMoveWidget(panel
->pcolorW
, 15, 20);
887 WMSetColorWellColor(panel
->pcolorW
,WMCreateRGBColor(scr
, 0x00, 0xddff, 0xffff, True
));
890 WMMapSubwidgets(panel
->pcolorF
);
892 panel
->pmodeF
= WMCreateFrame(panel
->win
);
893 WMResizeWidget(panel
->pmodeF
, 145, 70);
894 WMMoveWidget(panel
->pmodeF
, 115, 245);
896 panel
->pscalB
= WMCreateButton(panel
->pmodeF
, WBTOnOff
);
897 WMResizeWidget(panel
->pscalB
, 54, 50);
898 WMMoveWidget(panel
->pscalB
, 10, 10);
899 WMSetButtonImagePosition(panel
->pscalB
, WIPImageOnly
);
900 WMPerformButtonClick(panel
->pscalB
);
902 image
= RGetImageFromXPMData(WMScreenRContext(scr
), scaled_xpm
);
904 wwarning("internal error:%s", RMessageForError(RErrorCode
));
906 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
907 RDestroyImage(image
);
908 WMSetButtonImage(panel
->pscalB
, icon
);
909 WMReleasePixmap(icon
);
912 panel
->ptileB
= WMCreateButton(panel
->pmodeF
, WBTOnOff
);
913 WMResizeWidget(panel
->ptileB
, 54, 50);
914 WMMoveWidget(panel
->ptileB
, 75, 10);
915 WMSetButtonImagePosition(panel
->ptileB
, WIPImageOnly
);
916 image
= RGetImageFromXPMData(WMScreenRContext(scr
), tiled_xpm
);
918 wwarning("internal error:%s", RMessageForError(RErrorCode
));
920 icon
= WMCreatePixmapFromRImage(scr
, image
, 120);
921 RDestroyImage(image
);
922 WMSetButtonImage(panel
->ptileB
, icon
);
923 WMReleasePixmap(icon
);
925 WMGroupButtons(panel
->pscalB
, panel
->ptileB
);
927 WMMapSubwidgets(panel
->pmodeF
);
929 WMRealizeWidget(panel
->win
);
930 WMMapSubwidgets(panel
->win
);
932 WMPerformButtonClick(panel
->tsoliB
);
934 WMMapWidget(panel
->win
);
936 renderTextureButtons (panel
);
939 /* register notification observers */
940 WMAddNotificationObserver(notificationObserver
, panel
,
941 WMTextDidChangeNotification
,
950 *--------------------------------------------------------------------------
952 *--------------------------------------------------------------------------
957 char *ProgName
= "test";
959 void testOKButton(WMWidget
*self
, void *data
){
966 TexturePanel
*panel
= (TexturePanel
*)data
;
967 test
= GetTexturePanelTextureString(panel
);
971 dpy
= WMScreenDisplay(WMWidgetScreen(panel
->okB
));
972 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 250, 250,
974 XMapRaised(dpy
, win
);
977 image
= RenderTexturePanelTexture(panel
, 250, 250);
979 RConvertImage(WMScreenRContext(WMWidgetScreen(panel
->okB
)), image
, &pix
);
981 XCopyArea(dpy
, pix
, win
, (WMScreenRContext(WMWidgetScreen(panel
->okB
)))->copy_gc
, 0, 0, image
->width
, image
->height
,
984 SetTexturePanelTexture(panel
, test
);
988 void testCancelButton(WMWidget
*self
, void *data
){
989 wwarning("Exiting test....");
998 int main(int argc
, char **argv
)
1000 TexturePanel
*panel
;
1002 Display
*dpy
= XOpenDisplay("");
1007 WMInitializeApplication("Test", &argc
, argv
);
1010 wfatal("could not open display");
1014 scr
= WMCreateSimpleApplicationScreen(dpy
);
1016 panel
= CreateTexturePanel(scr
);
1018 SetTexturePanelOkAction(panel
,(WMAction
*)testOKButton
,panel
);
1019 SetTexturePanelCancelAction(panel
,(WMAction
*)testCancelButton
,panel
);
1021 ShowTexturePanel(panel
);
1023 SetTexturePanelTexture(panel
," ( tpixmap, ballot box.xpm, \"rgb:ff/de/ff\" ) ");
1025 WMScreenMainLoop(scr
);