2 #include <WINGs/WINGsP.h>
7 struct W_GeometryView
{
23 unsigned width
, height
;
27 unsigned showPosition
:1;
30 static void handleEvents(XEvent
* event
, void *clientData
);
31 static void paint(WGeometryView
* gview
);
33 WGeometryView
*WCreateGeometryView(WMScreen
* scr
)
37 static W_Class widgetClass
= 0;
40 widgetClass
= W_RegisterUserWidget();
43 gview
= malloc(sizeof(WGeometryView
));
47 memset(gview
, 0, sizeof(WGeometryView
));
49 gview
->widgetClass
= widgetClass
;
51 gview
->view
= W_CreateTopView(scr
);
57 gview
->view
->self
= gview
;
59 gview
->font
= WMSystemFontOfSize(scr
, 12);
61 W_DestroyView(gview
->view
);
67 gview
->bgColor
= WMCreateRGBColor(scr
, 0x3333, 0x6666, 0x9999, True
);
68 gview
->color
= WMWhiteColor(scr
);
70 WMCreateEventHandler(gview
->view
, ExposureMask
, handleEvents
, gview
);
72 snprintf(buffer
, sizeof(buffer
), "%+05i, %+05i", 0, 0);
74 gview
->textSize
.width
= WMWidthOfString(gview
->font
, buffer
, strlen(buffer
));
75 gview
->textSize
.height
= WMFontHeight(gview
->font
);
77 WMSetWidgetBackgroundColor(gview
, gview
->bgColor
);
79 W_ResizeView(gview
->view
, gview
->textSize
.width
+ 8, gview
->textSize
.height
+ 6);
84 void WSetGeometryViewShownPosition(WGeometryView
* gview
, int x
, int y
)
86 gview
->showPosition
= 1;
87 gview
->data
.pos
.x
= x
;
88 gview
->data
.pos
.y
= y
;
93 void WSetGeometryViewShownSize(WGeometryView
* gview
, unsigned width
, unsigned height
)
95 gview
->showPosition
= 0;
96 gview
->data
.size
.width
= width
;
97 gview
->data
.size
.height
= height
;
102 static void paint(WGeometryView
* gview
)
106 if (gview
->showPosition
) {
107 snprintf(buffer
, sizeof(buffer
), "%+5i , %+5i ", gview
->data
.pos
.x
, gview
->data
.pos
.y
);
109 snprintf(buffer
, sizeof(buffer
), "%+5i x %+5i ",
110 gview
->data
.size
.width
, gview
->data
.size
.height
);
113 WMDrawImageString(W_VIEW_SCREEN(gview
->view
),
114 W_VIEW_DRAWABLE(gview
->view
),
115 gview
->color
, gview
->bgColor
, gview
->font
,
116 (W_VIEW_WIDTH(gview
->view
) - gview
->textSize
.width
) / 2,
117 (W_VIEW_HEIGHT(gview
->view
) - gview
->textSize
.height
) / 2, buffer
, strlen(buffer
));
119 W_DrawRelief(W_VIEW_SCREEN(gview
->view
), W_VIEW_DRAWABLE(gview
->view
),
120 0, 0, W_VIEW_WIDTH(gview
->view
), W_VIEW_HEIGHT(gview
->view
), WRSimple
);
123 static void handleEvents(XEvent
* event
, void *clientData
)
125 WGeometryView
*gview
= (WGeometryView
*) clientData
;
127 switch (event
->type
) {