|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Howto manage objects in DrawingArea?Hello,
yet another noob question: i need to draw objects like Bezier curves or text onto a DrawingArea. I derived a own class from DrawingArea and made classes for every object i want to draw (e.g. BezierCurve). All these objects have a draw() method. But to draw the object this method of course needs to have a pointer to the DrawingArea. Not only to get the GDK::Window to draw on but also to get some properties like the offset and zoom, so the object knows at which position it should draw. My question is how to manage this nicely? Until now i passed every object a pointer to my DrawingArea class, but this is very ugly i think. Especially since i have an inclusion cycle because the DrawingArea header needs to include the objects headers which again need to include the DrawingArea. How can i manage this access better? e.g. how to the gtk widgets do it, what happens when i add a widget to a container. How does it know where it should draw itself on? thanks a lot in advance buergi _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
Re: Howto manage objects in DrawingArea?On Wed, 2009-07-01 at 15:44 +0200, buergi wrote: > Hello, > yet another noob question: > i need to draw objects like Bezier curves or text onto a DrawingArea. > I derived a own class from DrawingArea and made classes for every object > i want to draw (e.g. BezierCurve). All these objects have a draw() method. > But to draw the object this method of course needs to have a pointer to > the DrawingArea. Not only to get the GDK::Window to draw on but also to > get some properties like the offset and zoom, so the object knows at > which position it should draw. You could simply pass arguments to the draw() that included the offset/size. You could provide the window reference to the constructor and only when/if it changed. Simply providing the GdkWindow and geometry would also eliminate the circular reference issue. Chuck > thanks a lot in advance > > buergi > _______________________________________________ > gtkmm-list mailing list > gtkmm-list@... > http://mail.gnome.org/mailman/listinfo/gtkmm-list _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
Re: Howto manage objects in DrawingArea?Hi,
first of all I am not quite sure why you would want to split up a single responsibility (draw something in MyDrawingAreaWidget) over several classes. Perhaps it's some sort of requirement. But if your shape classes are not derived from a DrawingArea then they probably shouldn't draw themselves because, well, drawing the shapes is the responsibility of your MyDrawingAreaWidget. I would have my shape objects provide all the necessary information/computation instead and query them when I draw the shapes in MyDrawingAreaWidget. regards, Michael Am Mittwoch, den 01.07.2009, 15:44 +0200 schrieb buergi: > Hello, > yet another noob question: > i need to draw objects like Bezier curves or text onto a DrawingArea. > I derived a own class from DrawingArea and made classes for every object > i want to draw (e.g. BezierCurve). All these objects have a draw() method. > But to draw the object this method of course needs to have a pointer to > the DrawingArea. Not only to get the GDK::Window to draw on but also to > get some properties like the offset and zoom, so the object knows at > which position it should draw. > > My question is how to manage this nicely? > Until now i passed every object a pointer to my DrawingArea class, but > this is very ugly i think. > Especially since i have an inclusion cycle because the DrawingArea > header needs to include the objects headers which again need to include > the DrawingArea. > How can i manage this access better? e.g. how to the gtk widgets do it, > what happens when i add a widget to a container. How does it know where > it should draw itself on? > > thanks a lot in advance > > buergi _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
Re: Howto manage objects in DrawingArea?thanks for the answers
> first of all I am not quite sure why you would want to split up a single > responsibility (draw something in MyDrawingAreaWidget) over several > classes. Perhaps it's some sort of requirement. no actually it's not, thought it would be the best this way so all drawing stuff is done in the object which should be drawn. so the code which does curve handling is done all in one file and the code for text objects is done in another > But if your shape classes are not derived from a DrawingArea then they > probably shouldn't draw themselves because, well, drawing the shapes is > the responsibility of your MyDrawingAreaWidget. I would have my shape > objects provide all the necessary information/computation instead and > query them when I draw the shapes in MyDrawingAreaWidget. perhaps your right, that way everything might be easier, but i'm afraid that i'll get a huge DrawingArea class, since all the drawing and especially the event handling is done in that one class. hm and while i'm at reconsidering my whole concept :) i thought it would be good to move the whole code for the tools (selection tool, curve tool etc.) in seperate classes which implement methods like on_button_press_event, on_motion_notify_event etc. the DrawingArea class passes the events to the currently active tool by calling it's corresponding method. is that clever or is it again just a silly idea of mine? buergi _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
Clever event management? [was: Howto manage objects in DrawingArea?]Hello again,
can anyone give me a hint how to design a smart way to manage events, especially the mouse events. Project is still the same: in principle a simple vector graphics editor. First of all only bezier curve drawing/editing is most important. I've no idea how one usually makes a clever event handling. Of course the interpretation of the mouse events needs to be totally different depending on which tool is selected. I thought about making a class for each tool. The MyDrawingArea class passes the on_button_pressed etc. events to the active tool which handles them. I don't know if it's a clever way of handling the events, since i also saw many projects which had a huge central event handler class. Another way would be to include the event management totally in the MyDrawingArea class. Another thing is who should be responsible for moving an object e.g.? the object itself or the eventhandler class? i thing the object itself would be better since e.g. when dragging an object over the drawingarea i need to store the position where the object was before the drag started, so it's position can be reseted if one cancels the drag. but on the other hand i want to separate the abstract objects from the GUI event handling stuff, so i don't want to put any event handling routines in the beziercurve class itself. At the moment i'm totally confused how to approach all this event handling stuff. I'm very noob in planning somewhat larger projects, hope anyone got some hints for me. thanks so much in advance buergi _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
| Free embeddable forum powered by Nabble | Forum Help |