1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31 #include "TexturePanel.h"
33 typedef struct _Panel
{
37 CallbackRec callbacks
;
61 TexturePanel
*texturePanel
;
85 static void showData(_Panel
*panel
);
88 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
90 #define ICON_FILE "appearance"
92 #define TNEW_FILE "tnew"
93 #define TDEL_FILE "tdel"
94 #define TEDIT_FILE "tedit"
95 #define TEXTR_FILE "textr"
100 static char * blueled_xpm
[] = {
130 static char *blueled2_xpm
[] = {
131 /* width height num_colors chars_per_pixel */
164 #define FTITLE (1<<0)
165 #define UTITLE (1<<1)
166 #define OTITLE (1<<2)
167 #define MTITLE (1<<3)
171 #define EVERYTHING 0xff
176 #define TEXPREV_WIDTH 40
177 #define TEXPREV_HEIGHT 24
184 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
188 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
191 color
->red
= xcolor
.red
>> 8;
192 color
->green
= xcolor
.green
>> 8;
193 color
->blue
= xcolor
.blue
>> 8;
199 dumpRImage(char *path
, RImage
*image
)
203 f
= fopen(path
, "w");
208 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
209 image
->data
[3]!=NULL
? 4 : 3);
211 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
212 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
213 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
215 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
225 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
226 char *path
, int border
)
231 RContext
*rc
= WMScreenRContext(scr
);
236 type
= PLGetString(PLGetArrayElement(texture
, 0));
238 image
= RCreateImage(width
, height
, False
);
240 if (strcasecmp(type
, "solid")==0) {
242 str
= PLGetString(PLGetArrayElement(texture
, 1));
244 str2rcolor(rc
, str
, &rcolor
);
246 RClearImage(image
, &rcolor
);
247 } else if (strcasecmp(&type
[1], "gradient")==0) {
251 switch (toupper(type
[0])) {
253 style
= RVerticalGradient
;
256 style
= RHorizontalGradient
;
259 style
= RDiagonalGradient
;
263 str
= PLGetString(PLGetArrayElement(texture
, 1));
264 str2rcolor(rc
, str
, &rcolor
);
265 str
= PLGetString(PLGetArrayElement(texture
, 2));
266 str2rcolor(rc
, str
, &rcolor2
);
268 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
269 } else if (strcasecmp(&type
[2], "gradient")==0) {
274 switch (toupper(type
[1])) {
276 style
= RVerticalGradient
;
279 style
= RHorizontalGradient
;
282 style
= RDiagonalGradient
;
286 j
= PLGetNumberOfElements(texture
);
289 colors
= wmalloc(j
* sizeof(RColor
*));
291 for (i
= 2; i
< j
; i
++) {
292 str
= PLGetString(PLGetArrayElement(texture
, i
));
293 colors
[i
-2] = wmalloc(sizeof(RColor
));
294 str2rcolor(rc
, str
, colors
[i
-2]);
298 image
= RRenderMultiGradient(width
, height
, colors
, style
);
300 for (i
= 0; colors
[i
]!=NULL
; i
++)
304 } else if (strcasecmp(&type
[1], "pixmap")==0) {
310 str
= PLGetString(PLGetArrayElement(texture
, 1));
312 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
313 timage
= RLoadImage(rc
, path
, 0);
316 if (toupper(type
[0]) == 'T') {
317 if (timage
->width
< TEXPREV_WIDTH
318 || timage
->height
< TEXPREV_HEIGHT
) {
319 image
= RMakeTiledImage(timage
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
);
320 RDestroyImage(timage
);
327 if (w
- TEXPREV_WIDTH
> h
- TEXPREV_HEIGHT
) {
328 h
= (w
* TEXPREV_HEIGHT
)/TEXPREV_WIDTH
;
330 w
= (h
* TEXPREV_WIDTH
)/TEXPREV_HEIGHT
;
333 image
= RScaleImage(timage
, w
, h
);
334 RDestroyImage(timage
);
340 dumpRImage(path
, image
);
344 RBevelImage(image
, border
);
347 RConvertImage(rc
, image
, &pixmap
);
348 RDestroyImage(image
);
357 updatePreviewBox(_Panel
*panel
, int elements
)
359 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
360 Display
*dpy
= WMScreenDisplay(scr
);
361 /* RContext *rc = WMScreenRContext(scr);*/
366 TextureListItem
*titem
;
368 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
371 if (!panel
->preview
) {
374 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
375 220-4, 185-4, WMScreenDepth(scr
));
377 color
= WMGrayColor(scr
);
378 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
380 WMReleaseColor(color
);
385 if (elements
& FTITLE
) {
386 item
= WMGetListItem(panel
->texLs
, 0);
387 titem
= (TextureListItem
*)item
->clientData
;
389 pix
= renderTexture(scr
, titem
->prop
, 180, 20, NULL
, RBEV_RAISED2
);
391 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 180, 20, 5, 10);
393 XFreePixmap(dpy
, pix
);
395 if (elements
& UTITLE
) {
396 item
= WMGetListItem(panel
->texLs
, 1);
397 titem
= (TextureListItem
*)item
->clientData
;
399 pix
= renderTexture(scr
, titem
->prop
, 180, 20, NULL
, RBEV_RAISED2
);
401 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 180, 20, 10, 35);
403 XFreePixmap(dpy
, pix
);
405 if (elements
& OTITLE
) {
406 item
= WMGetListItem(panel
->texLs
, 2);
407 titem
= (TextureListItem
*)item
->clientData
;
409 pix
= renderTexture(scr
, titem
->prop
, 180, 20, NULL
, RBEV_RAISED2
);
411 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 180, 20, 15, 60);
413 XFreePixmap(dpy
, pix
);
415 if (elements
& MTITLE
) {
416 item
= WMGetListItem(panel
->texLs
, 3);
417 titem
= (TextureListItem
*)item
->clientData
;
419 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
421 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 20, 95);
423 XFreePixmap(dpy
, pix
);
425 if (elements
& MITEM
) {
426 item
= WMGetListItem(panel
->texLs
, 4);
427 titem
= (TextureListItem
*)item
->clientData
;
429 pix
= renderTexture(scr
, titem
->prop
, 100, 18, NULL
, RBEV_RAISED2
);
431 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 20, 115);
432 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 20, 115+18);
433 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 20, 115+36);
435 XFreePixmap(dpy
, pix
);
437 if (elements
& ICON
) {
438 item
= WMGetListItem(panel
->texLs
, 5);
439 titem
= (TextureListItem
*)item
->clientData
;
441 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
, RBEV_RAISED3
);
443 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 130, 100);
445 XFreePixmap(dpy
, pix
);
451 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
452 220-4, 185-4, WMScreenDepth(scr
));
454 WMSetLabelImage(panel
->prevL
, p
);
457 WMRedisplayWidget(panel
->prevL
);
467 cancelNewTexture(void *data
)
469 _Panel
*panel
= (_Panel
*)data
;
471 HideTexturePanel(panel
->texturePanel
);
478 makeFileName(char *prefix
, char *name
)
483 str
= wstrappend(prefix
, name
);
484 fname
= wstrdup(str
);
487 while (access(fname
, F_OK
)==0) {
491 sprintf(buf
, "%i", i
++);
492 fname
= wstrappend(str
, buf
);
503 okNewTexture(void *data
)
505 _Panel
*panel
= (_Panel
*)data
;
510 TextureListItem
*titem
;
511 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
513 titem
= wmalloc(sizeof(TextureListItem
));
514 memset(titem
, 0, sizeof(TextureListItem
));
516 HideTexturePanel(panel
->texturePanel
);
518 name
= GetTexturePanelTextureName(panel
->texturePanel
);
520 prop
= GetTexturePanelTexture(panel
->texturePanel
);
522 str
= PLGetDescription(prop
);
526 titem
->texture
= str
;
527 titem
->selectedFor
= 0;
529 titem
->path
= makeFileName(panel
->fprefix
, name
);
530 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
533 item
= WMAddListItem(panel
->texLs
, "");
534 item
->clientData
= titem
;
536 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
542 okEditTexture(void *data
)
544 _Panel
*panel
= (_Panel
*)data
;
549 TextureListItem
*titem
;
551 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
552 titem
= (TextureListItem
*)item
->clientData
;
554 HideTexturePanel(panel
->texturePanel
);
556 if (titem
->current
) {
557 name
= GetTexturePanelTextureName(panel
->texturePanel
);
563 prop
= GetTexturePanelTexture(panel
->texturePanel
);
565 str
= PLGetDescription(prop
);
567 PLRelease(titem
->prop
);
570 free(titem
->texture
);
571 titem
->texture
= str
;
573 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
574 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
575 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
578 WMRedisplayWidget(panel
->texLs
);
580 if (titem
->selectedFor
)
581 updatePreviewBox(panel
, titem
->selectedFor
);
587 editTexture(WMWidget
*w
, void *data
)
589 _Panel
*panel
= (_Panel
*)data
;
591 TextureListItem
*titem
;
593 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
594 titem
= (TextureListItem
*)item
->clientData
;
596 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
598 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
599 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
601 SetTexturePanelPixmapPath(panel
->texturePanel
,
602 GetObjectForKey("PixmapPath"));
603 ShowTexturePanel(panel
->texturePanel
);
609 newTexture(WMWidget
*w
, void *data
)
611 _Panel
*panel
= (_Panel
*)data
;
613 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
615 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
617 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
619 SetTexturePanelPixmapPath(panel
->texturePanel
,
620 GetObjectForKey("PixmapPath"));
621 ShowTexturePanel(panel
->texturePanel
);
627 deleteTexture(WMWidget
*w
, void *data
)
629 _Panel
*panel
= (_Panel
*)data
;
631 TextureListItem
*titem
;
635 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
636 row
= WMGetListSelectedItemRow(panel
->texLs
);
637 item
= WMGetListItem(panel
->texLs
, row
);
638 titem
= (TextureListItem
*)item
->clientData
;
640 if (titem
->selectedFor
& (1 << section
)) {
641 TextureListItem
*titem2
;
643 panel
->textureIndex
[section
] = section
;
644 item
= WMGetListItem(panel
->texLs
, section
);
645 titem2
= (TextureListItem
*)item
->clientData
;
646 titem2
->selectedFor
|= 1 << section
;
650 free(titem
->texture
);
651 PLRelease(titem
->prop
);
653 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
654 wsyserror("could not remove file %s", titem
->path
);
661 WMRemoveListItem(panel
->texLs
, row
);
662 WMSetButtonEnabled(panel
->delB
, False
);
669 extractTexture(WMWidget
*w
, void *data
)
671 _Panel
*panel
= (_Panel
*)data
;
674 WMScreen
*scr
= WMWidgetScreen(w
);
676 opanel
= WMGetOpenPanel(scr
);
677 WMSetFilePanelCanChooseDirectories(opanel
, False
);
678 WMSetFilePanelCanChooseFiles(opanel
, True
);
680 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
681 _("Select File"), NULL
)) {
682 path
= WMGetFilePanelFileName(opanel
);
685 OpenExtractPanelFor(panel
, path
);
695 changePage(WMWidget
*w
, void *data
)
697 _Panel
*panel
= (_Panel
*)data
;
700 TextureListItem
*titem
;
703 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
705 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
707 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
]
708 - WMGetListNumberOfRows(panel
->texLs
)/2);
710 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
712 titem
= (TextureListItem
*)item
->clientData
;
714 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
715 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
716 WMSetLabelText(panel
->texsL
, str
);
723 textureClick(WMWidget
*w
, void *data
)
725 _Panel
*panel
= (_Panel
*)data
;
728 TextureListItem
*titem
;
730 i
= WMGetListSelectedItemRow(panel
->texLs
);
732 item
= WMGetListItem(panel
->texLs
, i
);
734 titem
= (TextureListItem
*)item
->clientData
;
736 if (titem
->current
) {
737 WMSetButtonEnabled(panel
->delB
, False
);
739 WMSetButtonEnabled(panel
->delB
, True
);
746 textureDoubleClick(WMWidget
*w
, void *data
)
748 _Panel
*panel
= (_Panel
*)data
;
751 TextureListItem
*titem
;
754 /* unselect old texture */
755 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
757 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
758 titem
= (TextureListItem
*)item
->clientData
;
759 titem
->selectedFor
&= ~(1 << section
);
761 /* select new texture */
762 i
= WMGetListSelectedItemRow(panel
->texLs
);
764 item
= WMGetListItem(panel
->texLs
, i
);
766 titem
= (TextureListItem
*)item
->clientData
;
768 titem
->selectedFor
|= 1<<section
;
770 panel
->textureIndex
[section
] = i
;
772 WMRedisplayWidget(panel
->texLs
);
774 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
775 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
776 WMSetLabelText(panel
->texsL
, str
);
784 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
787 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
788 WMScreen
*scr
= WMWidgetScreen(lPtr
);
789 int width
, height
, x
, y
;
790 Display
*dpy
= WMScreenDisplay(scr
);
791 WMColor
*white
= WMWhiteColor(scr
);
793 WMColor
*black
= WMBlackColor(scr
);
794 TextureListItem
*titem
;
796 width
= rect
->size
.width
;
797 height
= rect
->size
.height
;
801 if (state
& WLDSSelected
)
802 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
804 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
806 item
= WMGetListItem(lPtr
, index
);
807 titem
= (TextureListItem
*)item
->clientData
;
810 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
811 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
813 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
814 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
815 else if (titem
->selectedFor
)
816 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
818 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
819 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
820 strlen(titem
->title
));
822 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
823 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
824 strlen(titem
->texture
));
827 WMReleaseColor(white
);
828 WMReleaseColor(black
);
834 loadRImage(WMScreen
*scr
, char *path
)
842 f
= fopen(path
, "r");
846 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
848 image
= RCreateImage(w
, h
, d
== 4);
849 for (i
= 0; i
< d
; i
++) {
850 fread(image
->data
[i
], 1, w
*h
, f
);
854 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
855 RDestroyImage(image
);
863 fillTextureList(WMList
*lPtr
)
865 proplist_t textureList
;
867 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
869 TextureListItem
*titem
;
870 WMScreen
*scr
= WMWidgetScreen(lPtr
);
872 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
876 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
879 texture
= PLGetArrayElement(textureList
, i
);
881 titem
= wmalloc(sizeof(TextureListItem
));
882 memset(titem
, 0, sizeof(TextureListItem
));
884 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
885 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
886 titem
->texture
= PLGetDescription(titem
->prop
);
887 titem
->selectedFor
= 0;
888 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
891 titem
->preview
= loadRImage(scr
, titem
->path
);
892 if (!titem
->preview
) {
893 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
894 TEXPREV_HEIGHT
, NULL
, 0);
896 item
= WMAddListItem(lPtr
, "");
897 item
->clientData
= titem
;
903 createPanel(Panel
*p
)
905 _Panel
*panel
= (_Panel
*)p
;
908 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
913 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
915 if (access(panel
->fprefix
, F_OK
)!=0) {
916 if (mkdir(panel
->fprefix
, 0755) < 0) {
917 wsyserror(panel
->fprefix
);
922 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
923 free(panel
->fprefix
);
924 panel
->fprefix
= tmp
;
925 if (access(panel
->fprefix
, F_OK
)!=0) {
926 if (mkdir(panel
->fprefix
, 0755) < 0) {
927 wsyserror(panel
->fprefix
);
932 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
933 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
934 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
936 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
937 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
939 panel
->frame
= WMCreateFrame(panel
->win
);
940 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
941 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
944 panel
->prevL
= WMCreateLabel(panel
->frame
);
945 WMResizeWidget(panel
->prevL
, 260, 165);
946 WMMoveWidget(panel
->prevL
, 15, 10);
947 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
949 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
950 WMResizeWidget(panel
->secP
, 260, 20);
951 WMMoveWidget(panel
->secP
, 15, 180);
952 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
953 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
954 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
955 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
956 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
957 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
958 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
959 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
961 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
964 panel
->texsL
= WMCreateLabel(panel
->frame
);
965 WMResizeWidget(panel
->texsL
, 260, 20);
966 WMMoveWidget(panel
->texsL
, 15, 205);
967 WMSetLabelWraps(panel
->texsL
, False
);
970 font
= WMBoldSystemFontOfSize(scr
, 12);
972 panel
->texL
= WMCreateLabel(panel
->frame
);
973 WMResizeWidget(panel
->texL
, 225, 18);
974 WMMoveWidget(panel
->texL
, 285, 10);
975 WMSetLabelFont(panel
->texL
, font
);
976 WMSetLabelText(panel
->texL
, _("Textures"));
977 WMSetLabelRelief(panel
->texL
, WRSunken
);
978 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
979 color
= WMDarkGrayColor(scr
);
980 WMSetWidgetBackgroundColor(panel
->texL
, color
);
981 WMReleaseColor(color
);
982 color
= WMWhiteColor(scr
);
983 WMSetLabelTextColor(panel
->texL
, color
);
984 WMReleaseColor(color
);
988 panel
->texLs
= WMCreateList(panel
->frame
);
989 WMResizeWidget(panel
->texLs
, 225, 144);
990 WMMoveWidget(panel
->texLs
, 285, 30);
991 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
992 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
993 WMHangData(panel
->texLs
, panel
);
994 WMSetListAction(panel
->texLs
, textureClick
, panel
);
995 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
997 /* command buttons */
999 font
= WMSystemFontOfSize(scr
, 10);
1002 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1003 WMResizeWidget(panel
->newB
, 56, 48);
1004 WMMoveWidget(panel
->newB
, 285, 180);
1005 WMSetButtonFont(panel
->newB
, font
);
1006 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1007 WMSetButtonText(panel
->newB
, _("New"));
1008 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1009 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1011 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1012 WMResizeWidget(panel
->ripB
, 56, 48);
1013 WMMoveWidget(panel
->ripB
, 341, 180);
1014 WMSetButtonFont(panel
->ripB
, font
);
1015 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1016 WMSetButtonText(panel
->ripB
, _("Extract..."));
1017 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1018 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1020 WMSetButtonEnabled(panel
->ripB
, False
);
1022 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1023 WMResizeWidget(panel
->editB
, 56, 48);
1024 WMMoveWidget(panel
->editB
, 397, 180);
1025 WMSetButtonFont(panel
->editB
, font
);
1026 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1027 WMSetButtonText(panel
->editB
, _("Edit"));
1028 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1029 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1031 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1032 WMResizeWidget(panel
->delB
, 56, 48);
1033 WMMoveWidget(panel
->delB
, 453, 180);
1034 WMSetButtonFont(panel
->delB
, font
);
1035 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1036 WMSetButtonText(panel
->delB
, _("Delete"));
1037 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1038 WMSetButtonEnabled(panel
->delB
, False
);
1039 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1041 WMReleaseFont(font
);
1045 WMRealizeWidget(panel
->frame
);
1046 WMMapSubwidgets(panel
->frame
);
1048 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1052 changePage(panel
->secP
, panel
);
1054 fillTextureList(panel
->texLs
);
1056 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1062 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1066 TextureListItem
*titem
;
1068 titem
= wmalloc(sizeof(TextureListItem
));
1069 memset(titem
, 0, sizeof(TextureListItem
));
1071 titem
->title
= wstrdup(title
);
1072 titem
->prop
= GetObjectForKey(key
);
1074 titem
->prop
= PLGetProplistWithDescription(defValue
);
1076 PLRetain(titem
->prop
);
1078 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1080 titem
->selectedFor
= 1<<index
;
1082 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1083 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1085 item
= WMAddListItem(list
, "");
1086 item
->clientData
= titem
;
1092 showData(_Panel
*panel
)
1096 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1098 panel
->textureIndex
[i
] = i
++;
1100 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1102 panel
->textureIndex
[i
] = i
++;
1104 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1105 "[Owner of Focused]", i
);
1106 panel
->textureIndex
[i
] = i
++;
1108 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1110 panel
->textureIndex
[i
] = i
++;
1112 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1114 panel
->textureIndex
[i
] = i
++;
1116 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1117 panel
->textureIndex
[i
] = i
++;
1119 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1121 panel->textureIndex[i] = i++;
1124 updatePreviewBox(panel
, EVERYTHING
);
1130 storeData(_Panel
*panel
)
1132 proplist_t textureList
;
1135 TextureListItem
*titem
;
1137 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1139 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1141 /* store list of textures */
1142 for (i
= 6; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1143 item
= WMGetListItem(panel
->texLs
, i
);
1144 titem
= (TextureListItem
*)item
->clientData
;
1146 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1147 PLRetain(titem
->prop
),
1148 PLMakeString(titem
->path
),
1151 PLAppendArrayElement(textureList
, texture
);
1154 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1155 PLRelease(textureList
);
1157 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1158 titem
= (TextureListItem
*)item
->clientData
;
1159 SetObjectForKey(titem
->prop
, "FTitleBack");
1161 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1162 titem
= (TextureListItem
*)item
->clientData
;
1163 SetObjectForKey(titem
->prop
, "UTitleBack");
1165 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1166 titem
= (TextureListItem
*)item
->clientData
;
1167 SetObjectForKey(titem
->prop
, "PTitleBack");
1169 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1170 titem
= (TextureListItem
*)item
->clientData
;
1171 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1173 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1174 titem
= (TextureListItem
*)item
->clientData
;
1175 SetObjectForKey(titem
->prop
, "MenuTextBack");
1177 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1178 titem
= (TextureListItem
*)item
->clientData
;
1179 SetObjectForKey(titem
->prop
, "IconBack");
1186 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1190 panel
= wmalloc(sizeof(_Panel
));
1191 memset(panel
, 0, sizeof(_Panel
));
1193 panel
->sectionName
= _("Appearance Preferences");
1197 panel
->callbacks
.createWidgets
= createPanel
;
1198 panel
->callbacks
.updateDomain
= storeData
;
1200 AddSection(panel
, ICON_FILE
);
1207 /****************************************************************************/
1211 typedef struct ExtractPanel
{
1224 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1226 ExtractPanel
*epanel
;
1229 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1231 epanel
= wmalloc(sizeof(ExtractPanel
));
1232 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1234 |WMClosableWindowMask
);
1235 WMResizeWidget(epanel
->win
, 245, 250);
1236 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1238 epanel
->label
= WMCreateLabel(epanel
->win
);
1239 WMResizeWidget(epanel
->label
, 225, 18);
1240 WMMoveWidget(epanel
->label
, 10, 10);
1241 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1242 WMSetLabelRelief(epanel
->label
, WRSunken
);
1244 color
= WMDarkGrayColor(scr
);
1245 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1246 WMReleaseColor(color
);
1248 color
= WMWhiteColor(scr
);
1249 WMSetLabelTextColor(epanel
->label
, color
);
1250 WMReleaseColor(color
);
1252 font
= WMBoldSystemFontOfSize(scr
, 12);
1253 WMSetLabelFont(epanel
->label
, font
);
1254 WMReleaseFont(font
);
1256 WMSetLabelText(epanel
->label
, _("Textures"));
1258 epanel
->list
= WMCreateList(epanel
->win
);
1259 WMResizeWidget(epanel
->list
, 225, 165);
1260 WMMoveWidget(epanel
->list
, 10, 30);
1264 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1265 WMResizeWidget(epanel
->closeB
, 74, 24);
1266 WMMoveWidget(epanel
->closeB
, 165, 215);
1267 WMSetButtonText(epanel
->closeB
, _("Close"));
1269 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1270 WMResizeWidget(epanel
->extrB
, 74, 24);
1271 WMMoveWidget(epanel
->extrB
, 80, 215);
1272 WMSetButtonText(epanel
->extrB
, _("Extract"));
1274 WMMapSubwidgets(epanel
->win
);
1277 /* take textures from file */
1281 WMRealizeWidget(epanel
->win
);
1283 WMMapWidget(epanel
->win
);