Hello Guest it is October 17, 2019, 02:14:09 AM

Author Topic: How are bitmap UI components expected to be used?  (Read 2769 times)

0 Members and 1 Guest are viewing this topic.

How are bitmap UI components expected to be used?
« on: July 27, 2014, 04:24:58 PM »
In my playground screen set, I have a touch off and probing screen.  In it I have a bitmap image of a simplified work piece and the probing operations that are possible off the work piece (surface, edge, corner probing, etc.).  I was hoping to be able to capture where I clicked on the image, but the bitmap component doesn't appear to support any feedback.  Am I barking up the wrong tree?

I guess I'm thinking of something similar to image maps in HTML.


-Freeman
« Last Edit: July 27, 2014, 04:36:57 PM by Analias »
I'm not a complete idiot...
    there are some parts missing.

Offline ger21

*
  • *
  •  6,288 6,288
    • View Profile
    • The CNC Woodworker
Re: How are bitmap UI components expected to be used?
« Reply #1 on: July 27, 2014, 04:44:07 PM »
A while back I think I requested the ability to use transparent buttons like you can do in Mach3. Hopefully they'll be able to implement them.

I also ran into some issues with layering buttons over bitmaps, or maybe it was bitmap buttons.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: How are bitmap UI components expected to be used?
« Reply #2 on: August 17, 2014, 12:28:26 AM »
I've made some progress on this.  It's not done by far, but I thought I would share for those who might be interested.

While chatting with Scott (poppabear) he mentioned the "Lua panels".  This got me thinking and I now have an embedded Lua panel loading my image and returning the mouse X and Y coordinates when the left mouse button is clicked.  This gets me closer to a component that can load an image and provide feed back when clicked on - think image maps like in HTML.  I'll probably use a second bitmap that mirrors the image shown and provides quick lookup if the user clicked in a roped off area or not.

To use this, add a Lua Panel to your screen set.  Cut-n-paste the code below into the script property of the panel.  Be sure to choose a different image.  My images are broken out into directory image of the screen set (ie. the .set file has been unzipped).  I will eventually need to know how to read a file from the zip if I want to keep my images in the screen set.  Brian, Steve, et al - if you have any guidance on how to read images from the screen set file, I would be very interested in hearing how.

I still need to wire in the proper events to catch resizing of the panel to resize the image on the fly.

Code: [Select]
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());
end

panel = mcLuaPanelParent

-- 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
I'm not a complete idiot...
    there are some parts missing.

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: How are bitmap UI components expected to be used?
« Reply #3 on: August 17, 2014, 08:44:30 AM »
Freeman,

To read in "Zip" files, in wx, look up "Resources", there are wx functions to read in resources from Zip files,
I.E. like Mach4 does.

Further, you can create "Transparent" Bit maps, in your Memory DC, and then place them, onto your "Probing" image.

One other thing, you can use a wx dc buffered that will help stop flicker.

Scott
« Last Edit: August 17, 2014, 08:47:14 AM by poppabear »
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: How are bitmap UI components expected to be used?
« Reply #4 on: August 17, 2014, 09:28:59 AM »
not quite following all this; but if you know the image name in the screenset image folder you can swap them with a scr.SetProperty function

    buttonImage = 'TOOLT9.BMP' -- known image name stored in the screen.set
    scr.SetProperty('bbutton29', 'Image', buttonImage);
Re: How are bitmap UI components expected to be used?
« Reply #5 on: August 17, 2014, 02:20:45 PM »
Scott,

I tried the following, assuming the screen set had already been loaded as a resource.  Unfortunately, it's failing bitmap:Ok() and showing the error.  Do you have an example of how to do this?

Code: [Select]
local wxXmlResource = wx.wxXmlResource:Get();
local imagePath = 'MSM_Probe_1.png';

function onPaint (event)
    local dc = wx.wxPaintDC(panel);

    local bitmap = wxXmlResource:LoadBitmap (imagePath);

    if (not bitmap or not bitmap:Ok()) then
        wx.wxLogError("Could not load image from '%s'!", imagePath);
        dc:delete();
        return;
    end

    dc:DrawBitmap (bitmap, 0,0, true);

    dc:delete ();
end

The error I get is:  XRC error: XRC resource "MSM_Probe_1.png" (class "wxBitmap") not found. 

I tried it with several paths variations with no luck.


-Freeman
I'm not a complete idiot...
    there are some parts missing.

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: How are bitmap UI components expected to be used?
« Reply #6 on: August 17, 2014, 03:52:10 PM »
try adding this at the top.

   wx.wxXmlResource:Get(InitAllHandlers());

if that doesn't work you may have to add the below before the one above (maybe),

   wx.wxFileSystem:AddHandler(wx.wxZipFSHandler);

Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/