diff --git a/src/include/xconfigs.h b/src/include/xconfigs.h index c6d6f99faa..6bb3819428 100644 --- a/src/include/xconfigs.h +++ b/src/include/xconfigs.h @@ -33,7 +33,7 @@ extern "C" { #endif #if !defined(CONFIG_AUTO_BOOT_COMMAND) -#define CONFIG_AUTO_BOOT_COMMAND "exec /romdisk/demos/" +#define CONFIG_AUTO_BOOT_COMMAND "exec /romdisk/examples/" #endif #if !defined(CONFIG_MAX_BRIGHTNESS) diff --git a/src/romdisk/demos/graphics/balls/Ball.lua b/src/romdisk/demos/graphics/balls/Ball.lua deleted file mode 100644 index 15b85bc17e..0000000000 --- a/src/romdisk/demos/graphics/balls/Ball.lua +++ /dev/null @@ -1,50 +0,0 @@ -local M = Class(DisplayObject) - -function M:init(image) - self.super:init() - - local width, height = application:getScreenSize() - local assets = application:getAssets() - - self.maxWidth = width - self.maxHeight = height - self.xdirection = 1 - self.ydirection = 1 - self.xspeed = math.random(40, 100) / 10 - self.yspeed = math.random(40, 100) / 10 - self.rspeed = math.random(-360, 360) * math.pi / 180 * 2 - - self:setX(math.random(40, self.maxWidth - 40)) - self:setY(math.random(40, self.maxHeight - 40)) - self:addChild(assets:loadDisplay(image):setAnchor(0.5, 0.5)) - self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) -end - -function M:onEnterFrame(e) - local x = self:getX() - local y = self:getY() - - x = x + (self.xspeed * self.xdirection) - y = y + (self.yspeed * self.ydirection) - - if x < 40 then - self.xdirection = 1 - end - - if x > self.maxWidth - 40 then - self.xdirection = -1 - end - - if y < 40 then - self.ydirection = 1 - end - - if y > self.maxHeight - 40 then - self.ydirection = -1 - end - - self:setPosition(x, y) - self:setRotation(self:getRotation() + self.rspeed) -end - -return M diff --git a/src/romdisk/demos/graphics/balls/ball1.png b/src/romdisk/demos/graphics/balls/ball1.png deleted file mode 100644 index 2381684c90..0000000000 Binary files a/src/romdisk/demos/graphics/balls/ball1.png and /dev/null differ diff --git a/src/romdisk/demos/graphics/balls/ball2.png b/src/romdisk/demos/graphics/balls/ball2.png deleted file mode 100644 index ae2c8cb827..0000000000 Binary files a/src/romdisk/demos/graphics/balls/ball2.png and /dev/null differ diff --git a/src/romdisk/demos/graphics/balls/ball3.png b/src/romdisk/demos/graphics/balls/ball3.png deleted file mode 100644 index 3281474169..0000000000 Binary files a/src/romdisk/demos/graphics/balls/ball3.png and /dev/null differ diff --git a/src/romdisk/demos/graphics/balls/ball4.png b/src/romdisk/demos/graphics/balls/ball4.png deleted file mode 100644 index d3e726455d..0000000000 Binary files a/src/romdisk/demos/graphics/balls/ball4.png and /dev/null differ diff --git a/src/romdisk/demos/graphics/balls/ball5.png b/src/romdisk/demos/graphics/balls/ball5.png deleted file mode 100644 index bff0faf00b..0000000000 Binary files a/src/romdisk/demos/graphics/balls/ball5.png and /dev/null differ diff --git a/src/romdisk/demos/scene1.png b/src/romdisk/demos/scene1.png deleted file mode 100644 index 08fdfa8ac4..0000000000 Binary files a/src/romdisk/demos/scene1.png and /dev/null differ diff --git a/src/romdisk/demos/scene2.lua b/src/romdisk/demos/scene2.lua deleted file mode 100644 index f00e0cc92c..0000000000 --- a/src/romdisk/demos/scene2.lua +++ /dev/null @@ -1,95 +0,0 @@ -local M = Class(DisplayObject) - -function M:init() - self.super:init() - - local width, height = application:getScreenSize() - local assets = application:getAssets() - self:addChild(assets:loadDisplay("scene2.png")) - - for i=1,5 do - local shape = DisplayShape.new(100, 50) - :setLineWidth(6) - :rectangle(0, 0, 100, 50) - :setSourceColor(1, 0, 0, 0.5) - :fillPreserve() - :setSourceColor(0, 0, 0) - :stroke() - :setPosition(math.random(0, width - 100), math.random(0, height - 50)) - - shape:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, shape) - shape:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, shape) - shape:addEventListener(Event.MOUSE_UP, self.onMouseUp, shape) - shape:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, shape) - shape:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove, shape) - shape:addEventListener(Event.TOUCHES_END, self.onTouchesEnd, shape) - shape:addEventListener(Event.TOUCHES_CANCEL, self.onTouchesCancel, shape) - - self:addChild(shape) - end -end - -function M:onMouseDown(e) - if self:hitTestPoint(e.info.x, e.info.y) then - self.touchid = -1 - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -function M:onMouseMove(e) - if self.touchid == -1 then - local dx = e.info.x - self.x0 - local dy = e.info.y - self.y0 - self:setX(self:getX() + dx) - self:setY(self:getY() + dy) - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -function M:onMouseUp(e) - if self.touchid == -1 then - self.touchid = nil - e:stopPropagation() - end -end - -function M:onTouchesBegin(e) - if self:hitTestPoint(e.info.x, e.info.y) then - self.touchid = e.info.id - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -function M:onTouchesMove(e) - if self.touchid == e.info.id then - local dx = e.info.x - self.x0 - local dy = e.info.y - self.y0 - self:setX(self:getX() + dx) - self:setY(self:getY() + dy) - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -function M:onTouchesEnd(e) - if self.touchid == e.info.id then - self.touchid = nil - e:stopPropagation() - end -end - -function M:onTouchesCancel(e) - if self.touchid == e.info.id then - self.touchid = nil - e:stopPropagation() - end -end - -return M diff --git a/src/romdisk/demos/scene2.png b/src/romdisk/demos/scene2.png deleted file mode 100644 index d8a36becce..0000000000 Binary files a/src/romdisk/demos/scene2.png and /dev/null differ diff --git a/src/romdisk/demos/TestCase.lua b/src/romdisk/examples/TestCase.lua similarity index 100% rename from src/romdisk/demos/TestCase.lua rename to src/romdisk/examples/TestCase.lua diff --git a/src/romdisk/examples/graphics/balls/Ball.lua b/src/romdisk/examples/graphics/balls/Ball.lua index 0920d72826..38803ae20d 100644 --- a/src/romdisk/examples/graphics/balls/Ball.lua +++ b/src/romdisk/examples/graphics/balls/Ball.lua @@ -3,19 +3,20 @@ local M = Class(DisplayObject) function M:init(image) self.super:init() - local width, height = application:getScreenSize() + local w, h = application:getScreenSize() local assets = application:getAssets() - self.maxWidth = width - self.maxHeight = height + self.maxWidth = w + self.maxHeight = h self.xdirection = 1 self.ydirection = 1 self.xspeed = math.random(40, 100) / 10 self.yspeed = math.random(40, 100) / 10 + self.rspeed = math.random(-360, 360) * math.pi / 180 * 2 - self:setX(math.random(0, self.maxWidth - 80)) - self:setY(math.random(0, self.maxHeight - 80)) - self:addChild(assets:loadDisplay(image)) + self:setX(math.random(40, self.maxWidth - 40)) + self:setY(math.random(40, self.maxHeight - 40)) + self:addChild(assets:loadDisplay(image):setAnchor(0.5, 0.5)) self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) end @@ -26,23 +27,24 @@ function M:onEnterFrame(e) x = x + (self.xspeed * self.xdirection) y = y + (self.yspeed * self.ydirection) - if x < 0 then + if x < 40 then self.xdirection = 1 end - if x > self.maxWidth - 80 then + if x > self.maxWidth - 40 then self.xdirection = -1 end - if y < 0 then + if y < 40 then self.ydirection = 1 end - if y > self.maxHeight - 80 then + if y > self.maxHeight - 40 then self.ydirection = -1 end self:setPosition(x, y) + self:setRotation(self:getRotation() + self.rspeed) end return M diff --git a/src/romdisk/examples/graphics/balls/bg.png b/src/romdisk/examples/graphics/balls/bg.png new file mode 100644 index 0000000000..596f170406 Binary files /dev/null and b/src/romdisk/examples/graphics/balls/bg.png differ diff --git a/src/romdisk/demos/graphics/balls/init.lua b/src/romdisk/examples/graphics/balls/init.lua similarity index 61% rename from src/romdisk/demos/graphics/balls/init.lua rename to src/romdisk/examples/graphics/balls/init.lua index 32a04818e6..3b9a8725d2 100644 --- a/src/romdisk/demos/graphics/balls/init.lua +++ b/src/romdisk/examples/graphics/balls/init.lua @@ -5,6 +5,13 @@ local M = Class(DisplayObject) function M:init() self.super:init() + local w, h = application:getScreenSize() + local assets = application:getAssets() + + self:addChild(DisplayShape.new(w, h) + :setSource(Pattern.texture(assets:loadTexture("graphics/balls/bg.png")):setExtend(Pattern.EXTEND_REPEAT)) + :paint()) + self:addChild(Ball.new("graphics/balls/ball1.png")) self:addChild(Ball.new("graphics/balls/ball2.png")) self:addChild(Ball.new("graphics/balls/ball3.png")) diff --git a/src/romdisk/examples/graphics/balls/main.lua b/src/romdisk/examples/graphics/balls/main.lua deleted file mode 100644 index a44f78d611..0000000000 --- a/src/romdisk/examples/graphics/balls/main.lua +++ /dev/null @@ -1,8 +0,0 @@ -local stage = application:getStage() -local Ball = require("Ball") - -stage:addChild(Ball.new("ball1.png")) -stage:addChild(Ball.new("ball2.png")) -stage:addChild(Ball.new("ball3.png")) -stage:addChild(Ball.new("ball4.png")) -stage:addChild(Ball.new("ball5.png")) diff --git a/src/romdisk/examples/graphics/cursor/init.lua b/src/romdisk/examples/graphics/cursor/init.lua new file mode 100644 index 0000000000..a7244d666c --- /dev/null +++ b/src/romdisk/examples/graphics/cursor/init.lua @@ -0,0 +1,23 @@ +local M = Class(DisplayObject) + +function M:init() + self.super:init() + + local w, h = application:getScreenSize() + local assets = application:getAssets() + + local w, h = application:getScreenSize() + self:addChild(DisplayShape.new(w, h):setSourceColor(1, 1, 1):paint()) + + local cursor = assets:loadDisplay("graphics/cursor/cursor.png") + :addEventListener(Event.MOUSE_DOWN, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.MOUSE_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.MOUSE_UP, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.TOUCHES_BEGIN, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.TOUCHES_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.TOUCHES_END, function(d, e) d:setPosition(e.info.x, e.info.y) end) + :addEventListener(Event.TOUCHES_CANCEL, function(d, e) d:setPosition(e.info.x, e.info.y) end) + self:addChild(cursor) +end + +return M diff --git a/src/romdisk/examples/graphics/cursor/main.lua b/src/romdisk/examples/graphics/cursor/main.lua deleted file mode 100644 index e4ba49def1..0000000000 --- a/src/romdisk/examples/graphics/cursor/main.lua +++ /dev/null @@ -1,13 +0,0 @@ -local stage = application:getStage() -local assets = application:getAssets() - -local cursor = assets:loadDisplay("cursor.png") - :addEventListener(Event.MOUSE_DOWN, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.MOUSE_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.MOUSE_UP, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.TOUCHES_BEGIN, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.TOUCHES_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.TOUCHES_END, function(d, e) d:setPosition(e.info.x, e.info.y) end) - :addEventListener(Event.TOUCHES_CANCEL, function(d, e) d:setPosition(e.info.x, e.info.y) end) - -stage:addChild(cursor) diff --git a/src/romdisk/demos/scene1.lua b/src/romdisk/examples/graphics/dragme/init.lua similarity index 86% rename from src/romdisk/demos/scene1.lua rename to src/romdisk/examples/graphics/dragme/init.lua index e6e7445c6e..588f9c8b47 100644 --- a/src/romdisk/demos/scene1.lua +++ b/src/romdisk/examples/graphics/dragme/init.lua @@ -3,11 +3,10 @@ local M = Class(DisplayObject) function M:init() self.super:init() - local width, height = application:getScreenSize() - local assets = application:getAssets() - self:addChild(assets:loadDisplay("scene1.png")) + local w, h = application:getScreenSize() + self:addChild(DisplayShape.new(w, h):setSourceColor(0.8, 0.7, 0.5):paint()) - for i=1,5 do + for i = 1, 5 do local shape = DisplayShape.new(100, 50) :setLineWidth(6) :rectangle(0, 0, 100, 50) @@ -15,7 +14,7 @@ function M:init() :fillPreserve() :setSourceColor(0, 0, 0) :stroke() - :setPosition(math.random(0, width - 100), math.random(0, height - 50)) + :setPosition(math.random(0, w - 100), math.random(0, h - 50)) shape:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, shape) shape:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, shape) diff --git a/src/romdisk/examples/graphics/dragme/main.lua b/src/romdisk/examples/graphics/dragme/main.lua deleted file mode 100644 index dc560bbde8..0000000000 --- a/src/romdisk/examples/graphics/dragme/main.lua +++ /dev/null @@ -1,86 +0,0 @@ -local stage = application:getStage() -local width, height = application:getScreenSize() - -local function onMouseDown(self, e) - if self:hitTestPoint(e.info.x, e.info.y) then - self.touchid = -1 - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -local function onMouseMove(self, e) - if self.touchid == -1 then - local dx = e.info.x - self.x0 - local dy = e.info.y - self.y0 - self:setX(self:getX() + dx) - self:setY(self:getY() + dy) - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -local function onMouseUp(self, e) - if self.touchid == -1 then - self.touchid = nil - e:stopPropagation() - end -end - -local function onTouchesBegin(self, e) - if self:hitTestPoint(e.info.x, e.info.y) then - self.touchid = e.info.id - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -local function onTouchesMove(self, e) - if self.touchid == e.info.id then - local dx = e.info.x - self.x0 - local dy = e.info.y - self.y0 - self:setX(self:getX() + dx) - self:setY(self:getY() + dy) - self.x0 = e.info.x - self.y0 = e.info.y - e:stopPropagation() - end -end - -local function onTouchesEnd(self, e) - if self.touchid == e.info.id then - self.touchid = nil - e:stopPropagation() - end -end - -local function onTouchesCancel(self, e) - if self.touchid == e.info.id then - self.touchid = nil - e:stopPropagation() - end -end - -for i=1,5 do - local shape = DisplayShape.new(100, 50) - :setLineWidth(6) - :rectangle(0, 0, 100, 50) - :setSourceColor(1, 0, 0, 0.5) - :fillPreserve() - :setSourceColor(0, 0, 0) - :stroke() - :setPosition(math.random(0, width - 100), math.random(0, height - 50)) - - shape:addEventListener(Event.MOUSE_DOWN, onMouseDown, shape) - shape:addEventListener(Event.MOUSE_MOVE, onMouseMove, shape) - shape:addEventListener(Event.MOUSE_UP, onMouseUp, shape) - shape:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin, shape) - shape:addEventListener(Event.TOUCHES_MOVE, onTouchesMove, shape) - shape:addEventListener(Event.TOUCHES_END, onTouchesEnd, shape) - shape:addEventListener(Event.TOUCHES_CANCEL, onTouchesCancel, shape) - - stage:addChild(shape) -end diff --git a/src/romdisk/demos/main.lua b/src/romdisk/examples/main.lua similarity index 79% rename from src/romdisk/demos/main.lua rename to src/romdisk/examples/main.lua index a76784e82c..7bab2b1b1a 100644 --- a/src/romdisk/demos/main.lua +++ b/src/romdisk/examples/main.lua @@ -1,15 +1,15 @@ local TestCase = require("TestCase") local stage = application:getStage() -local assets = application:getAssets() local width, height = application:getScreenSize() -application:setBackgroundColor(0.8, 0.8, 0.8) local testcases = TestCase.new({ - require("scene1"), - require("scene2"), - require("widgets.button"), require("graphics.balls"), + require("graphics.cursor"), + require("graphics.dragme"), + require("widgets.button"), + require("widgets.checkbox"), + require("widgets.radiobutton"), }) stage:addChild(testcases) @@ -19,4 +19,4 @@ stage:addChild(prevbtn) local nextbtn = Widget.Button.new({x = width - 150, y = height - 100, width = 100, height = 50}) :addEventListener("Click", function(d, e) testcases:next() end) -stage:addChild(nextbtn) +stage:addChild(nextbtn) \ No newline at end of file diff --git a/src/romdisk/demos/widgets/button/init.lua b/src/romdisk/examples/widgets/button/init.lua similarity index 77% rename from src/romdisk/demos/widgets/button/init.lua rename to src/romdisk/examples/widgets/button/init.lua index 29478a5e80..f21eb578c2 100644 --- a/src/romdisk/demos/widgets/button/init.lua +++ b/src/romdisk/examples/widgets/button/init.lua @@ -3,8 +3,8 @@ local M = Class(DisplayObject) function M:init() self.super:init() - local width, height = application:getScreenSize() - local assets = application:getAssets() + local w, h = application:getScreenSize() + self:addChild(DisplayShape.new(w, h):setSourceColor(1, 0.647, 0):paint()) local button = Widget.Button.new({x = 100, y = 100, width = 100, height = 50}) :addEventListener("Press", function(d, e) print("Button [Press]") end) diff --git a/src/romdisk/examples/widgets/button/main.lua b/src/romdisk/examples/widgets/button/main.lua deleted file mode 100644 index 5287d6d134..0000000000 --- a/src/romdisk/examples/widgets/button/main.lua +++ /dev/null @@ -1,8 +0,0 @@ -local stage = application:getStage() -local width, height = application:getScreenSize() - -local button = Widget.Button.new({x = 100, y = 100, width = 100, height = 50}) - :addEventListener("Press", function(d, e) print("Button [Press]") end) - :addEventListener("Release", function(d, e) print("Button [Release]") end) - :addEventListener("Click", function(d, e) print("Button [Click]") end) -stage:addChild(button) diff --git a/src/romdisk/examples/widgets/checkbox/init.lua b/src/romdisk/examples/widgets/checkbox/init.lua new file mode 100644 index 0000000000..c788231ea6 --- /dev/null +++ b/src/romdisk/examples/widgets/checkbox/init.lua @@ -0,0 +1,14 @@ +local M = Class(DisplayObject) + +function M:init() + self.super:init() + + local w, h = application:getScreenSize() + self:addChild(DisplayShape.new(w, h):setSourceColor(0.654, 1, 0):paint()) + + local checkbox = Widget.CheckBox.new({x = 100, y = 100}) + :addEventListener("Change", function(d, e) print("CheckBox changed:", e.info.checked) end) + self:addChild(checkbox) +end + +return M diff --git a/src/romdisk/examples/widgets/checkbox/main.lua b/src/romdisk/examples/widgets/checkbox/main.lua deleted file mode 100644 index 4e7f073564..0000000000 --- a/src/romdisk/examples/widgets/checkbox/main.lua +++ /dev/null @@ -1,6 +0,0 @@ -local stage = application:getStage() -local width, height = application:getScreenSize() - -local checkbox = Widget.CheckBox.new({x = 100, y = 100}) - :addEventListener("Change", function(d, e) print("CheckBox changed:", e.info.checked) end) -stage:addChild(checkbox) diff --git a/src/romdisk/examples/widgets/radiobutton/init.lua b/src/romdisk/examples/widgets/radiobutton/init.lua new file mode 100644 index 0000000000..fdcbdc0889 --- /dev/null +++ b/src/romdisk/examples/widgets/radiobutton/init.lua @@ -0,0 +1,14 @@ +local M = Class(DisplayObject) + +function M:init() + self.super:init() + + local w, h = application:getScreenSize() + self:addChild(DisplayShape.new(w, h):setSourceColor(0.4, 0.647, 0.5):paint()) + + local radiobutton = Widget.RadioButton.new({x = 100, y = 100}) + :addEventListener("Change", function(d, e) print("RadioButton changed:", e.info.checked) end) + self:addChild(radiobutton) +end + +return M diff --git a/src/romdisk/examples/widgets/radiobutton/main.lua b/src/romdisk/examples/widgets/radiobutton/main.lua deleted file mode 100644 index 381825dc43..0000000000 --- a/src/romdisk/examples/widgets/radiobutton/main.lua +++ /dev/null @@ -1,6 +0,0 @@ -local stage = application:getStage() -local width, height = application:getScreenSize() - -local radiobutton = Widget.RadioButton.new({x = 100, y = 100}) - :addEventListener("Change", function(d, e) print("RadioButton changed:", e.info.checked) end) -stage:addChild(radiobutton)