Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Started CentrePoint, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oeed committed Nov 8, 2014
1 parent 69807c2 commit 5cc13e2
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 33 deletions.
1 change: 0 additions & 1 deletion System/API/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ TruncateStringStart = function(sString, maxLength)
return sString
end


WrapText = function(text, maxWidth)
local lines = {''}
for word, space in text:gmatch('(%S+)(%s*)') do
Expand Down
16 changes: 16 additions & 0 deletions System/API/Program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,20 @@ SwitchTo = function(self)
Current.Program = self
Current.ProgramView:ForceDraw()
end
end

RenderPreview = function(self, width, height)
local preview = {}
local deltaX = self.AppRedirect.Size[1] / width
local deltaY = self.AppRedirect.Size[2] / height

for _x = 1, width do
local x = Helpers.Round(1 + (_x - 1) * deltaX)
preview[_x] = {}
for _y = 1, height do
local y = Helpers.Round(1 + (_y - 1) * deltaY)
preview[_x][_y] = self.AppRedirect.Buffer[y][x]
end
end
return preview
end
59 changes: 59 additions & 0 deletions System/Objects/CentrePoint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Inherit = 'View'


OnLoad = function(self)
self:GetObject('AboutButton').OnClick = function(itm)
Helpers.OpenFile('System/Programs/About OneOS.program')
end

self:GetObject('SettingsButton').OnClick = function(itm)
Helpers.OpenFile('System/Programs/Settings.program')
end

self:GetObject('UpdateButton').OnClick = function(itm)
CheckAutoUpdate(true)
end

self:GetObject('RestartButton').OnClick = function(itm)
Restart()
end

self:GetObject('ShutdownButton').OnClick = function(itm)
Shutdown()
end
self.Visible = false
end

local oldProgram = nil
Show = function(self)
-- self:UpdatePreviews()
self:UpdatePrograms()
oldProgram = Current.Program
Current.Program = nil
self.Bedrock:GetObject('Overlay').CenterPointMode = true
self.Bedrock:GetObject('Overlay'):GetObject('OneButton').Toggle = true
UpdateOverlay()
self.Visible = true
end

UpdatePrograms = function(self)
self:AddObject({
X = 10,
Y = 8,
Type = 'ProgramPreview',
Program = Current.Program
})
end

Hide = function(self)
-- self:UpdatePreviews()

self.Visible = false
self.Bedrock:GetObject('Overlay').CenterPointMode = false
self.Bedrock:GetObject('Overlay'):GetObject('OneButton').Toggle = false
if oldProgram and oldProgram.Running then
oldProgram:SwitchTo()
else
Current.Desktop:SwitchTo()
end
end
72 changes: 42 additions & 30 deletions System/Objects/Overlay.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Inherit = 'View'

TextColour = colours.black
BackgroundColour = colours.white
TextColour = colours.white
BackgroundColour = colours.grey
CenterPointMode = false

OnDraw = function(self, x, y)
if self.BackgroundColour then
Expand All @@ -11,31 +12,36 @@ end

OnLoad = function(self)
self:GetObject('OneButton').OnClick = function(btn)
if btn:ToggleMenu('onemenu') then

self.Bedrock:GetObject('DesktopMenuItem').OnClick = function(itm)
Current.Desktop:SwitchTo()
end

self.Bedrock:GetObject('AboutMenuItem').OnClick = function(itm)
Helpers.OpenFile('System/Programs/About OneOS.program')
end

self.Bedrock:GetObject('SettingsMenuItem').OnClick = function(itm)
Helpers.OpenFile('System/Programs/Settings.program')
end

self.Bedrock:GetObject('UpdateMenuItem').OnClick = function(itm)
CheckAutoUpdate(true)
end

self.Bedrock:GetObject('RestartMenuItem').OnClick = function(itm)
Restart()
end

self.Bedrock:GetObject('ShutdownMenuItem').OnClick = function(itm)
Shutdown()
end
-- if btn:ToggleMenu('onemenu') then

-- self.Bedrock:GetObject('DesktopMenuItem').OnClick = function(itm)
-- Current.Desktop:SwitchTo()
-- end

-- self.Bedrock:GetObject('AboutMenuItem').OnClick = function(itm)
-- Helpers.OpenFile('System/Programs/About OneOS.program')
-- end

-- self.Bedrock:GetObject('SettingsMenuItem').OnClick = function(itm)
-- Helpers.OpenFile('System/Programs/Settings.program')
-- end

-- self.Bedrock:GetObject('UpdateMenuItem').OnClick = function(itm)
-- CheckAutoUpdate(true)
-- end

-- self.Bedrock:GetObject('RestartMenuItem').OnClick = function(itm)
-- Restart()
-- end

-- self.Bedrock:GetObject('ShutdownMenuItem').OnClick = function(itm)
-- Shutdown()
-- end
-- end
if btn.Toggle then
self.Bedrock:GetObject('CentrePoint'):Show()
else
self.Bedrock:GetObject('CentrePoint'):Hide()
end
end

Expand All @@ -48,8 +54,11 @@ OnLoad = function(self)
self:UpdateButtons()
end

UpdateButtons = function(self)
if Current.Program then
UpdateButtons = function(self, backgroundColour, textColour)
if self.CenterPointMode then
self.BackgroundColour = colours.grey
self.TextColour = colours.white
elseif Current.Program then
if Current.Program.Environment.OneOS.ToolBarColor ~= colours.white then
self.BackgroundColour = Current.Program.Environment.OneOS.ToolBarColor
Current.Program.Environment.OneOS.ToolBarColour = Current.Program.Environment.OneOS.ToolBarColor
Expand Down Expand Up @@ -85,7 +94,7 @@ UpdateButtons = function(self)
local bg = self.BackgroundColour
local tc = self.TextColour
local button = ''
if Current.Program and Current.Program == program then
if not self.CenterPointMode and Current.Program and Current.Program == program then
bg = colours.lightBlue
tc = colours.white
button = 'x '
Expand All @@ -112,6 +121,9 @@ UpdateButtons = function(self)
obj.Program:Close()
end
else
if self.CenterPointMode then
self.Bedrock:GetObject('CentrePoint'):Hide()
end
obj.Program:SwitchTo()
end
self:UpdateButtons()
Expand Down
45 changes: 45 additions & 0 deletions System/Objects/ProgramPreview.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Inherit = 'View'
Width = 13
Height = 8
PreviewWidth = 12
PreviewHeight = 5
Program = nil
Preview = nil
Icon = nil

OnLoad = function(self)
if self.Program and self.Program.Running then
self.Preview = Current.Program:RenderPreview(self.PreviewWidth, self.PreviewHeight)
local path = Helpers.ParentFolder(self.Program.Path)..'/icon'
self.Icon = Drawing.LoadImage(path)
end
end

OnDraw = function(self, x, y)
if self.Program and self.Program.Running then
Drawing.DrawBlankArea(x + 1, y + 2, self.PreviewWidth, self.PreviewHeight, colours.grey)
Drawing.DrawBlankArea(x, y + 1, self.PreviewWidth, self.PreviewHeight, colours.white)

for _x, col in pairs(self.Preview) do
for _y, colour in ipairs(col) do
local char = '-'
if colour[1] == ' ' then
char = ' '
end
Drawing.WriteToBuffer(x+_x-1, y+_y, char, colour[2], colour[3])--' ', colours.black, colour)
end
end

Drawing.DrawCharactersCenter(x + 1, y, self.PreviewWidth - 1, 1, Helpers.TruncateString(self.Program.Title, self.Width - 2), colours.white, colours.transparent)
-- local img = Drawing.LoadImage(self.Program.Path..'/icon')--Helpers.IconForFile('/System/Program/Files.program')
if self.Icon then
Drawing.DrawImage(x + self.PreviewWidth - 4, y + self.PreviewHeight - 2, self.Icon, 4, 3)
end
Drawing.DrawCharacters(x, y, 'x', colours.red, colours.transparent)

end
end

OnClick = function(self, event, side, x, y)

end
78 changes: 78 additions & 0 deletions System/Views/centrepoint.view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
["Width"]="100%",
["Height"]="100%,-1",
["Visible"]=true,
["X"]=1,
["Y"]=2,
["BackgroundColour"]=32768,
["Children"]={
[1]={
["Width"]="100%",
["Height"]=3,
["Y"]=1,
["X"]=1,
["Type"]="View",
["BackgroundColour"]=128
},
[2]={
["Y"]=2,
["Width"]=49,
["X"]="50%,-24",
["Type"]="View",
["Children"]={
[1]={
["Y"]=1,
["X"]=1,
["Type"]="Button",
["Text"]="About",
["Name"]="AboutButton",
["BackgroundColour"]=1,
["TextColour"]=128
},
[2]={
["Y"]=1,
["X"]=9,
["Type"]="Button",
["Text"]="Update",
["Name"]="UpdateButton",
["BackgroundColour"]=1,
["TextColour"]=128
},
[3]={
["Y"]=1,
["X"]=18,
["Type"]="Button",
["Text"]="Settings",
["Name"]="SettingsButton",
["BackgroundColour"]=1,
["TextColour"]=128
},
[4]={
["Y"]=1,
["X"]=29,
["Type"]="Button",
["Text"]="Restart",
["Name"]="RestartButton",
["BackgroundColour"]=1,
["TextColour"]=128
},
[5]={
["Y"]=1,
["X"]=39,
["Type"]="Button",
["Text"]="Shutdown",
["Name"]="ShutdownButton",
["BackgroundColour"]=1,
["TextColour"]=128
},
}
},
[3]={
["Y"]="100%",
["X"]="100%,-10",
["Type"]="Label",
["Text"]="CentrePoint",
["TextColour"]=128
},
},
}
10 changes: 8 additions & 2 deletions System/Views/main.view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
["Height"]="100%,-1",
["Name"]="ProgramView",
["Type"]="ProgramView",
["Active"]=true
["Active"]=true,
},
[4]={
["Name"]="CentrePoint",
["Type"]="CentrePoint",
["InheritView"]="centrepoint",
["Visible"]=false,
},
[5]={
["Name"]="Overlay",
["Type"]="Overlay",
["InheritView"]="overlay"
["InheritView"]="overlay",
},
}
}

0 comments on commit 5cc13e2

Please sign in to comment.