Re: cairomm in a Gtk::Paned container



On 9/10/07, Pierre Benz <pbenz imaginet co za> wrote:
>
>  seems like a second attempt would be better.
>
>  http://people.cs.uct.ac.za/~bnzpie001/mazeassassin.cpp
>  http://people.cs.uct.ac.za/~bnzpie001/ma_mainwindow.cpp
> http://people.cs.uct.ac.za/~bnzpie001/ma_mainwindow.h
>  http://people.cs.uct.ac.za/~bnzpie001/ma_mapdraw.cpp
> http://people.cs.uct.ac.za/~bnzpie001/ma_mapdraw.h
>
>  So very very sorry for this
>  I'm going to step away from the keyboard now!!
>
>  Pierre
>
>  On Mon, 2007-09-10 at 18:27 +0200, Pierre Benz wrote:
>
>  There's a mistake on my links
>
>  it should be
>  http://people.cs,uct.ac.za/~bnzpie001/mazeassassin.cpp
>  http://people.cs.uct.ac.za/~bnzpie001/ma_mainwindow.cpp
> http://people.cs,uct.ac.za/~bnzpie001/ma_mainwindow.h
>  http://people.cs,uct.ac.za/~bnzpie001/ma_mapdraw.h
> http://people.cs.uct.ac.za/~bnzpie001/ma_mapdraw.cpp
>
>  so sorry
>  Pierre
>
>  On Mon, 2007-09-10 at 18:03 +0200, Pierre Benz wrote:
>
>  Hi
>
>  I'm trying to put cairo in a Gtk::Paned container via a Gtk::DrawingArea
> and seem to be hitting problems. I just went on the IRC channel, but I guess
> the guys there never realised to complete noobness that is me.
>
>  Anyways, my sourcecode can be found at
>  http://people.uct.ac.za/~bnzpie001/mazeassassin.cpp
>  http://people.uct.ac.za/~bnzpie001/ma_mainwindow.cpp
> http://people.uct.ac.za/~bnzpie001/ma_mainwindow.h
>  http://people.uct.ac.za/~bnzpie001/ma_mapdraw.cpp
> http://people.uct.ac.za/~bnzpie001/ma_mapdraw.h
>
>  mazeassassin is where int main is found and calls ma_mainwindow
>  mainwindow calls ma_mapdraw
>
>  basically what i'm trying to do is represent a 10x10 map made like
>  1111111111
>  1000000001
>  1000000001
>  1000000001
>  1000000001
>  1000000001
>  1000000001
>  1000000001
>  1000000001
>  1111111111
>
>  but present it via cairo, which will be put in a paned container, which
> itself would be put in a vbox.
>
>  If anyone feels like helping me out on this, I would be much appreciated.
>  plus if anyone could just demonstrate or draw a line from top left to
> bottom left of the pane, to demonstrate how it's done, i would love them for
> ever.
>
>  thanks in advance
>
>  Pierre _______________________________________________

You have a couple of issues here.
1) in ma_mainwindow.cpp, you are creating a MapDraw object (on the
stack) and then adding it to the m_pane widget.  the problem with this
is that as soon as the MainWindow constructor finishes, the MapDraw
object will be destroyed (you'll see the ~MapDraw() destructor get
called if you run the program in a debugger).  If you make it a class
member instead, it should work better.
2) You are adding the MapDraw object to a widget of type Gtk::Paned,
however this is a base class for the HPaned or VPaned objects and
you're not really supposed to use it directly -- use the HPaned or
VPaned class instead
3) your expose event handler was never called because of issue #1, but
if it had been called, it wouldn't have drawn anything.  Try something
like this instead:

bool
MapDraw::on_expose_event(GdkEventExpose* event){
    const double LINE_WIDTH = 2.0;
    Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
    cr->set_source_rgb(1.0, 0.0, 0.0);
    cr->set_line_width(LINE_WIDTH);
    Gdk::Rectangle allocation = get_allocation ();
    // move to top left corner (but shifted over by half a line width so that
    // the entire line width falls within the widget boundary
    cr->move_to(LINE_WIDTH / 2.0, 0.0);
    // 'draw' the path to bottom left corner
    cr->line_to(LINE_WIDTH / 2.0, allocation.get_height ());
    // stroke the path
    cr->stroke ();
    return true;
}

Once you've done all of that, you should see something drawn to the
screen.  Hope that helps.
-- 
jonner



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]