summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-14 22:56:39 +0800
committerruki <[email protected]>2017-12-14 11:40:00 +0800
commitb4c46182afdf442505f22bbf864ef2811933da49 (patch)
tree92c899970035ac4a40477267c1256e9c032fc9fe
parent54a0bf3c8688589708af4cc22bd7bbe8a83365d1 (diff)
improve compiler version
-rw-r--r--core/src/tbox/src/tbox/prefix/compiler.h2
-rw-r--r--xmake/core/ui/group.lua152
-rw-r--r--xmake/core/ui/rect.lua5
-rw-r--r--xmake/core/ui/view.lua42
4 files changed, 192 insertions, 9 deletions
diff --git a/core/src/tbox/src/tbox/prefix/compiler.h b/core/src/tbox/src/tbox/prefix/compiler.h
index b5b14f18e..ef1668d73 100644
--- a/core/src/tbox/src/tbox/prefix/compiler.h
+++ b/core/src/tbox/src/tbox/prefix/compiler.h
@@ -290,6 +290,8 @@
# define TB_COMPILER_VERSION_STRING "visual c++ .net 2015 (14.0)"
# elif (_MSC_VER == 1910 || _MSC_VER == 1911)
# define TB_COMPILER_VERSION_STRING "visual c++ .net 2017 (14.1)"
+# elif (_MSC_VER > 1911)
+# define TB_COMPILER_VERSION_STRING "visual c++ .net >= 2017 (14.1)"
# else
# error Unknown visual c++ Compiler Version
# endif
diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua
index 9588eb3a4..86cf81bc4 100644
--- a/xmake/core/ui/group.lua
+++ b/xmake/core/ui/group.lua
@@ -29,6 +29,8 @@ $Id: group.lua 18 2007-06-21 20:43:52Z tngd $
-- load modules
local view = require("ui/view")
+local rect = require("ui/rect")
+local point = require("ui/point")
local curses = require("ui/curses")
local dlist = require("base/dlist")
@@ -54,32 +56,172 @@ end
-- get all child views
function group:views()
- return self._VIEWS
+ return self._VIEWS:items()
+end
+
+-- get views count
+function group:count()
+ return self._VIEWS:size()
+end
+
+-- is empty?
+function group:empty()
+ return self._VIEWS:empty()
+end
+
+-- get the first view
+function group:first()
+ return self._VIEWS:first()
+end
+
+-- get the next view
+function group:next(v)
+ return self._VIEWS:next(v)
end
-- insert view
function group:insert(v)
- self:views():push(v)
+
+ -- check
+ assert(not v:parent() or v:parent() == self)
+
+ -- lock
+ self:lock()
+
+ -- this view has been inserted into this group? remove it first
+ if v:parent() == self then
+ self:remove(v)
+ end
+
+ -- center this view if centerx or centery are set
+ local bounds = v:bounds()
+ local org = point {bounds.sx, bounds.sy}
+ if v:option("centerx") then
+ org.x = math.floor((self:width() - v:width()) / 2)
+ end
+ if v:option("centery") then
+ org.y = math.floor((self:height() - v:height()) / 2)
+ end
+ bounds:move(org.x - bounds.sx, org.y - bounds.sy)
+ v:bounds_set(bounds)
+
+ -- insert this view
+ self._VIEWS:push(v)
+
+ -- set it's parent view
+ v:parent_set(self)
+
+ -- TODO select this view
+ if v:option("selectable") then
+-- self:select(v)
+ end
+
+ -- draw and show this view
+ v:draw()
+ v:show(true)
+
+ -- unlock
+ self:unlock()
end
-- remove view
function group:remove(v)
- self:views():remove(v)
+
+ -- check
+ assert(v:parent() == self)
+
+ -- lock
+ self:lock()
+
+ -- hide this view first
+ v:show(false)
+
+ -- remove view
+ self._VIEWS:remove(v)
+
+ -- TODO select next view
+
+ -- unlock
+ self:unlock()
end
-- execute group
function group:execute()
end
+-- draw group
+function group:draw()
+
+ -- draw sub views
+ for v in self:views() do
+ if v:state("visible") then
+ v:draw()
+ end
+ end
+end
+
+-- refresh group in parent window
+function group:refresh()
+ self:lock()
+ self:draw()
+ self:redraw(true)
+ self:unlock()
+end
+
+-- draw this child view
+function group:_draw_child(v)
+
+ -- draw it if this child view is in a vaild bounds
+ local bounds = v:bounds()
+ local r = bounds():intersect(rect{0, 0, self:width(), self:height()})
+ if r.ex > r.sx and r.ey > r.sy then
+
+ -- TODO
+ -- copy this child view to group window
+ local sx = bounds.sx; sx = sx > 0 and 0 or -sx
+ local sy = bounds.sy; sy = sy > 0 and 0 or -sy
+ v:window():copy(self:window(), sy, sx, r.sy, r.sx, r.ey - 1, r.ex - 1)
+ end
+end
+
+-- draw overlapping views about this child view
+function group:_draw_overlap(v)
+
+ -- lock
+ self:lock()
+
+ -- draw all overlapping areas
+ local bounds = v:bounds()
+ while v do
+
+ -- check for overlapping areas
+ if v:state("visible") and v:bounds():is_intersect(bounds) then
+
+ -- draw this child view
+ self:_draw_child(v)
+
+ -- if they overlap, join them.
+ -- use the resulting rectangle to check for overlapping areas on the following windows
+ bounds:union(v:bounds())
+ end
+
+ -- get the next view
+ v = self:next(v)
+ end
+
+ -- unlock
+ self:unlock()
+end
+
-- tostring(group, level)
function group:_tostring(level)
local str = ""
if self.views then
str = str .. string.format("<%s %s>", self:name(), tostring(self:bounds()))
- if not self:views():empty() then
+ if not self:empty() then
str = str .. "\n"
end
- for v in self:views():items() do
+ for v in self:views() do
for l = 1, level do
str = str .. " "
end
diff --git a/xmake/core/ui/rect.lua b/xmake/core/ui/rect.lua
index c7a11330f..0bb4ad958 100644
--- a/xmake/core/ui/rect.lua
+++ b/xmake/core/ui/rect.lua
@@ -72,6 +72,11 @@ function rect:grow(dx, dy)
return self
end
+-- is intersect?
+function rect:is_intersect(r)
+ return not self():intersect(r):empty()
+end
+
-- set rect with shared area between this rect and a given rect
function rect:intersect(r)
self.sx = math.max(self.sx, r.sx)
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index 1e7ef2a71..cc2edce01 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -65,6 +65,17 @@ function view:init(name, bounds)
state.modal = false -- is modal view?
self._STATE = state
+ -- init options
+ local options = object()
+ options.selectable = false -- true if window can be selected
+ options.top_select = false -- if true, selecting window will bring it to front
+ options.pre_event = false -- receive event before focused window
+ options.post_event = false -- receive event after focused window
+ options.centerx = false -- center horizontaly when inserting in parent
+ options.centery = false -- center verticaly when inserting in parent
+ options.validate = false -- validate
+ self._OPTIONS = options
+
-- init name
self._NAME = name
@@ -132,6 +143,11 @@ function view:parent()
return self._PARENT
end
+-- set the parent view
+function view:parent_set(parent)
+ self._PARENT = parent
+end
+
-- get the view window
function view:window()
return self._WINDOW
@@ -145,14 +161,14 @@ function view:canvas()
return self._CANVAS
end
--- on draw window
-function view:on_draw()
+-- draw view
+function view:draw()
self:canvas():clear()
end
-- refresh view in parent window
function view:refresh()
- self:on_draw()
+ self:draw()
self:redraw(true)
end
@@ -164,7 +180,7 @@ function view:redraw(on_parent)
self:lock()
local v = self
while v:parent() do
- v:parent():draw_child(v)
+ v:parent():_draw_overlap(v)
v = v:parent()
end
self:unlock()
@@ -209,6 +225,24 @@ function view:state_set(name, enable)
end
end
+-- get option
+function view:option(name)
+ return self._OPTIONS[name]
+end
+
+-- set option
+function view:option_set(name, enable)
+
+ -- state is not changed?
+ enable = enable or false
+ if self:option(name) == enable then
+ return
+ end
+
+ -- set option
+ self._OPTIONS[name] = enable
+end
+
-- tostring(view)
function view:__tostring()
return string.format("<%s %s>", self:name(), tostring(self:bounds()))