scribble-simple in C++, need help



Hi,

I'm trying to rewrite the scribble-simple example from the gtk tutorial
(http://www.levien.com/~slow/gtk/tutorial/gtk_tut-20.html ) in C++
using gtk--. But I'm having problems with calls to gdk_xxxx.
I thought that after the call to gdk_draw_rectangle() I should see
the white drawing area, but nothing happens and the drawing area
stays grey. The Window itself and the quit button are shown.
What's wrong with my code or is it something missing?

Thank's for any hints.

I'm using gtk---0.7.8 and gtk+-0.99.3
 

ciao
Alois



--------------------------------------------------------------

/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh
MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>
#include <gtk--.h>

// macros
#define GTKOBJ(obj)  ((GtkWidget*)obj->gtkobject)

/* Backing pixmap for drawing area */
static GdkPixmap *pixmap = NULL;


static gint
quit (GdkEventAny*) {

    // debug message
    printf("delete_event\n");

    // quit the application
    Gtk_Main::instance()->quit();
    return 0;
}


class MyGtk_DrawingArea : public Gtk_DrawingArea
{
public:
    MyGtk_DrawingArea()
    {
        // empty
    }

    // override default configure_event
    gint configure_event_impl(GdkEventConfigure *)
    {    
        // debug message
        printf("MyGtk_DrawingArea::configure_event_impl\n");
        
        // after this two calls we should see a white area
        // but nothing happens ???
        pixmap = gdk_pixmap_new(GTKOBJ(this)->window,
                  GTKOBJ(this)->allocation.width,
                  GTKOBJ(this)->allocation.height,
                  -1);
        
        gdk_draw_rectangle (pixmap,
                  GTKOBJ(this)->style->white_gc,
                  TRUE,
                  0, 0,
                  GTKOBJ(this)->allocation.width,
                  GTKOBJ(this)->allocation.height);
        
        return 0;
    }
};


int
main (int argc, char *argv[])
{
    Gtk_Window *window;
    MyGtk_DrawingArea *drawing_area;
    Gtk_VBox *vbox;
    Gtk_Button *button;

    Gtk_Main m( &argc, &argv );
    
    // create window
    window = new Gtk_Window(GTK_WINDOW_TOPLEVEL);
    window->set_title("Test Input");
    connect(window->delete_event, &quit);
    
    // create vbox
    vbox = new Gtk_VBox(FALSE, 0);
    window->add(vbox);
    vbox->show();

    // Create drawing area
    drawing_area = new MyGtk_DrawingArea();
    drawing_area->size(400, 200);
    vbox->pack_start(drawing_area, TRUE, TRUE, 0);
    
    // don't know if this is neccessary
    drawing_area->set_events(GDK_EXPOSURE_MASK
            | GDK_LEAVE_NOTIFY_MASK
            | GDK_BUTTON_PRESS_MASK
            | GDK_POINTER_MOTION_MASK
            | GDK_POINTER_MOTION_HINT_MASK);
    drawing_area->show();
    

    // add quit button
    button = new Gtk_Button("Quit");
    connect( button->clicked, Gtk_Main::instance(), &Gtk_Main::quit );
    vbox->pack_start(button, FALSE, FALSE, 0);    
    button->show();

    // make everything visible
    window->show();
    
    // start event loop
    m.run();
    
    return 0;
}



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