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.13 2005/07/30 06:21:10 rtv 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 // The menu bar widget 00167 GtkWidget *menu_bar; 00168 00169 // The status bar widget 00170 GtkStatusbar *status_bar; 00171 GtkProgressBar *perf_bar; 00172 GtkProgressBar *rt_bar; 00173 00174 GtkLabel *clock_label; 00175 00176 //GtkWidget* gcanvas; 00177 00178 // File in which to render xfig figures. 00179 FILE *file; 00180 00181 // Physical size of window 00182 int sizex, sizey; 00183 00184 // Coordinate transform 00185 // Logical coords of middle of canvas 00186 // and logical/device scale (eg m/pixel) 00187 double ox, oy; 00188 double sx, sy; 00189 00190 // Flag set if canvas has been destroyed 00191 int destroyed; 00192 00193 // Flags controlling background re-rendering 00194 int bg_dirty; 00195 00196 // Flags controlling foreground re-rendering 00197 int fg_dirty; 00198 struct _stg_rtk_region_t *fg_dirty_region; 00199 00200 // Non-zero if there are deferred calculations to be done. 00201 int calc_deferred; 00202 00203 // Movement mask for the canvas 00204 int movemask; 00205 00206 // Movie capture stuff 00207 FILE *movie_file; 00208 double movie_fps, movie_speed; 00209 int movie_frame; 00210 double movie_time, mpeg_time; 00211 unsigned char movie_lut[0x10000][3]; 00212 struct AVCodec *movie_codec; 00213 struct AVCodecContext *movie_context; 00214 00215 // Head of linked-list of top-level (parentless) figures. 00216 struct _stg_rtk_fig_t *fig; 00217 00218 // Head of linked-list of figures ordered by layer. 00219 struct _stg_rtk_fig_t *layer_fig; 00220 00221 // Head of linked-list of moveble figures. 00222 struct _stg_rtk_fig_t *moveable_fig; 00223 00224 // Mouse stuff 00225 int mouse_mode; 00226 double mouse_start_x, mouse_start_y, mouse_start_a; 00227 struct _stg_rtk_fig_t *zoom_fig; 00228 struct _stg_rtk_fig_t *mouse_over_fig; 00229 struct _stg_rtk_fig_t *mouse_selected_fig; 00230 struct _stg_rtk_fig_t *mouse_selected_fig_last; 00231 00232 // linked list of figs that are shown for a short period, then 00233 // hidden or destroyed - rtv experimental 00234 struct _stg_rtk_flasher_t *flashers; 00235 00236 // toggle these bytes to individually show and hide layers - rtv 00237 char layer_show[STK_CANVAS_LAYERS]; 00238 00239 // arbitrary user data 00240 void *userdata; 00241 00242 } stg_rtk_canvas_t; 00243 00244 00245 // Create a canvas on which to draw stuff. 00246 stg_rtk_canvas_t *stg_rtk_canvas_create(stg_rtk_app_t *app); 00247 00248 // Destroy the canvas 00249 void stg_rtk_canvas_destroy(stg_rtk_canvas_t *canvas); 00250 00251 // See if the canvas has been closed 00252 int stg_rtk_canvas_isclosed(stg_rtk_canvas_t *canvas); 00253 00254 // Set the canvas title 00255 void stg_rtk_canvas_title(stg_rtk_canvas_t *canvas, const char *title); 00256 00257 // Set the size of a canvas 00258 // (sizex, sizey) is the width and height of the canvas, in pixels. 00259 void stg_rtk_canvas_size(stg_rtk_canvas_t *canvas, int sizex, int sizey); 00260 00261 // Get the canvas size 00262 // (sizex, sizey) is the width and height of the canvas, in pixels. 00263 void stg_rtk_canvas_get_size(stg_rtk_canvas_t *canvas, int *sizex, int *sizey); 00264 00265 // Set the origin of a canvas 00266 // (ox, oy) specifies the logical point that maps to the center of the 00267 // canvas. 00268 void stg_rtk_canvas_origin(stg_rtk_canvas_t *canvas, double ox, double oy); 00269 00270 // Get the origin of a canvas 00271 // (ox, oy) specifies the logical point that maps to the center of the 00272 // canvas. 00273 void stg_rtk_canvas_get_origin(stg_rtk_canvas_t *canvas, double *ox, double *oy); 00274 00275 // Scale a canvas 00276 // Sets the pixel width and height in logical units 00277 void stg_rtk_canvas_scale(stg_rtk_canvas_t *canvas, double sx, double sy); 00278 00279 // Get the scale of the canvas 00280 // (sx, sy) are the pixel with and height in logical units 00281 void stg_rtk_canvas_get_scale(stg_rtk_canvas_t *canvas, double *sx, double *sy); 00282 00283 // Set the movement mask 00284 // Set the mask to a bitwise combination of STK_MOVE_TRANS, STK_MOVE_SCALE. 00285 // to enable user manipulation of the canvas. 00286 void stg_rtk_canvas_movemask(stg_rtk_canvas_t *canvas, int mask); 00287 00288 // Set the default font for text strokes 00289 void stg_rtk_canvas_font(stg_rtk_canvas_t *canvas, const char *fontname); 00290 00291 // Set the canvas backround color 00292 void stg_rtk_canvas_bgcolor(stg_rtk_canvas_t *canvas, double r, double g, double b); 00293 00294 // Set the default line width. 00295 void stg_rtk_canvas_linewidth(stg_rtk_canvas_t *canvas, int width); 00296 00297 // Re-render the canvas 00298 void stg_rtk_canvas_render(stg_rtk_canvas_t *canvas); 00299 00300 // Export an image. 00301 // [filename] is the name of the file to save. 00302 // [format] is the image file format (STK_IMAGE_FORMAT_JPEG, STK_IMAGE_FORMAT_PPM). 00303 void stg_rtk_canvas_export_image(stg_rtk_canvas_t *canvas, const char *filename, int format); 00304 00305 /* 00306 // Export canvas to xfig file 00307 int stg_rtk_canvas_export_xfig(stg_rtk_canvas_t *canvas, char *filename); 00308 */ 00309 00310 // Start movie capture. 00311 // [filename] is the name of the file to save. 00312 // [fps] is the rate at which the caller will write frames (e.g. 5fps, 10fps). 00313 // [speed] is the ultimate playback speed of the movie (e.g. 1x, 2x). 00314 int stg_rtk_canvas_movie_start(stg_rtk_canvas_t *canvas, 00315 const char *filename, double fps, double speed); 00316 00317 // Start movie capture. 00318 void stg_rtk_canvas_movie_frame(stg_rtk_canvas_t *canvas); 00319 00320 // Stop movie capture. 00321 void stg_rtk_canvas_movie_stop(stg_rtk_canvas_t *canvas); 00322 00323 // rtv experimental 00324 // Maintain a list of figures that are shown for a set time, then hidden. 00325 typedef struct _stg_rtk_flasher_t 00326 { 00327 struct _stg_rtk_fig_t* fig; // a figure to be shown for a set period 00328 int duration; // decremented on each call to stg_rtk_canvas_flash_update() 00329 int kill; // if zero, the fig is hidden on timeout, if non-zero, the 00330 // figure is destroyed instead 00331 00332 // list hooks 00333 struct _stg_rtk_flasher_t* next, *prev; 00334 } stg_rtk_flasher_t; 00335 00336 // Add this figure to the list of flashers. It will be shown until 00337 // stg_rtk_canvas_flash_update() is called [duration] times, then it will 00338 // be destroyed if [kill] is non-zero, or hidden, if [kill] is zero 00339 void stg_rtk_canvas_flash( stg_rtk_canvas_t* canvas, 00340 struct _stg_rtk_fig_t* fig, int duration, int kill ); 00341 00342 // Decrement the flasher's counters. Those that time out get hidden 00343 // and removed from the flasher list 00344 void stg_rtk_canvas_flash_update( stg_rtk_canvas_t* canvas ); 00345 00346 // show and hide individual layers 00347 void stg_rtk_canvas_layer_show( stg_rtk_canvas_t* canvas, int layer, char show ); 00348 00349 // end rtv experimental 00350 00351 /*************************************************************************** 00352 * Figure functions 00353 ***************************************************************************/ 00354 00355 // Structure describing a color 00356 typedef GdkColor stg_rtk_color_t; 00357 00358 // Callback function signatures 00359 typedef void (*stg_rtk_mouse_fn_t) (struct _stg_rtk_fig_t *fig, int event, int mode); 00360 00361 00362 // Structure describing a figure 00363 typedef struct _stg_rtk_fig_t 00364 { 00365 // Pointer to parent canvas 00366 struct _stg_rtk_canvas_t *canvas; 00367 00368 // Pointer to our parent figure 00369 struct _stg_rtk_fig_t *parent; 00370 00371 // Head of a linked-list of children. 00372 struct _stg_rtk_fig_t *child; 00373 00374 // Linked-list of siblings 00375 struct _stg_rtk_fig_t *sibling_next, *sibling_prev; 00376 00377 // Linked-list of figures ordered by layer 00378 struct _stg_rtk_fig_t *layer_next, *layer_prev; 00379 00380 // Linked-list of figures that are moveable. 00381 struct _stg_rtk_fig_t *moveable_next, *moveable_prev; 00382 00383 // Arbitrary user data 00384 void *userdata; 00385 00386 // Layer this fig belongs to 00387 int layer; 00388 00389 // Flag set to true if figure should be displayed 00390 int show; 00391 00392 // Movement mask (a bit vector) 00393 int movemask; 00394 00395 // Origin, scale of figure 00396 // relative to parent. 00397 double ox, oy, oa; 00398 double cos, sin; 00399 double sx, sy; 00400 00401 // Origin, scale of figure 00402 // in global cs. 00403 double dox, doy, doa; 00404 double dcos, dsin; 00405 double dsx, dsy; 00406 00407 // Bounding box for the figure in local cs; contains all of the 00408 // strokes for this figure. 00409 double min_x, min_y, max_x, max_y; 00410 00411 // Bounding region for the figure in device cs; contains all the 00412 // strokes for this figure. 00413 struct _stg_rtk_region_t *region; 00414 00415 // List of strokes 00416 int stroke_size; 00417 int stroke_count; 00418 struct _stg_rtk_stroke_t **strokes; 00419 00420 // Drawing context information. Just a list of default args for 00421 // drawing primitives. 00422 stg_rtk_color_t dc_color; 00423 //int dc_xfig_color; 00424 int dc_linewidth; 00425 00426 // if > 0, the visibility of this figure is toggled with this 00427 // interval. To stop blinking but remember the interval, make the 00428 // value negative. (rtv) 00429 int blink_interval_ms; 00430 00431 // Event callback functions. 00432 stg_rtk_mouse_fn_t mouse_fn; 00433 00434 00435 00436 } stg_rtk_fig_t; 00437 00438 00439 // Figure creation/destruction 00440 //stg_rtk_fig_t *stg_rtk_fig_create(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, int layer); 00441 stg_rtk_fig_t *stg_rtk_fig_create(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, int layer ); 00442 void stg_rtk_fig_destroy(stg_rtk_fig_t *fig); 00443 00444 // Recursively free a whole tree of figures (rtv) 00445 void stg_rtk_fig_and_descendents_destroy( stg_rtk_fig_t* fig ); 00446 00447 // create a figure and set its user data pointer (rtv) 00448 stg_rtk_fig_t *stg_rtk_fig_create_ex(stg_rtk_canvas_t *canvas, stg_rtk_fig_t *parent, 00449 int layer, void* userdata ); 00450 00451 // Set the mouse event callback function. 00452 void stg_rtk_fig_add_mouse_handler(stg_rtk_fig_t *fig, stg_rtk_mouse_fn_t callback); 00453 00454 // Unset the mouse event callback function. 00455 void stg_rtk_fig_remove_mouse_handler(stg_rtk_fig_t *fig, stg_rtk_mouse_fn_t callback); 00456 00457 // Clear all existing strokes from a figure. 00458 void stg_rtk_fig_clear(stg_rtk_fig_t *fig); 00459 00460 // Show or hide the figure 00461 void stg_rtk_fig_show(stg_rtk_fig_t *fig, int show); 00462 00463 // Set the movement mask 00464 // Set the mask to a bitwise combination of STK_MOVE_TRANS, STK_MOVE_ROT, etc, 00465 // to enable user manipulation of the figure. 00466 void stg_rtk_fig_movemask(stg_rtk_fig_t *fig, int mask); 00467 00468 // See if the mouse is over this figure 00469 int stg_rtk_fig_mouse_over(stg_rtk_fig_t *fig); 00470 00471 // See if the figure has been selected 00472 int stg_rtk_fig_mouse_selected(stg_rtk_fig_t *fig); 00473 00474 // Set the figure origin (local coordinates). 00475 void stg_rtk_fig_origin(stg_rtk_fig_t *fig, double ox, double oy, double oa); 00476 00477 // Set the figure origin (global coordinates). 00478 void stg_rtk_fig_origin_global(stg_rtk_fig_t *fig, double ox, double oy, double oa); 00479 00480 // Get the current figure origin (local coordinates). 00481 void stg_rtk_fig_get_origin(stg_rtk_fig_t *fig, double *ox, double *oy, double *oa); 00482 00483 // Set the figure scale 00484 void stg_rtk_fig_scale(stg_rtk_fig_t *fig, double scale); 00485 00486 // Set the color for strokes. Color is specified as an (r, g, b) 00487 // tuple, with values in range [0, 1]. 00488 void stg_rtk_fig_color(stg_rtk_fig_t *fig, double r, double g, double b); 00489 00490 // Set the color for strokes. Color is specified as an RGB32 value (8 00491 // bits per color). 00492 void stg_rtk_fig_color_rgb32(stg_rtk_fig_t *fig, int color); 00493 00494 // Set the color for strokes. Color is specified as an xfig color. 00495 //void stg_rtk_fig_color_xfig(stg_rtk_fig_t *fig, int color); 00496 00497 // Set the line width. 00498 void stg_rtk_fig_linewidth(stg_rtk_fig_t *fig, int width); 00499 00500 // Draw a single point. 00501 void stg_rtk_fig_point(stg_rtk_fig_t *fig, double ox, double oy); 00502 00503 // Draw a line between two points. 00504 void stg_rtk_fig_line(stg_rtk_fig_t *fig, double ax, double ay, double bx, double by); 00505 00506 // Draw a line centered on the given point. 00507 void stg_rtk_fig_line_ex(stg_rtk_fig_t *fig, double ox, double oy, double oa, double size); 00508 00509 // Draw a rectangle centered on (ox, oy) with orientation oa and size (sx, sy). 00510 void stg_rtk_fig_rectangle(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00511 double sx, double sy, int filled); 00512 00513 // Draw an ellipse centered on (ox, oy) with orientation oa and size (sx, sy). 00514 void stg_rtk_fig_ellipse(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00515 double sx, double sy, int filled); 00516 00517 // Draw an arc between min_th and max_th on the ellipse as above 00518 void stg_rtk_fig_ellipse_arc( stg_rtk_fig_t *fig, double ox, double oy, double oa, 00519 double sx, double sy, double min_th, double max_th); 00520 00521 // Create a polygon 00522 void stg_rtk_fig_polygon(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00523 int point_count, double points[][2], int filled); 00524 //int point_count, double* points, int filled); 00525 00526 // Draw an arrow from point (ox, oy) with orientation oa and length len. 00527 void stg_rtk_fig_arrow(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00528 double len, double head); 00529 00530 // Draw an arrow between points (ax, ay) and (bx, by). 00531 void stg_rtk_fig_arrow_ex(stg_rtk_fig_t *fig, double ax, double ay, 00532 double bx, double by, double head); 00533 00534 // create a fancy arrow that can be filled 00535 void stg_rtk_fig_arrow_fancy(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00536 double len, double head, double thickness, int filled ); 00537 00538 // Draw single or multiple lines of text. Lines are deliminted with 00539 // '\n'. 00540 void stg_rtk_fig_text(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00541 const char *text); 00542 00543 // Draw a grid. Grid is centered on (ox, oy) with size (dx, dy) with 00544 // spacing (sp). 00545 void stg_rtk_fig_grid(stg_rtk_fig_t *fig, double ox, double oy, 00546 double dx, double dy, double sp); 00547 00548 // Draw an image. bpp specifies the number of bits per pixel, and 00549 // must be 16. 00550 void stg_rtk_fig_image(stg_rtk_fig_t *fig, double ox, double oy, double oa, 00551 double scale, int width, int height, int bpp, void *image, void *mask); 00552 00553 // start toggling the show flag for the figure at approximately the 00554 // desired millisecond interval - set to < 1 to stop blinking 00555 void stg_rtk_fig_blink( stg_rtk_fig_t* fig, int interval_ms, int flag ); 00556 00557 00558 /*************************************************************************** 00559 * Primitive strokes for figures. 00560 ***************************************************************************/ 00561 00562 // Signature for stroke methods. 00563 typedef void (*stg_rtk_stroke_fn_t) (struct _stg_rtk_fig_t *fig, void *stroke); 00564 00565 00566 // Structure describing a stroke (base structure for all strokes). 00567 typedef struct _stg_rtk_stroke_t 00568 { 00569 // Color 00570 stg_rtk_color_t color; 00571 00572 // Xfig color 00573 //int xfig_color; 00574 00575 // Line width 00576 int linewidth; 00577 00578 // Function used to free data associated with stroke 00579 stg_rtk_stroke_fn_t freefn; 00580 00581 // Function used to compute onscreen appearance 00582 stg_rtk_stroke_fn_t calcfn; 00583 00584 // Function used to render stroke 00585 stg_rtk_stroke_fn_t drawfn; 00586 00587 // Function used to render stroke to xfig 00588 //stg_rtk_stroke_fn_t xfigfn; 00589 00590 } stg_rtk_stroke_t; 00591 00592 00593 // Struct describing a point 00594 typedef struct 00595 { 00596 double x, y; 00597 } stg_rtk_point_t; 00598 00599 00600 // Struct describing a point stroke 00601 typedef struct 00602 { 00603 stg_rtk_stroke_t stroke; 00604 00605 // Point in logical local coordinates. 00606 double ox, oy; 00607 00608 // Point in absolute physical coordinates. 00609 GdkPoint point; 00610 00611 } stg_rtk_point_stroke_t; 00612 00613 00614 // Polygon/polyline stroke 00615 typedef struct 00616 { 00617 stg_rtk_stroke_t stroke; 00618 00619 // Origin of figure in logical local coordinates. 00620 double ox, oy, oa; 00621 00622 // Zero if this is a polyline, Non-zero if this is a polygon. 00623 int closed; 00624 00625 // Non-zero if polygon should be filled. 00626 int filled; 00627 00628 // A list of points in the polygon, in both local logical 00629 // coordinates and absolute physical coordinates. 00630 int point_count; 00631 stg_rtk_point_t *lpoints; 00632 GdkPoint *ppoints; 00633 00634 } stg_rtk_polygon_stroke_t; 00635 00636 00637 // Struct describing text stroke 00638 typedef struct 00639 { 00640 stg_rtk_stroke_t stroke; 00641 00642 // Origin of the text in logical local coordinates. 00643 double ox, oy, oa; 00644 00645 // Origin of the text in absolute physical coordinates. 00646 GdkPoint point; 00647 00648 // The text 00649 char *text; 00650 00651 } stg_rtk_text_stroke_t; 00652 00653 00654 // Structure describing an image stroke 00655 typedef struct 00656 { 00657 stg_rtk_stroke_t stroke; 00658 00659 // Origin of figure in local logical coordinates. 00660 double ox, oy, oa; 00661 00662 // Rectangle containing the image (absolute physical coordinates). 00663 double points[4][2]; 00664 00665 // Image data 00666 double scale; 00667 int width, height, bpp; 00668 void *image, *mask; 00669 00670 } stg_rtk_image_stroke_t; 00671 00672 00673 /*************************************************************************** 00674 * Region manipulation (used internal for efficient redrawing). 00675 ***************************************************************************/ 00676 00677 // Info about a region 00678 typedef struct _stg_rtk_region_t 00679 { 00680 // Bounding box 00681 GdkRectangle rect; 00682 00683 } stg_rtk_region_t; 00684 00685 00686 // Create a new region. 00687 stg_rtk_region_t *stg_rtk_region_create(void); 00688 00689 // Destroy a region. 00690 void stg_rtk_region_destroy(stg_rtk_region_t *region); 00691 00692 // Set a region to empty. 00693 void stg_rtk_region_set_empty(stg_rtk_region_t *region); 00694 00695 // Set the region to the union of the two given regions. 00696 void stg_rtk_region_set_union(stg_rtk_region_t *regiona, stg_rtk_region_t *regionb); 00697 00698 // Set the region to the union of the region with a rectangle 00699 void stg_rtk_region_set_union_rect(stg_rtk_region_t *region, int ax, int ay, int bx, int by); 00700 00701 // Get the bounding rectangle for the region. 00702 void stg_rtk_region_get_brect(stg_rtk_region_t *region, GdkRectangle *rect); 00703 00704 // Test to see if a region is empty. 00705 int stg_rtk_region_test_empty(stg_rtk_region_t *region); 00706 00707 // Test for intersection betweenr regions. 00708 int stg_rtk_region_test_intersect(stg_rtk_region_t *regiona, stg_rtk_region_t *regionb); 00709 00710 00711 /*************************************************************************** 00712 * Menus : menus, submenus and menu items. 00713 ***************************************************************************/ 00714 00715 // Callback function signatures 00716 typedef void (*stg_rtk_menuitem_fn_t) (struct _stg_rtk_menuitem_t *menuitem); 00717 00718 00719 // Info about a menu 00720 typedef struct 00721 { 00722 // Which canvas we are attached to. 00723 stg_rtk_canvas_t *canvas; 00724 00725 // GTK widget holding the menu label widget. 00726 GtkWidget *item; 00727 00728 // GTK menu item widget. 00729 GtkWidget *menu; 00730 00731 } stg_rtk_menu_t; 00732 00733 00734 // Info about a menu item 00735 typedef struct _stg_rtk_menuitem_t 00736 { 00737 // Which menu we are attached to. 00738 stg_rtk_menu_t *menu; 00739 00740 // GTK menu item widget. 00741 GtkWidget *item; 00742 00743 // Flag set if item has been activated. 00744 int activated; 00745 00746 // Flag set if this is a check-menu item 00747 int checkitem; 00748 00749 // Flag set if item is checked. 00750 int checked; 00751 00752 // User data (mainly for callbacks) 00753 void *userdata; 00754 00755 // Callback function 00756 stg_rtk_menuitem_fn_t callback; 00757 00758 } stg_rtk_menuitem_t; 00759 00760 00761 // Create a menu 00762 stg_rtk_menu_t *stg_rtk_menu_create(stg_rtk_canvas_t *canvas, const char *label); 00763 00764 // Create a sub menu 00765 stg_rtk_menu_t *stg_rtk_menu_create_sub(stg_rtk_menu_t *menu, const char *label); 00766 00767 // Delete a menu 00768 void stg_rtk_menu_destroy(stg_rtk_menu_t *menu); 00769 00770 // Create a new menu item. Set check to TRUE if you want a checkbox 00771 // with the menu item 00772 stg_rtk_menuitem_t *stg_rtk_menuitem_create(stg_rtk_menu_t *menu, 00773 const char *label, int check); 00774 00775 // Set the callback for a menu item. This function will be called 00776 // when the user selects the menu item. 00777 void stg_rtk_menuitem_set_callback(stg_rtk_menuitem_t *item, 00778 stg_rtk_menuitem_fn_t callback); 00779 00780 // Delete a menu item. 00781 void stg_rtk_menuitem_destroy(stg_rtk_menuitem_t *item); 00782 00783 // Test to see if the menu item has been activated. Calling this 00784 // function will reset the flag. 00785 int stg_rtk_menuitem_isactivated(stg_rtk_menuitem_t *item); 00786 00787 // Set the check state of a menu item. 00788 void stg_rtk_menuitem_check(stg_rtk_menuitem_t *item, int check); 00789 00790 // Test to see if the menu item is checked. 00791 int stg_rtk_menuitem_ischecked(stg_rtk_menuitem_t *item); 00792 00793 // Enable/disable the menu item 00794 int stg_rtk_menuitem_enable(stg_rtk_menuitem_t *item, int enable); 00795 00796 00797 /*************************************************************************** 00798 * Tables : provides a list of editable var = value pairs. 00799 ***************************************************************************/ 00800 00801 // Info about a single item in a table 00802 typedef struct _stg_rtk_tableitem_t 00803 { 00804 struct _stg_rtk_tableitem_t *next, *prev; // Linked list of items 00805 struct _stg_rtk_table_t *table; 00806 GtkWidget *label; // Label widget 00807 GtkObject *adj; // Object for storing spin box results. 00808 GtkWidget *spin; // Spin box widget 00809 double value; // Last recorded value of the item 00810 } stg_rtk_tableitem_t; 00811 00812 00813 // Info about a table 00814 typedef struct _stg_rtk_table_t 00815 { 00816 struct _stg_rtk_table_t *next, *prev; // Linked list of tables 00817 stg_rtk_app_t *app; // Link to our parent app 00818 GtkWidget *frame; // A top-level window to put the table in. 00819 GtkWidget *table; // The table layout 00820 int destroyed; // Flag set to true if the GTK frame has been destroyed. 00821 int item_count; // Number of items currently in the table 00822 int row_count; // Number of rows currently in the table 00823 stg_rtk_tableitem_t *item; // Linked list of items that belong in the table 00824 } stg_rtk_table_t; 00825 00826 // Create a new table 00827 stg_rtk_table_t *stg_rtk_table_create(stg_rtk_app_t *app, int width, int height); 00828 00829 // Delete the table 00830 void stg_rtk_table_destroy(stg_rtk_table_t *table); 00831 00832 // Create a new item in the table 00833 stg_rtk_tableitem_t *stg_rtk_tableitem_create_int(stg_rtk_table_t *table, 00834 const char *label, int low, int high); 00835 00836 // Set the value of a table item (as an integer) 00837 void stg_rtk_tableitem_set_int(stg_rtk_tableitem_t *item, int value); 00838 00839 // Get the value of a table item (as an integer) 00840 int stg_rtk_tableitem_get_int(stg_rtk_tableitem_t *item); 00841 00842 #ifdef __cplusplus 00843 } 00844 #endif 00845 00846 #endif 00847
Generated on Thu Aug 11 13:08:10 2005 for Stage by 1.4.0