From: Gene B. <gen...@in...> - 2007-03-19 16:23:44
|
Can anyone supply info and/or code snippet concerning how to undo/redo text & primitives that are drawn on a canvas that is created via the following: my $dc = Wx::PaintDC->new( $self ); Thanks, Gene Eugene S. Beaumont Jr. Senior Consultant Intercept Technology Inc. *** Essayons *** Office: 1-404-352-0111 x924 Fax: 585.768.9372 http://www.intercept.com |
From: Mark D. <mar...@zn...> - 2007-03-19 18:32:23
|
Hi, I assume you just want to remove individual items rather than clear the whole canvas? Sorry, I have no code snippet but the function you need is Wx::DC::SetLogicalFunction The general approach is to repeat the drawing code after setting the appropriate logical function - so overwriting returns you to the original background. I don't have the correct logical functions to use, but hopefully this points you in the right direction. Regards Mark Gene Beaumont wrote: > Can anyone supply info and/or code snippet concerning how to undo/redo > text & primitives that are drawn on a canvas that is created via the > following: > > my $dc = Wx::PaintDC->new( $self ); > > Thanks, > Gene > > Eugene S. Beaumont Jr. > Senior Consultant > Intercept Technology Inc. > *** Essayons *** > Office: 1-404-352-0111 x924 > Fax: 585.768.9372 > http://www.intercept.com > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Mark D. <mar...@zn...> - 2007-03-21 19:41:42
|
Hi, wxWidgets DC is drawing not my area, but you are going to have to become familiar with the way device contexts and, I think, drag and drop work in wxWidgets. You'll have a fair bit of reading to do! (You need the wxWidgets help file(s) ) I did once have occasion to have to do some drawing in MSWin, so I think the basic concepts are as follows: Perhaps someone else more experienced can post any errors or even point out complete misunderstanding :-) For an example, you have your DC and you want to draw two elements on it - a rectangle and a text string. You need to retain the details of the elements and draw them all each time the GUI events request that you do so. So, every time you get an 'OnPaint' event from your Wx::PaintDC object, call the drawing code for all your elements. At this stage, the location on the DC that your elements get drawn to is always the same so you would always be using $dc->SetLogicalFunction(wxCOPY); To select and move the elements you will need to become familiar with responding to mouse events and probably 'drag and drop.' Essentially all you really want to do is reset the position of your element on the DC in response to some mouse actions. To give user the feeling of 'dragging' the element, when the user presses the mouse down in your window, you need to get the xy position of the mouse from the event. The outside bounds of each of your drawing elements can be described by a Wx::Rect object. You can construct this for your 'rectangle' element, simply by recording the x,y,w,h coordinates you used to create it. The bounding rectangle of your text can be found by calling $dc->GetTextExtent(). You would probably keep some objects of your own devising that define each separate drawing element in an array, with each object containing the necessary primitive information along with the bounding Wx::Rect. So, when you get an xy position for the mouse, you can iterate through the array checking each objects Wx::Rect member to see if the xy is within that rect. ($rect->Contains()). The ordering of the array is important so that if the elements on screen overlap, you get the topmost one returned for the xy position. Once you know which object has been selected by the mouse, you can respond to a 'drag' operation by simply drawing its bounding rect outline. For this you would use $dc->SetLogicalFunction(wxINVERT); Once that is set, repeating a drawing operation simply reverts the affected elements to the original colour (so it would work on a background containing many colours). So, you would have a 'draw_dragged_object' sub that accepted a bounding rect as a param and some flag or method of knowing if this is the start of a dragging operation or the end of the operation. So sub draw_dragged_object { my ($self, $obj, $startend, $dc) = @_; if($startend !~ /START/) { $self->_draw_invert_rect(elf->{_prior_rect},$dc ) } if($startend !~ /END/) { $self->_draw_invert_rect( $obj->Rect, $dc ); } $self->{_prior_rect} = $obj->Rect; } sub _draw_invert_rect { my($self, $rect, $dc) = @_; my $savelogic = $dc->SetLogicalFunction(wxINVERT); .... Do drawing $dc->SetLogicalFunction( $savelogic ); } When the mouse is released, you can save the position of your moved object and then you can go for the full redraw. (I think Update or Refresh will do this)? Then the standard OnPaint response of simply redrawing the objects will work The bounding area of any irregular object can be represented by a Wx::Region (so you can do the selection test.) The Demo module you need to look at is wxPrinting.pm Hope this helps get you started at least. Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-21 21:44:10
|
Hi, Just a couple of addenda: The OnPaint event, of course, comes from your Window, not the DC. my $savelogic = $dc->SetLogicalFunction(wxINVERT); - Completely wrong toolkit :-) You'd need my $savelogic = $dc->GetLogicalFunction(); $dc->SetLogicalFunction(wxINVERT); |
From: Mark D. <mar...@zn...> - 2007-03-28 17:44:55
|
Vaughn Staples wrote: > Mark, > > I've used the standard "ColourDialog" in wxPerl; does there also exist > ones for selecting line styles & fill patterns that are commonly used > when drawing on a canvas? I'm suspecting that what I'm seeking doesn't > exist ... I just want to rule it out. > Hi, You'll need your own custom dialogs for these things. On zooming, use $dc->SetUserScale. For example $dc->SetUserScale(0.5,0.5) zooms to 50%. You have to call SetUserScale everytime you use the dc, so in addition to in your drawing routines it also needs to go into your mouse events routines BEFORE you call $event->GetLogicalPosition( $dc ); Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-28 18:33:31
|
Hi, Having to set the user scale all over the place is poor, so you could do the following in your drawing canvas class. sub PrepareDC { my ($self, $dc) = @_; $self->SUPER::PrepareDC( $dc ); $dc->SetUserScale($self->get_user_scale() ); } sub get_user_scale { my ($self) = @_; return @{ $self->{_user_scale} }; } sub set_user_scale { my ($self, $scalex, $scaley) = @_; $self->{_user_scale} = [ $scalex, $scaley ]; } By overriding PrepareDC, you can just put setting the user scale in the one place. EXCEPT: You do still have to put it in one extra place - your OnDraw routine. OnDraw prepares the DC for you - which should still work - but doesn't because PrepareDC is apparantly just a wrapper for DoPrepareDC. Internally, OnDraw calls DoPrepareDC directly. DoPrepareDC is not wrapped by wxPerl so we can't override that. Gnash. So for now, you'll need ... sub OnDraw { my ($self, $dc) = @_; $dc->SetUserScale($self->get_user_scale() ); ..... ..... But at least it is only in one place. I shall test wrapping DoPrepareDC and post a diff a little later. If you are on MSWin, I will have incorporated changes in PPMs too. B.T.W. I do have to create something that uses all these functions myself in the near future so having you 'debug' the process in your work is very useful to me too. Regards Mark Mark Dootson wrote: > Vaughn Staples wrote: >> Mark, >> >> I've used the standard "ColourDialog" in wxPerl; does there also exist >> ones for selecting line styles & fill patterns that are commonly used >> when drawing on a canvas? I'm suspecting that what I'm seeking doesn't >> exist ... I just want to rule it out. >> > > Hi, > > You'll need your own custom dialogs for these things. > > On zooming, use $dc->SetUserScale. > > For example > > $dc->SetUserScale(0.5,0.5) > > zooms to 50%. > > You have to call SetUserScale everytime you use the dc, so in addition to in your drawing routines it also needs to go into your mouse events routines BEFORE you call $event->GetLogicalPosition( $dc ); > > Regards > > Mark > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Mark D. <mar...@zn...> - 2007-03-28 22:18:49
|
Mark Dootson wrote: > > I shall test wrapping DoPrepareDC and post a diff a little later. If you are on MSWin, I will have incorporated changes in PPMs too. > Or maybe not! I have wrapped DoPrepareDC and that works fine. It still doesn't really solve the issue though: Within wxWidgets itself, there is a hack used to make OnDraw work. The base class for ScrolledWindow checks if any handler of a wxPaintEvent in a derived class actually did anything. If it didn't, the base class still calls its own handler for the event. That handler does the following. wxPaintDC dc(m_win); DoPrepareDC(dc); OnDraw(dc); note: the problem here is that the base class DoPrepareDC is called - NOT any DoPrepareDC in any derived class. Gnash. So, for now, to do what I suggested in the earlier post, you would do as follows. (You don't actually need a separate OnDraw sub anymore of course) sub new { ....... ....... EVT_PAINT( $self, \&OnPaint ); $self->set_user_scale(0.5,0.5); ....... ....... } sub OnPaint { my ($self, $event) = @_; $event->Skip(1); my $dc = Wx::PaintDC->new($self); $self->PrepareDC( $dc ); $self->OnDraw($dc); } sub OnDraw { my($self, $dc) = @_; ........... ........... } sub PrepareDC { my ($self, $dc) = @_; $self->SUPER::PrepareDC( $dc ); $dc->SetUserScale( $self->get_user_scale() ); } sub get_user_scale { my ($self) = @_; return @{ $self->{_user_scale} }; } sub set_user_scale { my ($self, $scalex, $scaley) = @_; $self->{_user_scale} = [ $scalex, $scaley ]; } --------------------------------------------------- It would be nice to have wxPerl act like the C wxWidgets docs suggest so I'll not post a diff for DoPrepareDC. To make that work would mean installing a default wxPaintEvent handler for wxScrolledWindow in wxPerl. Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-29 05:11:04
Attachments:
scrollwin.diff
|
Hi, The attached diff solves the problem and the code below now works as expected. Note, you have to call DoPrepareDC to get the overridden method - just like it says in the docs :-) Having a method loaded via Wx.pm looks a bit crufty - but it was the best I could manage and does the 'right' thing vs inheritance etc. (I think). Anyone for further testing ? Mark sub new { ....... ....... $self->set_user_scale(0.5,0.5); ....... ....... } sub OnDraw { my($self, $dc) = @_; ........... ........... } sub DoPrepareDC { my ($self, $dc) = @_; $self->SUPER::DoPrepareDC( $dc ); $dc->SetUserScale( $self->get_user_scale() ); } sub get_user_scale { my ($self) = @_; return @{ $self->{_user_scale} }; } sub set_user_scale { my ($self, $scalex, $scaley) = @_; $self->{_user_scale} = [ $scalex, $scaley ]; } |
From: Mark D. <mar...@zn...> - 2007-03-29 05:56:37
|
Mark Dootson wrote: > Hi, > > The attached diff solves the problem and the code below now works as expected. Err .. no it doesn't. It introduces strangeness when scrolling. Sigh. |
From: Mark D. <mar...@zn...> - 2007-03-29 20:30:59
Attachments:
scrollwin.diff
|
Mark Dootson wrote: > > It introduces strangeness when scrolling. > The attached diff fixes my scrolling problems and all now works happily whether via OnDraw or EVT_PAINT. No crufty changes to Wx.pm either :-) Thanks Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-30 00:10:57
|
As a final piece in my ScrolledWindow saga, there's http://www.wxperl.co.uk/example6.pl.txt This works as is with the posted diff. To use without the posted diff, you must uncomment the EVT_PAINT call and comment out 'OnDraw'. It also has a 'run refresh loop' option on the menu bar so you can watch it consume all your resources. :-) (it shouldn't). It works as a way to observe the issue I've been trying to resolve and a crude test if you decide to apply the diff. No more GDI from me this week. Regards Mark |
From: Vaughn S. <vau...@in...> - 2007-04-04 13:54:52
|
All, I am seeking a way to construct a concave polygon on a glCanvas window. = I understand that it is mandatory to describe concave polygons as a = "tessellation" ... and I cannot locate any information in this regard. At a macro level I'm thinking that I should be able to implement a = subroutine as shown below; any information would be greatly appreciated. Vaughn ######################################## sub drawConcaveOutline ######################################## { ## Create the tesselator object my $pTess =3D gluNewTess(); ## Set callback functions gluTessCallback($pTess, GLU_BEGIN, \&glBegin); gluTessCallback($pTess, GLU_VERTEX, \&glVertex2fv); gluTessCallback($pTess, GLU_END, \&glEnd); ## Smooth minimizes seeing tessellation glShadeModel(GL_SMOOTH);=20 =20 ## Begin the polygon gluBeginPolygon($pTess); ## Begin the one and only contour gluBeginContour($pTess); ## Feed in the list of vertices ## ## << Not sure the syntax here >> =20 ## Close contour and polygon gluEndContour($pTess); gluEndPolygon($pTess); ## All done with tesselator object gluDeleteTess($pTess); } |
From: Vaughn S. <vau...@in...> - 2007-03-21 11:07:58
Attachments:
ImageEditor.py
|
Mark, Good morning & thanks for the post. Is there a particular source of information that I should seek for background information on the "SetLogicalFunction" method? I've spent the last several hours scouring the 'net for details and have mostly come up empty handed. I did locate several programming examples ... albeit nothing written in Perl. The best (attached) is written in Python, and is unfortunately beyond my grasp in terms of how to implement in Perl. In studying the attached, as a novice, it does spur recognition that the undo/redo capability is fundamental to marking up displayed images. Basic drawing (lines/rects/text) on an image is fairly straightforward. But interacting with the drawn primitives after-the-fact is really what I'm after ... the ability to select, move, delete ... and that's where I'm stuck. Any further thoughts would be greatly appreciated. Best regards, Vaughn ----- Original Message ----- From: "Mark Dootson" <mar...@zn...> To: "Gene Beaumont" <gen...@in...> Cc: <wxp...@li...> Sent: Monday, March 19, 2007 2:32 PM Subject: Re: [wxperl-users] DCPaint Widget Question Hi, I assume you just want to remove individual items rather than clear the whole canvas? Sorry, I have no code snippet but the function you need is Wx::DC::SetLogicalFunction The general approach is to repeat the drawing code after setting the appropriate logical function - so overwriting returns you to the original background. I don't have the correct logical functions to use, but hopefully this points you in the right direction. Regards Mark Gene Beaumont wrote: > Can anyone supply info and/or code snippet concerning how to undo/redo > text & primitives that are drawn on a canvas that is created via the > following: > > my $dc = Wx::PaintDC->new( $self ); > > Thanks, > Gene > > Eugene S. Beaumont Jr. > Senior Consultant > Intercept Technology Inc. > *** Essayons *** > Office: 1-404-352-0111 x924 > Fax: 585.768.9372 > http://www.intercept.com > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ wxperl-users mailing list wxp...@li... https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Vaughn S. <vau...@in...> - 2007-03-22 18:56:00
|
Mark, I have a lot of what I have been seeking to accomplish now implemented; the ability to select, undo, redo, etc., work fluently (thanks!). Question ... where would be a good place to look for information on "refresh" and "update" as you have listed below? The reason I ask deals with the difficulties that I am having perfecting a "move" transaction. Selecting the object at the init location is OK, drawing it at the destination is OK, but I'm looking to maintain the rectangle on the tip of the cursor as I gently move it around the canvas. The brute force manner that I am accomplishing it right now is to constantly delete the rectangle at the formerly drawn position ... briefly draw it at the current mouse (X,Y) ... and repeat each interval as you continue to move the cursor. Lots of processing ... & the paint subroutine I use basically redraws *everything* ... not just the single rectangle I have selected to move. Thoughts? I am hoping that I can somehow instruct wxPerl to simply update the draw of the selected item instead of the whole sheet. Thanks, Vaughn ----- Original Message ----- From: "Mark Dootson" <mar...@zn...> To: "Vaughn Staples" <vau...@in...> Cc: "Gene Beaumont" <gen...@in...>; <wxp...@li...> Sent: Wednesday, March 21, 2007 2:41 PM Subject: Re: [wxperl-users] DCPaint Widget Question Hi, wxWidgets DC is drawing not my area, but you are going to have to become familiar with the way device contexts and, I think, drag and drop work in wxWidgets. You'll have a fair bit of reading to do! (You need the wxWidgets help file(s) ) I did once have occasion to have to do some drawing in MSWin, so I think the basic concepts are as follows: Perhaps someone else more experienced can post any errors or even point out complete misunderstanding :-) For an example, you have your DC and you want to draw two elements on it - a rectangle and a text string. You need to retain the details of the elements and draw them all each time the GUI events request that you do so. So, every time you get an 'OnPaint' event from your Wx::PaintDC object, call the drawing code for all your elements. At this stage, the location on the DC that your elements get drawn to is always the same so you would always be using $dc->SetLogicalFunction(wxCOPY); To select and move the elements you will need to become familiar with responding to mouse events and probably 'drag and drop.' Essentially all you really want to do is reset the position of your element on the DC in response to some mouse actions. To give user the feeling of 'dragging' the element, when the user presses the mouse down in your window, you need to get the xy position of the mouse from the event. The outside bounds of each of your drawing elements can be described by a Wx::Rect object. You can construct this for your 'rectangle' element, simply by recording the x,y,w,h coordinates you used to create it. The bounding rectangle of your text can be found by calling $dc->GetTextExtent(). You would probably keep some objects of your own devising that define each separate drawing element in an array, with each object containing the necessary primitive information along with the bounding Wx::Rect. So, when you get an xy position for the mouse, you can iterate through the array checking each objects Wx::Rect member to see if the xy is within that rect. ($rect->Contains()). The ordering of the array is important so that if the elements on screen overlap, you get the topmost one returned for the xy position. Once you know which object has been selected by the mouse, you can respond to a 'drag' operation by simply drawing its bounding rect outline. For this you would use $dc->SetLogicalFunction(wxINVERT); Once that is set, repeating a drawing operation simply reverts the affected elements to the original colour (so it would work on a background containing many colours). So, you would have a 'draw_dragged_object' sub that accepted a bounding rect as a param and some flag or method of knowing if this is the start of a dragging operation or the end of the operation. So sub draw_dragged_object { my ($self, $obj, $startend, $dc) = @_; if($startend !~ /START/) { $self->_draw_invert_rect(elf->{_prior_rect},$dc ) } if($startend !~ /END/) { $self->_draw_invert_rect( $obj->Rect, $dc ); } $self->{_prior_rect} = $obj->Rect; } sub _draw_invert_rect { my($self, $rect, $dc) = @_; my $savelogic = $dc->SetLogicalFunction(wxINVERT); .... Do drawing $dc->SetLogicalFunction( $savelogic ); } When the mouse is released, you can save the position of your moved object and then you can go for the full redraw. (I think Update or Refresh will do this)? Then the standard OnPaint response of simply redrawing the objects will work The bounding area of any irregular object can be represented by a Wx::Region (so you can do the selection test.) The Demo module you need to look at is wxPrinting.pm Hope this helps get you started at least. Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-22 23:58:15
|
Hi, I was trying to explain a lot of steps and concepts when really some example code would have been better. As I want to complete something myself where I have to move drawn objects about a canvas, I made sure what I was proposing actually works with an example which I've posted at: http://www.wxperl.co.uk/example3.pl.txt I'm not sure if it would work with the wxGDI interface, but if I had a lot of objects to draw I could speed up the user experience by doing the actual drawing to a separate memoryDC only when the drawing objects actually changed. Then for screen updates, I'd use the built-in fast bitmap BitBit function ($dc->Blit() ) to just copy the region of the bitmap I needed to update to the screen. But with fewer objects to draw, the approach in the example should work just fine. Regards Mark |
From: Vaughn S. <vau...@in...> - 2007-03-27 13:54:57
|
Mark, A new question concerning the canvas. With the drawing objects now complete, I need to save the canvas data as an image file ... such as a BMP, JPG, or GIF. Thoughts? Vaughn ----- Original Message ----- From: "Mark Dootson" <mar...@zn...> To: "Vaughn Staples" <vau...@in...> Cc: <wxp...@li...> Sent: Thursday, March 22, 2007 7:58 PM Subject: Re: [wxperl-users] DCPaint Widget Question Hi, I was trying to explain a lot of steps and concepts when really some example code would have been better. As I want to complete something myself where I have to move drawn objects about a canvas, I made sure what I was proposing actually works with an example which I've posted at: http://www.wxperl.co.uk/example3.pl.txt I'm not sure if it would work with the wxGDI interface, but if I had a lot of objects to draw I could speed up the user experience by doing the actual drawing to a separate memoryDC only when the drawing objects actually changed. Then for screen updates, I'd use the built-in fast bitmap BitBit function ($dc->Blit() ) to just copy the region of the bitmap I needed to update to the screen. But with fewer objects to draw, the approach in the example should work just fine. Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-27 19:49:47
|
Vaughn Staples wrote: > Mark, > > A new question concerning the canvas. > > With the drawing objects now complete, I need to save the canvas data as > an image file ... such as a BMP, JPG, or GIF. Hi Vaughn Procedure below shows the basics. You just have to look up the Wx::FileDialog in the docs and in Wx::Demo to see about selecting filename / filetype. Regards Mark sub evt_menu_file_save { my ($self, $event) = @_; $event->Skip(1); # allow event to be processed by further handlers # have user select a file name and type my $filename = 'c:/testimage.png'; my $imagetype = wxBITMAP_TYPE_PNG; # get the device context we have drawn on my $canvas = $self->get_control('Canvas'); my $dc = Wx::ClientDC->new( $canvas ); $canvas->PrepareDC( $dc ); #get the dimensions my ( $width, $height ) = $dc->GetSizeWH(); # create a bitmap to draw on my $bmp = Wx::Bitmap->new($width, $height, -1); # select it into a memory dc my $mdc = Wx::MemoryDC->new(); $mdc->SelectObject($bmp); # copy the source dc to the memory dc $mdc->Blit(0,0,$width,$height,$dc,0,0); # get our bitmap back by selecting a null bitmap into the memory dc $mdc->SelectObject(wxNullBitmap); # create image out of bitmap and save my $img = Wx::Image->new($bmp); # $img->SaveFile($filename , $imagetype); # lets scale it just for fun my $scaled = $img->Scale(int($width / 2), int($height/2)); $scaled->SaveFile($filename , $imagetype); } |
From: Vaughn S. <vau...@in...> - 2007-03-27 19:03:36
|
Mark, Perl on my end could not locate the method "get_control"; I had to modify the lines from: my $canvas = $self->get_control('Canvas'); my $dc = Wx::ClientDC->new( $canvas ); $canvas->PrepareDC( $dc ); to: my $dc = Wx::ClientDC->new( $self ); $self->PrepareDC( $dc ); Any thoughts as to what could be the problem? After making the changes it all worked fine (thanks!). Vaughn ----- Original Message ----- From: "Mark Dootson" <mar...@zn...> To: "Vaughn Staples" <vau...@in...> Cc: <wxp...@li...> Sent: Tuesday, March 27, 2007 2:22 PM Subject: Re: [wxperl-users] DCPaint Widget Question Vaughn Staples wrote: > Mark, > > A new question concerning the canvas. > > With the drawing objects now complete, I need to save the canvas data > as > an image file ... such as a BMP, JPG, or GIF. Hi Vaughn Procedure below shows the basics. You just have to look up the Wx::FileDialog in the docs and in Wx::Demo to see about selecting filename / filetype. Regards Mark sub evt_menu_file_save { my ($self, $event) = @_; $event->Skip(1); # allow event to be processed by further handlers # have user select a file name and type my $filename = 'c:/testimage.png'; my $imagetype = wxBITMAP_TYPE_PNG; # get the device context we have drawn on my $canvas = $self->get_control('Canvas'); my $dc = Wx::ClientDC->new( $canvas ); $canvas->PrepareDC( $dc ); #get the dimensions my ( $width, $height ) = $dc->GetSizeWH(); # create a bitmap to draw on my $bmp = Wx::Bitmap->new($width, $height, -1); # select it into a memory dc my $mdc = Wx::MemoryDC->new(); $mdc->SelectObject($bmp); # copy the source dc to the memory dc $mdc->Blit(0,0,$width,$height,$dc,0,0); # get our bitmap back by selecting a null bitmap into the memory dc $mdc->SelectObject(wxNullBitmap); # create image out of bitmap and save my $img = Wx::Image->new($bmp); # $img->SaveFile($filename , $imagetype); # lets scale it just for fun my $scaled = $img->Scale(int($width / 2), int($height/2)); $scaled->SaveFile($filename , $imagetype); } |
From: Mark D. <mar...@zn...> - 2007-03-27 21:16:00
|
Vaughn Staples wrote: > Mark, > > Perl on my end could not locate the method "get_control"; I had to > modify the lines from: > Hi, Sorry, the code was a paste in for the previous example. There is no 'get_control' as part of Wx - it is implemented in the example code. Glad you were able to implement it anyway. Thanks Mark |
From: Vaughn S. <vau...@in...> - 2007-03-27 21:37:37
|
Mark, Excellent ... found it. Next question ... I have found that when setting the cursor style as shown below, the cursor does not change until I click down on the canvas. Then it works fine. Is there something that I can invoke to change it immediately without forcing the LMB click? $self->SetCursor( Wx::Cursor->new( wxCURSOR_ARROW ) ); Thanks, Vaughn ----- Original Message ----- From: "Mark Dootson" <mar...@zn...> To: "Vaughn Staples" <vau...@in...> Cc: <wxp...@li...> Sent: Tuesday, March 27, 2007 5:15 PM Subject: Re: [wxperl-users] DCPaint Widget Question Vaughn Staples wrote: > Mark, > > Perl on my end could not locate the method "get_control"; I had to > modify the lines from: > Hi, Sorry, the code was a paste in for the previous example. There is no 'get_control' as part of Wx - it is implemented in the example code. Glad you were able to implement it anyway. Thanks Mark |
From: Mark D. <mar...@zn...> - 2007-03-27 22:29:34
|
Vaughn Staples wrote: > Mark, > > Excellent ... found it. > > Next question ... I have found that when setting the cursor style as > shown below, the cursor does not change until I click down on the > canvas. Then it works fine. Is there something that I can invoke to > change it immediately without forcing the LMB click? > > $self->SetCursor( Wx::Cursor->new( wxCURSOR_ARROW ) ); > Hi Vaughn. Example now including cursor code at http://www.wxperl.co.uk/example4.pl.txt Cursor is set at lines 64,94 and 109. It seems to work as expected. Are you,perhaps, not following where exactly you are setting the cursor? wxCURSOR_ARROW is the default cursor, so it may not be apparant from a visual check that it has been set? Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-28 08:25:45
|
Hi, I don't think there are any 'built ins' for drawing arrows. The 'Join' and 'Cap' styles for the Wx::Pen are best understood if you consider very wide lines. Then, join styles of miter, bevel and round make sense. For an arrow, I think you are going to have to work out the points that you need to pass to $dc->DrawPolygon. If you want the arrows to look good when your lines are at a variety of angles, it will probably need some experimentation. Regards Mark Vaughn Staples wrote: > > I've been seeking tonight for a method to draw arrows on a canvas. I > recognize through the documentation that "lines" have the ability to set > an endpoint type, but the list in the wxWidgets documentation does not > provide for an arrow/pointer type. Do you have a recommendation? > |
From: Vaughn S. <vau...@in...> - 2007-03-28 09:33:34
|
Mark, I've used the standard "ColourDialog" in wxPerl; does there also exist ones for selecting line styles & fill patterns that are commonly used when drawing on a canvas? I'm suspecting that what I'm seeking doesn't exist ... I just want to rule it out. Thanks, Vaughn |