gtk newbie bitmap question
- From: Reed Lawson <reedlawson yahoo com>
- To: gtk-app-devel-list gnome org
- Cc: reedlawson yahoo com
- Subject: gtk newbie bitmap question
- Date: Fri, 17 Oct 2003 09:04:49 -0700 (PDT)
Hi,
I am so green at GTK, that I don't really know
what I'm doing, but my goal is to write a 1 bit
bitmap (XBM format) that is 240 x 64 bits to a
small 240x64 window. eventually I want to embelish
this, but first I'd just like to get it on the
screen. I #include the XBM file, so its a const
in my code.
I'm going through the 2.0 Tutorial (which is Great,
btw). I got the 'hello world' thing going just fine
so I'm pretty sure my src install is working. I
skipped
ahead to the "Scribble" app because I thought it was
closest to my app. I got the "config_event" and
"expose_event" things to work. It does draw a
nice white window 240x64. Feels like I am almost
there But:
When I try to change the depth from -1 to 1 on the
call to gdk_pixmap_new(), I get an long winded
error message when I try to run it. So, I thought
I'd try using some of the "bitmap" API in gdk.
Here is what I ended up with which compiles with
no errors but when run, gives the same
long winded error:
-----------------------------------------------------
The program 'lcdd' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter
attributes)'.
(Details: serial 140 error_code 8 request_code 62
minor_code 0)
(Note to programmers: normally, X errors are
reported asynchronously;
that is, you will receive the error a while after
causing it.
To debug your program, run it with the --sync
command line
option to change this behavior. You can then get a
meaningful
backtrace from your debugger if you break on the
gdk_x_error() function.)
r
-----------------------------------------------------
Can anyone tell me why? I know it must be something
really stupid.
Thanks!
#include "bike.xbm"
/* Backing pixmap for drawing area */
static GdkBitmap *bitmap = NULL;
/* Create a new backing pixmap of the appropriate size
*/
static gboolean
configure_event( GtkWidget *widget, GdkEventConfigure
*event )
{
if (bitmap)
g_object_unref (bitmap);
bitmap = gdk_bitmap_create_from_data
(widget->window,
bike_bits,
widget->allocation.width,
widget->allocation.height);
return TRUE;
}
/* Redraw the screen from the backing pixmap */
static gboolean
expose_event( GtkWidget *widget, GdkEventExpose *event
)
{
gdk_draw_pixmap(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
bitmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width,
event->area.height);
return FALSE;
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *drawing_area;
/* Initialize Gtk */
gtk_init (&argc, &argv);
/* Make the main window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* make a drawing area widget */
drawing_area = gtk_drawing_area_new();
/* Set the size of the drawing area */
/* gtk_drawing_area_size is depreciated */
gtk_widget_set_size_request(drawing_area,
LCD_X_SIZE,
LCD_Y_SIZE);
/* When the window is given the "delete_event"
signal (this is given
* by the window manager, usually by the "close"
option, or on the
* titlebar), we ask it to call the delete_event
() function
* as defined above. The data passed to the
callback
* function is NULL and is ignored in the callback
function. */
g_signal_connect (G_OBJECT (window),
"delete_event",
G_CALLBACK (delete_event), NULL);
/* Here we connect the "destroy" event to a signal
handler.
* This event occurs when we call
gtk_widget_destroy() on the window,
* or if we return FALSE in the "delete_event"
callback. */
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
/* Connect up to the "configure" event */
g_signal_connect (G_OBJECT (drawing_area),
"configure_event",
G_CALLBACK (configure_event),
NULL);
/* Connect up to the "expose" event */
g_signal_connect (G_OBJECT (drawing_area),
"expose_event",
G_CALLBACK (expose_event),
NULL);
/* This packs the button into the window (a gtk
container). */
gtk_container_add (GTK_CONTAINER (window),
drawing_area);
/* The final step is to display this newly created
widget. */
gtk_widget_show (drawing_area);
/* This is the last thing we call. */
gtk_widget_show (window);
gtk_main ();
return 0;
=====
Reed Lawson
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]