GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pixmap.H
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef PIXMAP_H_
18 #define PIXMAP_H_
19 
20 #include <gtk/gtk.h>
21 
22 class Pixmap {
23  protected:
24  GtkWidget *widget;
25  GdkPixmap *pixmap;
26 
30  GtkWidget* show(void) {
31  gtk_widget_show(widget);
32  return widget;
33  }
37  GtkWidget* hide(void) {
38  gtk_widget_hide(widget);
39  return widget;
40  }
41 
42 
44  static gboolean configure_event( GtkWidget *widget, GdkEventConfigure *event, gpointer data) {
45  Pixmap *da=static_cast<Pixmap*>(data);
46  da->setPixmap(gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1));
47  gdk_draw_rectangle (da->getPixmap(), widget->style->black_gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
48 
49  return TRUE;
50  }
51 
53  static gboolean expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer data) {
54  Pixmap *da=static_cast<Pixmap*>(data);
55  gdk_draw_drawable(widget->window, widget->style->fg_gc[gtk_widget_get_state (widget)], da->getPixmap(), event->area.x, event->area.y, event->area.x, event->area.y,
56  event->area.width, event->area.height);
57 
58  return FALSE;
59  }
60 
62  void destroyPixmap(void){
63  if (pixmap){
64  g_object_unref(pixmap);
65  pixmap=NULL;
66  }
67  }
68 
69  void init(int width, int height){
70  pixmap=NULL;
71  widget=gtk_drawing_area_new ();
72  show();
73 
74  g_signal_connect (GTK_OBJECT(widget), "expose_event", (GtkSignalFunc) expose_event, this);
75  g_signal_connect (GTK_OBJECT(widget), "configure_event", (GtkSignalFunc) configure_event, this);
76 
77  gtk_drawing_area_size(GTK_DRAWING_AREA(widget), width, height);
78  }
79  public:
80 
83  Pixmap(){
84  init(200, 200);
85  }
90  Pixmap(int width, int height){
91  init(width, height);
92  }
93 
96  virtual ~Pixmap(void) {
97  destroyPixmap();
98  }
99 
103  GtkWidget *getWidget(void){return widget;}
104 
108  GdkPixmap *getPixmap(void){return pixmap;}
109 
113  void setPixmap(GdkPixmap *pixmap_){
114  destroyPixmap();
115  pixmap=pixmap_;
116  }
117 
118 
119 };
120 #endif //PIXMAP_H_