From 525c2f17c09ed4c2e0a23196eef6966755b62dfc Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 May 2012 17:35:33 +0800 Subject: [PATCH 1/3] use rendertext in TextWidget for text background support --- widget.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/widget.lua b/widget.lua index f317c8e35..92ec0cf88 100644 --- a/widget.lua +++ b/widget.lua @@ -164,27 +164,36 @@ TextWidget = Widget:new{ color = 15, _bb = nil, _length = 0, + _height = 0, _maxlength = 1200, } -function TextWidget:_render() - local h = self.face.size * 1.3 - self._bb = Blitbuffer.new(self._maxlength, h) - self._length = renderUtf8Text(self._bb, 0, h*0.8, self.face, self.text, self.color) -end +--function TextWidget:_render() + --local h = self.face.size * 1.3 + --self._bb = Blitbuffer.new(self._maxlength, h) + --self._length = renderUtf8Text(self._bb, 0, h*0.8, self.face, self.text, self.color) +--end function TextWidget:getSize() - if not self._bb then - self:_render() - end - return { w = self._length, h = self._bb:getHeight() } + --if not self._bb then + --self:_render() + --end + --return { w = self._length, h = self._bb:getHeight() } + + self._length = sizeUtf8Text(0, G_width, self.face, self.text, true).x + self._height = self.face.size * 1.3 + return { + w = self._length, + h = self._height, + } end function TextWidget:paintTo(bb, x, y) - if not self._bb then - self:_render() - end - bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight()) + --if not self._bb then + --self:_render() + --end + --bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight()) + renderUtf8Text(bb, x, y+self._height*0.8, self.face, self.text, true) end function TextWidget:free() From e2fc72b411be3c0fe329a11899c93940619fda06 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 May 2012 17:36:01 +0800 Subject: [PATCH 2/3] add more styles for menu item icons --- dialog.lua | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/dialog.lua b/dialog.lua index 19f7b0043..31c8c3737 100644 --- a/dialog.lua +++ b/dialog.lua @@ -265,17 +265,37 @@ ItemShortCutIcon = WidgetContainer:new{ height = 22, key = nil, bordersize = 2, + radius = 0, + style = "square" } function ItemShortCutIcon:init() if not self.key then return end + + local radius = 0 + local background = 0 + if self.style == "rounded_corner" then + radius = math.floor(self.width/2) + elseif self.style == "grey_square" then + background = 3 + end + + --@TODO calculate font size by icon size 01.05 2012 (houqp) + if self.key:len() > 1 then + sc_face = Font:getFace("ffont", 14) + else + sc_face = Font:getFace("scfont", 22) + end + self[1] = HorizontalGroup:new{ HorizontalSpan:new{ width = 5 }, FrameContainer:new{ padding = 0, bordersize = self.bordersize, + radius = radius, + background = background, dimen = { w = self.width, h = self.height, @@ -287,7 +307,7 @@ function ItemShortCutIcon:init() }, TextWidget:new{ text = self.key, - face = Font:getFace("scfont", 22) + face = sc_face, }, }, }, @@ -307,6 +327,7 @@ MenuItem = WidgetContainer:new{ width = nil, height = nil, shortcut = nil, + shortcut_style = "square", } function MenuItem:init() @@ -331,6 +352,8 @@ function MenuItem:init() width = shortcut_icon_w, height = shortcut_icon_h, key = self.shortcut, + radius = shortcut_icon_r, + style = self.shortcut_style, }, HorizontalSpan:new{ width = 5 }, UnderlineContainer:new{ @@ -453,7 +476,14 @@ function Menu:_updateItems() local i = (self.page - 1) * self.perpage + c if i <= self.items then local item_shortcut = nil + local shortcut_style = "square" if self.is_enable_shortcut then + -- give different shortcut_style to keys in different + -- lines of keyboard + if c >= 11 and c <= 20 then + --shortcut_style = "rounded_corner" + shortcut_style = "grey_square" + end item_shortcut = self.item_shortcuts[c] if item_shortcut == "Enter" then item_shortcut = "Ent" @@ -464,7 +494,8 @@ function Menu:_updateItems() face = self.cface, width = self.width - 14, height = self.item_height, - shortcut = item_shortcut + shortcut = item_shortcut, + shortcut_style = shortcut_style, } table.insert(item_group, item_tmp) table.insert(self.layout, {item_tmp}) From 12bf282ef290340e7b9a668854e749042d2816a7 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 2 May 2012 11:33:34 +0800 Subject: [PATCH 3/3] fix bug in paintRoundedRect rounded up decimal leads to wrong claculation for bottom corners --- graphics.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphics.lua b/graphics.lua index 394032e48..6a35fd8fb 100644 --- a/graphics.lua +++ b/graphics.lua @@ -10,6 +10,8 @@ Draw a border @r: radius of for border's corner (nil or 0 means right corner border) --]] function blitbuffer.paintBorder(bb, x, y, w, h, bw, c, r) + x, y = math.ceil(x), math.ceil(y) + h, w = math.ceil(h), math.ceil(w) if not r or r == 0 then bb:paintRect(x, y, w, bw, c) bb:paintRect(x, y+h-bw, w, bw, c) @@ -38,6 +40,8 @@ Fill a rounded corner rectangular area @r: radius of for four corners --]] function blitbuffer.paintRoundedRect(bb, x, y, w, h, c, r) + x, y = math.ceil(x), math.ceil(y) + h, w = math.ceil(h), math.ceil(w) if not r or r == 0 then bb:paintRect(x, y, w, h, c) else @@ -49,7 +53,6 @@ function blitbuffer.paintRoundedRect(bb, x, y, w, h, c, r) end - --[[ Draw a progress bar according to following args: