comparison console/libgnt/gntmain.c @ 13869:5642f4658b59

[gaim-migrate @ 16335] A bunch of stuff that doesn't really do much. I am trying to get the "expose" thingy going where a widget will redraw some of its parts when some other widget covering it is destroyed. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 25 Jun 2006 03:15:41 +0000
parents c1e3f7c75c3f
children 0d0ab1e39d0a
comparison
equal deleted inserted replaced
13868:b355f7ed1814 13869:5642f4658b59
6 #include <locale.h> 6 #include <locale.h>
7 7
8 static GList *focus_list; 8 static GList *focus_list;
9 static int max_x; 9 static int max_x;
10 static int max_y; 10 static int max_y;
11
12 static GHashTable *nodes;
13
14 static void free_node(gpointer data);
11 15
12 void gnt_screen_take_focus(GntWidget *widget) 16 void gnt_screen_take_focus(GntWidget *widget)
13 { 17 {
14 focus_list = g_list_prepend(focus_list, widget); 18 focus_list = g_list_prepend(focus_list, widget);
15 } 19 }
93 gnt_init_colors(); 97 gnt_init_colors();
94 98
95 max_x = getmaxx(stdscr); 99 max_x = getmaxx(stdscr);
96 max_y = getmaxy(stdscr); 100 max_y = getmaxy(stdscr);
97 101
102 nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node);
103
98 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); 104 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
99 noecho(); 105 noecho();
100 refresh(); 106 refresh();
101 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); 107 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
102 g_type_init(); 108 g_type_init();
106 { 112 {
107 GMainLoop *loop = g_main_new(FALSE); 113 GMainLoop *loop = g_main_new(FALSE);
108 g_main_run(loop); 114 g_main_run(loop);
109 } 115 }
110 116
117 /*********************************
118 * Stuff for 'window management' *
119 *********************************/
120
121 typedef struct
122 {
123 GntWidget *me;
124 GList *below; /* List of widgets below me */
125 GList *above; /* List of widgets above me */
126 } GntNode;
127
128 static void
129 free_node(gpointer data)
130 {
131 GntNode *node = data;
132 g_list_free(node->below);
133 g_list_free(node->above);
134 g_free(node);
135 }
136
137 static void
138 check_intersection(gpointer key, gpointer value, gpointer data)
139 {
140 GntNode *n = value;
141 GntNode *nu = data;
142
143 if (value == NULL)
144 return;
145
146 if (n->me->priv.x + n->me->priv.width < nu->me->priv.x)
147 return;
148 if (nu->me->priv.x + nu->me->priv.width < n->me->priv.x)
149 return;
150
151 if (n->me->priv.y + n->me->priv.height < nu->me->priv.y)
152 return;
153 if (nu->me->priv.y + nu->me->priv.height < n->me->priv.y)
154 return;
155
156 n->above = g_list_prepend(n->above, nu->me);
157 nu->below = g_list_prepend(nu->below, n->me);
158 }
159
160 void gnt_screen_occupy(GntWidget *widget)
161 {
162 /* XXX: what happens if this is called more than once for the same widget?
163 * perhaps _release first? */
164 GntNode *node = g_new0(GntNode, 1);
165 node->me = widget;
166
167 g_hash_table_foreach(nodes, check_intersection, node);
168 g_hash_table_replace(nodes, widget, node);
169 }
170
171 void gnt_screen_release(GntWidget *widget)
172 {
173 GList *iter;
174 GntNode *node = g_hash_table_lookup(nodes, widget);
175 if (node == NULL || node->below == NULL) /* Yay! Nothing to do. */
176 return;
177
178 /* XXX: This is not going to work.
179 * It will be necessary to build a topology and go from there. */
180 for (iter = node->below; iter; iter = iter->next)
181 {
182 GntWidget *w = iter->data;
183 int left, right, top, bottom;
184
185 left = MAX(widget->priv.x, w->priv.x) - w->priv.x;
186 right = MIN(widget->priv.x + widget->priv.width, w->priv.x + w->priv.width) - w->priv.x;
187
188 top = MAX(widget->priv.y, w->priv.y) - w->priv.y;
189 bottom = MIN(widget->priv.y + widget->priv.height, w->priv.y + w->priv.height) - w->priv.y;
190
191 gnt_widget_expose(w, left, top, right - left, bottom - top);
192 }
193
194 g_hash_table_remove(nodes, widget);
195 }
196