local frame = nil; local panel = nil; local m_id = 0; local inst = mc.mcGetInstance(inst); local imageFileName = 'holesnew.jpg'; local imageBasePath = 'C:/Mach4Hobby1953/Wizards/'; function GetNextID() m_id = m_id+1; return m_id; end if (mcLuaPanelParent == nil) then imageBasePath = imageBasePath; end local image = wx.wxImage(); if (not image:LoadFile(imageBasePath..imageFileName, wx.wxBITMAP_TYPE_JPEG)) then mc.mcCntlSetLastError(inst, "Could not load image from !" .. imageFileName); dc:delete(); return; end local bitmap = wx.wxBitmap(image);--wx.wxBitmap local wsize = wx.wxSize(image:GetWidth(), image:GetHeight()); function main() if(mcLuaPanelParent == nil)then frame = wx.wxFrame( wx.NULL, -- no parent wx.wxID_ANY, -- whatever for wxWindow ID "My Frame Caption", -- frame caption wx.wxDefaultPosition, -- place the frame in default position wsize, -- wx.wxDefaultSize, -- default frame size wx.wxDEFAULT_FRAME_STYLE+wx.wxSTAY_ON_TOP); -- def, stay on top --remove +wx.wxSTAY_ON_TOP if you want them to NOT stay on top panel = wx.wxPanel(frame, wx.wxID_ANY); fileMenu = wx.wxMenu(); fileMenu:Append(wx.wxID_EXIT, "E&xit", "Some Exit Message"); local menuBar = wx.wxMenuBar(); frame:SetMenuBar(menuBar); frame:CreateStatusBar(1); frame:SetStatusText("Some Status Text"); frame:Connect( wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) frame:Close(true); end ); frame:Connect( wx.wxEVT_CLOSE_WINDOW, function (event) event:Skip(); end ); else panel = mcLuaPanelParent; local window = panel:GetParent(); local wsize = window:GetSize(); panel:SetSize(wsize); panel:Connect( wx.wxEVT_CLOSE_WINDOW, function (event) event:Skip(); end ); end mainSizer = wx.wxBoxSizer(wx.wxVERTICAL); GridSizer = wx.wxFlexGridSizer( 2, 1, 0, 0 );--2 rows, 1 column, no x/y spacing between local ID_PROBING_PANEL = GetNextID (); local probingPanel = wx.wxPanel ( panel, ID_PROBING_PANEL, wx.wxDefaultPosition, panel:GetSize(), --wx.wxSize(520, 520), 0, ''); GridSizer:Add( probingPanel, 0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL+wx.wxALIGN_LEFT, 2) buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL ); if (mcLuaPanelParent == nil) then-- Only add if this not a panel script. ID_CLOSE_BUTTON = GetNextID(); closeButton = wx.wxButton( panel, ID_CLOSE_BUTTON, "E&xit"); buttonSizer:Add( closeButton, 0, wx.wxALIGN_CENTER+wx.wxALL, 1 ); end mainSizer:Add(GridSizer, 0, wx.wxALIGN_CENTER+wx.wxLEFT+wx.wxRIGHT, 0); mainSizer:Add(buttonSizer, 0, wx.wxALIGN_RIGHT+wx.wxRIGHT, 0); --panel:SetSizer( mainSizer ); --panel:Fit(); if(mcLuaPanelParent == nil) then panel:Connect(ID_CLOSE_BUTTON, wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event) frame:Destroy() end); --frame:Fit(); --frame:Show(true); else local window = panel:GetParent(); window:Connect(wx.wxID_ANY, wx.wxEVT_SIZE, function(event) local wsize = event:GetSize(); local width = wsize:GetWidth();--ADDED THIS!!!!!!!!! local height = wsize:GetHeight();--ADDED THIS!!!!!!!!! panel:SetSize(wsize); panel:FitInside(); image:Rescale(width, height);--ADDED THIS!!!!!!!!! bitmap = wx.wxBitmap(image);--ADDED THIS!!!!!!!!! probingPanel:SetSize(wsize); local dc = wx.wxPaintDC(probingPanel);--ADDED THIS!!!!!!!!! dc:DrawBitmap (bitmap, 0,0, true);--ADDED THIS!!!!!!!!! dc:delete (); --ADDED THIS!!!!!!!!! probingPanel:FitInside(); end); end probingPanel:Connect(wx.wxEVT_PAINT, function (event) local dc = wx.wxPaintDC(probingPanel); dc:DrawBitmap (bitmap, 0,0, true); dc:delete (); end) probingPanel:Connect(wx.wxEVT_LEFT_DOWN, function (event) mouseXdn = event:GetX(); mouseYdn = event:GetY(); --wx.wxMessageBox("LEFT CLICK - X: "..tostring(mouseX)..", Y: "..tostring(mouseY)); mc.mcCntlSetLastError(inst,"Mouse Click Down Location is @ X: "..tostring(mouseXdn)..", Y: "..tostring(mouseYdn)); end); probingPanel:Connect(wx.wxEVT_LEFT_UP, function (event) local mouseXup = event:GetX(); local mouseYup = event:GetY(); local diffX = mouseXup-mouseXdn; local diffY = mouseYup-mouseYdn; --wx.wxMessageBox("LEFT CLICK - X: "..tostring(mouseX)..", Y: "..tostring(mouseY)); mc.mcCntlSetLastError(inst,"Mouse Click Up Location is @ X: "..tostring(mouseXup)..", Y: "..tostring(mouseYup)); mc.mcCntlSetLastError(inst,"Difference in X: "..tostring(diffX)..", Y: "..tostring(diffY)); end); end main(); wx.wxGetApp():MainLoop();