2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#ifndef __CAIRO_DOCK_DRAW_OPENGL__
22
#define __CAIRO_DOCK_DRAW_OPENGL__
26
#include <gdk/x11/gdkglx.h>
27
#include <gtk/gtkgl.h>
30
#include "cairo-dock-struct.h"
31
#include "cairo-dock-opengl.h"
32
#include "cairo-dock-container.h"
37
*@file cairo-dock-draw-opengl.h This class provides some useful functions to draw with OpenGL.
40
void cairo_dock_set_icon_scale (Icon *pIcon, CairoContainer *pContainer, double fZoomFactor);
42
void cairo_dock_draw_icon_opengl (Icon *pIcon, CairoDock *pDock);
44
void cairo_dock_translate_on_icon_opengl (Icon *icon, CairoContainer *pContainer, double fDockMagnitude);
46
/** Draw an icon, according to its current parameters : position, transparency, reflect, rotation, stretching. Also draws its indicators, label, and quick-info. It generates a CAIRO_DOCK_RENDER_ICON notification.
47
*@param icon the icon to draw.
48
*@param pDock the dock containing the icon.
49
*@param fDockMagnitude current magnitude of the dock.
50
*@param bUseText TRUE to draw the labels.
52
void cairo_dock_render_one_icon_opengl (Icon *icon, CairoDock *pDock, double fDockMagnitude, gboolean bUseText);
54
void cairo_dock_render_hidden_dock_opengl (CairoDock *pDock);
59
/** Load a cairo surface into an OpenGL texture. The surface can be destroyed after that if you don't need it. The texture will have the same size as the surface.
60
*@param pImageSurface the surface, created with one of the 'cairo_dock_create_surface_xxx' functions.
61
*@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture.
63
GLuint cairo_dock_create_texture_from_surface (cairo_surface_t *pImageSurface);
65
/** Load a pixels buffer representing an image into an OpenGL texture.
66
*@param pTextureRaw a buffer of pixels.
67
*@param iWidth width of the image.
68
*@param iHeight height of the image.
69
*@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture.
71
GLuint cairo_dock_load_texture_from_raw_data (const guchar *pTextureRaw, int iWidth, int iHeight);
73
/** Load an image on the dock into an OpenGL texture. The texture will have the same size as the image. The size is given as an output, if you need it for some reason.
74
*@param cImagePath path to an image.
75
*@param fImageWidth pointer that will be filled with the width of the image.
76
*@param fImageHeight pointer that will be filled with the height of the image.
77
*@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture.
79
GLuint cairo_dock_create_texture_from_image_full (const gchar *cImagePath, double *fImageWidth, double *fImageHeight);
81
/** Load an image on the dock into an OpenGL texture. The texture will have the same size as the image.
82
*@param cImagePath path to an image.
83
*@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture.
85
#define cairo_dock_create_texture_from_image(cImagePath) cairo_dock_create_texture_from_image_full (cImagePath, NULL, NULL)
87
/** Delete an OpenGL texture from the Graphic Card.
88
*@param iTexture variable containing the ID of a texture.
90
#define _cairo_dock_delete_texture(iTexture) glDeleteTextures (1, &iTexture)
92
/** Update the icon's texture with its current cairo surface. This allows you to draw an icon with libcairo, and just copy the result to the OpenGL texture to be able to draw the icon in OpenGL too.
93
*@param pIcon the icon.
95
void cairo_dock_update_icon_texture (Icon *pIcon);
96
/** Update the icon's label texture with its current label surface.
97
*@param pIcon the icon.
99
void cairo_dock_update_label_texture (Icon *pIcon);
100
/** Update the icon's quick-info texture with its current quick-info surface.
101
*@param pIcon the icon.
103
void cairo_dock_update_quick_info_texture (Icon *pIcon);
105
void cairo_dock_draw_hidden_appli_icon (Icon *pIcon, CairoContainer *pContainer, gboolean bStateChanged);
110
/** Enable texture drawing.
112
#define _cairo_dock_enable_texture(...) do { \
113
glEnable (GL_BLEND);\
114
glEnable (GL_TEXTURE_2D);\
115
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);\
116
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);\
117
glEnable (GL_LINE_SMOOTH);\
118
glPolygonMode (GL_FRONT, GL_FILL); } while (0)
120
/** Disable texture drawing.
122
#define _cairo_dock_disable_texture(...) do { \
123
glDisable (GL_TEXTURE_2D);\
124
glDisable (GL_LINE_SMOOTH);\
125
glDisable (GL_BLEND); } while (0)
127
/** Set the alpha channel to a current value, other channels are set to 1.
130
#define _cairo_dock_set_alpha(fAlpha) glColor4f (1., 1., 1., fAlpha)
132
/** Set the color blending to overwrite.
134
#define _cairo_dock_set_blend_source(...) glBlendFunc (GL_ONE, GL_ZERO)
136
/** Set the color blending to mix, for premultiplied texture.
138
#define _cairo_dock_set_blend_alpha(...) glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
140
/** Set the color blending to mix.
142
#define _cairo_dock_set_blend_over(...) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
144
/** Set the color blending to mix on a pbuffer.
146
#define _cairo_dock_set_blend_pbuffer(...) glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
148
#define _cairo_dock_apply_current_texture_at_size(w, h) do { \
150
glTexCoord2f(0., 0.); glVertex3f(-.5*w, .5*h, 0.);\
151
glTexCoord2f(1., 0.); glVertex3f( .5*w, .5*h, 0.);\
152
glTexCoord2f(1., 1.); glVertex3f( .5*w, -.5*h, 0.);\
153
glTexCoord2f(0., 1.); glVertex3f(-.5*w, -.5*h, 0.);\
155
#define _cairo_dock_apply_current_texture_at_size_with_offset(w, h, x, y) do { \
157
glTexCoord2f(0., 0.); glVertex3f(x-.5*w, y+.5*h, 0.);\
158
glTexCoord2f(1., 0.); glVertex3f(x+.5*w, y+.5*h, 0.);\
159
glTexCoord2f(1., 1.); glVertex3f(x+.5*w, y-.5*h, 0.);\
160
glTexCoord2f(0., 1.); glVertex3f(x-.5*w, y-.5*h, 0.);\
162
#define _cairo_dock_apply_current_texture_portion_at_size_with_offset(u, v, du, dv, w, h, x, y) do { \
164
glTexCoord2f(u, v); glVertex3f(x-.5*w, y+.5*h, 0.);\
165
glTexCoord2f(u+du, v); glVertex3f(x+.5*w, y+.5*h, 0.);\
166
glTexCoord2f(u+du, v+dv); glVertex3f(x+.5*w, y-.5*h, 0.);\
167
glTexCoord2f(u, v+dv); glVertex3f(x-.5*w, y-.5*h, 0.);\
170
/** Draw a texture centered on the current point, at a given size.
171
*@param iTexture the texture
175
#define _cairo_dock_apply_texture_at_size(iTexture, w, h) do { \
176
glBindTexture (GL_TEXTURE_2D, iTexture);\
177
_cairo_dock_apply_current_texture_at_size (w, h); } while (0)
179
/** Apply a texture centered on the current point and at the given scale.
180
*@param iTexture the texture
182
#define _cairo_dock_apply_texture(iTexture) _cairo_dock_apply_texture_at_size (iTexture, 1, 1)
184
/** Draw a texture centered on the current point, at a given size, and with a given transparency.
185
*@param iTexture the texture
188
*@param fAlpha the transparency, between 0 and 1.
190
#define _cairo_dock_apply_texture_at_size_with_alpha(iTexture, w, h, fAlpha) do { \
191
_cairo_dock_set_alpha (fAlpha);\
192
_cairo_dock_apply_texture_at_size (iTexture, w, h); } while (0)
194
#define cairo_dock_apply_texture _cairo_dock_apply_texture
195
#define cairo_dock_apply_texture_at_size _cairo_dock_apply_texture_at_size
196
void cairo_dock_draw_texture_with_alpha (GLuint iTexture, int iWidth, int iHeight, double fAlpha);
197
void cairo_dock_draw_texture (GLuint iTexture, int iWidth, int iHeight);
199
void cairo_dock_apply_icon_texture (Icon *pIcon);
200
void cairo_dock_apply_icon_texture_at_current_size (Icon *pIcon, CairoContainer *pContainer);
201
void cairo_dock_draw_icon_texture (Icon *pIcon, CairoContainer *pContainer);
206
#define _CAIRO_DOCK_PATH_DIM 2
207
#define _cairo_dock_define_static_vertex_tab(iNbVertices) static GLfloat pVertexTab[(iNbVertices) * _CAIRO_DOCK_PATH_DIM]
208
#define _cairo_dock_return_vertex_tab(...) return pVertexTab
209
#define _cairo_dock_set_vertex_x(_i, _x) pVertexTab[_CAIRO_DOCK_PATH_DIM*_i] = _x
210
#define _cairo_dock_set_vertex_y(_i, _y) pVertexTab[_CAIRO_DOCK_PATH_DIM*_i+1] = _y
211
#define _cairo_dock_set_vertex_xy(_i, _x, _y) do {\
212
_cairo_dock_set_vertex_x(_i, _x);\
213
_cairo_dock_set_vertex_y(_i, _y); } while (0)
214
#define _cairo_dock_close_path(i) _cairo_dock_set_vertex_xy (i, pVertexTab[0], pVertexTab[1])
215
#define _cairo_dock_set_vertex_pointer(pVertexTab) glVertexPointer (_CAIRO_DOCK_PATH_DIM, GL_FLOAT, 0, pVertexTab)
217
const GLfloat *cairo_dock_generate_rectangle_path (double fDockWidth, double fFrameHeight, double fRadius, gboolean bRoundedBottomCorner, int *iNbPoints);
218
GLfloat *cairo_dock_generate_trapeze_path (double fDockWidth, double fFrameHeight, double fRadius, gboolean bRoundedBottomCorner, double fInclination, double *fExtraWidth, int *iNbPoints);
220
void cairo_dock_draw_frame_background_opengl (GLuint iBackgroundTexture, double fDockWidth, double fFrameHeight, double fDockOffsetX, double fDockOffsetY, const GLfloat *pVertexTab, int iNbVertex, CairoDockTypeHorizontality bHorizontal, gboolean bDirectionUp, double fDecorationsOffsetX);
221
void cairo_dock_draw_current_path_opengl (double fLineWidth, double *fLineColor, int iNbVertex);
223
/** Draw a rectangle with rounded corners. The rectangle will be centered at the current point. The current matrix is altered.
224
*@param fRadius radius if the corners.
225
*@param fLineWidth width of the line. If set to 0, the background will be filled with the provided color, otherwise the path will be stroke with this color.
226
*@param fFrameWidth width of the rectangle, without the corners.
227
*@param fFrameHeight height of the rectangle, including the corners.
228
*@param fDockOffsetX translation on X before drawing the rectangle.
229
*@param fDockOffsetY translation on Y before drawing the rectangle.
230
*@param fLineColor color of the line if fLineWidth is non nul, or color of the background otherwise.
232
void cairo_dock_draw_rounded_rectangle_opengl (double fRadius, double fLineWidth, double fFrameWidth, double fFrameHeight, double fDockOffsetX, double fDockOffsetY, double *fLineColor);
234
GLfloat *cairo_dock_generate_string_path_opengl (CairoDock *pDock, gboolean bIsLoop, gboolean bForceConstantSeparator, int *iNbPoints);
235
void cairo_dock_draw_string_opengl (CairoDock *pDock, double fStringLineWidth, gboolean bIsLoop, gboolean bForceConstantSeparator);
242
/** Create a texture from a text. The text is drawn in white, so that you can later colorize it with a mere glColor.
243
*@param cText the text
244
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
245
*@param pSourceContext a cairo context, not altered by the function.
246
*@param iWidth a pointer that will be filled with the width of the texture.
247
*@param iHeight a pointer that will be filled with the height of the texture.
248
*@return a newly allocated texture.
250
GLuint cairo_dock_create_texture_from_text_simple (const gchar *cText, const gchar *cFontDescription, cairo_t* pSourceContext, int *iWidth, int *iHeight);
252
/// Structure used to load a font for OpenGL text rendering.
253
struct _CairoDockGLFont {
264
/** Load a font into bitmaps. You can load any characters of font with this function. The drawback is that each character is a bitmap, that is to say you can't zoom them.
265
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
266
*@param first first character to load.
267
*@param count number of characters to load.
268
*@return a newly allocated opengl font.
270
CairoDockGLFont *cairo_dock_load_bitmap_font (const gchar *cFontDescription, int first, int count);
272
/** Load a font into textures. You can then render your text like a normal texture (zoom, etc). The drawback is that only a mono font can be used with this function.
273
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
274
*@param first first character to load.
275
*@param count number of characters to load.
276
*@return a newly allocated opengl font.
278
CairoDockGLFont *cairo_dock_load_textured_font (const gchar *cFontDescription, int first, int count);
280
/** Like the previous function, but loads the characters from an image. The image must be squared and contain the 256 extended ASCII characters in the alphabetic order.
281
*@param cImagePath path to the image.
282
*@return a newly allocated opengl font.
284
CairoDockGLFont *cairo_dock_load_textured_font_from_image (const gchar *cImagePath);
286
/** Free an opengl font.
287
*@param pFont the font.
289
void cairo_dock_free_gl_font (CairoDockGLFont *pFont);
291
/** Compute the size a text will take for a given font.
292
*@param cText the text
293
*@param pFont the font.
294
*@param iWidth a pointer that will be filled with the width of the text.
295
*@param iHeight a pointer that will be filled with the height of the text.
297
void cairo_dock_get_gl_text_extent (const gchar *cText, CairoDockGLFont *pFont, int *iWidth, int *iHeight);
299
/** Render a text for a given font. In the case of a bitmap font, the current raster position is used. In the case of a texture font, the current model view is used.
300
*@param cText the text
301
*@param pFont the font.
303
void cairo_dock_draw_gl_text (const guchar *cText, CairoDockGLFont *pFont);
305
/** Like /ref cairo_dock_draw_gl_text but at a given position.
306
*@param cText the text
307
*@param pFont the font.
308
*@param x x position of the left bottom corner of the text.
309
*@param y y position of the left bottom corner of the text.
311
void cairo_dock_draw_gl_text_at_position (const guchar *cText, CairoDockGLFont *pFont, int x, int y);
313
/** Like /ref cairo_dock_draw_gl_text but resize the text so that it fits into a given area. Only works for a texture font.
314
*@param cText the text
315
*@param pFont the font.
316
*@param iWidth iWidth of the area.
317
*@param iHeight iHeight of the area
318
*@param bCentered whether the text is centered on the current position or not.
320
void cairo_dock_draw_gl_text_in_area (const guchar *cText, CairoDockGLFont *pFont, int iWidth, int iHeight, gboolean bCentered);
322
/** Like /ref cairo_dock_draw_gl_text_in_area and /ref cairo_dock_draw_gl_text_at_position.
323
*@param cText the text
324
*@param pFont the font.
325
*@param x x position of the left bottom corner of the text.
326
*@param y y position of the left bottom corner of the text.
327
*@param iWidth iWidth of the area.
328
*@param iHeight iHeight of the area
329
*@param bCentered whether the text is centered on the given position or not.
331
void cairo_dock_draw_gl_text_at_position_in_area (const guchar *cText, CairoDockGLFont *pFont, int x, int y, int iWidth, int iHeight, gboolean bCentered);
334
GLuint cairo_dock_texture_from_pixmap (Window Xid, Pixmap iBackingPixmap);