20130313
[gdash.git] / src / gtk / gtkscreen.cpp
blob5d8f7646631153cce003d75fa145224e0c2a5aab
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "config.h"
19 #include <gtk/gtk.h>
21 #include "gtk/gtkpixmap.hpp"
22 #include "gtk/gtkscreen.hpp"
23 #include "cave/helper/colors.hpp"
25 void GTKScreen::fill_rect(int x, int y, int w, int h, const GdColor& c)
27 GdkColor col;
28 col.red=c.get_r()*257; // 257, as 255*257=65535
29 col.green=c.get_g()*257; // 257, as 255*257=65535
30 col.blue=c.get_b()*257; // 257, as 255*257=65535
31 gdk_gc_set_rgb_fg_color(gc, &col);
32 gdk_draw_rectangle(pixmap, gc, TRUE, x, y, w, h);
35 void GTKScreen::blit_full(Pixmap const &src, int dx, int dy, int x, int y, int w, int h) const
37 GTKPixmap const &srcgtk=static_cast<GTKPixmap const &>(src);
39 if (srcgtk.mask) {
40 gdk_gc_set_clip_mask(gc, srcgtk.mask);
41 gdk_gc_set_clip_origin(gc, dx, dy);
43 gdk_draw_drawable(pixmap, gc, srcgtk.pixmap, x, y, dx, dy, w, h);
44 if (srcgtk.mask) {
45 gdk_gc_set_clip_mask(gc, NULL);
46 gdk_gc_set_clip_origin(gc, 0, 0);
50 void GTKScreen::set_clip_rect(int x1, int y1, int w, int h)
52 GdkRectangle rect;
53 rect.x=x1;
54 rect.y=y1;
55 rect.width=w;
56 rect.height=h;
57 gdk_gc_set_clip_rectangle(gc, &rect);
60 void GTKScreen::remove_clip_rect()
62 gdk_gc_set_clip_rectangle(gc, NULL);
66 GTKScreen::GTKScreen(GtkWidget *drawing_area_)
67 : Screen(),
68 drawing_area(drawing_area_),
69 pixmap(NULL),
70 gc(NULL)
72 gtk_widget_set_double_buffered(drawing_area, FALSE);
76 void GTKScreen::configure_size() {
77 gtk_widget_set_size_request(drawing_area, w, h);
78 if (pixmap)
79 g_object_unref(pixmap);
80 if (gc)
81 g_object_unref(gc);
82 pixmap = gdk_pixmap_new(GDK_DRAWABLE(drawing_area->window), w, h, -1);
83 gc = gdk_gc_new(GDK_DRAWABLE(pixmap));
87 void GTKScreen::set_title(char const *title) {
88 GtkWidget *toplevel = gtk_widget_get_toplevel(drawing_area);
89 gtk_window_set_title(GTK_WINDOW(toplevel), title);
93 void GTKScreen::flip() {
94 gdk_draw_drawable(drawing_area->window, gc, pixmap, 0, 0, 0, 0, w, h);