ASCII-GFX  2.0
Functions | Variables
gfx.cpp File Reference
#include "gfx.h"
#include "gridfont.h"

Functions

void init_gfx ()
 init ASCII GFX More...
 
void init_color ()
 init ASCII GFX color display More...
 
void exit_gfx ()
 exit ASCII GFX More...
 
void set_window (WINDOW *w)
 set the drawing window More...
 
void use_color (int index)
 use indexed color pair for foreground/background colors of characters More...
 
void use_attr_bold ()
 use attribute bold More...
 
void use_attr_blink ()
 use attribute blink More...
 
void use_attr_reverse ()
 use attribute reverse More...
 
void use_attr_normal ()
 use attribute normal More...
 
void draw_text (int y, int x, const char *format,...)
 draw a formatted text at position (x, y) More...
 
void draw_sprite (int y, int x, const char *text)
 draw a sprite at barycenter position (x, y) More...
 
void draw_area (int y, int x, int sy, int sx, const int *data)
 draw a screen area at top-left position (x, y) with size (sx, sy) More...
 
void draw_grid_text (int y, int x, const char *text)
 draw a text string with grid font characters at top-left position (x, y) More...
 
void draw_line (int y1, int x1, int y2, int x2, int ch, bool background)
 draw a line from position (x1, y1) to (x2, y2) More...
 
void draw_frame (int y1, int x1, int y2, int x2, int ch)
 draw a frame from position (y1, x1) to (y2, x2) More...
 
void draw_circle (int yc, int xc, int r, int ch, double aspect)
 draw a circle at center position (xc, yc) with radius r More...
 
void draw_points (int yc, int xc, int y, int x, int ay, int ax, double aspect, int ch)
 
void draw_ellipse (int yc, int xc, int ay, int ax, int ch, double aspect)
 draw a ellipse at center position (xc, yc) with principle axis ax and ay More...
 
int peek (int y, int x)
 peek at location (y, x) and return the displayed character More...
 
int get_keycode ()
 return wide keycode More...
 
void cursor_keycode (int keycode, int *dx, unsigned int *dy)
 decode wide keycode More...
 
int * convert_char_text (const char *text, int sx, int sy, int ch, bool interprete)
 helper for converting a text string into an ASCII data buffer More...
 
char * get_string_buffer (int n)
 helper for allocating a temporarily used string buffer More...
 

Variables

static WINDOW * W = NULL
 
static char * string_buffer = NULL
 
static int buffer_size = 0
 

Function Documentation

◆ convert_char_text()

int* convert_char_text ( const char *  text,
int  sx,
int  sy,
int  ch = -1,
bool  interprete = false 
)

helper for converting a text string into an ASCII data buffer

  • "ch" is the character that represents transparent areas
  • when "interprete" is enabled treat special characters as follows:
    • ^ as overscore
    • # as checker board
    • B as bold attribute
    • digits as color attributes
    • 0 to clear attributes

◆ cursor_keycode()

void cursor_keycode ( int  keycode,
int *  dx,
unsigned int *  dy 
)

decode wide keycode

  • if a cursor event has been observed as a wide keycode, the function decodes it
  • the function returns a corresponding direction vector (dx, dy) via call-by-reference

◆ draw_area()

void draw_area ( int  y,
int  x,
int  sy,
int  sx,
const int *  data 
)

draw a screen area at top-left position (x, y) with size (sx, sy)

  • the data is made up from consecutive lines of characters

◆ draw_circle()

void draw_circle ( int  yc,
int  xc,
int  r,
int  ch = -1,
double  aspect = 2 
)

draw a circle at center position (xc, yc) with radius r

  • Bresenham's circle drawing algorithm
  • "ch" is the character used to draw the circle
    • by default graphical characters are used

◆ draw_ellipse()

void draw_ellipse ( int  yc,
int  xc,
int  ay,
int  ax,
int  ch = -1,
double  aspect = 2 
)

draw a ellipse at center position (xc, yc) with principle axis ax and ay

  • Bresenham's ellipse drawing algorithm
  • "ch" is the character used to draw the ellipse
    • by default graphical characters are used

◆ draw_frame()

void draw_frame ( int  y1,
int  x1,
int  y2,
int  x2,
int  ch = -1 
)

draw a frame from position (y1, x1) to (y2, x2)

  • "ch" is the character used to draw the frame
    • by default graphical characters are used

◆ draw_grid_text()

void draw_grid_text ( int  y,
int  x,
const char *  text 
)

draw a text string with grid font characters at top-left position (x, y)

  • the grid font needs to be initialized beforehand via init_grid_font()
  • the grid text is made up from consecutive text lines separated by \n

◆ draw_line()

void draw_line ( int  y1,
int  x1,
int  y2,
int  x2,
int  ch = -1,
bool  background = false 
)

draw a line from position (x1, y1) to (x2, y2)

  • symmetrified Bresenham algorithm
  • "ch" is the character used to draw the line
    • by default graphical characters are used
  • "background" makes the line appear in non-empty background areas only

◆ draw_points()

void draw_points ( int  yc,
int  xc,
int  y,
int  x,
int  ay,
int  ax,
double  aspect,
int  ch 
)

◆ draw_sprite()

void draw_sprite ( int  y,
int  x,
const char *  text 
)

draw a sprite at barycenter position (x, y)

  • the sprite text needs to be a string that is terminated by \0
  • the sprite text is made up from consecutive text lines separated by \n
  • if the sprite position is outside of the screen the text will wrap around

◆ draw_text()

void draw_text ( int  y,
int  x,
const char *  format,
  ... 
)

draw a formatted text at position (x, y)

  • non-printable characters like \n will be ignored

◆ exit_gfx()

void exit_gfx ( )

exit ASCII GFX

  • close the standard screen of NCurses

◆ get_keycode()

int get_keycode ( )

return wide keycode

◆ get_string_buffer()

char* get_string_buffer ( int  n)

helper for allocating a temporarily used string buffer

  • provides a buffer for a string with at most n characters
  • it allocates memory for the n characters plus the terminal nul character

◆ init_color()

void init_color ( )

init ASCII GFX color display

  • default colors are white, red, green, blue with indices 1-4
  • and composite colors yellow, cyan, magenta with indices 5-7
  • plus special inverse and black colors with indices 8-9

◆ init_gfx()

void init_gfx ( )

init ASCII GFX

  • setup the standard screen of NCurses
  • the screen origin (0, 0) is at the top left corner

◆ peek()

int peek ( int  y,
int  x 
)

peek at location (y, x) and return the displayed character

◆ set_window()

void set_window ( WINDOW *  w)

set the drawing window

  • by default the standard screen is used

◆ use_attr_blink()

void use_attr_blink ( )

use attribute blink

◆ use_attr_bold()

void use_attr_bold ( )

use attribute bold

◆ use_attr_normal()

void use_attr_normal ( )

use attribute normal

◆ use_attr_reverse()

void use_attr_reverse ( )

use attribute reverse

◆ use_color()

void use_color ( int  index = 1)

use indexed color pair for foreground/background colors of characters

  • colors need to be initialized beforehand via init_color()
  • 1 = white/black
  • 2 = red/black
  • 3 = green/black
  • 4 = blue/black
  • 5 = yellow/black
  • 6 = cyan/black
  • 7 = magenta/black
  • 8 = black/white
  • 9 = black/black

Variable Documentation

◆ buffer_size

int buffer_size = 0
static

◆ string_buffer

char* string_buffer = NULL
static

◆ W

WINDOW* W = NULL
static