John Labenski <jlaben...@gmail.com> wrote: (11/05/2009 01:16) >A few comments about your code. You should call wxFrame::Show(true) as the >last line in your window creation code to allow it to be laid out properly.
Ok, I'd chosen to do it earlier to avoid flow conflicts so I could show some info in a frame while the bitmap loaded and data got processed, but I've learned enough about changing pre-created stuff to show it and change it later, so the new code (complete rewrite, as explained below) does this now. >You should use the wxMouseEvent's position function. > True. In some of my tests I do, that one had some older code lines. I had to correct this same thing a few hours ago in the new scheme I've worked up. >You select a wxBitmap into the wxMemoryDC before using it right? wxBitmaps >may not be initialized on creation so it's full of random bits, but I am not >sure of this. You can always draw a rectangle to clear it. Yes, I did that to test it but what's interesting is what happens when you don't. :) Specifically what's really cool is what happens when two panels are used, same size, same parent. That was my initial, original attempt, and I saw this strange behaviour that I decided to exploit. The Layer (overlay) panel is created FIRST, but 'appears' on top, I connect all user-control events to the layer, not the visible panel. In OnPaint() I draw the bitmap to the Chart panel then draw stuff on the Layer panel so it appears to draw on the image directly, but does not, as the right mouse click will demonstrate in the new code. Regarding the other mails about the Rat-racing Mousewheel, I tried event:Skip(false) but that also failed to stop it, but I'd already written something new, bypassing the issue entirely, as you say, I needed to avoid conflict with existing behaviour, so I went for a basic direct method. I'll describe how, and first why: If I do DrawBitmap(BITMAP,0,0,false) with the DC being a panel that was scrolled to 20,20, I'd expect to see the bitmap offset by 20 pixels in each axis along with the panel. This I did not see. I found that the 0,0 in DrawBitmap() overrode it, so I decided to forget the ScrolledWindow() AND the general Panel:ScrollWindow() method. I decided to modify the DrawBitmap axis values directly and base all my calculations around that. Not only does it work, but it performs better by far than the original ScrolledWindow did, no fighting with inbuilt behaviour, and it's faster, and does not have the horrible dual-tracked flicker that moving the ScrolledWindow did when grabbing it and scrolling both axes at once. it works as clean and fast as in any program I've seen on this system now. function Main() FRAME=wx.wxFrame(wx.NULL,-1,"",wx.wxDefaultPosition,wx.wxSize(800,600),wx.wxDEFAULT_FRAME_STYLE) FRAME:CreateStatusBar() FRAME:SetStatusText(" ") LAYER=wx.wxPanel(FRAME,-1,wx.wxPoint(0,0)) PANEL=wx.wxPanel(FRAME,-1,wx.wxPoint(0,0)) TT=wx.wxToolTip(" \n") LAYER:SetToolTip(TT) FRAME:Centre() FRAME:Show(true) BITMAP=wx.wxBitmap("Something big, maybe 9000,6000 pixels.jpg") BX,BY,LX,LY,OX,OY,MX,MY=BITMAP:GetWidth(),BITMAP:GetHeight(),0,0,0,0,0,0 TOGGLE=1 FRAME:Connect(wx.wxEVT_SIZE,ReSize) LAYER:Connect(wx.wxEVT_RIGHT_DOWN,function(E) TOGGLE=1-TOGGLE PANEL:Refresh() LAYER:Refresh() end) LAYER:Connect(wx.wxEVT_MOTION,OnMotion) LAYER:Connect(wx.wxEVT_ERASE_BACKGROUND,function() end) PANEL:Connect(wx.wxEVT_ERASE_BACKGROUND,function() end) LAYER:Connect(wx.wxEVT_PAINT,OnPaint) collectgarbage("collect") end TABLE={{}} TABLE[0]={} for X=0,1270,20 do table.insert(TABLE[1],X) table.insert(TABLE[1],0) table.insert(TABLE[1],X) table.insert(TABLE[1],1023) end for Y=0,1014,20 do table.insert(TABLE[0],0) table.insert(TABLE[0],Y) table.insert(TABLE[0],1279) table.insert(TABLE[0],Y) end function ReSize(E) CX,CY=FRAME:GetClientSizeWH() PANEL:SetClientSize(CX,CY) LAYER:SetClientSize(CX,CY) CX,CY=CX-BX,CY-BY if LX<(CX) then LX=CX end if LY<(CY) then LY=CY end LAYER:Refresh() PANEL:Refresh() end --==================== Mouse Handling ====================-- function OnMotion(E) if E:LeftIsDown() then LX,LY=OX+E:GetX()-MX,OY+E:GetY()-MY TT:SetTip("") if LX>0 then LX=0 end if LY>0 then LY=0 end if LX<(CX) then LX=CX end if LY<(CY) then LY=CY end PANEL:Refresh() LAYER:Refresh() else OX,OY=LX,LY MX,MY=E:GetX(),E:GetY() TT:SetTip("X = "..E:GetX()-OX.."\nY = "..E:GetY()-OY) end end --==================== Track Drawing =====================-- function OnPaint(E) local DC=wx.wxPaintDC(PANEL) if BITMAP then DC:DrawBitmap(BITMAP,LX,LY,false) end DC:delete() local DC,P=wx.wxPaintDC(LAYER),wx.wxPen() P:SetColour(255,0,0) P:SetWidth(1) DC:SetPen(P) for N=1,#TABLE[TOGGLE]-2,2 do DC:DrawLine(TABLE[TOGGLE][N]+LX,TABLE[TOGGLE][N+1]+LY,TABLE[TOGGLE][N+2]+LX,TABLE[TOGGLE][N+3]+LY) end DC:delete() P:delete() end Main() I invite you to try to break it. :) So far as I can tell it's resistant to any kind of strange stuff like starting a drag from the status bar onto the client area, a trick which even Scribble will balk at, I found, at least, it will if it's done before the first line is drawn. Another thing I found is that the current method allows a lot of reduction, it's the simplest as well as the best form I've done to date, withu no strange responses to user input if it's resized or if the drag movement goes beyond the edge and stops, or returns. So long as that dual-panel transparency trick doesn't invoke something it shouldn't, I'm going to stay with it, though I do have a fallback plan of grabbing a client-area-sized peice of the bitmap as overlay to draw on if I must. That would be slower though. ------------------------------------------------------------------------------ The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users