Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Canvas size and non-shape painting

Help
iwbnwif
2013-10-10
2013-11-09
  • iwbnwif
    iwbnwif
    2013-10-10

    I have a couple of simple (hopefully) questions:

    1. How can the size of the wxSFShapeCanvas be 'fixed'. I.e. how can I make it at least 1000 x 1000 pixels? At the moment it seems to resize to the extents of all the objects added or the window size, whichever is greater.

    2. Is it safe to draw directly to the canvas, i.e. add lines, text etc. by overriding wxSFShapeCanvas::OnDraw or processing EVT_PAINT? I would like to add a border / title block to my drawings but don't need them to be managed by wxSFDiagramManager (but do them it to be scaled via the ScaledDC).

    Thanks for helping!

     
  • iwbnwif
    iwbnwif
    2013-10-12

    More research has found the answer to question 1. To achieve a fixed canvas size, subclass wxSFShapeCanvas and override wxSFShapeCanvas::OnUpdateVirtualSize.

     
  • Ad 2: Please, could you try to use overrided wxSFShapeCanvas::DrawContent(...) virtual function and let me to know whether it worked for you? You must use the latest SVN trunk code (rev 419 or higher).

     
  • iwbnwif
    iwbnwif
    2013-10-29

    Thank you for this change, I tried it and it works!

    I am sorry but my original question wasn't clear. I want to draw mostly using the normal wxShapeFramework functionality but also want to add a static border to the diagrams.

    For example imagine an electrical schematic where the components are wxRectShapes etc. but around the outside is a drawing border and also there is a title block. The border and title block are static and don't need to be clickable.

    What I think might be okay is below the section "// show grid" to add a call to a virtual function like "DrawStaticObjects" which can then be overridden in an application. For now I have overridden wxSFShapeCanvas::DrawContent(..) as you suggest but copy and pasted all the original code into the overide and added my border drawing bits after the grid is drawn

     
  • You don't need to copy the sources of original DrawContent() function into your custom implementation: try to use the following approach:

    void MyCanvas::DrawContent(wxDC& dc, bool fromPaint)
    {
        // draw original content
        wxSFShapeCanvas::DrawContent(dc, fromPaint);
    
        // here you can place your drawing code
        // ...
    }
    

    Of course, your drawing will appear on the top of the original content but it should be ok for your needs. If you want to draw UNDER the chart, then I have to allow user to suppress clearing of the canvas before drawing (i.e. disable solid or/and gradient fill of the canvas) - I suppose it could be implemented as a new cancas style. In this case, you could place your drawing code also before the invocation of the original DrawContent() function.

    Another option is to declare new function like:

    virtual void DrawBackground(wxDC &dc, bool fromPaint) and call it below the grid drawing as you suggested but IMHO the first solution is more flexible. Any thoughts?

     
    Last edit: Michal Bližňák 2013-10-30
  • iwbnwif
    iwbnwif
    2013-10-30

    Doh! yes of course I could have done this. For some reason I was blinkered into thinking I would have call the base class DrawContent at the end of my override.

    With regards to a virtual DrawBackground, I am not sure how many people would need such a function but as well as my case it would allow a custom grid, adding a wallpaper, 'DRAFT' watermark etc.

    Well maybe the answer is to have a virtual DrawBackground before the shapes are drawn and a virtual DrawForeground afterwards. Just a thought...

     
  • I have updated wxSF:

    • Added virtual function wxSFShapeCanvas::DrawBackground(...) called before wxSFShapeCanvas::DrawContent(...)
      responsible for drawing of the canvas background and grid.
    • Added virtual function wxSFShapeCanvas::DrawForeground(...) called after wxSFShapeCanvas::DrawContent(...)
      responsible for drawing onto the top of the diagram.

    I hope the changes will match your needs.

     
  • iwbnwif
    iwbnwif
    2013-11-08

    Thank you, this is perfect!

    I would like to be able to contribute something back this project, please let me know if there is any help you need.

     
  • What about to commit your AutoWrapTextShape class?.. ;) Also testing on Windows 8 would be appreciated. Moreover, if you use wxSF for any academic research/projects, you could put references to my articles dealing with wxSF into your articles if any.

     
  • iwbnwif
    iwbnwif
    2013-11-08

    I would be very happy to commit the AutoWrapTextShape but I can't work out how to do so!

    At the moment I am more or less using wxWidgets etc. for my own entertainment but in the back of my mind are some more serious ideas and I will of course credit your framework if they ever come about.

     
  • You can attach the sources (e.g. in some archive) here and I will look at it and commit.

     
  • iwbnwif
    iwbnwif
    2013-11-09

    Here it is. Please bear in mind that I am very much a newbie!! At least I can tell you there are the following problems:

    1. I have used range-based for loops in at least 3 places, so this requires -std=gnu++11 to compile (mingw). Possibly these should be changed to be more portable.
    2. At the moment only circles and rectangles work well.
    3. I am working on being able to define margins, left and right seem more or less okay, but the top and bottom mess up the circle alignment.
    4. There is a DEBUG_MODE global variable that is currently #define'd at the top of the c++ file. This helps you to visualize how the wrapping is being done in real time and in my test application it is toggleable at run time from the UI. However in the source I uploaded it is fixed.
    5. There is not much in the way of protections so it would be pretty easy to cause a crash if the wrong parameters are set.

    All comments / critics are very, very welcome as I would like to improve :)

     
  • iwbnwif
    iwbnwif
    2013-11-09

    AutoWrapTextShape.zip

     
    Attachments