Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Work on gui

  • Loading branch information...
commit 617a15b6791b10945244b4c103724c1bc6d3ef5e 1 parent 7fa8c1f
@jimbauwens jimbauwens authored
View
103 2 - FormulaPro/FPGui.lua
@@ -9,69 +9,76 @@ function FormulaPro:paint(gc)
end
-boxx = box("40","18","Add var")
-FormulaPro:appendWidget(boxx, "5", "5")
+add_unit_button = sButton("Add unit...", function () push_screen(add_unit) end)
+FormulaPro:appendWidget(add_unit_button, "5", "5")
+add_unit_button:focus()
-userAv = sList()
-FormulaPro:appendWidget(userAv, "5", "25")
+user_added = sList()
+FormulaPro:appendWidget(user_added, "5", "25")
-userAv.hh = "70"
-userAv.ww = "40"
+user_added.hh = "70"
+user_added.ww = "40"
-function boxx:enterKey()
- push_screen(addV)
-end
+user_added.items = {}
-function boxx:mouseDown()
- push_screen(addV)
-end
-userAv.items = {}
+computer_computed = sList()
+FormulaPro:appendWidget(computer_computed, "55", "5")
+computer_computed.hh = "90"
+computer_computed.ww = "40"
-knownV = sList()
-FormulaPro:appendWidget(knownV, "55", "5")
+----
-knownV.hh = "90"
-knownV.ww = "40"
+function compute()
+ remove_screen()
+ FormulaPro.known[units[units_list.sel][1]] = tonumber(unit_value.value)
+ user_added.items = {}
+ for i,v in pairs(FormulaPro.known) do
+ table.insert(user_added.items, i .. ": " .. v)
+ end
+ local res=find_data(FormulaPro.known)
+ computer_computed.items = {}
+ for i,v in pairs(res) do
+
+ table.insert(computer_computed.items, i .. ": " .. v)
+ end
+end
-----
-addV = Screen("10","30","80","40")
+add_unit = Dialog("Add unit","10","10","80","85")
-function addV:paint(gc)
- gc:setColorRGB(240,240,240)
- gc:fillRect(self.x, self.y, self.w, self.h)
- gc:setColorRGB(0,0,0)
- gc:drawRect(self.x, self.y, self.w, self.h)
-end
+unit_value = sInput()
+unit_value.ww = "77"
+unit_value.number = true
-addD = sInput()
-addV:appendWidget(addD, "10", "10")
-addD.ww = "80"
-addD.number = true
-addD.value = "0"
+units_list = sList()
+units_list.hh = "50"
+units_list.ww = "77"
-addU = sList()
-addV:appendWidget(addU, "10", "40")
-addU.hh = 2*18+1
-addU.ww = "80"
+lbl1 = sLabel("Value:", addD)
+lbl2 = sLabel("Unit:", addU)
-for unit, val in pairs(units) do
- table.insert(addU.items, val[3][1][3] .. " (" .. val[3][1][2] .. ")")
+button_ok = sButton("OK", compute)
+button_esc = sButton("Cancel", remove_screen)
+
+add_unit:appendWidget(lbl1, "2", "18")
+add_unit:appendWidget(lbl2, "2", "38")
+add_unit:appendWidget(unit_value, "20", "18")
+add_unit:appendWidget(units_list, "20", "38")
+add_unit:appendWidget(button_ok, "60", "82")
+add_unit:appendWidget(button_esc, "75", "82")
+
+function Dialog:pushed()
+ unit_value:focus()
end
-function addU:enterKey()
+function Dialog:escapeKey()
remove_screen()
- FormulaPro.known[units[self.sel][1]] = tonumber(addD.value)
- userAv.items = {}
- for i,v in pairs(FormulaPro.known) do
- table.insert(userAv.items, i .. ": " .. v)
- end
- local res=find_data(FormulaPro.known)
- knownV.items = {}
- for i,v in pairs(res) do
-
- table.insert(knownV.items, i .. ": " .. v)
- end
+end
+
+
+--add items to list
+for unit, val in pairs(units) do
+ table.insert(units_list.items, val[3][1][3] .. " (" .. val[3][1][2] .. ")")
end
View
57 Global Libraries/screen.lua
@@ -14,6 +14,7 @@ Screens = {}
function push_screen(screen)
table.insert(Screens, screen)
platform.window:invalidate()
+ current_screen():pushed()
end
function remove_screen(screen)
@@ -57,6 +58,8 @@ function Screen:drawWidgets(gc)
end
end
+function Screen:pushed() end
+
function Screen:appendWidget(widget, xx, yy)
widget.xx = xx
widget.yy = yy
@@ -64,6 +67,7 @@ function Screen:appendWidget(widget, xx, yy)
widget:size()
table.insert(self.widgets, widget)
+ widget.pid = #self.widgets
end
function Screen:getWidget()
@@ -158,7 +162,7 @@ function Screen:getWidgetIn(x, y)
end
function Screen:mouseDown(x, y)
- local n, widget = self:getWidgetIn(x-self.x, y-self.y)
+ local n, widget = self:getWidgetIn(x, y)
if n then
if self.focus~=0 then self:getWidget().hasFocus = false self:getWidget():loseFocus() end
self.focus = n
@@ -166,7 +170,7 @@ function Screen:mouseDown(x, y)
widget.hasFocus = true
widget:getFocus()
- widget:mouseDown(x-self.x, y-self.y)
+ widget:mouseDown(x, y)
else
if self.focus~=0 then self:getWidget().hasFocus = false self:getWidget():loseFocus() end
self.focus = 0
@@ -174,17 +178,62 @@ function Screen:mouseDown(x, y)
end
function Screen:mouseUp(x, y)
if self.focus~=0 then
- self:getWidget():mouseUp(x-self.x, y-self.y)
+ self:getWidget():mouseUp(x, y)
end
self:invalidate()
end
function Screen:mouseMove(x, y)
if self.focus~=0 then
- self:getWidget():mouseMove(x-self.x, y-self.y)
+ self:getWidget():mouseMove(x, y)
end
end
+--Dialog screen
+
+Dialog = class(Screen)
+
+function Dialog:init(title,xx,yy,ww,hh)
+ self.yy = yy
+ self.xx = xx
+ self.hh = hh
+ self.ww = ww
+ self.title = title
+ self:size()
+
+ self.widgets = {}
+ self.focus = 0
+end
+
+function Dialog:paint(gc)
+ gc:setColorRGB(224,224,224)
+ gc:fillRect(self.x, self.y, self.w, self.h)
+
+ for i=1, 14,2 do
+ gc:setColorRGB(32+i*3, 32+i*4, 32+i*3)
+ gc:fillRect(self.x, self.y+i, self.w,2)
+ end
+ gc:setColorRGB(32+16*3, 32+16*4, 32+16*3)
+ gc:fillRect(self.x, self.y+15, self.w, 10)
+
+ gc:setColorRGB(128,128,128)
+ gc:drawRect(self.x, self.y, self.w, self.h)
+ gc:drawRect(self.x-1, self.y-1, self.w+2, self.h+2)
+
+ gc:setColorRGB(96,100,96)
+ gc:fillRect(self.x+self.w+1, self.y, 1, self.h+2)
+ gc:fillRect(self.x, self.y+self.h+2, self.w+3, 1)
+
+ gc:setColorRGB(104,108,104)
+ gc:fillRect(self.x+self.w+2, self.y+1, 1, self.h+2)
+ gc:fillRect(self.x+1, self.y+self.h+3, self.w+3, 1)
+ gc:fillRect(self.x+self.w+3, self.y+2, 1, self.h+2)
+ gc:fillRect(self.x+2, self.y+self.h+4, self.w+3, 1)
+
+ gc:setColorRGB(255,255,255)
+ gc:drawString(self.title, self.x + 4, self.y+2, "top")
+end
+
------------------------------------------------------------------
-- Bindings to the on events --
------------------------------------------------------------------
View
127 Global Libraries/widgets.lua
@@ -28,13 +28,25 @@ function Widget:paint(gc)
--gc:drawRect(self.x, self.y, self.w, self.h)
end
+function Widget:focus()
+ if self.parent.focus~=0 then
+ self.parent:getWidget().hasFocus = false
+ self.parent:getWidget():loseFocus()
+ end
+ self.hasFocus = true
+ self.parent.focus = self.pid
+ self:getFocus()
+end
+
function Widget:getFocus() end
function Widget:loseFocus() end
function Widget:arrowKey(key)end
function Widget:mouseDown(x, y) end
function Widget:mouseUp(x, y) end
function Widget:mouseMove(x, y) end
-function Widget:enterKey() end
+function Widget:enterKey()
+ self.parent:switchFocus(1)
+end
function Widget:charIn() end
function Widget:escapeKey() end
function Widget:backspaceKey() end
@@ -101,6 +113,7 @@ end
function sList:prePaint(gc)
self.hitems = math.floor((self.h-1)/self.itemh)
+ self.h = self.hitems*self.itemh+1
end
function sList:paint(gc)
@@ -157,13 +170,7 @@ function sList:mouseUp(xx, yy)
end
end
-function sList:enterKey()
- self:action(self.sel, self.items[self.sel])
-end
-
-function sList:action(n, item)
-end
------------------------------------------------------------------
@@ -188,13 +195,13 @@ function sInput:paint(gc)
gc:setColorRGB(unpack(self.bgcolor))
gc:fillRect(x, y, self.w, self.h)
- if self.hasFocus then
- gc:setPen("medium", "smooth")
- end
+
gc:setColorRGB(0,0,0)
gc:drawRect(x, y, self.w, self.h)
- gc:setPen("thin", "smooth")
-
+ if self.hasFocus then
+ gc:drawRect(x-1, y-1, self.w+2, self.h+2)
+ end
+
local text = ""
local p = 0
@@ -213,6 +220,9 @@ function sInput:paint(gc)
else
gc:drawString(text, x-4+self.w-gc:getStringWidth(text), y-2, "top")
end
+ if self.hasFocus then
+ gc:fillRect(self.x+(text==self.value and gc:getStringWidth(text)+2 or self.w-4), self.y, 1, self.h)
+ end
end
@@ -227,3 +237,96 @@ function sInput:backspaceKey()
self.value = self.value:usub(1,-2)
end
+--Label
+
+sLabel = class(Widget)
+
+function sLabel:init(text, widget)
+ self.widget = widget
+ self.text = text
+ self.dw = 100
+ self.dh = 20
+ self.lim = false
+ self.color = {0,0,0}
+ self.font = {"sansserif", "r", 11}
+ self.p = "top"
+
+end
+
+function sLabel:paint(gc)
+ local text = ""
+ local ttext
+ if self.lim then
+ if gc:getStringWidth(self.text)<self.w then
+ text = self.text
+ else
+ for i=1, #self.text do
+ ttext = self.text:sub(1,i)
+ if gc:getStringWidth(ttext .. "..")>self.w then
+ break
+ end
+ text = ttext
+ end
+ text = text .. ".."
+ end
+ else
+ text = self.text
+ end
+
+ gc:setFont(unpack(self.font))
+ gc:setColorRGB(unpack(self.color))
+ gc:drawString(text, self.x, self.y-2, self.p)
+end
+
+function sLabel:getFocus()
+ if self.widget then
+ self.widget:focus()
+ end
+end
+
+
+--Button widget
+
+sButton = class(Widget)
+
+function sButton:init(text, action)
+ self.text = text
+ self.action = action
+
+ self.dh = 27
+ self.dw = 48
+
+ self.bordercolor = {136,136,136}
+
+end
+
+function sButton:paint(gc)
+
+ self.w = gc:getStringWidth(self.text)+8
+ gc:setColorRGB(248,252,248)
+ gc:fillRect(self.x+2, self.y+2, self.w-4, self.h-4)
+ gc:setColorRGB(0,0,0)
+
+ gc:drawString(self.text, self.x+4, self.y+2, "top")
+
+ gc:setColorRGB(unpack(self.bordercolor))
+ gc:fillRect(self.x + 2, self.y, self.w-4, 2)
+ gc:fillRect(self.x + 2, self.y+self.h-2, self.w-4, 2)
+
+ gc:fillRect(self.x, self.y+2, 1, self.h-4)
+ gc:fillRect(self.x+1, self.y+1, 1, self.h-2)
+ gc:fillRect(self.x+self.w-1, self.y+2, 1, self.h-4)
+ gc:fillRect(self.x+self.w-2, self.y+1, 1, self.h-2)
+
+ if self.hasFocus then
+ gc:setColorRGB(40, 148, 184)
+ gc:drawRect(self.x-2, self.y-2, self.w+3, self.h+3)
+ gc:drawRect(self.x-3, self.y-3, self.w+5, self.h+5)
+ end
+end
+
+function sButton:enterKey()
+ if self.action then self.action() end
+end
+
+sButton.mouseUp = sButton.enterKey
View
4 main.lua
@@ -2,6 +2,10 @@
main = Screen()
+function main:paint(gc)
+ gc:drawString("Press menu...",10,10,"top")
+end
+
function notDone()
print("Not Done Yet")
end
Please sign in to comment.
Something went wrong with that request. Please try again.