Skip to content
Browse files

modified: ../DisplayManX.lua

	modified:   ../OpenVGApp.lua
	new file:   test_moveview.lua
	modified:   test_tiger.lua
  • Loading branch information...
1 parent 2a2094a commit 26123a678dd7fb9808d895798c8e1ba7f13cab6c @Wiladams committed Nov 10, 2012
Showing with 114 additions and 18 deletions.
  1. +9 −6 DisplayManX.lua
  2. +4 −0 OpenVGApp.lua
  3. +60 −0 tests/test_moveview.lua
  4. +41 −12 tests/test_tiger.lua
View
15 DisplayManX.lua
@@ -587,6 +587,11 @@ DMXView.new = function(display, x, y, width, height, layer, pformat, resource, o
end
DMXView.CopyPixelBuffer = function(self, pbuff, x, y, width, height)
+ x = x or 0
+ y = y or 0
+ width = width or pbuff.Width;
+ height = height or pbuff.Height;
+
self.Resource:CopyPixelBuffer(pbuff, x, y, width, height)
end
@@ -636,9 +641,9 @@ DMXView.MoveTo = function(self, x, y)
return false;
end
-print("DMXView.MoveTo() - ", x, y, self.Width, self.Height);
+--print("DMXView.MoveTo() - ", x, y, self.Width, self.Height);
- local dst_rect = VC_RECT_T(0, 0, self.Width, self.Height);
+ local dst_rect = VC_RECT_T(x, y, self.Width, self.Height);
local src_rect = VC_RECT_T( 0, 0, lshift(self.Width, 16), lshift(self.Height, 16) );
self.X = x;
@@ -647,19 +652,17 @@ print("DMXView.MoveTo() - ", x, y, self.Width, self.Height);
local mask = 0;
local transform = self.Transform or ffi.C.VC_IMAGE_ROT0;
-print("change_flags: ", change_flags);
+--print("change_flags: ", change_flags);
local success, err = DisplayManX.element_change_attributes(update.Handle, self.Surface.Handle,
change_flags,
self.Layer,
self.Opacity,
- dest_rect,
+ dst_rect,
src_rect,
mask,
transform);
---print("DMXView:MoveTo(), ", success, err);
-
update:SubmitSync();
end
View
4 OpenVGApp.lua
@@ -8,6 +8,7 @@ local band = bit.band
-- Bring in the necessary UI stuff
local rpiui = require "rpiui"
+local DMX = require "DisplayManX"
local Keyboard = require "Keyboard"
local EventLoop = require "EventLoop"
@@ -26,6 +27,9 @@ OpenVGApp.init = function(width, height, x, y)
width = width or 640;
height = height or 480;
+ -- Setup Display object
+ OpenVGApp.Display = DMX.DMXDisplay();
+
-- Setup the event loop stuff
OpenVGApp.Loop = EventLoop.new(15);
OpenVGApp.Keyboard = Keyboard.new();
View
60 tests/test_moveview.lua
@@ -0,0 +1,60 @@
+package.path = package.path..";../?.lua"
+
+local ffi = require "ffi"
+local DMX = require "DisplayManX"
+
+local Display = DMX.DMXDisplay();
+
+local screenWidth, screenHeight = Display:GetSize();
+local ratio = screenWidth / screenHeight;
+local displayHeight = 320;
+local displayWidth = 640;
+
+
+-- Create resource used for capturing screen
+local resource = DMXResource(displayWidth, displayHeight);
+
+-- Do the snapshot
+Display:Snapshot(resource);
+
+-- Get the pixel data so it can be copied
+-- to multiple views
+local pixeldata, err = resource:ReadPixelData();
+
+
+local viewCount = 20
+local views = {}
+
+for i=1,viewCount do
+ local x = math.random(0,screenWidth -1);
+ local y = math.random(0,screenHeight - 1);
+
+--print(string.format("[%d, %d]", x, y));
+
+ x = x - displayWidth/2
+ if x < 0 then
+ x = 0
+ elseif x + displayWidth/2 > screenWidth-1 then
+ x = screenWidth-1-displayWidth
+ end
+
+ y = y - displayHeight/2
+ if y < 0 then
+ y = 0
+ elseif y + displayHeight > screenHeight-1 then
+ y = screenHeight-1-displayHeight
+ end
+
+
+ local view = Display:CreateView(displayWidth, displayHeight, x, y)
+ view:CopyPixelBuffer(pixeldata);
+ table.insert(views, view);
+
+ -- Wait a bit
+ --ffi.C.sleep(1);
+end
+
+ffi.C.sleep(3);
+
+
+
View
53 tests/test_tiger.lua 100755 → 100644
@@ -21,17 +21,19 @@ local VG = EGL.Lib;
local PS = require "PSLoader";
-local screenWidth = 640;
-local screenHeight = 480;
+local viewWidth = 640;
+local viewHeight = 480;
-local app = OpenVGApp.init(screenWidth, screenHeight, 10, 10);
+local app = OpenVGApp.init(viewWidth, viewHeight, 10, 10);
+
+local screenWidth, screenHeight = app.Display:GetSize();
local tigerModel = require "tiger";
local tigerscene = {
- Width = screenWidth;
- Height = screenHeight;
+ Width = viewWidth;
+ Height = viewHeight;
rotateN = 0.0;
rotateFactor = 3;
ClearColor = ffi.new("VGfloat[4]", 1,1,1,1);
@@ -83,29 +85,56 @@ app.OnIdle = function(vgapp)
tigerscene.rotateN = tigerscene.rotateN + (1.0 * tigerscene.rotateFactor);
end
+local XIncrement = 5;
+local YIncrement = 5;
+
app.OnKeyUp = function(kbd, keycode)
+--print("KEY: ", keycode);
-- Halt the loop if they press the "Esc" key
if keycode == KEY_ESC then
return app:Stop();
end
+ local x = app.Window.X
+ local y = app.Window.Y;
+
-- Move the window around the screen
-- using the keyboard arrow keys
if keycode == KEY_RIGHT then
- local x = app.Window.X + 1;
- local y = app.Window.Y;
-
- return app.Window:MoveTo(x, y)
+ x = app.Window.X + XIncrement;
end
if keycode == KEY_LEFT then
- local x = app.Window.X - 1;
- local y = app.Window.Y;
+ x = app.Window.X - XIncrement;
+ end
+
+ if keycode == KEY_HOME then
+ x = 0
+ end
+
+ if keycode == KEY_END then
+ x = screenWidth - app.Window.Width;
+ end
+
+ if keycode == KEY_UP then
+ y = y - YIncrement;
+ end
+
+ if keycode == KEY_DOWN then
+ y = y + YIncrement
+ end
+
+ if keycode == KEY_PAGEUP then
+ y = 0;
+ end
- return app.Window:MoveTo(x,y)
+ if keycode == KEY_PAGEDOWN then
+ y = screenHeight - app.Window.Height
end
+ -- Move the window
+ app.Window:MoveTo(x,y);
-- Change direction of rotation when space
-- bar is pressed

0 comments on commit 26123a6

Please sign in to comment.
Something went wrong with that request. Please try again.