The Graphics structure uses bitmaps to maintain many operations. The DisplayGraphics structure allows you to draw operations directly on the screen. You can draw graphics primitives,as well as text with the current font.
Because TGraph is its parent structure, the Graphics structure's functions are defined in TGraph structure. For example, manipulations of graphics primitives are implemented in TGraph structure.
To use some Graphics functions, you must obtain the Display Graphics Context from the init_module function. This context has only one parameter (the main application module parameter) and it must be obtained from the module_t structure.
See examples for related functions.
Simple Graphics constructor.
Creates an empty Graphics object.
#include <cybiko.h> ... struct Graphics gfx; Graphics_ctor( &gfx ); ... Graphics_dtor( &gfx, LEAVE_MEMORY );
The extended version of the Graphics_ctor function.
Creates a Graphics object that is associated with a Bitmap object.
#include <cybiko.h> ... struct Bitmap bitmap; struct Graphics gfx; ... Bitmap_ctor_Ex1( &bitmap, "screen.pic" ); Graphics_ctor_Ex( &gfx, &bitmap ); ... Graphics_dtor( &gfx, LEAVE_MEMORY ); Bitmap_dtor( &bitmap, LEAVE_MEMORY );
Allows the bitmap 'bmp' to be drawn in a specified position (left, top) in 'fm' mode.
#include <cybiko.h> ... struct module_t main_module; struct Bitmap bitmap; ... init_module( &main_module ); Bitmap_ctor_Ex1( &bitmap, "screen.pic" ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_draw_bitmap( main_module.m_gfx, &bitmap, 30, 40, BM_NORMAL ); ...
Allows the character 'fc' to be drawn in the current font in specified position (x, y).
#include <cybiko.h> ... int pos; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); pos = Graphics_draw_char( main_module.m_gfx, 10, 10, 'c' ); ...
Draws a horizontal line from point (x , y) to point (xx , y).
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_draw_hline( main_module.m_gfx, 10, 10, 60 ); ...
Draws a solid line from point ( x , y ) to point ( xx , yy ).
#include <cybiko.h> ... struct module_t main_module; int pos; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_draw_line( main_module.m_gfx, 10, 10, 20, 20); ...
Draws a rectangular frame in the current color.
#include <cybiko.h> ... struct module_t main_module; int pos; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_draw_rect( main_module.m_gfx, 10, 10, 20, 20); ...
Duplicates the Graphics_draw_rect function.
#include <cybiko.h> ... struct module_t main_module; struct rect_t rectangle={0,0,100,100}; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_draw_rect_Ex( main_module.m_gfx, &rectangle ); ...
Allows 'text' to be drawn in the current font, in the specified position (left , top).
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); Graphics_draw_text( main_module.m_gfx, "Any text", 10, 10 ); ...
Duplicates the Graphics_draw_text function.
If the length of the string exceeds the number of 'flen' pixels, the string will be truncated.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); Graphics_draw_text_Ex( main_module.m_gfx, "Any Text", 10, 10, 20 ); ...
Draws a vertical line from point (x , y) to point (x , yy).
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_draw_vline( main_module.m_gfx, 10, 10, 20); ...
Deletes a Graphics object.
#include <cybiko.h> ... struct Graphics gfx; Graphics_ctor( &gfx ); ... Graphics_dtor( &gfx, LEAVE_MEMORY );
Fills a rectangle with the current color.
The rectangle is defined by fx, fy, fw, and fh parameters.
#include <cybiko.h> ... struct module_t main_module; int pos; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_fill_rect( main_module.m_gfx, 10, 10, 20, 20); ...
Duplicates the Graphics_fill_rect function.
#include <cybiko.h> ... struct module_t main_module; struct rect_t rectangle={0,0,100,100}; ... init_module( &main_module ); TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); Graphics_fill_rect_Ex( main_module.m_gfx, &rectangle ); ...
Fills the screen with the 'fc' color.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); Graphics_fill_screen( main_module.m_gfx, CLR_LTGRAY); ...
Returns the current Bitmap context for drawing.
#include <cybiko.h> ... struct module_t main_module; struct Bitmap * bitmap; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. bitmap = Graphics_get_bitmap( main_module.m_gfx ); ...
Returns a pointer to the Graphics object's associated image.
#include <cybiko.h> ... struct module_t main_module; struct Graphics gfx_fp; ... Graphics_put_background( main_module.m_gfx, Graphics_get_buf_addr( &gfx_fp )) ; ...
Returns the total number of bytes in the screen buffer.
#include <cybiko.h> ... struct module_t main_module; char* ptr_display_buffer; ... init_module( &main_module ); ptr_display_buffer = (char* ) malloc( Graphics_get_bytes_total( main_module.m_gfx ) ); ...
Returns the current font's height.
#include <cybiko.h> ... int font_height; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); font_height = Graphics_get_char_height( main_module.m_gfx ); ...
Returns the current font's character width.
#include <cybiko.h> ... int char_width; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); char_width = Graphics_get_char_width( main_module.m_gfx, 'g' ); ...
Returns a clip region.
It is defined by coordinates that are stored in a rect_t object.
#include <cybiko.h> ... struct module_t main_module; struct rect_t clip_region; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_clip_Ex( main_module.m_gfx, &clip_region ); if ( (clip_region.x != 0) || ( clip_region.y != 0) || ( clip_region.w != SCREEN_WIDTH) ||( clip_region.h != SCREEN_HEIGHT) ) Graphics_set_clip( main_module.m_gfx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); ...
Returns the current foreground color.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); if ( Graphics_get_color( main_module.m_gfx ) != CLR_LTGRAY ) Graphics_set_color( main_module.m_gfx, CLR_LTGRAY); ...
Returns the current draw mode.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); if ( Graphics_get_draw_mode( main_module.m_gfx ) != DM_PUT ) Graphics_set_draw_mode( main_module.m_gfx, DM_PUT); ...
Returns the current font.
#include <cybiko.h> ... struct Font * ptr_font; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); ... ptr_font = Graphics_get_font( main_module.m_gfx ); ...
Returns the color of the pixel with coordinate ( fx , fy ).
#include <cybiko.h> ... struct module_t main_module; if ( Graphics_get_pixel( main_module.m_gfx, 10, 30 ) == CLR_BLACK ) Graphics_set_pixel( main_module.m_gfx, 10, 30, CLR_WHITE ); ...
Treats fp as a pointer to a background image and sends the image to its destination.
#include <cybiko.h> ... struct module_t main_module; struct Graphics gfx_fp; ... Graphics_put_background( main_module.m_gfx, Graphics_get_buf_addr( &gfx_fp )) ; ...
Scrolls a rectangle area that is defined by delta x, delta y in 'ptr_rectangle'.
#include <cybiko.h> ... struct module_t main_module; init_module(&main_module); ... TGraph_fill_rect( main_module.m_gfx, 10, 10, 20, 40 ); DisplayGraphics_show( main_module.m_gfx ); ... // Make some graphic operation ... Graphics_scroll( main_module.m_gfx, 10, 10, 20, 40, 10, 10 ); DisplayGraphics_show( main_module.m_gfx ); ...
Sets a bitmap 'bmp' as the destination for drawings.
#include <cybiko.h> ... struct Bitmap bitmap; struct Graphics vgfx; ... Graphics_ctor( &vgfx ); // SCREEN_WIDTH and SCREEN_HEIGHT are described in the 'Defines' section. Bitmap_ctor_Ex2( &bitmap, SCREEN_WIDTH, SCREEN_HEIGHT, 2 ); ... // Now all drawing operations in the 'vgfx' graphics context will be performed on the 'bitmap' object. Graphics_set_bitmap( &vgfx, &bitmap ); ...
Sets the current background color by calling TGraph_set_bkcolor.
#include <cybiko.h> ... struct module_t main_module; struct Bitmap bmp; ... init_module( &main_module ); // Creates a bitmap from the file "root.ico". Bitmap_ctor_Ex1( &bmp, "root.ico" ); ... // Set draw mode to mode OR. Graphics_set_draw_mode( main_module.m_gfx, DM_OR ); // Set transparent color to CLR_BLACK Graphics_set_bkcolor( main_module.m_gfx, CLR_BLACK ); // Draw all pixels of the bitmap except pixels with CLR_BLACK color. Graphics_draw_bitmap( main_module.m_gfx, &bmp, 30, 40, BM_NORMAL ); ... Bitmap_dtor( &bmp, LEAVE_MEMORY ); ...
Sets a clip region, defined by the coordinates stored in the fx, fy, fw, and fh parameters.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_clip ( main_module.m_gfx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); ...
Duplicates the Graphics_set_clip function.
The region coordinates are stored in a rect_t object.
#include <cybiko.h> ... struct module_t main_module; struct rect_t clip_region; struct rect_t new_clip_reg; init_module( &main_module ); ... new_clip_reg.x = 10; new_clip_reg.y = 10; new_clip_reg.h = 100; new_clip_reg.w = 100; ... // main_module.m_gfx is a pointer to the Cybiko graphics context. TGraph_get_clip ( main_module.m_gfx, &clip_region ); if ( (clip_region.x != 0) || ( clip_region.y != 0) || ( clip_region.w != SCREEN_WIDTH) ||( clip_region.h != SCREEN_HEIGHT) ) TGraph_set_clip_Ex( main_module.m_gfx, &new_clip_reg ); ...
Sets the current foreground color.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); if ( Graphics_get_color( main_module.m_gfx ) != CLR_LTGRAY ) Graphics_set_color( main_module.m_gfx, CLR_LTGRAY); ...
Sets the current draw mode.
#include <cybiko.h> ... struct module_t main_module; ... init_module( &main_module ); if ( Graphics_get_draw_mode( main_module.m_gfx ) != DM_PUT ) Graphics_set_draw_mode( main_module.m_gfx, DM_PUT); ...
Sets the current font.
#include <cybiko.h> ... int str_plen; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); ...
The color, defined by the 'fc' parameter.
Sets the color of the pixel at coordinates ( fx , fy ).
#include <cybiko.h> ... struct module_t main_module; if ( Graphics_get_pixel( main_module.m_gfx, 10, 30 ) == CLR_BLACK ) Graphics_set_pixel( main_module.m_gfx, 10, 30, CLR_WHITE ); ...
Returns the width (in pixels) of a string 'str' for the current font.
#include <cybiko.h> ... int str_plen; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); ... str_plen = Graphics_string_width( main_module.m_gfx, "Any string" ); ...
The extended version of the Graphics_string_width function.
Returns the width (in pixels) of the first 'len' symbols of a string 'str'.
#include <cybiko.h> ... int str_plen; struct module_t main_module; ... init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. Graphics_set_font( main_module.m_gfx, cool_normal_font ); ... str_plen = Graphics_string_width_Ex( main_module.m_gfx, "Any string", 20 ); ...