diff options
author | Keith Packard <keithp@keithp.com> | 2012-02-27 15:07:04 +1300 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-02-27 15:07:04 +1300 |
commit | ca7b0e66dc6973c821e556f29c1bbf03ffdbc869 (patch) | |
tree | 2282bc9cd995210e2e80cbab50a406de6519deef /nichrome | |
parent | af95017d333909c957b10391d3fef23b965206dc (diff) |
Allow contained objects to be deactivated
This eliminates them from display, layout and input.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'nichrome')
-rw-r--r-- | nichrome/nichrome-box.5c | 39 | ||||
-rw-r--r-- | nichrome/nichrome.5c | 40 |
2 files changed, 74 insertions, 5 deletions
diff --git a/nichrome/nichrome-box.5c b/nichrome/nichrome-box.5c index 85fa883..582e309 100644 --- a/nichrome/nichrome-box.5c +++ b/nichrome/nichrome-box.5c @@ -106,7 +106,7 @@ extend namespace Nichrome { &item_t item = &box.items[i]; item.contained.print (&item.contained, indent + 2); do_indent(indent + 4); - printf ("layout %v\n", item.layout); + printf ("active %v layout %v\n", item.contained.active, item.layout); } do_indent(indent); printf ("}\n"); @@ -123,6 +123,7 @@ extend namespace Nichrome { items = items, realized = false, print = box_print, + active = true, }; for (int i = 0; i < dim (items); i++) { @@ -225,6 +226,9 @@ extend namespace Nichrome { for (int i = 0; i < dim (box.items); i++) { + if (!box.items[i].contained.active) + continue; + &layout_t child = &box.items[i].layout; if (box.dir == dir_t.horizontal) { @@ -273,6 +277,10 @@ extend namespace Nichrome { for (int i = 0; i < dim (box.items); i++) { &item_t item = &box.items[i]; + + if (!item.contained.active) + continue; + &layout_t child_layout = &item.layout; real delta_this; @@ -381,7 +389,7 @@ extend namespace Nichrome { { get_glue (¶m, &(real size), &(real stretch)); return (item_t) { - contained = &(glue_t) { .print = glue_print }, + contained = &(glue_t) { .print = glue_print, .active = true }, layout = { natural_width = size, natural_height = size, @@ -423,6 +431,33 @@ extend namespace Nichrome { { add_item (&box, glue_item (param ...)); } + + protected void set_active (&contained_t contained, bool active) { + &contained_t top = &contained; + + while (&top.container != &no_container) { + &box_t container = &top.container; + &top = &container; + } + &box_t top_box = ⊤ + + void set_all_active (&contained_t contained) { + contained.active = active; + if (is_type (contained, box_t)) { + &box_t box = &contained; + printf ("setting box active %v\n", active); + for (int i = 0; i < dim(box.items); i++) + set_all_active(&box.items[i].contained); + printf ("done setting box active %v\n", active); + } else { + box_resize(&contained.container, &contained); + } + } + + set_all_active(&contained); + if (!is_uninit(&(&top_box.nichrome))) + Nichrome::redraw(&top_box.nichrome); + } } /* diff --git a/nichrome/nichrome.5c b/nichrome/nichrome.5c index 3b3cc39..a1f4e62 100644 --- a/nichrome/nichrome.5c +++ b/nichrome/nichrome.5c @@ -101,6 +101,7 @@ namespace Nichrome { &container_t container; configure_handler_t configure; print_handler_t print; + bool active; } contained_t; /* @@ -143,6 +144,7 @@ namespace Nichrome { bool running; mutex drawing; thread self; + int suspend_draw; } nichrome_t; public widget_t no_widget; @@ -174,12 +176,36 @@ namespace Nichrome { public void redraw (&nichrome_t nichrome) { if (is_uninit (&nichrome.self)) return; - if (Thread::current() != nichrome.self) + if (Thread::current() != nichrome.self && nichrome.suspend_draw == 0) draw (&nichrome); else nichrome.draw = true; } + public void suspend_draw(&nichrome_t nichrome) { + ++nichrome.suspend_draw; + } + + public void release_draw(&nichrome_t nichrome) { + assert (nichrome.suspend_draw > 0, "mismatched suspend_draw/release_draw calls"); + --nichrome.suspend_draw; + if (!nichrome.running) + return; + printf ("release running %v\n", nichrome.running); + printf ("release suspend_draw %d\n", nichrome.suspend_draw); + printf ("release draw %v\n", nichrome.draw); + printf ("release thread %v\n", nichrome.self); + if (nichrome.suspend_draw == 0 && nichrome.draw && Thread::current() != nichrome.self) + draw(&nichrome); + } + + public void set_active(&nichrome_t nichrome, &contained_t contained, bool active) { + if (active != contained.active) { + contained.active = active; + redraw (&nichrome); + } + } + public namespace Widget { protected void configure (&widget_t widget, rect_t geometry) { widget.geometry = geometry; @@ -202,6 +228,7 @@ namespace Nichrome { widget.outline = natural; widget.draw = natural; widget.print = print; + widget.active = true; Nichrome::add (&nichrome, &widget); } @@ -267,7 +294,7 @@ namespace Nichrome { x = a.x; y = a.y; for (int w = 0; w < dim (nichrome.widgets); w++) { &widget_t widget = &nichrome.widgets[w]; - if (Widget::in_widget (&widget, x, y)) + if (widget.active && Widget::in_widget (&widget, x, y)) return &widget; } return &no_widget; @@ -460,6 +487,10 @@ namespace Nichrome { for (i = dim (nichrome.widgets) - 1; i >= 0; i--) { &widget_t widget = &nichrome.widgets[i]; + + if (!widget.active) + continue; + if (!is_uninit (&widget.draw)) { save (cr); translate (cr, widget.geometry.x, widget.geometry.y); @@ -504,8 +535,9 @@ namespace Nichrome { nichrome.surface = Cairo::Surface::create_window (name, width, height); nichrome.event = Cairo::Surface::open_event (nichrome.surface); - nichrome.draw = true; + nichrome.draw = false; nichrome.resize = true; + nichrome.running = false; nichrome.widgets = ((&widget_t)[...]) {}; nichrome.scale = (point_t) { x = 1, y = 1 }; nichrome.destroy = destroy; @@ -516,6 +548,7 @@ namespace Nichrome { &nichrome.outline_widget = &no_widget; nichrome.outline_cr = cairo (&nichrome); nichrome.drawing = Mutex::new (); + nichrome.suspend_draw = 0; return &nichrome; } @@ -557,6 +590,7 @@ namespace Nichrome { public void main_loop (&nichrome_t nichrome) { nichrome.running = true; + nichrome.draw = true; nichrome.self = Thread::current (); string event_line; |