On Sun, Mar 1, 2009 at 3:22 PM, lostgallifreyan
<lostgallifre...@gmail.com> wrote:
>
> First, the code, in FULL because the one thing that made my day most 
> difficult is snippets out of context. So much easier if a copy/paste of a 
> working example can be had, then debugging is simple, focus on what change 
> breaks something. For small examples I see no better way than this..
>
> function main()
>  FRAME=wx.wxFrame(wx.NULL,-1,"GPS 
> Plot",wx.wxDefaultPosition,wx.wxSize(1024,768),wx.wxDEFAULT_FRAME_STYLE)
>  FRAME:Centre()  FRAME:Show(true)
>  FRAME:CreateStatusBar()
>
>  BITMAP=wx.wxBitmap("../Charts/Ashton Court.gif",wx.wxBITMAP_TYPE_GIF)
>  local X,Y=BITMAP:GetWidth(),BITMAP:GetHeight()
>  SCROLL=wx.wxScrolledWindow(FRAME,-1)  SCROLL:SetScrollbars(1,1,X,Y)
>  CHART=wx.wxPanel(SCROLL,-1,wx.wxPoint(0,0),wx.wxSize(X,Y))
>
>  CHART:Connect(wx.wxEVT_LEFT_DOWN,OnLeftDown)
>  CHART:Connect(wx.wxEVT_MOTION,OnMotion)
>  CHART:Connect(wx.wxEVT_PAINT,OnPaint)
> end
>
> --====================  Mouse Handling  ====================--
>
> MX,MY,VX,VY=0,0,0,0
>
> function OnLeftDown(event)
>  MX,MY,VX,VY=wx.wxGetMousePosition():GetX(),wx.wxGetMousePosition():GetY(),SCROLL:GetViewStart()
> end
>
> function OnMotion(event)
>  if event:LeftIsDown() then
>    
> SCROLL:Scroll(VX+MX-wx.wxGetMousePosition():GetX(),VY+MY-wx.wxGetMousePosition():GetY())
>  end
> end
>
> --====================  Track Drawing  =====================--
>
> function OnPaint(event)
>  local DC=wx.wxPaintDC(CHART)
>  DC:DrawBitmap(BITMAP,0,0,false)

-- YOU MUST DELETE THE PEN and COLOUR!
    local c = wx.wxColour(255,0,0)
    local p = wx.wxPen(c,1,wx.wxSOLID)
>  DC:SetPen(p)
    p:delete()
    c:delete()
>  DC:DrawLine(0,0,600,600)
>  DC:delete()
> end
>
> --==========================================================--
>
> main()
>
>
>
> The questions:
> Why does it need s status bar? It still borks and displays nothing without 
> that being there, and I still can't see why..

Move FRAME:Show(true) to the end of the main() function, this forces a
refresh and everything will be laid out by then.

> Is there a way to make the BITMAP draw once and still work, so I can delete 
> it once it's drawn to the DC for the CHART panel? Is this even in line with 
> the advice on deleting large bitmaps to save resources in MSW?

No, you have to repaint it every time a wxPaintEvent is sent. This is
normal for GUI programs and even if somebody else drew it for you it'd
still have to store the bitmap.

You should also add a wx.wxEVT_ERASE_BACKGROUND handler that does
nothing, the same as event:Skip(false), to reduce flicker.

> Is it wise to expand the OnPaint() function to assign the wxPen and wxColour 
> to variables on creation so I can delete them individually? I'm not clear as 
> to whether they are orphaned and consuming resources after the DC:delete(). I 
> do suspect that something persists, as after a few tens of loads in a 
> session, the script was failing to draw the chart, only the line.

You MUST always delete these, see above and the docs,
http://wxlua.sourceforge.net/docs/wxlua.html, and search for "Must
delete".

> And, why DC:delete() not DC:Delete() like XYZ:Refresh() or ABC:Show()...? :) 
> Small case-sensitive gotchas like this are one thing that really makes it 
> tough to debug stuff for newcomers.

"delete" is a reserved word in C++ so it cannot be a function name.
Therefore, wxLua can add it as a function to the userdata without any
worries that we will hide any existing functions.

> If the code is now correct, I want to focus on scaling, so should I do this 
> by converting the loaded bitmap to a wxImage() or would it be faster just to 
> load prescaled bitmaps? If the former, can you give me a minimal template for 
> building the needed conversions into the current code? I can convert to image 
> but I'm not clear at what point the image should be deleted after 
> reconversion to bitmap, or even how to reconvert it.

I would load the original as a wxImage and convert it to a wxBitmap
for drawing, saving both of these. If the zoom changes, use the
wxImage functions to rescale into the same wxBimap and use this to
draw into your DC. That way your wxBitmap is ready to go when it comes
time to paint. If you plan to zoom way in or the image is huge you may
want to crop the wxImage to a temporary wxImage of the size and
position of the scrolled window before scaling it, then create the
wxBitmap for drawing, but note that you will have to do this in real
time for scrolling.

> You mentioned cropping. This sounds good if it allows a speed gain by 
> avoiding having to draw the whole of a large image. Will it do that though? I 
> imagine that the dragging of the image will cause this image crop and display 
> to occur with every pixel-shift of motion, and not be fast at all.

I have had success with doing what I mentioned above, it has been fast enough.

Hope this helps,
    John

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to