The TGraph structure is implemented by raster and 2D-graphics. It is designated for working with graphic primitives like rectangles, lines and pixels. It functions similarly to many other SDK structures, in that you must use a TGraph constructor to create the TGraph object, and release it after use with a TGraph deconstructor.
The structure diagram below shows that TGraph is a parent structure for other structures such as Graphics and DisplayGraphics. This means that raster and 2D-graphics operations for Graphics and DisplayGraphics structures are implemented in their parent structure.
To use all TGraph functions you must obtain the Display Graphics Context from the init_module function. It has only one parameter, called the main application module parameter, and it must be obtained by the module_t structure.
See examples for related functions.
Draws a horizontal line from point ( x , y ) to point ( dx , y ).
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. if ( TGraph_get_color( main_module.m_gfx ) != CLR_LTGRAY ) TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_draw_hline( main_module.m_gfx, 10, 10, 20); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Draws a solid line from point ( x1 , y1 ) to point ( x2 , y2 ).
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY or CLR_BLACK. if ( TGraph_get_color( main_module.m_gfx ) != CLR_LTGRAY ) TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_draw_line( main_module.m_gfx, 10, 10, 20, 60 ); ... // To send the current graphics page to the TGraph_draw_rect_Ex Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Draws a rectangular frame.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to Cybiko graphics context TGraph_draw_rect( main_module.m_gfx, 10, 10, 100, 100 ); ... // To send the current graphics page to Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
The extended version of the TGraph_draw_rect function.
Draws a rectangular frame using the info contained in a rect_t object.
#include <cybiko.h> ... struct rect_t rc; struct module_t main_module; init_module( &main_module ); rc.y = rc.x = 10; rc.w = rc.h = 100; ... // main_module.m_gfx is a pointer to Cybiko graphics context TGraph_draw_rect_Ex( main_module.m_gfx, &rc ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Draws vertical line from point ( x , y ) to point ( x , dy ).
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one from following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. if ( TGraph_get_color( main_module.m_gfx ) != CLR_LTGRAY ) TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_draw_vline( main_module.m_gfx, 10, 10, 20); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Fills a rectangle at the specified coordinates with the current color.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_fill_rect( main_module.m_gfx, 5, 5, 30, 30 ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
The extended version of the TGraph_fill_rect function.
Fills a rectangle at the specified coordinates with the current color.
#include <cybiko.h> ... struct rect_t rc; struct module_t main_module; init_module( &main_module ); rc.y = rc.x = 10; rc.w = rc.h = 100; ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_fill_rect_Ex( main_module.m_gfx, &rc ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Fills the screen with the color 'fc'.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_fill_screen function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. TGraph_fill_screen( main_module.m_gfx, CLR_BLACK ); ... // To send the current graphisc page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Returns a pointer to an image of a TGraph object's destination.
#include <cybiko.h> ... struct module_t main_module; struct TGraph gfx; ... init_module( &main_module ); ... TGraph_put_background( main_module.m_gfx, TGraph_get_buf_addr( &gfx ) ); ...
Returns the screen buffer size, in bytes.
#include <cybiko.h> ... struct module_t main_module; char* ptr_display_buffer; init_module( &main_module ); ... // Allocating memory for buffer ptr_display_buffer = (char* ) malloc( TGraph_get_bytes_total( main_module.m_gfx ) ); ... // Make some graphics operation ( draw a picture, for instance) ... // Save the screen memcpy( ptr_display_buffer, DisplayGraphics_get_page_ptr(main_module.m_gfx, 0), TGraph_get_bytes_total(main_module.m_gfx)); ... // Make another graphics operation ... // Restore the screen. Works very fast. TGraph_put_background( main_module.m_gfx, ptr_display_buffer ); ... // Make another graphics operation ... // Restore the screen again. TGraph_put_background( main_module.m_gfx, ptr_display_buffer ); ... free( ptr_display_buffer );
Returns the clip region stored in the 'rc' 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. 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( main_module.m_gfx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); ...
Returns a TGraph object's current color.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. if ( TGraph_get_color( main_module.m_gfx ) != CLR_LTGRAY ) TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_fill_rect( main_module.m_gfx, 5, 5, 30, 30 ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Returns the current draw mode of a TGraph object.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); ... // The second parameter in the TGraph_set_draw_mode function is the draw mode value. // This value must be one of the following: DM_XOR, DM_OR, or DM_PUT. if ( TGraph_get_draw_mode( main_module.m_gfx ) != DM_PUT ) TGraph_set_draw_mode( main_module.m_gfx, DM_PUT ); TGraph_fill_rect( main_module.m_gfx, 5, 5, 30, 30 ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Returns the color of the pixel at coordinate ( x , y ).
#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. TGraph_get_clip ( main_module.m_gfx, &clip_region ); if ( TGraph_get_pixel( main_module.m_gfx, 10, 30 ) == CLR_BLACK ) TGraph_set_pixel( main_module.m_gfx, 10, 30, CLR_WHITE ); ...
Sets an image pointed by ptr_background as a background image.
#include <cybiko.h> ... struct module_t main_module; char* ptr_display_buffer; init_module( &main_module ); ... // Allocating memory for buffer ptr_display_buffer = (char* ) malloc( TGraph_get_bytes_total( main_module.m_gfx ) ); ... // Make some graphics operation ( draw a picture, for instance) ... // Save the screen memcpy( ptr_display_buffer, DisplayGraphics_get_page_ptr(main_module.m_gfx, 0), TGraph_get_bytes_total(main_module.m_gfx)); ... // Make another graphics operation ... // Restore the screen. Works very fast. TGraph_put_background( main_module.m_gfx, ptr_display_buffer ); ... // Make another graphics operation ... // Restore the screen again. TGraph_put_background( main_module.m_gfx, ptr_display_buffer ); ... free( ptr_display_buffer );
Scrolls the rectangle defined by ( x, y, width, height ) parameters.
The scroll values are dx and dy.
#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 graphics operation ... TGraph_scroll( main_module.m_gfx, 10, 10, 20, 40, 10, 10 ); DisplayGraphics_show( main_module.m_gfx ); ...
Sets the transparent color as the color defined in the 'color' parameter.
#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. TGraph_set_draw_mode( main_module.m_gfx, DM_OR ); // Set transparent color to CLR_BLACK TGraph_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 the clipping region.
#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. 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( main_module.m_gfx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); ...
Sets the clipping region.
This is an extended version of the TGraph_set_clip function.
#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 foreground color.
#include <cybiko.h> ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. if ( TGraph_get_color( main_module.m_gfx ) != CLR_LTGRAY ) TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); TGraph_draw_line( main_module.m_gfx, 10, 10, 20, 60 ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Sets the current draw mode of a TGraph object.
#include "cybiko.h" ... struct module_t main_module; init_module( &main_module ); ... // main_module.m_gfx is a pointer to the Cybiko graphics context. // The second parameter in the TGraph_set_color function is the color value. // This value must be one of the following: CLR_WHITE, CLR_LTGRAY, CLR_DKGRAY, or CLR_BLACK. TGraph_set_color( main_module.m_gfx, CLR_LTGRAY ); ... // The second parameter in the TGraph_set_draw_mode function is the draw mode value. // This value must be one of the following: DM_XOR, DM_OR, or DM_PUT. if ( TGraph_get_draw_mode( main_module.m_gfx ) != DM_PUT ) TGraph_set_draw_mode( main_module.m_gfx, DM_PUT ); TGraph_fill_rect( main_module.m_gfx, 5, 5, 30, 30 ); ... // To send the current graphics page to the Cybiko display you should use this function DisplayGraphics_show( main_module.m_gfx );
Sets the color for the pixel at the coordinates ( x, y ).
#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. TGraph_get_clip ( main_module.m_gfx, &clip_region ); if ( TGraph_get_pixel( main_module.m_gfx, 10, 30 ) == CLR_BLACK ) TGraph_set_pixel( main_module.m_gfx, 10, 30, CLR_WHITE ); ...