|
libxputty
0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
|
|
Go to the documentation of this file.
24 static void draw_message_label(
Widget_t *w,
int width,
int height) {
26 cairo_text_extents_t extents;
28 cairo_set_font_size (w->
crb, 12.0);
30 for(;i<(int)mb->
lin;i++) {
31 cairo_text_extents(w->
crb,mb->
message[i] , &extents);
32 cairo_move_to (w->
crb, 100, ((40)+(extents.height * (2*i))));
34 cairo_new_path (w->
crb);
38 static void draw_message_window(
void *w_,
void* user_data) {
40 XWindowAttributes attrs;
41 XGetWindowAttributes(w->
app->
dpy, (Window)w->
widget, &attrs);
42 int width_t = attrs.width;
43 int height_t = attrs.height;
44 if (attrs.map_state != IsViewable)
return;
46 cairo_rectangle(w->
crb,0,0,width_t,height_t);
51 int width = cairo_xlib_surface_get_width(w->
image);
52 int height = cairo_xlib_surface_get_height(w->
image);
53 double x = 64.0/(double)(width);
54 double y = 64.0/(double)height;
55 double x1 = (double)height/64.0;
56 double y1 = (double)(width)/64.0;
57 cairo_scale(w->
crb, x,y);
58 cairo_set_source_surface (w->
crb, w->
image, 50, 50);
59 cairo_rectangle(w->
crb,50, 50, width, height);
61 cairo_scale(w->
crb, x1,y1);
63 draw_message_label(w,width_t,height_t);
67 static void draw_entry(
void *w_,
void* user_data) {
70 XWindowAttributes attrs;
71 XGetWindowAttributes(w->
app->
dpy, (Window)w->
widget, &attrs);
72 int width = attrs.width;
73 int height = attrs.height;
74 if (attrs.map_state != IsViewable)
return;
77 cairo_rectangle(w->
cr,0,0,width,height);
78 cairo_fill_preserve (w->
cr);
80 cairo_set_line_width(w->
cr, 2.0);
83 cairo_set_font_size (w->
cr, 9.0);
85 cairo_move_to (w->
cr, 2, 9);
86 cairo_show_text(w->
cr,
" ");
89 static void entry_add_text(
void *w_,
void *label_) {
92 char *label = (
char*)label_;
97 cairo_text_extents_t extents;
99 cairo_set_font_size (w->
cr, 11.0);
108 cairo_set_font_size (w->
cr, 12.0);
111 cairo_move_to (w->
cr, 2, 12.0+extents.height);
116 static void entry_clip(
Widget_t *w) {
118 cairo_text_extents_t extents;
120 cairo_set_font_size (w->
cr, 11.0);
140 cairo_set_font_size (w->
cr, 12.0);
143 cairo_move_to (w->
cr, 2, 12.0+extents.height);
148 static void message_okay_callback(
void *w_,
void* user_data) {
167 static void message_no_callback(
void *w_,
void* user_data) {
181 static void radio_box_set_active(
Widget_t *w) {
191 else if (wid == w) mb->
response = response;
196 static void radio_box_button_pressed(
void *w_,
void* button_,
void* user_data) {
199 radio_box_set_active(w);
203 static void create_checkboxes(
Widget_t *w) {
205 int y = (mb->
lin + 1) * 24 +12;
207 for(;i<(int)mb->
sel;i++) {
214 static void entry_get_text(
void *w_,
void *key_,
void *user_data) {
217 XKeyEvent *key = (XKeyEvent*)key_;
235 case 11: entry_clip(w);
244 Xutf8LookupString(w->
xic, key, buf,
sizeof(buf) - 1, &keysym, &status);
245 if(status == XLookupChars || status == XLookupBoth){
246 entry_add_text(w, buf);
251 static void create_entry_box(
Widget_t *w) {
262 static void check_for_message(
MessageBox *mb,
const char *message) {
264 if(!strlen(message))
return;
266 char *ms =strdup(message);
267 char * p = strtok (ms,
"|");
272 p = strtok (NULL,
"|");
279 static void check_for_choices(
MessageBox *mb,
const char *choices) {
281 if(!strlen(choices))
return;
283 char *ms =strdup(choices);
284 char * p = strtok (ms,
"|");
289 p = strtok (NULL,
"|");
296 static void check_for_style(
MessageBox *mb,
int style) {
303 static void mg_mem_free(
void *w_,
void* user_data) {
311 for(;i<(int)mb->
lin;i++) {
315 for(;i<(int)mb->
sel;i++) {
323 const char *message,
const char *choices) {
335 check_for_message(mb, message);
336 check_for_choices(mb, choices);
337 check_for_style(mb, style);
339 wid->
label = message;
346 char *alternate_title = NULL;
347 char *button_title = (
char*)
"OK";
352 alternate_title = (
char*)
"INFO";
358 alternate_title = (
char*)
"WARNING";
364 alternate_title = (
char*)
"ERROR";
370 alternate_title = (
char*)
"QUESTION";
375 button_title = (
char*)
"YES";
380 alternate_title = (
char*)
"SELECTION";
382 create_checkboxes(wid);
387 alternate_title = (
char*)
"TEXT ENTRY";
389 create_entry_box(wid);
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Widget_t * open_message_dialog(Widget_t *w, int style, const char *title, const char *message, const char *choices)
open_message_dialog - open a non blocking dialog window, lines in message chould be separated by the ...
void widget_set_icon_from_surface(Widget_t *w, Pixmap *icon_, cairo_surface_t *image)
widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used...
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
evfunc key_press_callback
evfunc button_press_callback
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
xevfunc mem_free_callback
#define IS_UTF8(c)
IS_UTF8 - check if a char contain UTF 8 formated signs.
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
#define max(x, y)
max - set a minimal value (x) as return value
void use_base_color_scheme(Widget_t *w, Color_state st)
use_base_color_scheme - use base Colors to paint on Widget_t
xevfunc value_changed_callback