Fixed paths, because mr Alex "Big Mouth" Perez was unable to get them right
[wmaker-crm.git] / src / geomview.c
blobf1ce258109f93b1cea28c2d1f05d507c28320a6b
4 #include <WINGs/WINGsP.h>
8 typedef struct W_GeometryView {
9 W_Class widgetClass;
10 WMView *view;
12 WMColor *color;
13 WMColor *bgColor;
15 WMFont *font;
17 WMSize textSize;
19 union {
20 struct {
21 int x, y;
22 } pos;
23 struct {
24 unsigned width, height;
25 } size;
26 } data;
28 unsigned showPosition:1;
29 } WGeometryView;
33 static void handleEvents(XEvent *event, void *clientData);
34 static void paint(WGeometryView *gview);
37 WGeometryView*
38 WCreateGeometryView(WMScreen *scr)
40 WGeometryView *gview;
41 char buffer[64];
42 static W_Class widgetClass = 0;
44 if (!widgetClass) {
45 widgetClass = W_RegisterUserWidget();
48 gview = malloc(sizeof(WGeometryView));
49 if (!gview) {
50 return NULL;
52 memset(gview, 0, sizeof(WGeometryView));
54 gview->widgetClass = widgetClass;
56 gview->view = W_CreateTopView(scr);
57 if (!gview->view) {
58 wfree(gview);
60 return NULL;
62 gview->view->self = gview;
64 gview->font = WMSystemFontOfSize(scr, 12);
65 if (!gview->font) {
66 W_DestroyView(gview->view);
67 wfree(gview);
69 return NULL;
72 gview->bgColor = WMCreateRGBColor(scr, 0x3333, 0x6666, 0x9999, True);
73 gview->color = WMWhiteColor(scr);
75 WMCreateEventHandler(gview->view, ExposureMask, handleEvents, gview);
77 snprintf(buffer, sizeof(buffer), "%+05i, %+05i", 0, 0);
79 gview->textSize.width = WMWidthOfString(gview->font, buffer,
80 strlen(buffer));
81 gview->textSize.height = WMFontHeight(gview->font);
83 WMSetWidgetBackgroundColor(gview, gview->bgColor);
85 W_ResizeView(gview->view, gview->textSize.width+8,
86 gview->textSize.height+6);
88 return gview;
92 void
93 WSetGeometryViewShownPosition(WGeometryView *gview, int x, int y)
95 gview->showPosition = 1;
96 gview->data.pos.x = x;
97 gview->data.pos.y = y;
99 paint(gview);
103 void
104 WSetGeometryViewShownSize(WGeometryView *gview,
105 unsigned width, unsigned height)
107 gview->showPosition = 0;
108 gview->data.size.width = width;
109 gview->data.size.height = height;
111 paint(gview);
116 static void
117 paint(WGeometryView *gview)
119 char buffer[64];
121 if (gview->showPosition) {
122 snprintf(buffer, sizeof(buffer), "%+5i , %+5i ",
123 gview->data.pos.x, gview->data.pos.y);
124 } else {
125 snprintf(buffer, sizeof(buffer), "%+5i x %+5i ",
126 gview->data.size.width, gview->data.size.height);
129 WMDrawImageString(W_VIEW_SCREEN(gview->view),
130 W_VIEW_DRAWABLE(gview->view),
131 gview->color, gview->bgColor, gview->font,
132 (W_VIEW_WIDTH(gview->view)-gview->textSize.width)/2,
133 (W_VIEW_HEIGHT(gview->view)-gview->textSize.height)/2,
134 buffer, strlen(buffer));
136 W_DrawRelief(W_VIEW_SCREEN(gview->view), W_VIEW_DRAWABLE(gview->view),
137 0, 0, W_VIEW_WIDTH(gview->view), W_VIEW_HEIGHT(gview->view),
138 WRSimple);
143 static void
144 handleEvents(XEvent *event, void *clientData)
146 WGeometryView *gview = (WGeometryView*)clientData;
148 switch (event->type) {
149 case Expose:
150 paint(gview);
151 break;