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_DATA_RENDERER__
22
#define __CAIRO_DOCK_DATA_RENDERER__
26
#include "cairo-dock-struct.h"
30
*@file cairo-dock-data-renderer.h This class defines the Data Renderer structure and API.
31
* A CairoDataRenderer is a generic way to render onto an icon a set of values defined by : {yk = f(tk)}, k=0..n where yk is a vector.
32
* Data Renderers are binded to an icon, and initialized with a set of attributes, that derives from a CairoDataRendererAttribute, with the function /ref cairo_dock_add_new_data_renderer_on_icon.
33
* You update a Data Renderer with /ref cairo_dock_render_new_data_on_icon, providing it the correct number of values.
34
* If you want to change any parameter of a Data Renderer, use /ref cairo_dock_reload_data_renderer_on_icon, which keeps the history.
35
* To remove the Data Renderer from an icon, use /ref cairo_dock_remove_data_renderer_on_icon.
42
struct _CairoDataToRenderer {
45
gdouble *pValuesBuffer;
47
gdouble *pMinMaxValues;
51
#define CAIRO_DOCK_DATA_FORMAT_MAX_LEN 20
52
/// Prototype of a function used to format the values in a short readable format (to be displayed as quick-info).
53
typedef void (*CairoDockGetValueFormatFunc) (double fValue, int iNumValue, gchar *cFormatBuffer, int iBufferLength, gpointer data);
54
/// Generic DataRenderer attributes structure. The attributes of any implementation of a DataRenderer will derive from this class.
55
struct _CairoDataRendererAttribute {
59
gdouble *pMinMaxValues;
60
gboolean bUpdateMinMax;
61
gboolean bWriteValues;
63
CairoDockGetValueFormatFunc format_value;
67
gdouble fTextColor[3];
70
typedef CairoDataRenderer * (*CairoDataRendererNewFunc) (void);
71
typedef void (*CairoDataRendererLoadFunc) (CairoDataRenderer *pDataRenderer, cairo_t *pSourceContext, CairoContainer *pContainer, CairoDataRendererAttribute *pAttribute);
72
typedef void (*CairoDataRendererRenderFunc) (CairoDataRenderer *pDataRenderer, cairo_t *pCairoContext);
73
typedef void (*CairoDataRendererRenderOpenGLFunc) (CairoDataRenderer *pDataRenderer);
74
typedef void (*CairoDataRendererReloadFunc) (CairoDataRenderer *pDataRenderer, cairo_t *pSourceContext);
75
typedef void (*CairoDataRendererFreeFunc) (CairoDataRenderer *pDataRenderer);
76
/// Interface of a DataRenderer.
77
struct _CairoDataRendererInterface {
78
CairoDataRendererNewFunc new;
79
CairoDataRendererLoadFunc load;
80
CairoDataRendererRenderFunc render;
81
CairoDataRendererRenderOpenGLFunc render_opengl;
82
CairoDataRendererReloadFunc reload;
83
CairoDataRendererFreeFunc free;
87
struct _CairoDataRendererEmblem {
89
gdouble fWidth, fHeight;
91
cairo_surface_t *pSurface;
95
struct _CairoDataRendererTextZone {
97
gdouble fWidth, fHeight;
102
/// Generic DataRenderer. Any implementation of a DataRenderer will derive from this class.
103
struct _CairoDataRenderer {
104
// fill at init by the high level renderer.
105
/// interface of the Data Renderer.
106
CairoDataRendererInterface interface;
107
// fill at load time independantly of the renderer type.
108
/// internal data to be drawn by the renderer.it
109
CairoDataToRenderer data;
110
/// size of the drawing area.
111
gint iWidth, iHeight; // taille du contexte de dessin.
112
/// specific function to format the values as text.
113
CairoDockGetValueFormatFunc format_value;
114
/// buffer for the text.
115
gchar cFormatBuffer[CAIRO_DOCK_DATA_FORMAT_MAX_LEN+1];
116
/// data passed to the format fonction.
117
gpointer pFormatData;
118
/// TRUE <=> the Data Renderer should dynamically update the range of the values.
119
gboolean bUpdateMinMax;
120
/// TRUE <=> the Data Renderer should write the values as text itself.
121
gboolean bWriteValues;
122
/// the time it will take to update to the new value, with a smooth animation (require openGL capacity)
124
// fill at load time by the high level renderer.
125
/// the rank of the renderer, eg the number of values it can display at once (for exemple, 1 for a bar, 2 for a dual-gauge)
126
gint iRank; // nbre de valeurs que peut afficher 1 unite (en general : gauge:1/2, graph:1/2, bar:1)
127
/// set to TRUE <=> the renderer can draw the values as text itself.
128
gboolean bCanRenderValueAsText;
130
/// the animation counter for the smooth movement.
131
gint iSmoothAnimationStep;
132
/// latency due to the smooth movement (0 means the displayed value is the current one, 1 the previous)
134
/// an optionnal list of tiltes to be displayed on the Data Renderer next to each value. Same size as the set of values.
136
/// color of the titles.
137
gdouble fTextColor[3];
138
/// an optionnal list of emblems to be displayed on the Data Renderer next to each value. Same size as the set of values.
140
/// an optionnal list of emblems to be displayed on the Data Renderer to indicate the nature of each value. Same size as the set of values.
141
CairoDataRendererEmblem *pEmblems;
142
/// an optionnal list of titles to be displayed on the Data Renderer to indicate the nature of each value. Same size as the set of values.
143
CairoDataRendererTextZone *pTextZones;
148
/// Renderer manipulation
150
/** Get the default GLX font for Data Renderer. It can render strings of digits from 0 to 9. Don't destroy it.
151
*@return the default GLX font*/
152
CairoDockGLFont *cairo_dock_get_default_data_renderer_font (void);
154
void cairo_dock_unload_default_data_renderer_font (void);
157
/**Add a Data Renderer on an icon (usually the icon of an applet). A Data Renderer is a view that will be used to display a set a values on the icon.
158
*@param pIcon the icon
159
*@param pContainer the icon's container
160
*@param pSourceContext a drawing context
161
*@param pAttribute attributes defining the Renderer*/
162
void cairo_dock_add_new_data_renderer_on_icon (Icon *pIcon, CairoContainer *pContainer, cairo_t *pSourceContext, CairoDataRendererAttribute *pAttribute);
164
/**Draw the current values associated with the Renderer on the icon.
165
*@param pIcon the icon
166
*@param pContainer the icon's container
167
*@param pCairoContext a drawing context on the icon
168
*@param pNewValues a set a new values (must be of the size defined on the creation of the Renderer)*/
169
void cairo_dock_render_new_data_on_icon (Icon *pIcon, CairoContainer *pContainer, cairo_t *pCairoContext, double *pNewValues);
171
/**Remove the Data Renderer of an icon. All the allocated ressources will be freed.
172
*@param pIcon the icon*/
173
void cairo_dock_remove_data_renderer_on_icon (Icon *pIcon);
175
/**Reload the Data Renderer of an icon. If no attributes are provided, it simply reload it with its current attributes. History is kept.
176
*@param pIcon the icon
177
*@param pContainer the icon's container
178
*@param pSourceContext a drawing context
179
*@param pAttribute new attributes defining the Renderer, or NULL to keep the current ones*/
180
void cairo_dock_reload_data_renderer_on_icon (Icon *pIcon, CairoContainer *pContainer, cairo_t *pSourceContext, CairoDataRendererAttribute *pAttribute);
183
/** Resize the history of a DataRenderer of an icon, that is to say change the number of previous values that are remembered by the DataRenderer.
184
*@param pIcon the icon
185
*@param iNewMemorySize the new size of history*/
186
void cairo_dock_resize_data_renderer_history (Icon *pIcon, int iNewMemorySize);
188
/** Redraw the DataRenderer of an icon, with the current values.
189
*@param pIcon the icon
190
*@param pContainer the icon's container
191
*@param pSourceContext a drawing context*/
192
void cairo_dock_refresh_data_renderer (Icon *pIcon, CairoContainer *pContainer, cairo_t *pSourceContext);
198
/**Get the elementary part of a Data Renderer
199
*@param r a high level data renderer
200
*@return a CairoDataRenderer* */
201
#define CAIRO_DATA_RENDERER(r) (&(r)->dataRenderer)
202
/**Get the data of a Data Renderer
203
*@param pRenderer a data renderer
204
*@return a CairoDataToRenderer* */
205
#define cairo_data_renderer_get_data(pRenderer) (&(pRenderer)->data);
206
/**Get the elementary part of a Data Renderer Attribute
207
*@param pAttr a high level data renderer attribute
208
*@return a CairoDataRendererAttribute* */
209
#define CAIRO_DATA_RENDERER_ATTRIBUTE(pAttr) ((CairoDataRendererAttribute *) pAttr)
212
/*#define cairo_data_renderer_set_attribute(pRendererAttribute, cAttributeName, ) g_datalist_get_data (pRendererAttribute->pExtraProperties)
213
#define cairo_data_renderer_get_attribute(pRendererAttribute, cAttributeName) g_datalist_get_data (pRendererAttribute->pExtraProperties)*/
218
/**Get the lower range of the i-th value.
219
*@param pRenderer a data renderer
220
*@param i the number of the value
222
#define cairo_data_renderer_get_min_value(pRenderer, i) (pRenderer)->data.pMinMaxValues[2*i]
223
/**Get the upper range of the i-th value.
224
*@param pRenderer a data renderer
225
*@param i the number of the value
227
#define cairo_data_renderer_get_max_value(pRenderer, i) (pRenderer)->data.pMinMaxValues[2*i+1]
228
/**Get the i-th value at the time t.
229
*@param pRenderer a data renderer
230
*@param i the number of the value
231
*@param t the time (in number of steps)
233
#define cairo_data_renderer_get_value(pRenderer, i, t) pRenderer->data.pTabValues[pRenderer->data.iCurrentIndex+t > pRenderer->data.iMemorySize ? pRenderer->data.iCurrentIndex+t-pRenderer->data.iMemorySize : pRenderer->data.iCurrentIndex+t < 0 ? pRenderer->data.iCurrentIndex+t+pRenderer->data.iMemorySize : pRenderer->data.iCurrentIndex+t][i]
234
/**Get the current i-th value.
235
*@param pRenderer a data renderer
236
*@param i the number of the value
238
#define cairo_data_renderer_get_current_value(pRenderer, i) pRenderer->data.pTabValues[pRenderer->data.iCurrentIndex][i]
239
/**Get the previous i-th value.
240
*@param pRenderer a data renderer
241
*@param i the number of the value
243
#define cairo_data_renderer_get_previous_value(pRenderer, i) cairo_data_renderer_get_value (pRenderer, i, -1)
244
/**Get the normalized i-th value (between 0 and 1) at the time t.
245
*@param pRenderer a data renderer
246
*@param i the number of the value
247
*@param t the time (in number of steps)
248
*@return a double in [0,1]*/
249
#define cairo_data_renderer_get_normalized_value(pRenderer, i, t) MAX (0, MIN (1, (cairo_data_renderer_get_value (pRenderer, i, t) - cairo_data_renderer_get_min_value (pRenderer, i)) / (cairo_data_renderer_get_max_value (pRenderer, i) - cairo_data_renderer_get_min_value (pRenderer, i))))
250
/**Get the normalized current i-th value (between 0 and 1).
251
*@param pRenderer a data renderer
252
*@param i the number of the value
253
*@return a double in [0,1]*/
254
#define cairo_data_renderer_get_normalized_current_value(pRenderer, i) cairo_data_renderer_get_normalized_value(pRenderer, i, 0)
255
/**Get the normalized previous i-th value (between 0 and 1).
256
*@param pRenderer a data renderer
257
*@param i the number of the value
258
*@return a double in [0,1]*/
259
#define cairo_data_renderer_get_normalized_previous_value(pRenderer, i) cairo_data_renderer_get_normalized_value(pRenderer, i, -1)
260
/**Get the normalized current i-th value (between 0 and 1), taking into account the latency of the smooth movement.
261
*@param pRenderer a data renderer
262
*@param i the number of the value
263
*@return a double in [0,1]*/
264
#define cairo_data_renderer_get_normalized_current_value_with_latency(pRenderer, i) (pRenderer->fLatency == 0 ? cairo_data_renderer_get_normalized_current_value (pRenderer, i) : cairo_data_renderer_get_normalized_current_value (pRenderer, i) * (1 - pRenderer->fLatency) + cairo_data_renderer_get_normalized_previous_value (pRenderer, i) * pRenderer->fLatency);
269
/**Write a value in a readable text format.
270
*@param pRenderer a data renderer
271
*@param fValue the normalized value
272
*@param i the number of the value
273
*@param cBuffer a buffer where to write*/
274
#define cairo_data_renderer_format_value_full(pRenderer, fValue, i, cBuffer) do {\
275
if (pRenderer->format_value != NULL)\
276
(pRenderer)->format_value (fValue, i, cBuffer, CAIRO_DOCK_DATA_FORMAT_MAX_LEN, (pRenderer)->pFormatData);\
278
snprintf (cBuffer, CAIRO_DOCK_DATA_FORMAT_MAX_LEN, fValue < .0995 ? "%.1f" : (fValue < 1 ? " %.0f" : "%.0f"), fValue * 100.); } while (0)
279
/**Write a value in a readable text format in the renderer text buffer.
280
*@param pRenderer a data renderer
281
*@param fValue the normalized value
282
*@param i the number of the value*/
283
#define cairo_data_renderer_format_value(pRenderer, fValue, i) cairo_data_renderer_format_value_full (pRenderer, fValue, i, (pRenderer)->cFormatBuffer)
285
#define cairo_data_renderer_can_write_value(pRenderer) (pRenderer)->bCanRenderValueAsText