Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: tst_wxPaint.rbw Type: application/octet-stream Size: 4446 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040622/abc8ba85/tst_wxPaint-0001.obj
Hello Shanko This is a copy of a post that was recently answered for me. =============================From: alex fenton (alex@delete.pressure.to) Subject: Re: Comparison of GLs for plotting (x,y,z) pts? View this article only Newsgroups: comp.lang.ruby Date: 2004-06-20 06:34:10 PST Todd Gardner wrote:> My goal is to have my application plot arrays of (x,y) and possibly > (x,y,z) data points in "real time". I would also like to write text > on the graphs. I would like to ask for a knowledgeable comparison and > contrast of the multitudes of graphic utility libraries out there > capable of doing this seemingly SIMPLE plotting....> WxRuby - I don''t know how to draw lines yet in this library.In WxRuby you could use a Device Context to draw lines, points, fills, ellipses, etc, plus text onto a frame. For a full list of methods available see the WxWidgets docs: http://www.wxwidgets.org/manuals/2.4.2/wx105.htm#wxdc I haven''t used these classes in detail, so I don''t know whether the bindings are complete, but the following simple example worked for me using wxruby-0.3.0 (current release is 0.4.0) chrz alex --------------------------- require ''wxruby'' class MyDrawingFrame < Wx::Frame def initialize(*args) super(*args) evt_paint { on_paint } end def on_paint paint do | dc | dc.clear dc.draw_line( 0, 0, 50, 100) dc.draw_line( 50, 100, 100, 75) dc.draw_text( ''a label'', 52, 102) end end end class MyApp < Wx::App def on_init() frame = MyDrawingFrame.new(nil, -1, ''Drawing'') frame.set_client_size( Wx::Size.new(200,200)) frame.show() end end MyApp.new().main_loop()============================= Todd -----Original Message----- From: wxruby-users-bounces@rubyforge.org [mailto:wxruby-users-bounces@rubyforge.org]On Behalf Of Shashank Date Sent: Tuesday, June 22, 2004 6:20 AM To: General discussion of wxRuby Cc: Shashank Date Subject: [Wxruby-users] Tracking Mouse motion I am writting a "scribble" like application using wxRuby 0.4.0 on Win XP Home. I would like to track the movement of the mouse over the canvas ** while the left button is pressed **. What events should I be looking for ? I have looked at EVT_MOTION and EVT_LEFT_DOWN and got them working individually. But I do not know how to look for the _combination_ of those two. DRAG_MOVE may be ? Also, how do I draw a _continuous_ line which tracks the mouse motion? I got it to draw spots at different (x,y) co-ords, but the result is, umm, spotty :-) See attached code. TIA, -- shanko -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20040622/164b7675/attachment.htm
Shashank Date wrote:> I am writting a "scribble" like application using wxRuby 0.4.0 on Win XP Home. > > I would like to track the movement of the mouse over the canvas > ** while the left button is pressed **. What events should I be looking for ? > I have looked at EVT_MOTION and EVT_LEFT_DOWN and got them working individually. > But I do not know how to look for the _combination_ of those two.I don''t have time to actually try code right now, but the wxMouseEvent page of the wxWindows docs suggests that you would want to catch EVT_MOTION, and in your handler you would call left_is_down to find out whether the user is dragging or not. Alternatively, you could also catch EVT_LEFT_DOWN and EVT_LEFT_UP and set and clear a flag in your class to indicate whether dragging is happening.> Also, how do I draw a _continuous_ line which tracks the mouse motion? > I got it to draw spots at different (x,y) co-ords, but the result is, > umm, spotty :-)I would probably remember the previous mouse position, and when a new motion event is caught, draw a line between the old point and the new point. Cheers, Kevin
Thanks, Todd ! I learnt about draw_text from your example. ----- Original Message ----- From: Todd G. Gardner To: General discussion of wxRuby Sent: Tuesday, June 22, 2004 9:02 AM Subject: RE: [Wxruby-users] Tracking Mouse motion Hello Shanko This is a copy of a post that was recently answered for me. ============================= From: alex fenton (alex@delete.pressure.to) Subject: Re: Comparison of GLs for plotting (x,y,z) pts? View this article only Newsgroups: comp.lang.ruby Date: 2004-06-20 06:34:10 PST Todd Gardner wrote:> My goal is to have my application plot arrays of (x,y) and possibly > (x,y,z) data points in "real time". I would also like to write text > on the graphs. I would like to ask for a knowledgeable comparison and > contrast of the multitudes of graphic utility libraries out there > capable of doing this seemingly SIMPLE plotting....> WxRuby - I don''t know how to draw lines yet in this library.In WxRuby you could use a Device Context to draw lines, points, fills, ellipses, etc, plus text onto a frame. For a full list of methods available see the WxWidgets docs: http://www.wxwidgets.org/manuals/2.4.2/wx105.htm#wxdc I haven''t used these classes in detail, so I don''t know whether the bindings are complete, but the following simple example worked for me using wxruby-0.3.0 (current release is 0.4.0) chrz alex --------------------------- require ''wxruby'' class MyDrawingFrame < Wx::Frame def initialize(*args) super(*args) evt_paint { on_paint } end def on_paint paint do | dc | dc.clear dc.draw_line( 0, 0, 50, 100) dc.draw_line( 50, 100, 100, 75) dc.draw_text( ''a label'', 52, 102) end end end class MyApp < Wx::App def on_init() frame = MyDrawingFrame.new(nil, -1, ''Drawing'') frame.set_client_size( Wx::Size.new(200,200)) frame.show() end end MyApp.new().main_loop()============================= Todd -----Original Message----- From: wxruby-users-bounces@rubyforge.org [mailto:wxruby-users-bounces@rubyforge.org]On Behalf Of Shashank Date Sent: Tuesday, June 22, 2004 6:20 AM To: General discussion of wxRuby Cc: Shashank Date Subject: [Wxruby-users] Tracking Mouse motion I am writting a "scribble" like application using wxRuby 0.4.0 on Win XP Home. I would like to track the movement of the mouse over the canvas ** while the left button is pressed **. What events should I be looking for ? I have looked at EVT_MOTION and EVT_LEFT_DOWN and got them working individually. But I do not know how to look for the _combination_ of those two. DRAG_MOVE may be ? Also, how do I draw a _continuous_ line which tracks the mouse motion? I got it to draw spots at different (x,y) co-ords, but the result is, umm, spotty :-) See attached code. TIA, -- shanko ------------------------------------------------------------------------------ _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20040622/9cc5cebc/attachment.htm
Hi Kevin, Thanks for responding inspite of your busy schedule (moving and all..) ----- Original Message ----- From: "Kevin Smith" <wxruby@qualitycode.com> To: "General discussion of wxRuby" <wxruby-users@rubyforge.org> Sent: Tuesday, June 22, 2004 11:13 AM Subject: Re: [Wxruby-users] Tracking Mouse motion> Alternatively, you could also catch EVT_LEFT_DOWN and EVT_LEFT_UP and > set and clear a flag in your class to indicate whether dragging is > happening. > > > Also, how do I draw a _continuous_ line which tracks the mouse motion? > > I got it to draw spots at different (x,y) co-ords, but the result is, > > umm, spotty :-) > > I would probably remember the previous mouse position, and when a new > motion event is caught, draw a line between the old point and the newpoint. Yep, that is exactly what I did. See attached code for a complete working example. Ways to make it better are always welcome. -- shanko -------------- next part -------------- A non-text attachment was scrubbed... Name: tst_wxPaint.rbw Type: application/octet-stream Size: 5861 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040622/e0e3af1f/tst_wxPaint.obj
I am trying to understand the use of Wx::Region and cannot find any examples of usage around. I want to be able to "rubber-band" a region on Wx::PaintDC and cut&paste it some where on the canvas. Any suggestions? -- shanko
Shashank Date wrote:> I am trying to understand the use of Wx::Region and cannot find any examples > of usage around. > > I want to be able to "rubber-band" a region on Wx::PaintDC and cut&paste it > some where on the canvas.I have not used regions in wxWindows, but I used them in Windows several years ago.... that was Windows 3.1 :-) It looks like you would construct the region from a polygon. If I understand what you want to do, I would next create a destination bitmap (you might need to initialize it to be blank), and create a MemoryDC pointing to it. Then call MemoryDC#set_clipping_region. From that point, any drawing to that dc would be constrained to that region. Any attempts to draw outside the region would be ignored. Hopefully that applies to blit as well. blit from the PaintDC into the MemoryDC. Now, you can blit the bitmap back into your PaintDC at a different location, probably after calling set_clipping_region at the destination in your PaintDC. Good luck, Kevin
----- Original Message ----- From: "Kevin Smith" <wxruby@qualitycode.com>> It looks like you would construct the region from a polygon. If I > understand what you want to do, I would next create a destination bitmap > (you might need to initialize it to be blank), and create a MemoryDC > pointing to it. Then call MemoryDC#set_clipping_region. > > From that point, any drawing to that dc would be constrained to that > region. Any attempts to draw outside the region would be ignored. > Hopefully that applies to blit as well. blit from the PaintDC into the > MemoryDC. > > Now, you can blit the bitmap back into your PaintDC at a different > location, probably after calling set_clipping_region at the destination > in your PaintDC.Hmmm... that looks more involved than what I had assumed and I am not sure I have understood it all. Do you know of any sample code to go by? I was able to blit from a source ClientDC to another ClientDC easily, like: # ---------------------------- @source_dc = Wx::ClientDC.new(self) unless @source_dc if @source_dc xdest, ydest, width, height, xsrc, ysrc = 0,0,100,200,0,0 dc = Wx::ClientDC.new(@canvas) dc.blit(xdest, ydest, width, height, @source_dc, xsrc, ysrc, Wx::COPY) dc.free @source_dc.free @source_dc = nil end # ---------------------------- But I could not figure out how to blit when the source and the destination ClientDCs were the same (i.e. @canvas in the code above). TIA, -- shanko
----- Original Message ----- From: "Shashank Date" <sdate@everestkc.net> >> But I could not figure out how to blit when the source and the > destination ClientDCs were the same (i.e. @canvas in the code > above).My bad ...I take that back. I was able to do it once I set the source, dest co-ords correctly. Sorry for the noise. -- shanko