rtk.h
Go to the documentation of this file.00001 /* 00002 * STK2 : stage's internal graphics toolkit based on RTK2 00003 * 00004 * Copyright (C) 2001-2005 Andrew Howard ahoward@usc.edu, Richard 00005 * Vaughan vaughan@sfu.ca 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 /* 00024 * Desc: Combined Stk functions 00025 * Author: Andrew Howard, Richard Vaughan 00026 00027 * CVS: $Id: rtk.h,v 1.17 2006/07/27 02:33:02 pooya Exp $ 00028 */ 00029 00030 #ifndef STK_H 00031 #define STK_H 00032 00033 #include <stdio.h> 00034 #include <math.h> 00035 #include <gtk/gtk.h> 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #define STK_CANVAS_LAYERS 100 00042 00043 // Movement mask for canvases 00044 #define STK_MOVE_PAN (1 << 0) 00045 #define STK_MOVE_ZOOM (1 << 1) 00046 00047 // Movement masks for figures 00048 #define STK_MOVE_TRANS (1 << 0) 00049 #define STK_MOVE_ROT (1 << 1) 00050 #define STK_MOVE_SCALE (1 << 2) 00051 00052 // Event codes for figures 00053 #define STK_EVENT_PRESS 1 00054 #define STK_EVENT_MOTION 2 00055 #define STK_EVENT_RELEASE 3 00056 #define STK_EVENT_MOUSE_OVER 4 00057 #define STK_EVENT_MOUSE_NOT_OVER 5 00058 00059 // Export image formats 00060 #define STK_IMAGE_FORMAT_JPEG 0 00061 #define STK_IMAGE_FORMAT_PPM 1 00062 #define STK_IMAGE_FORMAT_PNG 2 00063 #define STK_IMAGE_FORMAT_PNM 3 00064 00065 // Color space conversion macros 00066 #define STK_RGB16(r, g, b) (((b) >> 3) | (((g) & 0xFC) << 3) | (((r) & 0xF8) << 8)) 00067 #define STK_R_RGB16(x) (((x) >> 8) & 0xF8) 00068 #define STK_G_RGB16(x) (((x) >> 3) & 0xFC) 00069 #define STK_B_RGB16(x) (((x) << 3) & 0xF8) 00070 00071 00072 // Useful forward declarations 00073 struct _stg_rtk_canvas_t; 00074 struct _stg_rtk_table_t; 00075 struct _stg_rtk_fig_t; 00076 struct _stg_rtk_stroke_t; 00077 struct _stg_rtk_region_t; 00078 struct _stg_rtk_menuitem_t; 00079 00080 struct _stg_rtk_flasher_t; // rtv experimental 00081 00082 struct AVCodec; 00083 struct AVCodecContext; 00084 00085 00086 /*************************************************************************** 00087 * Library functions 00088 ***************************************************************************/ 00089 00090 // Initialise the library. 00091 // Pass in the program arguments through argc, argv 00092 int stg_rtk_initxx(int *argc, char ***argv); 00093 00094 00095 /*************************************************************************** 00096 * Application functions 00097 ***************************************************************************/ 00098 00099 // Structure describing and application 00100 typedef struct _stg_rtk_app_t 00101 { 00102 int must_quit; 00103 int has_quit; 00104 00105 // Linked list of canvases 00106 struct _stg_rtk_canvas_t *canvas; 00107 00108 // Linked list of tables 00109 struct _stg_rtk_table_t *table; 00110 00111 } stg_rtk_app_t; 00112 00113 // Create the application 00114 stg_rtk_app_t *stg_rtk_app_create(void); 00115 00116 // Destroy the application 00117 void stg_rtk_app_destroy(stg_rtk_app_t *app); 00118 00119 // Main loop for the app (blocking). Will return only when the gui is closed by 00120 // the user. 00121 int stg_rtk_app_main(stg_rtk_app_t *app); 00122 00123 // Do the initial main loop stuff 00124 void stg_rtk_app_main_init(stg_rtk_app_t *app); 00125 00126 // Do the final main loop stuff 00127 void stg_rtk_app_main_term(stg_rtk_app_t *app); 00128 00129 // Process pending events (non-blocking). Returns non-zero if the app 00130 // should quit. 00131 int stg_rtk_app_main_loop(stg_rtk_app_t *app); 00132 00133 00134 /*************************************************************************** 00135 * Canvas functions 00136 ***************************************************************************/ 00137 00138 // Structure describing a canvas 00139 typedef struct _stg_rtk_canvas_t 00140 { 00141 // Linked list of canvases 00142 struct _stg_rtk_canvas_t *next, *prev; 00143 00144 // Link to our parent app 00145 struct _stg_rtk_app_t *app; 00146 00147 // Gtk stuff 00148 //GtkWidget *frame; 00149 //GtkWidget *layout; 00150 GtkWidget *canvas; 00151 // GDK stuff 00152 GdkPixmap *bg_pixmap, *fg_pixmap; 00153 GdkGC *gc; 00154 GdkColormap *colormap; 00155 //GdkFont *font; 00156 00157 // Default font name 00158 //char *fontname; 00159 00160 // Canvas background color 00161 GdkColor bgcolor; 00162 00163 // Default line width 00164 int linewidth; 00165 00166 // Physical size of window 00167 int sizex, sizey; 00168 00169 // Coordinate transform 00170 // Logical coords of middle of canvas 00171 // and logical/device scale (eg m/pixel) 00172 double ox, oy; 00173 double sx, sy; 00174 00175 // Flag set if canvas has been destroyed 00176 int destroyed; 00177 00178 // Flags controlling background re-rendering 00179 int bg_dirty; 00180 00181 // Flags controlling foreground re-rendering 00182 int fg_dirty; 00183 struct _stg_rtk_region_t *fg_dirty_region; 00184 00185 // Non-zero if there are deferred calculations to be done. 00186 int calc_deferred; 00187 00188 // Movement mask for the canvas 00189 int movemask; 00190 00191 // Head of linked-list of top-level (parentless) figures. 00192 struct _stg_rtk_fig_t *fig; 00193 00194 // Head of linked-list of figures ordered by layer. 00195 struct _stg_rtk_fig_t *layer_fig; 00196 00197 // Head of linked-list of moveble figures. 00198 struct _stg_rtk_fig_t *moveable_fig; 00199 00200 // Mouse stuff 00201 int mouse_mode; 00202 double mouse_start_x, mouse_start_y, mouse_start_a; 00203 struct _stg_rtk_fig_t *zoom_fig; 00204 struct _stg_rtk_fig_t *mouse_over_fig; 00205 struct _stg_rtk_fig_t *mouse_selected_fig; 00206 struct _stg_rtk_fig_t *mouse_selected_fig_last; 00207 00208 // linked list of figs that are shown for a short period, then 00209 // hidden or destroyed - rtv experimental 00210 struct _stg_rtk_flasher_t *flashers; 00211 00212 // toggle these bytes to individually show and hide layers - rtv 00213 char layer_show[STK_CANVAS_LAYERS]; 00214 00215 // arbitrary user data 00216 void *userdata; 00217 00218 } stg_rtk_canvas_t; 00219 00220 00221 // Create a canvas on which to draw stuff. 00222 stg_rtk_canvas_t *stg_rtk_canvas_create(stg_rtk_app_t *app); 00223 00224 // Destroy the canvas 00225 void stg_rtk_canvas_destroy(stg_rtk_canvas_t *canvas); 00226 00227 // See if the canvas has been closed 00228 int stg_rtk_canvas_isclosed(stg_rtk_canvas_t *canvas); 00229 00230 // Set the canvas title 00231 void stg_rtk_canvas_title(stg_rtk_canvas_t *canvas, const char *title); 00232 00233 // Set the size of a canvas 00234 // (sizex, sizey) is the width and height of the canvas, in pixels. 00235 void stg_rtk_canvas_size(stg_rtk_canvas_t *canvas, int sizex, int sizey); 00236 00237 // Get the canvas size 00238 // (sizex, sizey) is the width and height of the canvas, in pixels. 00239 void stg_rtk_canvas_get_size(stg_rtk_canvas_t *canvas, int *sizex, int *sizey); 00240 00241 // Set the origin of a canvas 00242 // (ox, oy) specifies the logical point that maps to the center of the 00243 // canvas. 00244 void stg_rtk_canvas_origin(stg_rtk_canvas_t *canvas, double ox, double oy); 00245 00246 // Get the origin of a canvas 00247 // (ox, oy) specifies the logical point that maps to the center of the 00248 // canvas. 00249 void stg_rtk_canvas_get_origin(stg_rtk_canvas_t *canvas, double *ox, double *oy); 00250 00251 // Scale a canvas 00252 // Sets the pixel width and height in logical units 00253 void stg_rtk_canvas_scale(stg_rtk_canvas_t *canvas, double sx, double sy); 00254 00255 // Get the scale of the canvas 00256 // (sx, sy) are the pixel with and height in logical units 00257 void stg_rtk_canvas_get_scale(stg_rtk_canvas_t *canvas, double *sx, double *sy); 00258 00259 // Set the movement mask 00260 // Set the mask to a bitwise combination of STK_MOVE_TRANS, STK_MOVE_SCALE. 00261 // to enable user manipulation of the canvas. 00262 void stg_rtk_canvas_movemask(stg_rtk_canvas_t *canvas, int mask); 00263 00264 // Set the default font for text strokes 00265 // void stg_rtk_canvas_font(stg_rtk_canvas_t *canvas, const char *fontname); 00266 00267 // Set the canvas backround color 00268 void stg_rtk_canvas_bgcolor(stg_rtk_canvas_t *canvas, double r, double g, double b); 00269 00270 // Set the default line width. 00271 void stg_rtk_canvas_linewidth(stg_rtk_canvas_t *canvas, int width); 00272 00273 // Re-render the canvas 00274 void stg_rtk_canvas_render(stg_rtk_canvas_t *canvas); 00275 00276 // Export an image. 00277 // [filename] is the name of the file to save. 00278 // [format] is the image file format (STK_IMAGE_FORMAT_JPEG, STK_IMAGE_FORMAT_PPM). 00279 void stg_rtk_canvas_export_image(stg_rtk_canvas_t *canvas, const char *filename, int format); 00280 00281 /* 00282 // Export canvas to xfig file 00283 int stg_rtk_canvas_export_xfig(stg_rtk_canvas_t *canvas, char *filename); 00284 */ 00285 00286 // Start movie capture. 00287 // [filename] is the name of the file to save. 00288 // [fps] is the rate at which the caller will write frames (e.g. 5fps, 10fps). 00289 // [speed] is the ultimate playback speed of the movie (e.g. 1x, 2x). 00290 int stg_rtk_canvas_movie_start(stg_rtk_canvas_t *canvas, 00291 const char *filename, double fps, double speed); 00292 00293 // Start movie capture. 00294 void stg_rtk_canvas_movie_frame(stg_rtk_canvas_t *canvas); 00295 00296 // Stop movie capture. 00297 void stg_rtk_canvas_movie_stop(stg_rtk_canvas_t *canvas); 00298 00299 // rtv experimental 00300 // Maintain a list of figures that are shown for a set time, then hidden. 00301 typedef struct _stg_rtk_flasher_t 00302 { 00303 struct _stg_rtk_fig_t* fig; // a figure to be shown for a set period 00304 int duration; // decremented on each call to stg_rtk_canvas_flash_update() 00305 int kill; // if zero, the fig is hidden on timeout, if non-zero, the 00306 // figure is destroyed instead 00307 00308 // list hooks 00309 struct _stg_rtk_flasher_t* next, *prev; 00310 } stg_rtk_flasher_t; 00311 00312 // Add this figure to the list of flashers. It will be shown until 00313 // stg_rtk_canvas_flash_update() is called [duration] times, then it will 00314 // be destroyed if [kill] is non-zero, or hidden, if [kill] is zero 00315 void stg_rtk_canvas_flash( stg_rtk_canvas_t* canvas, 00316 struct _stg_rtk_fig_t* fig, int duration, int kill ); 00317 00318 // Decrement the flasher's counters. Those that time out get hidden 00319 // and removed from the flasher list 00320 void stg_rtk_canvas_flash_update( stg_rtk_canvas_t* canvas ); 00321 00322 // show and hide individual layers 00323 void stg_rtk_canvas_layer_show( stg_rtk_canvas_t* canvas, int layer, char show ); 00324 00325 // end rtv experimental 00326 00327 /*************************************************************************** 00328 * Figure functions 00329 ***************************************************************************/ 00330 00331 // Structure describing a color 00332 typedef GdkColor stg_rtk_color_t; 00333 00334 // Callback function signatures 00335 typedef void (*stg_rtk_mouse_fn_t) (struct _stg_rtk_fig_t *fig, int event, int mode); 00336 00337 00338 // Structure describing a figure 00339 typedef struct _stg_rtk_fig_t 00340 { 00341 // Pointer to parent canvas 00342 struct _stg_rtk_canvas_t *canvas; 00343 00344 // Pointer to our parent figure 00345 struct _stg_rtk_fig_t *parent; 00346 00347 // Head of a linked-list of children. 00348 struct _stg_rtk_fig_t *child; 00349 00350 // Linked-list of siblings 00351 struct _stg_rtk_fig_t *sibling_next, *sibling_prev; 00352 00353 // Linked-list of figures ordered by layer 00354 struct _stg_rtk_fig_t *layer_next, *layer_prev; 00355 00356 // Linked-list of figures that are moveable. 00357 struct _stg_rtk_fig_t *moveable_next, *moveable_prev; 00358 00359 // Arbitrary user data 00360 void *userdata; 00361 00362 // Layer this fig belongs to 00363 int layer; 00364 00365 // Flag set to true if figure should be displayed 00366 int show; 00367 00368 // Movement mask (a bit vector) 00369 int movemask; 00370 00371 // Origin, scale of figure 00372 // relative to parent. 00373 double ox, oy, oa; 00374 double cos, sin; 00375 double sx, sy; 00376 00377 // Origin, scale of figure 00378 // in global cs. 00379 double dox, doy, doa; 00380 double dcos, dsin; 00381 double dsx, dsy; 00382 00383 // Bounding box for the figure in local cs; contains all of the 00384 // strokes for this figure. 00385 double min_x, min_y, max_x, max_y; 00386 00387 // Bounding region for the figure in device cs; contains all the 00388 // strokes for this figure. 00389 struct _stg_rtk_region_t *region; 00390 00391 // List of strokes 00392 int stroke_size; 00393 int stroke_count; 00394 struct _stg_rtk_stroke_t **strokes; 00395 00396 // Drawing context information. Just a list of default args for 00397 // drawing primitives. 00398 stg_rtk_color_t dc_color; 00399 //int dc_xfig_color; 00400 int dc_linewidth; 00401 00402 // if > 0, the visibility of this figure is toggled with this 00403 // interval. To stop blinking but remember the interval, make the 00404 // value negative. (rtv) 00405 int blink_interval_ms; 00406 00407 // Event callback functions. 00408 stg_rtk_mouse_fn_t mouse_fn; 00409 00410 } stg_rtk_fig_t; 00411 00412 00413 // Figure creation/destruction 00414 //stg_rtk_fig_t *stg_rtk_fig_create(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, int layer); 00415 stg_rtk_fig_t *stg_rtk_fig_create(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, int layer ); 00416 void stg_rtk_fig_destroy(stg_rtk_fig_t *fig); 00417 00418 // destroy figure after at least life_ms milliseconds 00419 void stg_rtk_fig_destroy_later( stg_rtk_fig_t* fig, int life_ms ); 00420 00421 00422 // Recursively free a whole tree of figures (rtv) 00423 void stg_rtk_fig_and_descendents_destroy( stg_rtk_fig_t* fig ); 00424 00425 // create a figure and set its user data pointer (rtv) 00426 stg_rtk_fig_t *stg_rtk_fig_create_ex(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, 00427 int layer, void* userdata ); 00428 00429 // Set the mouse event callback function. 00430 void stg_rtk_fig_add_mouse_handler(stg_rtk_fig_t *fig, stg_rtk_mouse_fn_t callback); 00431 00432 // Unset the mouse event callback function. 00433 void stg_rtk_fig_remove_mouse_handler(stg_rtk_fig_t *fig, stg_rtk_mouse_fn_t callback); 00434 00435 // Clear all existing strokes from a figure. 00436 void stg_rtk_fig_clear(stg_rtk_fig_t *fig); 00437 00438 // Show or hide the figure 00439 void stg_rtk_fig_show(stg_rtk_fig_t *fig, int show); 00440 00441 // Set the movement mask 00442 // Set the mask to a bitwise combination of STK_MOVE_TRANS, STK_MOVE_ROT, etc, 00443 // to enable user manipulation of the figure. 00444 void stg_rtk_fig_movemask(stg_rtk_fig_t *fig, int mask); 00445 00446 // See if the mouse is over this figure 00447 int stg_rtk_fig_mouse_over(stg_rtk_fig_t *fig); 00448 00449 // See if the figure has been selected 00450 int stg_rtk_fig_mouse_selected(stg_rtk_fig_t *fig); 00451 00452 // Set the figure origin (local coordinates). 00453 void stg_rtk_fig_origin(stg_rtk_fig_t *fig, double ox, double oy, double oa); 00454 00455 // Set the figure origin (global coordinates). 00456 void stg_rtk_fig_origin_global(stg_rtk_fig_t *fig, double ox, double oy, double oa); 00457 00458 // Get the current figure origin (local coordinates). 00459 void stg_rtk_fig_get_origin(stg_rtk_fig_t *fig, double *ox, double *oy, double *oa); 00460 00461 // Set the figure scale 00462 void stg_rtk_fig_scale(stg_rtk_fig_t *fig, double scale); 00463 00464 // Set the color for strokes. Color is specified as an (r, g, b) 00465 // tuple, with values in range [0, 1]. 00466 void stg_rtk_fig_color(stg_rtk_fig_t *fig, double r, double g, double b); 00467 00468 // Set the color for strokes. Color is specified as an RGB32 value (8 00469 // bits per color). 00470 void stg_rtk_fig_color_rgb32(stg_rtk_fig_t *fig, int color); 00471 00472 // Set the color for strokes. Color is specified as an xfig color. 00473 //void stg_rtk_fig_color_xfig(stg_rtk_fig_t *fig, int color); 00474 00475 // Set the line width. 00476 void stg_rtk_fig_linewidth(stg_rtk_fig_t *fig, int width); 00477 00478 // Draw a single point. 00479 void stg_rtk_fig_point(stg_rtk_fig_t *fig, double ox, double oy); 00480 00481 // Draw a line between two points. 00482 void stg_rtk_fig_line(stg_rtk_fig_t *fig, double ax, double ay, double bx, double by); 00483 00484 // Draw a line centered on the given point. 00485 void stg_rtk_fig_line_ex(stg_rtk_fig_t *fig, double ox, double oy, double oa, double size); 00486 00487 // Draw a rectangle centered on (ox, oy) with orientation oa and size (sx, sy). 00488 void stg_rtk_fig_rectangle(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00489 double sx, double sy, int filled); 00490 00491 // Draw an ellipse centered on (ox, oy) with orientation oa and size (sx, sy). 00492 void stg_rtk_fig_ellipse(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00493 double sx, double sy, int filled); 00494 00495 // Draw an arc between min_th and max_th on the ellipse as above 00496 void stg_rtk_fig_ellipse_arc( stg_rtk_fig_t *fig, double ox, double oy, double oa, 00497 double sx, double sy, double min_th, double max_th); 00498 00499 // Create a polygon 00500 void stg_rtk_fig_polygon(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00501 int point_count, double points[][2], int filled); 00502 //int point_count, double* points, int filled); 00503 00504 // Draw an arrow from point (ox, oy) with orientation oa and length len. 00505 void stg_rtk_fig_arrow(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00506 double len, double head); 00507 00508 // Draw an arrow between points (ax, ay) and (bx, by). 00509 void stg_rtk_fig_arrow_ex(stg_rtk_fig_t *fig, double ax, double ay, 00510 double bx, double by, double head); 00511 00512 // create a fancy arrow that can be filled 00513 void stg_rtk_fig_arrow_fancy(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00514 double len, double head, double thickness, int filled ); 00515 00516 // Draw single or multiple lines of text. Lines are deliminted with 00517 // '\n'. 00518 void stg_rtk_fig_text(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00519 const char *text); 00520 00521 // Draw single or multiple lines of text in a bubble. Lines are deliminted with 00522 // '\n'. 00523 void stg_rtk_fig_text_bubble(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00524 const char *text, double bx, double by); 00525 00526 // Draw a grid. Grid is centered on (ox, oy) with size (dx, dy) with 00527 // spacing (sp). 00528 void stg_rtk_fig_grid(stg_rtk_fig_t *fig, double ox, double oy, 00529 double dx, double dy, double sp); 00530 00531 // Draw an image. bpp specifies the number of bits per pixel, and 00532 // must be 16. 00533 void stg_rtk_fig_image(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00534 double scale, int width, int height, int bpp, void *image, void *mask); 00535 00536 // start toggling the show flag for the figure at approximately the 00537 // desired millisecond interval - set to < 1 to stop blinking 00538 void stg_rtk_fig_blink( stg_rtk_fig_t* fig, int interval_ms, int flag ); 00539 00540 00541 /*************************************************************************** 00542 * Primitive strokes for figures. 00543 ***************************************************************************/ 00544 00545 // Signature for stroke methods. 00546 typedef void (*stg_rtk_stroke_fn_t) (struct _stg_rtk_fig_t *fig, void *stroke); 00547 00548 00549 // Structure describing a stroke (base structure for all strokes). 00550 typedef struct _stg_rtk_stroke_t 00551 { 00552 // Color 00553 stg_rtk_color_t color; 00554 00555 // Xfig color 00556 //int xfig_color; 00557 00558 // Line width 00559 int linewidth; 00560 00561 // Function used to free data associated with stroke 00562 stg_rtk_stroke_fn_t freefn; 00563 00564 // Function used to compute onscreen appearance 00565 stg_rtk_stroke_fn_t calcfn; 00566 00567 // Function used to render stroke 00568 stg_rtk_stroke_fn_t drawfn; 00569 00570 // Function used to render stroke to xfig 00571 //stg_rtk_stroke_fn_t xfigfn; 00572 00573 } stg_rtk_stroke_t; 00574 00575 00576 // Struct describing a point 00577 typedef struct 00578 { 00579 double x, y; 00580 } stg_rtk_point_t; 00581 00582 00583 // Struct describing a point stroke 00584 typedef struct 00585 { 00586 stg_rtk_stroke_t stroke; 00587 00588 // Point in logical local coordinates. 00589 double ox, oy; 00590 00591 // Point in absolute physical coordinates. 00592 GdkPoint point; 00593 00594 } stg_rtk_point_stroke_t; 00595 00596 00597 // Polygon/polyline stroke 00598 typedef struct 00599 { 00600 stg_rtk_stroke_t stroke; 00601 00602 // Origin of figure in logical local coordinates. 00603 double ox, oy, oa; 00604 00605 // Zero if this is a polyline, Non-zero if this is a polygon. 00606 int closed; 00607 00608 // Non-zero if polygon should be filled. 00609 int filled; 00610 00611 // A list of points in the polygon, in both local logical 00612 // coordinates and absolute physical coordinates. 00613 int point_count; 00614 stg_rtk_point_t *lpoints; 00615 GdkPoint *ppoints; 00616 00617 } stg_rtk_polygon_stroke_t; 00618 00619 00620 // Struct describing text stroke 00621 typedef struct 00622 { 00623 stg_rtk_stroke_t stroke; 00624 00625 // Origin of the text in logical local coordinates. 00626 double ox, oy, oa; 00627 00628 // Text width and height calculated by Pango 00629 double width, height; 00630 00631 // Origin of the text in absolute physical coordinates. 00632 GdkPoint point; 00633 00634 // Pango layout 00635 PangoLayout *layout; 00636 00637 // The text 00638 char *text; 00639 00640 } stg_rtk_text_stroke_t; 00641 00642 00643 // Structure describing an image stroke 00644 typedef struct 00645 { 00646 stg_rtk_stroke_t stroke; 00647 00648 // Origin of figure in local logical coordinates. 00649 double ox, oy, oa; 00650 00651 // Rectangle containing the image (absolute physical coordinates). 00652 double points[4][2]; 00653 00654 // Image data 00655 double scale; 00656 int width, height, bpp; 00657 void *image, *mask; 00658 00659 } stg_rtk_image_stroke_t; 00660 00661 00662 /*************************************************************************** 00663 * Region manipulation (used internal for efficient redrawing). 00664 ***************************************************************************/ 00665 00666 // Info about a region 00667 typedef struct _stg_rtk_region_t 00668 { 00669 // Bounding box 00670 GdkRectangle rect; 00671 00672 } stg_rtk_region_t; 00673 00674 00675 // Create a new region. 00676 stg_rtk_region_t *stg_rtk_region_create(void); 00677 00678 // Destroy a region. 00679 void stg_rtk_region_destroy(stg_rtk_region_t *region); 00680 00681 // Set a region to empty. 00682 void stg_rtk_region_set_empty(stg_rtk_region_t *region); 00683 00684 // Set the region to the union of the two given regions. 00685 void stg_rtk_region_set_union(stg_rtk_region_t *regiona, stg_rtk_region_t *regionb); 00686 00687 // Set the region to the union of the region with a rectangle 00688 void stg_rtk_region_set_union_rect(stg_rtk_region_t *region, int ax, int ay, int bx, int by); 00689 00690 // Get the bounding rectangle for the region. 00691 void stg_rtk_region_get_brect(stg_rtk_region_t *region, GdkRectangle *rect); 00692 00693 // Test to see if a region is empty. 00694 int stg_rtk_region_test_empty(stg_rtk_region_t *region); 00695 00696 // Test for intersection betweenr regions. 00697 int stg_rtk_region_test_intersect(stg_rtk_region_t *regiona, stg_rtk_region_t *regionb); 00698 00699 00700 /*************************************************************************** 00701 * Menus : menus, submenus and menu items. 00702 ***************************************************************************/ 00703 00704 // Callback function signatures 00705 typedef void (*stg_rtk_menuitem_fn_t) (struct _stg_rtk_menuitem_t *menuitem); 00706 00707 00708 // Info about a menu 00709 typedef struct 00710 { 00711 // Which canvas we are attached to. 00712 stg_rtk_canvas_t *canvas; 00713 00714 // GTK widget holding the menu label widget. 00715 GtkWidget *item; 00716 00717 // GTK menu item widget. 00718 GtkWidget *menu; 00719 00720 } stg_rtk_menu_t; 00721 00722 00723 // Info about a menu item 00724 typedef struct _stg_rtk_menuitem_t 00725 { 00726 // Which menu we are attached to. 00727 stg_rtk_menu_t *menu; 00728 00729 // GTK menu item widget. 00730 GtkWidget *item; 00731 00732 // Flag set if item has been activated. 00733 int activated; 00734 00735 // Flag set if this is a check-menu item 00736 int checkitem; 00737 00738 // Flag set if item is checked. 00739 int checked; 00740 00741 // User data (mainly for callbacks) 00742 void *userdata; 00743 00744 // Callback function 00745 stg_rtk_menuitem_fn_t callback; 00746 00747 } stg_rtk_menuitem_t; 00748 00749 00750 // Create a menu 00751 stg_rtk_menu_t *stg_rtk_menu_create(stg_rtk_canvas_t *canvas, const char *label); 00752 00753 // Create a sub menu 00754 stg_rtk_menu_t *stg_rtk_menu_create_sub(stg_rtk_menu_t *menu, const char *label); 00755 00756 // Delete a menu 00757 void stg_rtk_menu_destroy(stg_rtk_menu_t *menu); 00758 00759 // Create a new menu item. Set check to TRUE if you want a checkbox 00760 // with the menu item 00761 stg_rtk_menuitem_t *stg_rtk_menuitem_create(stg_rtk_menu_t *menu, 00762 const char *label, int check); 00763 00764 // Set the callback for a menu item. This function will be called 00765 // when the user selects the menu item. 00766 void stg_rtk_menuitem_set_callback(stg_rtk_menuitem_t *item, 00767 stg_rtk_menuitem_fn_t callback); 00768 00769 // Delete a menu item. 00770 void stg_rtk_menuitem_destroy(stg_rtk_menuitem_t *item); 00771 00772 // Test to see if the menu item has been activated. Calling this 00773 // function will reset the flag. 00774 int stg_rtk_menuitem_isactivated(stg_rtk_menuitem_t *item); 00775 00776 // Set the check state of a menu item. 00777 void stg_rtk_menuitem_check(stg_rtk_menuitem_t *item, int check); 00778 00779 // Test to see if the menu item is checked. 00780 int stg_rtk_menuitem_ischecked(stg_rtk_menuitem_t *item); 00781 00782 // Enable/disable the menu item 00783 int stg_rtk_menuitem_enable(stg_rtk_menuitem_t *item, int enable); 00784 00785 00786 /*************************************************************************** 00787 * Tables : provides a list of editable var = value pairs. 00788 ***************************************************************************/ 00789 00790 // Info about a single item in a table 00791 typedef struct _stg_rtk_tableitem_t 00792 { 00793 struct _stg_rtk_tableitem_t *next, *prev; // Linked list of items 00794 struct _stg_rtk_table_t *table; 00795 GtkWidget *label; // Label widget 00796 GtkObject *adj; // Object for storing spin box results. 00797 GtkWidget *spin; // Spin box widget 00798 double value; // Last recorded value of the item 00799 } stg_rtk_tableitem_t; 00800 00801 00802 // Info about a table 00803 typedef struct _stg_rtk_table_t 00804 { 00805 struct _stg_rtk_table_t *next, *prev; // Linked list of tables 00806 stg_rtk_app_t *app; // Link to our parent app 00807 GtkWidget *frame; // A top-level window to put the table in. 00808 GtkWidget *table; // The table layout 00809 int destroyed; // Flag set to true if the GTK frame has been destroyed. 00810 int item_count; // Number of items currently in the table 00811 int row_count; // Number of rows currently in the table 00812 stg_rtk_tableitem_t *item; // Linked list of items that belong in the table 00813 } stg_rtk_table_t; 00814 00815 // Create a new table 00816 stg_rtk_table_t *stg_rtk_table_create(stg_rtk_app_t *app, int width, int height); 00817 00818 // Delete the table 00819 void stg_rtk_table_destroy(stg_rtk_table_t *table); 00820 00821 // Create a new item in the table 00822 stg_rtk_tableitem_t *stg_rtk_tableitem_create_int(stg_rtk_table_t *table, 00823 const char *label, int low, int high); 00824 00825 // Set the value of a table item (as an integer) 00826 void stg_rtk_tableitem_set_int(stg_rtk_tableitem_t *item, int value); 00827 00828 // Get the value of a table item (as an integer) 00829 int stg_rtk_tableitem_get_int(stg_rtk_tableitem_t *item); 00830 00831 #ifdef __cplusplus 00832 } 00833 #endif 00834 00835 #endif 00836
Generated on Thu Dec 13 13:55:21 2007 for Stage by 1.4.6