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

Commit

Permalink
Added more animations, finished centerpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oeed committed Nov 8, 2014
1 parent 5cc13e2 commit 77d3791
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 49 deletions.
9 changes: 8 additions & 1 deletion System/API/Bedrock.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--Bedrock Build: 267
--Bedrock Build: 269
--This code is squished down in to one, rather hard to read file.
--As such it is not much good for anything other than being loaded as an API.
--If you want to look at the code to learn from it, copy parts or just take a look,
Expand Down Expand Up @@ -1281,6 +1281,8 @@ Inherit = 'View'
ChildOffset = false
ContentWidth = 0
ContentHeight = 0
ScrollBarBackgroundColour = colours.lightGrey
ScrollBarColour = colours.lightBlue
CalculateContentSize = function(self)
local function calculateObject(obj)
Expand Down Expand Up @@ -1319,6 +1321,8 @@ UpdateScroll = function(self)
["Y"] = 1,
["Width"] = 1,
["Height"] = self.Height,
["BackgroundColour"] = self.ScrollBarBackgroundColour,
["BarColour"] = self.ScrollBarColour,
["Z"]=999
})
Expand Down Expand Up @@ -1840,6 +1844,7 @@ Title = ''
Flashing = false
CanClose = true
OnCloseButton = nil
OldActiveObject = nil
OnLoad = function(self)
--self:GetObject('View') = self.Bedrock:ObjectFromFile({Type = 'View',Width = 10, Height = 5, BackgroundColour = colours.red}, self)
Expand All @@ -1861,6 +1866,7 @@ LoadView = function(self)
if self.OnViewLoad then
self.OnViewLoad(view)
end
self.OldActiveObject = self.Bedrock:GetActiveObject()
self.Bedrock:SetActiveObject(view)
end
Expand Down Expand Up @@ -1893,6 +1899,7 @@ OnDraw = function(self, x, y)
end
Close = function(self)
self.Bedrock:SetActiveObject(self.OldActiveObject)
self.Bedrock.Window = nil
self.Bedrock:RemoveObject(self)
if self.OnClose then
Expand Down
36 changes: 23 additions & 13 deletions System/API/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ end
OpenFile = function(path, args)
args = args or {}
if fs.exists(path) then
if Current.Bedrock then
local centrePoint = Current.Bedrock:GetObject('CentrePoint')
if centrePoint.Visible then
centrePoint:Hide()
end
end

local extension = Helpers.Extension(path)
if extension == 'shortcut' then
h = fs.open(path, 'r')
Expand All @@ -31,7 +38,7 @@ OpenFile = function(path, args)
local _path = Indexer.FindFileInFolder(extension, 'Icons')
if _path and not _path:find('System/Images/Icons/') then
Helpers.OpenFile(Helpers.ParentFolder(Helpers.ParentFolder(_path)), {path})
elseif _path then
else
OpenFileWith(path)
end
else
Expand Down Expand Up @@ -327,24 +334,32 @@ OpenFileWith = function(path, bedrock)
local text = 'Choose the program you want to open this file with.'
local height = #Helpers.WrapText(text, 26)

local items = {}

for i, v in ipairs(fs.list('Programs/')) do
if string.sub( v, 1, 1 ) ~= '.' then
table.insert(items, v)
end
end

local children = {
{
["Y"]="100%,-1",
["X"]="100%,-4",
["X"]="100%,-5",
["Name"]="OpenButton",
["Type"]="Button",
["Text"]="Open",
OnClick = function()
local selected = bedrock.Window:GetObject('ListView').Selected
if selected then
OneOS.Run(value, selected.Path, path)
OpenFile('Programs/' .. selected.Text, {path})
bedrock.Window:Close()
end
end
},
{
["Y"]="100%,-1",
["X"]="100%,-13",
["X"]="100%,-14",
["Name"]="CancelButton",
["Type"]="Button",
["Text"]="Cancel",
Expand All @@ -353,21 +368,16 @@ OpenFileWith = function(path, bedrock)
end
},
{
["Y"]=2,
["Y"]=6,
["X"]=2,
["Height"]="100%,-3",
["Height"]="100%,-8",
["Width"]="100%,-2",
["Name"]="ListView",
["Type"]="ListView",
["TextColour"]=128,
["BackgroundColour"]=0,
["CanSelect"]=true,
["Items"]={
{["Text"] = 'Desktop', ["Path"] = '/Desktop/'},
{["Text"] = 'Documents', ["Path"] = '/Desktop/Documents/'},
{["Text"] = 'Programs', ["Path"] = '/Programs/'},
{["Text"] = 'Computer', ["Path"] = '/'},
},
["Items"]=items,
},
{
["Y"]=2,
Expand All @@ -381,7 +391,7 @@ OpenFileWith = function(path, bedrock)
}

local view = {
Children = {children},
Children=children,
Width=28,
Height=10+height
}
Expand Down
157 changes: 146 additions & 11 deletions System/Objects/CentrePoint.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
Inherit = 'View'

local oldProgram = nil
local oldActive = nil
local oldProgramPosition = nil

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

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

Expand All @@ -21,36 +26,166 @@ OnLoad = function(self)
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
self:UpdatePrograms()
oldActive = self.Bedrock:GetActiveObject()
Current.Program = nil
self.Bedrock:GetObject('Overlay').CenterPointMode = true
self.Bedrock:GetObject('Overlay'):GetObject('OneButton').Toggle = true
self.Bedrock:SetActiveObject(nil)
UpdateOverlay()
self.Visible = true
self:AnimateEntry()
end

function AnimateEntry(self)
local animatePreview = self:GetObject('AnimateProgramPreview')
if Settings:GetValues()['UseAnimations'] then
animatePreview.Visible = true
animatePreview.X = 1
animatePreview.Y = 1
animatePreview.Width = self.Width
animatePreview.Height = self.Height
animatePreview.Program = oldProgram
animatePreview:UpdatePreview()

local steps = 5
local deltaW = (self.Width - ProgramPreview.PreviewWidth) / steps
local deltaH = (self.Height - ProgramPreview.PreviewHeight) / steps
local deltaX = deltaW
local deltaY = deltaH
if oldProgramPosition then
deltaX = (self.X - oldProgramPosition.X) / steps
deltaY = (self.Y - oldProgramPosition.Y - 1) / steps
end

self.Bedrock:GetObject('Overlay'):Draw()
for i = 1, steps do
animatePreview.X = animatePreview.X - deltaX
animatePreview.Y = animatePreview.Y - deltaY
animatePreview.Width = animatePreview.Width - deltaW
animatePreview.Height = animatePreview.Height - deltaH
animatePreview:UpdatePreview()
self:Draw()
Drawing.DrawBuffer()
end
self.Bedrock:Draw()
end
animatePreview.Visible = false
end

function AnimateExit(self)
local animatePreview = self:GetObject('AnimateProgramPreview')
Current.Program = oldProgram
Current.ProgramView.CachedProgram = nil
Current.ProgramView:ForceDraw()
if Settings:GetValues()['UseAnimations'] then
local previews = self:GetObjects('ProgramPreview')

for i, v in ipairs(previews) do
if v.Program == oldProgram then
oldProgramPosition = self.Bedrock:GetAbsolutePosition(v)
end
end

animatePreview.Visible = true
animatePreview.X = oldProgramPosition.X
animatePreview.Y = oldProgramPosition.Y
animatePreview.Width = ProgramPreview.PreviewWidth
animatePreview.Height = ProgramPreview.PreviewHeight
animatePreview.Program = oldProgram
animatePreview:UpdatePreview()

local steps = 5
local deltaW = (ProgramPreview.PreviewWidth - self.Width - 1) / steps
local deltaH = (ProgramPreview.PreviewHeight - self.Height - 1) / steps
local deltaX = deltaW
local deltaY = deltaH
if oldProgramPosition then
deltaX = (oldProgramPosition.X - 1) / steps
deltaY = (oldProgramPosition.Y - 1) / steps
end

for i = 1, steps do
animatePreview.X = animatePreview.X - deltaX
animatePreview.Y = animatePreview.Y - deltaY
animatePreview.Width = animatePreview.Width - deltaW
animatePreview.Height = animatePreview.Height - deltaH
if i == steps then
animatePreview.X = 1
animatePreview.Y = 1
animatePreview.Width = self.Width
animatePreview.Height = self.Height
self.Bedrock:GetObject('Overlay'):UpdateButtons()
self.Bedrock:GetObject('Overlay'):Draw()
end
animatePreview:UpdatePreview()
self:Draw()
Drawing.DrawBuffer()
end
self.Bedrock:Draw()
end
animatePreview.Visible = false
end

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

local maxCols = math.floor(self.Width / (2 + ProgramPreview.Width))
local currentY = 3

local rows = {}
for i, program in ipairs(Current.Programs) do
local row = math.ceil(i / maxCols)
Log.i(row)
if not rows[row] then
rows[row] = {}
end
table.insert(rows[row], program)
end

local scrollView = self:GetObject('ScrollView')
for i, row in ipairs(rows) do
local currentX = math.ceil((self.Width - (#row * (2 + ProgramPreview.Width)) + 2)/2)
for i2, program in ipairs(row) do
local obj = scrollView:AddObject({
X = currentX,
Y = currentY,
Type = 'ProgramPreview',
Program = program,
OnClick = function(prv, event, side, x, y)
if not prv.Program.Hidden and ((x == 1 and y == 1) or side == 3) then
prv.Program:Close()
prv.Bedrock:GetObject('CentrePoint'):UpdatePrograms()
else
oldProgram = prv.Program
prv.Bedrock:GetObject('CentrePoint'):Hide()
-- prv.Program:SwitchTo()
end
end
})
if program == oldProgram then
oldProgramPosition = self.Bedrock:GetAbsolutePosition(obj)
end
currentX = currentX + 2 + ProgramPreview.Width
end
currentY = currentY + ProgramPreview.Height + 1
end
scrollView:UpdateScroll()
end

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

self.Visible = false
self.Bedrock:GetObject('Overlay').CenterPointMode = false
self.Bedrock:GetObject('Overlay'):GetObject('OneButton').Toggle = false
self:AnimateExit()
self.Visible = false
self.Bedrock:SetActiveObject(oldActive)
if oldProgram and oldProgram.Running then
oldProgram:SwitchTo()
else
Expand Down
Loading

0 comments on commit 77d3791

Please sign in to comment.