diff options
| author | ruki <[email protected]> | 2017-12-15 22:44:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-15 10:29:37 +0800 |
| commit | d81f894af27987981ef3fe39e013ad3f1fadfbcf (patch) | |
| tree | 1678fafa209ee07cd1ab19375ffbc3b84c87cdee /xmake/core/ui/view.lua | |
| parent | b4c46182afdf442505f22bbf864ef2811933da49 (diff) | |
update screen in view
Diffstat (limited to 'xmake/core/ui/view.lua')
| -rw-r--r-- | xmake/core/ui/view.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index cc2edce01..73539a854 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -28,6 +28,7 @@ $Id: view.lua 18 2007-06-21 20:43:52Z tngd $ --------------------------------------------------------------------------]] -- load modules +local log = require("ui/log") local object = require("ui/object") local canvas = require("ui/canvas") local curses = require("ui/curses") @@ -35,6 +36,9 @@ local curses = require("ui/curses") -- define module local view = view or object() +-- the screen lock/update counter +local screen_lock = 0 + -- new view instance function view:new(name, bounds) @@ -148,6 +152,16 @@ function view:parent_set(parent) self._PARENT = parent end +-- get the application +function view:application() + return self._APPLICATION +end + +-- set the application +function view:application_set(app) + self._APPLICATION = app +end + -- get the view window function view:window() return self._WINDOW @@ -189,10 +203,16 @@ end -- lock view function view:lock() + screen_lock = screen_lock + 1 end -- unlock view function view:unlock() + assert(screen_lock > 0) + screen_lock = screen_lock - 1 + if screen_lock == 0 then + self:_update_screen() + end end -- show view? @@ -243,6 +263,34 @@ function view:option_set(name, enable) self._OPTIONS[name] = enable end +-- update screen +function view:_update_screen() + + -- get application + local app = self:application() + assert(app, "cannot get application from view(" .. self:name() .. ")") + + -- is visible? + if not app:state("visible") then + return + end + + -- trace + log:print("view(%s): update screen ..", self:name()) + + -- get main window + local main_window = curses.main_window() + + -- update screen + app:window():copy(main_window, 0, 0, 0, 0, app:height() - 1, app:width() - 1) + + -- mark as refresh + main_window:noutrefresh() + + -- do update + curses.doupdate() +end + -- tostring(view) function view:__tostring() return string.format("<%s %s>", self:name(), tostring(self:bounds())) |
