GNOME Bugzilla – Bug 120417
book: DrawingArea chapter ported to gtkmm2
Last modified: 2004-12-22 21:47:04 UTC
The DrawingArea section of the tutorial contains some example code with errors that prevent it compiling. 1) It calls size() which doesn't exist, 2) It uses . rather than ->.
Created attachment 19426 [details] [review] Fixes to sample code in tutorial
Is this in a code snippet or a full example? Full examples should be pulled in from examples/book/something/, like the other examples. I notice that there is some old gtk 1.2 code in there - this chapter really needs to be deal with or removed.
Looks like it is a complete program, but there is no corresponding code in the examples/book that I can see. (Did you mean that I had patched the wrong file, or that I should split it out into a new file?) I must admit I've not looked at the rest of that chapter, it only came to my attention that this code needed fixing when someone asked about it on the mailing list today.
It should be a separate set of source files, like the existing examples in examples/book. It should have a similar style and structure to the existing samples. You would still need to path gtkmm-tut.xml to pull in the source code.
Created attachment 19457 [details] [review] Updates the drawing area section (could be better explained, but at least it is now correct)
Created attachment 19458 [details] New sample code for the drawingarea section of the docs
The documentation update patch (id=19457) supercedes the first, simpler patch (id=19426). It also includes updates to some Makefile.am files that assume examples/book/drawingarea has been moved to examples/drawingarea. Attachment (id=19458) contains a tar.bz2 of the new sample code that should be extracted in examples/book (cvs diff -u misses new files, as I don't think I can cvs add them). I may later work on the wording some more as I believe that there is still much room for improvement, but I think it would be useful to at least get to the point where what is said is correct for the current version.
This is great, and people will be very grateful for this, but we need to make a few changes: 1. The directories should have more meaningful names than drawingarea1 and drawingarea2. Maybe drawingarea_line and drawingarea_text? 2. They should have the same structure as the other examples: - We usually have separate window .h and .cc files and a main.cc file. We have one class per file, so you might need to put the derived DrawingArea in separate files. - Use the Main::run(window) technique and show_all_children() instead of show_all(). - Use capitals for class names, instead of lower case and _. - Put protected members at the end of class declarations. - I think we use one simple gtkmm.h include. 3. In the get_window()->draw_line(get_style()->get_black_gc(), 5, 2, 5, 20); line, can we please use variables for the window and gc, to make it look more concise? 4. *_event() signal handlers are confusing, so we need a comment saying what the return value does.
Created attachment 19483 [details] Replacement drawingareas.tar.bz2 with updated example code
Created attachment 19484 [details] [review] tutorial xml file patch, with paths changed to reflect renamed drawingarea{1,2} to drawingarea_{lines,text}
Thanks for the comments - I'd originally tried to make as few changes as possible from the original to make it work with current gtkmm. I've just attached updated patches that incorporate the changes requested.
This is checked in, with a few minor source code changes: - Use of m_ prefix with member variables. - Use of 2 spaces instead of tabs. - I removed the member variables from one of the examples because they are not used. I don't think they are used in the other example, but it's bigger, and people can probably imagine how they might be useful. - I have removed the old drawingarea example. Well done. It's great to finally have this done.
Oops, something isn't working: http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch14s03.html The examples should be at the end of the chapter, by the way, with a screenshot, like the others. Reopening.
I am fixing this.
Fixed: http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch14.html Thanks again.