Author Topic: BETA - Image Editor plugin  (Read 52864 times)

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
BETA - Image Editor plugin
« on: March 28, 2010, 08:34:30 pm »
Hello guys,

 I have started to program a new Code::Blocks plugin.
 Its purpose: open and edit all images / icons directly inside CodeBlocks. It will simplify the creation / update of all kind of small images (useful for toolbars, for example).
 
  It is of course a SIMPLE editor: nothing fancy, it is more a clone of MS Paint than a clone of Photoshop.
  I have attached the source code (a cbplugin) - the archive also contains a compiled version (windows Vista - Codeblocks SVN 6181
 - MingW TDM 4.4.1)

   The current status is : ALPHA
   What is done:
      - basic editor class for images
      - mime handler done - viewing images works
      - a color picker class is done & tested
      - a wxToggleBitmapButton has been done (not available in wxWidgets 2.8.10. It is a copy of the one from wxWidgets 2.9.0)
      - Undo / Redo mechanism implemented & tested
      - Paste implemented & tested
    
    What remains to be done:
      - Copy & Cut (done, but needs testing...)
      - Save & Save As (done, but needs testing...)
      - implement all the tools (draw line, draw rectangle, ... the bulk of what is remaining)
      - better integration with CodeBlocks (title of the tab in wxAUI does not show a "*" when modified)
      - interface with wxSmith (cryogen made a patch for that : the DialogBox for choosing an image should have a new option. see thread http://forums.codeblocks.org/index.php/topic,372.165.html )
      - testing on Linux

    BUGS :
      - reopening the same bmp makes code::blocks quit without warning

    LIST OF CLASSES:
      xpm_color_picker : a color picker class - display a few different colors. Double-click on 1 color allows complete customization
      xpm_editor : the plugin itself (a MIME plugin)
      xpm_editor_base : the Image Editor. Use internally a xpm_editor_panel, which actually does the bulk of the work
      xpm_editor_panel : the GUI interface for the editor (wxSmith item)
      xpm_undo : a class to manage the UNDO & REDO buffers, and performs the REDO / UNDO action
      xpm_imageeditorarray : to keep track of the opened Image Editors in CodeBlocks. I suspect this class is provoking the BUG
      xpm_toggle_bmp_button : a bitmap toggle button (not available in wxWidgets 2.8.10)

Let me know what you think !

Seb

[attachment deleted by admin]
« Last Edit: October 18, 2010, 09:04:03 pm by seb_seb0 »

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #1 on: March 28, 2010, 08:43:56 pm »
Here is a screenshot



[attachment deleted by admin]

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Image Editor - new plugin
« Reply #2 on: March 28, 2010, 08:49:03 pm »
Excellant! I've had this on my TO-DO list for some time, so I am very glad to see this one.  I'll give it a try, and let you know how it works for me.

Ringo

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Image Editor - new plugin
« Reply #3 on: March 28, 2010, 08:49:14 pm »
whoa this is so cool!  :shock:

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 202
Re: Image Editor - new plugin
« Reply #4 on: March 29, 2010, 12:39:28 am »
Nice work! thank you.

To show the correct title on the tab:
in XpmEditorBase (derived from EditorBase) add a method:
Code: [Select]
void XpmEditorBase::UpdateModified()
{
    if ( GetModified() )
        SetTitle( _T("*") + GetShortName() );
    else
        SetTitle( GetShortName() );
}
and call it whenever the content changed (Do / Undo / Save / SaveAs ...).

Additionally overwrite EditorBases' virtual void SetFilename(const wxString& filename); with the following implementation:
Code: [Select]
void XpmEditorBase::SetFilename(const wxString& filename)
{
    m_Filename = filename;
    wxFileName fname;
    fname.Assign(m_Filename);
    m_Shortname = fname.GetFullName();
}

Take a look at HexEditor or NassiShneidermanPlugin (see my sig) how it's done. But these steps should do.

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #5 on: March 31, 2010, 11:08:56 pm »
Thank you danselmi.
I have solved the crashing bug !

I have implemented some of the functionalities now - I will probably post a Beta this week-end.

Now Save & Save As are working, and they are saving in the correct format.
Drawing has been buffered, and flicker is removed.
I have also simplified the plugins itself (removed the xpm_imageeditorarray class). The simpler it is, the easier it will be to maintain.

I have preferred to focus on removing the bug and getting the code base clean and correct, instead of implementing too fast all the features. I do not want to give a buggy plugin...

What remains to do (in this order):
      - better integration with CodeBlocks (title of the tab in wxAUI does not show a "*" when modified) - still to be solved
         Danselmi: I have seen your suggestion, but I did not have the time to do it yet. This will be my next step
      - Selection + Copy & Cut (done, but needs testing...)
      - Pen tool (the simplest one)
      - implement all the tools (draw line, draw rectangle, ... the bulk of what is remaining)
      - interface with wxSmith (cryogen made a patch for that : the DialogBox for choosing an image should have a new option. see thread http://forums.codeblocks.org/index.php/topic,372.165.html )
      - testing on Linux

what I will do on version 2:
     - integrate a configuration panel: Undo buffer, Color Palette, how to handle XPM file by default (use the Text Editor or the Image Editor).

I have put the last version of the project on SourceForge:
https://sourceforge.net/projects/xpmeditor/

Let me know what you think.
Best regards,

Sebastien
« Last Edit: March 31, 2010, 11:12:41 pm by seb_seb0 »

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #6 on: April 10, 2010, 08:50:42 pm »
Hello,

I have updated the plugin. It is still not finished, but now it is usable

What is new:
    1 - all bugs solved. No more crashing of CodeBlocks :-) (and the code was simplified. I have solved the problem by copying some parts of the HexEditor plugin).
    2 - Integration with CodeBlocks: all problems of file naming / modification flags solved
    3 - Undo / Redo improved
    4 - Work around a nasty bug in wxWidgets(wxDC.SetUserScale is not accurate - on big zoom factor, I had a 4 pixels error for 400 x 200 bitmaps...). This is what took me the most of my time
    5 - Cut / Copy / Paste implemented & tested
    6 - Save / SaveAs / Load implemented & tested
        All formats supported by wxWidgets are supported by the plugin (most notable: bmp, xpm, png)
    7 - following tools are implemented:
            Rectangle selection
            Polygon selection
            Pen
            Pipette
            Fill
     8 - ColourPicker improved: Left click select the Line colour, right click select the fill colour. A small toggle button can invert this behaviour.

What remain to do:
    1 - implement the rest of the tools
            brush (working on it)
            line
            curve
            eraser
            rectangle
            rounded rectangle
            ellipse
            polygon

    2 - resize selection / stretch selection / drag selection

    3 - add a configuration panel:
            How to handle XPMs (open it as text, as image, or ask the user each time)
            Undo / Redo buffer size
            Color palette (how many colors, and which one).

        All these options are already implemented in the code,and accessible in the main plugin interface
        What remains to do is to create the panel, and add it in the CodeBlocks option (and save the options).

nice to have, but not necessary for 1st release

    4 - add a jpg quality option

    5 - add a color depth option

    6 - add a file filter in the global CodeBlocks file open / save dialog box (it is already crowed with many file types, so I am not sure if it is a good idea)

    7 - testing on Linux & Mac
    
    8 - interface with wxSmith (cryogen made a patch for that : the DialogBox for choosing an image should have a new option. see thread http://forums.codeblocks.org/index.php/topic,372.165.html  )
   
    9 - Transparency : sometimes the transparency mask disappears when using some customed colours

I have updated the code on sourceforge:
https://sourceforge.net/projects/xpmeditor/

Let me know what you think.
And do not hesitate to report me any bugs !

Sebastien
« Last Edit: April 10, 2010, 08:58:59 pm by seb_seb0 »

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 202
Re: Image Editor - new plugin
« Reply #7 on: April 11, 2010, 01:54:25 pm »
Hi Sebastien

You made great progress!

A few thoughts:
  • AFAIK it is not foreseen to add a file filter in the global CodeBlocks file open / save dialog box. The only way I found is to generate a lexer-configuration file (even if there does not exist a scintilla-lexer for bitmaps ).
  • Why do you not commit the code to the svn repo on sorceforge? It is also helpful for you.
  • Most other plugins use CamelCase namings (class and filenames) but this is only a matter of personal taste.

regards,
danselmi

« Last Edit: April 11, 2010, 05:38:33 pm by danselmi »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9594
Re: Image Editor - new plugin
« Reply #8 on: April 11, 2010, 08:02:24 pm »
I have updated the code on sourceforge:
https://sourceforge.net/projects/xpmeditor/
It took me a while to find out you are not using SVN on sourceforge... (why?!). Now I can give tit a try, too... :)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #9 on: April 11, 2010, 09:43:44 pm »
Hello,

I have updated the .7Z archive on Sourceforge. (I have not done it in SVN because I do not know how to do it yet. I will find how, but it takes time, and I prefer to use this time for developping the plugin).
https://sourceforge.net/projects/xpmeditor/

EDIT: now the plugin is also available as a SVN repository on sourceforge.

What changed:
  - change the name of all the classes and of the plugin to CamelCase (I have followed the suggestion from DanSelmi)
  - nearly all the tools are implemented !! (only the Text tool is not done)

What remains to do:
  - points 2 to 9 from my previous list.

Optimisations possible:
  - Undo / Redo buffers should be smarter (maybe store only a sub-bitmap and its position...)
  - wxMouseEvent tends so skip some coordinates. I do not know yet if it is my plugin who is slow, or if it comes from wxWidgets.

Once it is done, I will need to test thoroughly before final release.
I will need testers for Linux & Mac

1 side note: the tool is not at all optimized (or you may say otherwise: it is optimized for small bitmaps).
In theory, you can edit a 2000 x 2000 bitmap. In practice, it can be challenging for the CPU. (especially UNDO / REDO buffer which stores the whole bitmap each time).

But as I said, the goal I had in my mind was Toolbars / Menu icons fast edition. They are very often smaller than 2000 x 2000.

Let me know what you think !

Sebastien
« Last Edit: April 11, 2010, 10:54:50 pm by seb_seb0 »

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #10 on: April 11, 2010, 10:53:37 pm »
OK, now it is available on sourceforge, with SVN.
It was not as complicated as I feared.

Sebastien

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Image Editor - new plugin
« Reply #11 on: April 12, 2010, 12:03:56 am »
Does not work on linux.
You copied the source of the bitmap-togglebutton from the msw-sources of wxWidgets, that does not work.
And using the sources from src/gtk is not so easy.

No bitmaps shown (OnPaint is never called) and after a click on any button C::B blocks xfce and I have to kill it from a console.

I started to move to wxCustmButton of wxSmithContribItems, bitmaps are shown, but no other functions (yet).

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #12 on: April 12, 2010, 09:49:27 pm »
Does not work on linux.
You copied the source of the bitmap-togglebutton from the msw-sources of wxWidgets, that does not work.
And using the sources from src/gtk is not so easy.

No bitmaps shown (OnPaint is never called) and after a click on any button C::B blocks xfce and I have to kill it from a console.

I started to move to wxCustmButton of wxSmithContribItems, bitmaps are shown, but no other functions (yet).

  This is good to know - I tried to find a simple solution for having a toolbox of push buttons with bitmap icons, but apparently this one is far from being ideal.
  I do not know wxCustomButton (part of wxThings if I am not mistaken). I have tried a few month ago to compile wxThings with wxWidgets 2.9.0, but without success.
 
  Another possible solution is to use a toolbar with radio buttons - it should do the trick.
  Or use the same solution as wxSmith (I do not know yet what it is using, but it works).

  Currently, I am in the process of cleaning the code of bugs (I do not work on new features for now), so as soon it is finished, I will look into the problem.

  Since you have more experience than me in programming for wxGTK, what is your suggestion / idea ?

Sebastien

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Image Editor - new plugin
« Reply #13 on: April 12, 2010, 10:34:14 pm »
I think using wxCustomButton (from wxThings) for a C::B plugin is safe and it's part of the wxSmithContribItems (even if it might not be compilable with wx2.9).

C::B is not fully compatible with wx2.9, even if the core app is compilable in the meantime.
There is still an ugly crash if C::B ends due to problems with the event-handlers of the listcontrol-loggers.

And parts of contrib-plugins do not even compile.

A wx2.9 crash on linux when starting the dialogs that uses wxListBook (editorconf, settings, ...) is fixed in wxWidgets trunk since yesterday : http://trac.wxwidgets.org/ticket/11698#comment:8, that's a big step forward, because there was no easy workaround for that issue (without patching wxWidgets).

Before we switch to wx 2.9 or more likely to 3.0 (as it will be the next release) all incompatibilities will (have to) be fixed.

You can see how to use wxCustombutton in ThreadSearch-plugin (SearchInPanel.*), but I made the changes manually, because dje the original-developer of the ThreadSearch-plugin used glade to create the gui, and I prefer wxSmith (or doing it the old way, by hand).
As you use wxSmith for your panel it should be not so hard to switch to it (and it should work on linux and windows).

I hope the post is not too chaotic, but I have a terrible headache at the moment and can not really think straightforward.

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Image Editor - new plugin
« Reply #14 on: April 12, 2010, 10:58:04 pm »
Thank you for the answer.
In any case, it is easier to change now, when the plugin is in development than in 6 months, when I will have forgotten everything.
And I prefer to change a few things than having a buggy plugin which work only on my computer.

I will give a try with wxCustomButton, even if I need to modify it a bit for compilation. I will add the relevant files directly to the project to avoid external dependencies (I will look first at ThreadSearch plugin to know how it is done).

I was anyway surprised that it was so difficult to find such a simple control as a bitmap toggle button, while at the same time you find complex control like wxGrid or wxDataView.

I have also thought about a wxToolBar in the wxPanel (not recommended by the docs), or see if wxAUI is usable on wxPanel (apparently you need a wxFrame).

So to sum-up: I will try the wxCustomButton (a copy paste from ThreadSearch plugin, as much as possible).

And keep in mind that I have only a MS Window computer (no LINUX, no Mac) : so any feedback for how the plugin work (or not) on these platforms is welcome
I will try to compile wxGTK on Windows, and Codeblocks as well - maybe I can have a second platform for testing.

Good luck for your headache - I know the problem...