Mach 4 Build 1936
When using a Lua Panel, the initial size is set by the screen editor. When panel resized, when the Mach 4 is loaded or resized, the Lua Panel (as pointed to by mcLuaPanelParent) does not resize appropriately.
To test, drop a Lua Panel into a screen set. Insert the code below as the script property of the Lua Panel. Use your own image, set the size of the Lua Panel smaller than your image to force it to crop. My image was 380x380 pixels, my panel is 350x350 px. Exit the screen editor to cause Mach 4 to resize the contents of the screen set.
Note that image is cropped to the initial size of the Lua Panel, and is surrounded on the left and bottom by blank space. Clicking on the image causes the onLeftUP() event handler to fire and show the X/Y coordinates of the click. Clicking outside of the image, in the solid blank area, returns no feed back.
local panel = mcLuaPanelParent
function onPaint (event)
local dc = wx.wxPaintDC(panel);
local image = wx.wxImage();
if (not image:LoadFile('./screens/MyStdMill/images/MSM_Probe_1.png', wx.wxBITMAP_TYPE_PNG)) then
wx.wxLogError("Could not load image from '%s'!", imagePath);
dc:delete();
return;
end
--image:Resize(panel.getSize());
local bitmap = wx.wxBitmap(image);
dc:DrawBitmap (bitmap, 0,0, true);
dc:delete ();
end
function onLeftUp (event)
local mouseX = event:GetX();
local mouseY = event:GetY();
wx.wxMessageBox("LEFT CLICK - X: "..tostring(mouseX)..", Y: "..tostring(mouseY));
end
function onSize (event)
local size = panel.getSize();
wx.wxMessageBox('Width: %d, Height: %d', size.getWidth(), size.getHeight());
event:skip();
end
-- connect the paint event handler function with the paint event
panel:Connect(wx.wxEVT_PAINT, onPaint)
panel:Connect(wx.wxEVT_LEFT_UP, onLeftUp);
panel:Connect(wx.wxEVT_SIZE, onSize);
-Freeman