General support for focused/inactive windows

This commit is contained in:
Kevin Lange 2012-11-19 21:24:21 -08:00
parent 07a5ee3c55
commit ae6b72606b
24 changed files with 84 additions and 20 deletions

View File

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

View File

Before

Width:  |  Height:  |  Size: 205 B

After

Width:  |  Height:  |  Size: 205 B

View File

Before

Width:  |  Height:  |  Size: 291 B

After

Width:  |  Height:  |  Size: 291 B

View File

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View File

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 199 B

View File

Before

Width:  |  Height:  |  Size: 384 B

After

Width:  |  Height:  |  Size: 384 B

View File

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 230 B

View File

Before

Width:  |  Height:  |  Size: 428 B

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

View File

@ -179,6 +179,11 @@ void resize_callback(window_t * window) {
ttk_render();
}
void focus_callback(window_t * window) {
decors(wina);
ttk_render();
}
int main (int argc, char ** argv) {
int left = 30;
int top = 30;
@ -189,6 +194,7 @@ int main (int argc, char ** argv) {
setup_windowing();
resize_window_callback = resize_callback;
focus_changed_callback = focus_callback;
/* Do something with a window */
wina = window_create(left, top, width, height);
@ -225,7 +231,7 @@ int main (int argc, char ** argv) {
button_thin->fore_color = rgb(255,255,255);
ttk_button * button_quit = ttk_new_button("X", quit_app);
ttk_position((ttk_object *)button_quit, width - 23, 2, 20, 20);
ttk_position((ttk_object *)button_quit, width - 33, 12, 20, 20);
button_quit->fill_color = rgb(255,0,0);
button_quit->fore_color = rgb(255,255,255);

View File

@ -212,6 +212,10 @@ void resize_callback(window_t * win) {
display();
}
void focus_callback() {
display();
}
int main(int argc, char ** argv) {
setup_windowing();
@ -221,6 +225,7 @@ int main(int argc, char ** argv) {
draw_fill(ctx,rgb(0,0,0));
init_decorations();
focus_changed_callback = focus_callback;
map_x = WINDOW_SIZE - (64 * 9) / 2;
map_y = WINDOW_SIZE - (64 * 9) / 2;

View File

@ -160,6 +160,10 @@ void resize_callback(window_t * win) {
redraw();
}
void focus_callback(window_t * win) {
redraw();
}
int main(int argc, char * argv[]) {
@ -225,6 +229,8 @@ int main(int argc, char * argv[]) {
window = window_create(left, top, width + decor_width(), height + decor_height());
init_decorations();
focus_changed_callback = focus_callback;
ctx = init_graphics_window(window);
redraw();

View File

@ -17,6 +17,8 @@ uint32_t decor_right_width = 6;
#define TEXT_OFFSET_X 10
#define TEXT_OFFSET_Y 16
#define INACTIVE 8
#define BORDERCOLOR rgb(60,60,60)
#define BACKCOLOR rgb(20,20,20)
#define TEXTCOLOR rgb(255,255,255)
@ -34,7 +36,7 @@ static int lly_offset = 3;
static int lrx_offset = 3;
static int lry_offset = 3;
static sprite_t * sprites[8];
static sprite_t * sprites[16];
#define TEXT_OFFSET 24
@ -46,18 +48,27 @@ static void init_sprite_png(int id, char * path) {
void init_decorations() {
init_shmemfonts();
init_sprite_png(0, "/usr/share/ttk/ul.png");
init_sprite_png(1, "/usr/share/ttk/um.png");
init_sprite_png(2, "/usr/share/ttk/ur.png");
init_sprite_png(3, "/usr/share/ttk/ml.png");
init_sprite_png(4, "/usr/share/ttk/mr.png");
init_sprite_png(5, "/usr/share/ttk/ll.png");
init_sprite_png(6, "/usr/share/ttk/lm.png");
init_sprite_png(7, "/usr/share/ttk/lr.png");
init_sprite_png(0, "/usr/share/ttk/active/ul.png");
init_sprite_png(1, "/usr/share/ttk/active/um.png");
init_sprite_png(2, "/usr/share/ttk/active/ur.png");
init_sprite_png(3, "/usr/share/ttk/active/ml.png");
init_sprite_png(4, "/usr/share/ttk/active/mr.png");
init_sprite_png(5, "/usr/share/ttk/active/ll.png");
init_sprite_png(6, "/usr/share/ttk/active/lm.png");
init_sprite_png(7, "/usr/share/ttk/active/lr.png");
init_sprite_png(INACTIVE + 0, "/usr/share/ttk/inactive/ul.png");
init_sprite_png(INACTIVE + 1, "/usr/share/ttk/inactive/um.png");
init_sprite_png(INACTIVE + 2, "/usr/share/ttk/inactive/ur.png");
init_sprite_png(INACTIVE + 3, "/usr/share/ttk/inactive/ml.png");
init_sprite_png(INACTIVE + 4, "/usr/share/ttk/inactive/mr.png");
init_sprite_png(INACTIVE + 5, "/usr/share/ttk/inactive/ll.png");
init_sprite_png(INACTIVE + 6, "/usr/share/ttk/inactive/lm.png");
init_sprite_png(INACTIVE + 7, "/usr/share/ttk/inactive/lr.png");
}
void render_decorations(window_t * window, gfx_context_t * ctx, char * title) {
void render_decorations_(window_t * window, gfx_context_t * ctx, char * title, int decors_active) {
int width = window->width;
int height = window->height;
@ -82,28 +93,45 @@ void render_decorations(window_t * window, gfx_context_t * ctx, char * title) {
}
}
draw_sprite(ctx, sprites[0], 0, 0);
draw_sprite(ctx, sprites[decors_active + 0], 0, 0);
for (int i = 0; i < width - (ul_width + ur_width); ++i) {
draw_sprite(ctx, sprites[1], i + ul_width, 0);
draw_sprite(ctx, sprites[decors_active + 1], i + ul_width, 0);
}
draw_sprite(ctx, sprites[2], width - ur_width, 0);
draw_sprite(ctx, sprites[decors_active + 2], width - ur_width, 0);
for (int i = 0; i < height - (u_height + l_height); ++i) {
draw_sprite(ctx, sprites[3], 0, i + u_height);
draw_sprite(ctx, sprites[4], width - mr_width, i + u_height);
draw_sprite(ctx, sprites[decors_active + 3], 0, i + u_height);
draw_sprite(ctx, sprites[decors_active + 4], width - mr_width, i + u_height);
}
draw_sprite(ctx, sprites[5], 0, height - l_height);
draw_sprite(ctx, sprites[decors_active + 5], 0, height - l_height);
for (int i = 0; i < width - (ll_width + lr_width); ++i) {
draw_sprite(ctx, sprites[6], i + ll_width, height - l_height);
draw_sprite(ctx, sprites[decors_active + 6], i + ll_width, height - l_height);
}
draw_sprite(ctx, sprites[7], width - lr_width, height - l_height);
draw_sprite(ctx, sprites[decors_active + 7], width - lr_width, height - l_height);
set_font_face(FONT_SANS_SERIF_BOLD);
set_font_size(12);
int title_offset = (width / 2) - (draw_string_width(title) / 2);
draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), title);
if (decors_active == 0) {
draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), title);
} else {
draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), title);
}
}
void render_decorations(window_t * window, gfx_context_t * ctx, char * title) {
if (!window->focused) {
render_decorations_(window, ctx, title, INACTIVE);
} else {
render_decorations_(window, ctx, title, 0);
}
}
void render_decorations_inactive(window_t * window, gfx_context_t * ctx, char * title) {
render_decorations_(window, ctx, title, INACTIVE);
}
uint32_t decor_width() {
return decor_left_width + decor_right_width;
}

View File

@ -23,6 +23,7 @@ uint32_t decor_right_width;
* redraw them.
*/
void render_decorations(window_t * window, gfx_context_t * ctx, char * title);
void render_decorations_inactive(window_t * window, gfx_context_t * ctx, char * title);
/*
* Run me once to set things up

View File

@ -39,6 +39,7 @@ static window_t * get_window (wid_t wid) {
void (*mouse_action_callback)(w_mouse_t *) = NULL;
void (*resize_window_callback)(window_t *) = NULL;
void (*focus_changed_callback)(window_t *) = NULL;
/* Window Object Management */
@ -381,6 +382,14 @@ static void process_window_evt (uint8_t command, w_window_t evt) {
wins_last_new = window;
break;
case WE_FOCUSCHG:
window = get_window(evt.wid);
window->focused = evt.left;
if (focus_changed_callback) {
focus_changed_callback(window);
}
break;
case WE_RESIZED:
/* XXX: We need a lock or something to contend the window buffer */
fprintf(stderr, "Received WINDOW_RESIZED event\n");

View File

@ -71,6 +71,7 @@ typedef struct {
#define WE_RESIZED 0x31 /* Your window has been resized or moved */
#define WE_DESTROYED 0x32 /* Window has been removed */
#define WE_REDRAWN 0x34
#define WE_FOCUSCHG 0x35
#define WE_GROUP_MASK 0xF0
#define WE_KEY_EVT 0x10 /* Some sort of keyboard event */
@ -131,6 +132,7 @@ typedef struct {
uint16_t z; /* Stack order */
uint8_t use_alpha;
/* END UNUSED IN CLIENT */
uint8_t focused;
uint8_t * buffer; /* Window buffer */
uint16_t bufid; /* We occasionally replace the buffer; each is uniquely-indexed */
@ -179,4 +181,6 @@ void (*mouse_action_callback)(w_mouse_t *);
void (*resize_window_callback)(window_t *);
void (*focus_changed_callback)(window_t *);
#endif

View File

@ -682,6 +682,10 @@ void resize_callback(window_t * window) {
reinit();
}
void focus_callback(window_t * window) {
render_decors();
}
void
term_write_char(
uint32_t val,
@ -1334,6 +1338,7 @@ int main(int argc, char ** argv) {
/* Create the window */
window = window_create(x,y, window_width + decor_left_width + decor_right_width, window_height + decor_top_height + decor_bottom_height);
resize_window_callback = resize_callback;
focus_changed_callback = focus_callback;
window_enable_alpha(window);