1 /* Copyright 2002      The gtkmm Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17 
18 #ifndef _GDKMM_GENERAL_H
19 #define _GDKMM_GENERAL_H
20 
21 #include <gdkmm/pixbuf.h>
22 #include <gdkmm/color.h>
23 #include <gdkmm/rectangle.h>
24 #include <gdkmm/rgba.h>
25 #include <gdkmm/glcontext.h>
26 #include <gdkmm/window.h>
27 #include <cairomm/context.h>
28 #include <cairomm/region.h>
29 #include <cairomm/surface.h>
30 
31 namespace Gdk
32 {
33 
34 #ifndef GDKMM_DISABLE_DEPRECATED
35 /**  @deprecated Use per-monitor information.
36  */
37 int screen_width();
38 
39 /**  @deprecated Use per-monitor information.
40  */
41 int screen_height();
42 
43 /**  @deprecated Use per-monitor information.
44  */
45 int screen_width_mm();
46 
47 /**  @deprecated Use per-monitor information.
48  */
49 int screen_height_mm();
50 
51 /**  @deprecated Use Gdk::Display::flush() instead.
52  */
53 void flush();
54 #endif //GDKMM_DISABLE_DEPRECATED
55 
56 namespace Cairo
57 {
58 
59 #ifndef GDKMM_DISABLE_DEPRECATED
60 
61 /** Sets the specified Gdk::Color as the source color of the Cairo context.
62  * @param context The cairo context.
63  * @param color The color to use as the source color.
64  *
65  * @newin{2,10}
66  * @deprecated Use set_source_rgba() instead.
67  */
68 void set_source_color(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Gdk::Color& color);
69 
70 #endif //GDKMM_DISABLE_DEPRECATED
71 
72 /** Sets the specified Gdk::RGBA as the source color of the Cairo context.
73  * @param context The cairo context.
74  * @param color The color to use as the source color.
75  *
76  * @newin{3,0}
77  */
78 void set_source_rgba(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Gdk::RGBA& color);
79 
80 /** Sets the given pixbuf as the source pattern for the %Cairo context.
81  * The pattern has an extend mode of Cairo::EXTEND_NONE and is aligned
82  * so that the origin of pixbuf is @a pixbuf_x, @a pixbuf_y.
83  * @param context The cairo context.
84  * @param pixbuf A Gdk::Pixbuf
85  * @param pixbuf_x X coordinate of location to place upper left corner of pixbuf.
86  * @param pixbuf_y Y coordinate of location to place upper left corner of pixbuf.
87  *
88  * @newin{2,10}
89  */
90 void set_source_pixbuf(const ::Cairo::RefPtr< ::Cairo::Context >& context,
91   const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, double pixbuf_x = 0, double pixbuf_y = 0);
92 
93 /** Adds the given rectangle to the current path of the context.
94  *
95  * @param context A cairo context.
96  * @param rectangle A rectangle to add to the path of the context.
97  *
98  * @newin{2,10}
99  */
100 void add_rectangle_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Gdk::Rectangle& rectangle);
101 
102 /** Adds the given region to the current path of the context.
103  *
104  * @param context A cairo context.
105  * @param region A region to add to the path of the context.
106  *
107  * @newin{2,10}
108  */
109 void add_region_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, const ::Cairo::RefPtr< ::Cairo::Region>& region);
110 
111 /** This is a convenience function around Cairo::Context::get_clip_extents().
112  * It rounds the clip extents to integer coordinates and returns
113  * a boolean indicating if a clip area exists.
114  *
115  * @param context A cairo context.
116  * @param[out] rectangle Return location for the clip rectangle.
117  * @returns <tt>true</tt> if a clip rectangle exists, <tt>false</tt> if all
118  *          of @a context is clipped and all drawing can be skipped.
119  *
120  * @newin{3,24}
121  */
122 bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context, Gdk::Rectangle& rectangle);
123 
124 /** This is a convenience function around Cairo::Context::get_clip_extents().
125  *
126  * @param context A cairo context.
127  * @returns <tt>true</tt> if a clip rectangle exists, <tt>false</tt> if all
128  *          of @a context is clipped and all drawing can be skipped.
129  *
130  * @newin{3,24}
131  */
132 bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context);
133 
134 /** Creates a region that covers the area where the given
135  * @a surface is more than 50% opaque.
136  *
137  * This function takes into account device offsets that might be
138  * set with Cairo::Surface::set_device_offset().
139  *
140  * @param surface A cairo surface.
141  * @returns A cairo region.
142  *
143  * @newin{3,24}
144  */
145 ::Cairo::RefPtr< ::Cairo::Region> create_region_from_surface(const ::Cairo::RefPtr< ::Cairo::Surface>& surface);
146 
147 /** Creates an image surface with the same contents as the pixbuf.
148  *
149  * @param pixbuf A Gdk::Pixbuf.
150  * @param scale The scale of the new surface, or 0 to use same as @a for_window.
151  * @param for_window The window this will be drawn to, or an empty
152  *        Glib::RefPtr<Gdk::Window> if none.
153  * @returns A new cairo surface.
154  *
155  * @newin{3,24}
156  */
157 ::Cairo::RefPtr< ::Cairo::ImageSurface> create_surface_from_pixbuf(const Glib::RefPtr<const Gdk::Pixbuf>& pixbuf,
158   int scale, const Glib::RefPtr<Gdk::Window>& for_window = {});
159 
160 /** This is the main way to draw GL content in gtkmm.
161  * It takes a render buffer ID (@a source_type == GL_RENDERBUFFER) or a texture id
162  * (@a source_type == GL_TEXTURE) and draws it onto @a context with an OVER operation,
163  * respecting the current clip. The top left corner of the rectangle specified by
164  * @a x, @a y, @a width and @a height will be drawn at the current (0,0) position
165  * of the cairo context.
166  *
167  * This will work for *all* cairo contexts, as long as @a window is realized, but the
168  * fallback implementation that reads back the pixels from the buffer may be
169  * used in the general case. In the case of direct drawing to a window with
170  * no special effects applied to @a context it will however use a more efficient
171  * approach.
172  *
173  * For GL_RENDERBUFFER the code will always fall back to software for buffers
174  * with alpha components, so make sure you use GL_TEXTURE if using alpha.
175  *
176  * Calling this may change the current GL context.
177  *
178  * @param context A cairo context.
179  * @param window The window we're rendering for (not necessarily into).
180  * @param source The GL ID of the source buffer.
181  * @param source_type The type of the @a source.
182  * @param buffer_scale The scale-factor that the @a source buffer is allocated for.
183  * @param x The source x position in @a source to start copying from in GL coordinates.
184  * @param y The source y position in @a source to start copying from in GL coordinates.
185  * @param width The width of the region to draw.
186  * @param height The height of the region to draw.
187  *
188  * @newin{3,24}
189  */
190 void draw_from_gl(const ::Cairo::RefPtr< ::Cairo::Context >& context,
191   const Glib::RefPtr<Gdk::Window>& window, int source, int source_type,
192   int buffer_scale, int x, int y, int width, int height);
193 
194 } //namespace Cairo
195 
196 } //namespace Gdk
197 
198 #endif //_GDKMM_GENERAL_H
199