CDM  v0.9
Console Draw Motor, C librarly for quickly developing Windows console applications with advanced graphics. https://github.com/komo97/CDM
CDM.h File Reference

This file contains every definition, structure and function needed to use CDM. More...

Data Structures

struct  CDMTiles
 A structure that contains raw data for the console to process, most structures used in CDM require this component. More...
 
struct  CDMEvent
 A structure containing the events required to check input inside CDM. More...
 
struct  CDMContext
 A context in which CDM will run. It contains the handle for the console window, color information buffers, character buffers, the size of the window inside it's rect and an event structure to get key events. More...
 
struct  CDMPixelData
 The data of a single pixel. More...
 
struct  CDMPalette
 A palette for a CDMSurface. It contains the four types of pixel that the surface is able to be used. More...
 
struct  CDMSurface
 A representation of an image that is able to be interpreted by CDM. More...
 
struct  CDMText
 A representation of a text object able to be interpreted by CDM. More...
 
struct  CDMColorScheme
 This structure serves the purpose of a color palette. You can select which palette is active and displaying at any time using CDMSetActiveScheme. The default values for colors are this, in binary.
0x00362b00 Black
0x00423607 Gray
0x00756e58 Green
0x00837b65 Yellow
0x00969483 Blue
0x00a1a193 Aqua
0x00d5e8ee White
0x00e3f6fd BrightWhite
0x000089b5 BrightYellow
0x00164bcb Red
0x002f32dc LightRed
0x008236d3 LightPurple
0x00c4716c Purple
0x00d28b26 LightBlue
0x0098a12a LightAqua
0x00009985 LightGreen
. More...
 

Macros

#define _IN_
 Describes a parameter that will only be used for data input and is required. More...
 
#define _OUT_
 Describes a parameter that will only be used for data output and is required. More...
 
#define _INOUT_
 Describes a parameter that will be used for data input and output and is required. More...
 
#define _INOPT_
 Describes a parameter that will only be used for data input and is not required. More...
 
#define _OUTOPT_
 Describes a parameter that will only be used for data output and is not required. More...
 
#define _INOUTOPT_
 Describes a parameter that will be used for data input and output and is not required. More...
 

Typedefs

typedef SMALL_RECT CDMRect
 Defines an alias representing the CDM rectangle, contains a left, right, top and bottom properties. More...
 
typedef COORD CDMCoord
 Defines an alias representing the CDM coordinate, contains an X and a Y property. More...
 
typedef char CDMEnum
 Defines an alias representing the CDM enum, this type is completely symbolic and describes a parameter that requires to be filled with an enumeration. More...
 
typedef unsigned char CDMErrno
 Defines an alias representing the CDM error number, a simple type for checking errors inside the API. More...
 

Enumerations

enum  CDMLetterColor {
  CLEAR = -1, BLACK = 0, DARKBLUE = FOREGROUND_BLUE, DARKGREEN = FOREGROUND_GREEN,
  DARKCYAN = FOREGROUND_GREEN | FOREGROUND_BLUE, DARKRED = FOREGROUND_RED, DARKMAGENTA = FOREGROUND_RED | FOREGROUND_BLUE, DARKYELLOW = FOREGROUND_RED | FOREGROUND_GREEN,
  DARKGRAY = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, GRAY = FOREGROUND_INTENSITY, BLUE = FOREGROUND_INTENSITY | FOREGROUND_BLUE, GREEN = FOREGROUND_INTENSITY | FOREGROUND_GREEN,
  CYAN = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE, RED = FOREGROUND_INTENSITY | FOREGROUND_RED, MAGENTA = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE, YELLOW = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN,
  WHITE = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, LCOLOR1 = BLACK, LCOLOR2 = DARKBLUE, LCOLOR3 = DARKGREEN,
  LCOLOR4 = DARKCYAN, LCOLOR5 = DARKRED, LCOLOR6 = DARKMAGENTA, LCOLOR7 = DARKYELLOW,
  LCOLOR8 = DARKGRAY, LCOLOR9 = GRAY, LCOLOR10 = GREEN, LCOLOR11 = CYAN,
  LCOLOR12 = RED, LCOLOR13 = MAGENTA, LCOLOR14 = YELLOW, LCOLOR15 = WHITE
}
 Describes a parameter that will be used for data input and output and it maps all the possible colors for the letters that can be used inside CDM. More...
 
enum  CDMBackgroundColor {
  BCLEAR = -1, BBLACK = 0, BDARKBLUE = BACKGROUND_BLUE, BDARKGREEN = BACKGROUND_GREEN,
  BDARKCYAN = BACKGROUND_GREEN | BACKGROUND_BLUE, BDARKRED = BACKGROUND_RED, BDARKMAGENTA = BACKGROUND_RED | BACKGROUND_BLUE, BDARKYELLOW = BACKGROUND_RED | BACKGROUND_GREEN,
  BDARKGRAY = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE, BGRAY = BACKGROUND_INTENSITY, BBLUE = BACKGROUND_INTENSITY | BACKGROUND_BLUE, BGREEN = BACKGROUND_INTENSITY | BACKGROUND_GREEN,
  BCYAN = BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE, BRED = BACKGROUND_INTENSITY | BACKGROUND_RED, BMAGENTA = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_BLUE, BYELLOW = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN,
  BWHITE = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE, BCOLOR1 = BBLACK, BCOLOR2 = BDARKBLUE, BCOLOR3 = BDARKGREEN,
  BCOLOR4 = BDARKCYAN, BCOLOR5 = BDARKRED, BCOLOR6 = BDARKMAGENTA, BCOLOR7 = BDARKYELLOW,
  BCOLOR8 = BDARKGRAY, BCOLOR9 = BGRAY, BCOLOR10 = BGREEN, BCOLOR11 = BCYAN,
  BCOLOR12 = BRED, BCOLOR13 = BMAGENTA, BCOLOR14 = BYELLOW, BCOLOR15 = BWHITE
}
 Describes a parameter that will be used for data input and output and it maps all the possible colors for the letters that can be used inside CDM. More...
 
enum  CDMExtraOptions { reverseColors = COMMON_LVB_REVERSE_VIDEO, underscore = COMMON_LVB_UNDERSCORE, Alpha = 100 }
 Values that represent extra options for coloring letters and backgrounds. Exclusive for advanced usage. More...
 
enum  CDMColorSets {
  Set1 = 0x0001, Set2 = 0x0002, Set3 = 0x0004, Set4 = 0x0008,
  SetAlpha = 0x0010
}
 Values that represent the color sets to be used inside CDMSetPixel. Each one represents one combination of a background color, a letter color and a character. More...
 
enum  CDMBool { CDMFalse = 0, CDMTrue = 1 }
 Boolean implementation. More...
 
enum  CDMKey {
  mbleft = VK_LBUTTON, mbright = VK_RBUTTON, backspace = VK_BACK, tab = VK_TAB,
  clear = VK_CLEAR, returnK = VK_RETURN, shift = VK_SHIFT, ctrl = VK_CONTROL,
  alt = VK_MENU, pause = VK_PAUSE, caps = VK_CAPITAL, esc = VK_ESCAPE,
  space = VK_SPACE, pgup = VK_PRIOR, pgdown = VK_NEXT, end = VK_END,
  left = VK_LEFT, right = VK_RIGHT, up = VK_UP, down = VK_DOWN,
  print = VK_PRINT, insert = VK_INSERT, del = VK_DELETE, zero = 0x30,
  one = 0x31, two = 0x32, three = 0x33, four = 0x34,
  five = 0x35, six = 0x36, seven = 0x37, eight = 0x38,
  nine = 0x39, A = 0x41, B, C,
  D, E, F, G,
  H, I, J, K,
  L, M, N, O,
  P, Q, R, S,
  T, U, V, W,
  X, Y, Z, add = 0x6B,
  separator, substract, decimal, divide,
  f1, f2, f3, f4,
  f5, f6, f7, f8,
  f9, f10, f11, f12,
  lshift = 0xA0, rshift, lctrl, rctrl,
  lalt, ralt, KeysEnd
}
 Values that represent all possible inputs inside CDM. More...
 
enum  CDMMode { mode3d, mode2d }
 Values that represent the rendering mode of CDM, not to be used right now. More...
 

Functions

CDMContextCDMCreateContext (const _IN_ short width, const _IN_ short height)
 The setup function of CDM. Must be called before anything else. CDM requires a context to work, most of the functions here require a context to be used. Status: Working. More...
 
void CDMChangeWindowSize (_INOUT_ CDMContext **ctx, const _IN_ short width, const _IN_ short height)
 Changes the window size of a context. May be called at any time, however it will clear the screen once its done. Status: Working. More...
 
void CDMToggleFullscreen (CDMContext **_INOUT_ ctx, const _IN_ CDMBool val)
 Toggles full screen mode. Status: May be working on older platforms. More...
 
void CDMSetWindowTitle (const _IN_ wchar_t *title)
 Sets the title of the console. Just a wrapper for a WINAPI functionality. Status: Working. More...
 
void CDMSetFontAndSize (_INOUT_ CDMContext **ctx, const _IN_ wchar_t *fontName, const _IN_ short width, const _IN_ short height)
 Sets the font and font size of the console. The recommended font name is L"Terminal" for its unique characteristic of allowing square pixels, however most fonts can be used. It's important to include L at the start of your string, since this function requires a wchar_t* instead of a regular char. Status: Working. More...
 
void CDMSetCursorVisibility (_INOUT_ CDMContext **ctx, const _IN_ CDMBool status)
 Sets the visibility of the console's cursor. Status: Working. More...
 
void CDMActivateMouseInput (_INOUT_ CDMContext **ctx)
 Activates mouse input recognition for the console. Status: Working. More...
 
CDMSurfaceCDMCreateSurface (const _IN_ short posX, const _IN_ short posY, const _IN_ short sizeX, const _IN_ short sizeY)
 Creates a surface. A surface is the base representation of an image in CDM Most every object used in CDM will most likely be a surface. Status: Working. More...
 
CDMSurfaceCDMReadImg (const _IN_ char *fileName, _OUTOPT_ CDMColorScheme *scheme)
 Reads a .cdi image file into a CDMSurface. The file must be generated exactly the same as CDMExportSrfcToImg, for it to work using this function. The usage of the structure may be imperative. Status: Working. More...
 
void CDMExportSrfcToImg (const _IN_ CDMContext *ctx, const _IN_ CDMSurface *srfc, const _IN_ char *fileName, const _IN_ size_t nameSize)
 Exports a surface to a .cdi image. Status: Working. More...
 
CDMTextCDMTextWrapper (_IN_ wchar_t *text, const _IN_ CDMLetterColor color, const _IN_ CDMBackgroundColor background)
 Since CDM basically hijacks the console, functions like printf are not enabled. No output will be shown using them, instead you must use the text as an object, this means you have much more control of the position and design of your text, at the expense of making a little bit harder to use. Moreover, repeated uses of the same text box will not require you to create a new object or call anything else other than adding this object to the context, or drawing it directly. All text begins in the ( 0 , 0 ) coordinate. Status: Working. More...
 
CDMTextCDMTextWrapper_s (_IN_ wchar_t *text, const _IN_ size_t textSize, const _IN_ CDMLetterColor color, const _IN_ CDMBackgroundColor background)
 Since CDM basically hijacks the console, functions like printf are disabled. No output will be shown using them, instead you must use the text as an object, this means you have much more control of the position and design of your text, at the expense of making a little bit harder to use. Moreover, repeated uses of the same text box will not require you to create a new object or call anything else other than adding this object to the context, or drawing it directly. All text begins in the ( 0 , 0 ) coordinate. Status: Working. More...
 
void CDMChangeText (CDMText **txt, const _IN_ wchar_t *text)
 Changes the text content of a CDMText. Status: Working. More...
 
void CDMSetForegroundColor (_INOUT_ CDMSurface **surface, const _IN_ CDMLetterColor c1, const _IN_ CDMLetterColor c2, const _IN_ CDMLetterColor c3, const _IN_ CDMLetterColor c4)
 A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four foreground colors that the Surface will use from the color palette. Status: Working. More...
 
void CDMSetBackgroundColor (_INOUT_ CDMSurface **surface, const _IN_ CDMBackgroundColor c1, const _IN_ CDMBackgroundColor c2, const _IN_ CDMBackgroundColor c3, const _IN_ CDMBackgroundColor c4)
 A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four background colors that the Surface will use from the color palette. Status: Working. More...
 
void CDMSetCharacters (_INOUT_ CDMSurface **surface, const _IN_ wchar_t c1, const _IN_ wchar_t c2, const _IN_ wchar_t c3, const _IN_ wchar_t c4)
 A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four characters that the Surface will use. Status: Working. More...
 
void CDMFreeSurface (_INOUT_ CDMSurface **surface)
 Simple dynamic memory allocation free method. Status: Working. More...
 
void CDMFreeText (_INOUT_ CDMText **txt)
 Simple dynamic memory allocation free method. Status: Working. More...
 
void CDMFreeContext (_INOUT_ CDMContext **ctx)
 Simple dynamic memory allocation free method. Status: Working. More...
 
void CDMPrepareSurface (_INOUT_ CDMSurface **surface)
 This should only be called each time the surface's contents were modified before calling a draw or add function. Internally this function converts the image's values to raw data that the console understands. Status: Working. More...
 
void CDMPrepareText (_INOUT_ CDMText **txt)
 This should only be called each time the text's contents were modified before calling a draw or add function. Internally this function converts the text's values to raw data that the console understands. Status: Working. More...
 
void CDMDrawSurface (_INOUT_ CDMContext **ctx, _IN_ CDMSurface *surface)
 Draws directly a surface in the context, instead of batching it with other draws. I highly recommend using the batch function (Add, then CDMDraw) over this one, to make the program run faster. Status: Partially works. More...
 
void CDMAddSurfaceToContext (_INOUT_ CDMContext **ctx, _IN_ CDMSurface *surface)
 Adds a surface to the context, and thus batching its draw with every other added object, the batch will be completely flushed once CDMDraw is called. Status: Working. More...
 
void CDMDrawText (_INOUT_ CDMContext **ctx, _IN_ CDMText *txt)
 Draws directly a text in the context, instead of batching it with other draws. I highly recommend using the batch function (Add, then CDMDraw) over this one, to make the program run faster. Status: Partially Works. More...
 
void CDMAddTextToContext (_INOUT_ CDMContext **ctx, _IN_ CDMText *txt)
 Adds a text to the context, and thus batching its draw with every other added object, the batch will be completely flushed once CDMDraw is called. Status: Working. More...
 
void CDMSetColorRGB (_INOUT_ CDMColorScheme *data, _IN_ short position, _IN_ short r, _IN_ short g, _IN_ short b)
 Sets an RGB color inside a ColorScheme. Every color goes from 0 to 255, however every value passes through a modulo operation to assure no weird behavior will happen. Status: Working. More...
 
void CDMSetColorBin (_INOUT_ CDMColorScheme *data, _IN_ short position, const _IN_ DWORD color)
 Sets an RGB color inside a ColorScheme. This function accepts an already converted to binary RGB color. You may use Windows.h macro RGB(r,g,b) to get the data. Status: Working. More...
 
void CDMClearScreen (_INOUT_ CDMContext **ctx)
 Clears the current buffer. It does not make the whole screen black. For that you may use CDMFillScreen.This function is implemented like this to reduce overhead on the program by reducing assignations and comparisons. Status: Working. More...
 
void CDMFillScreen (_INOUT_ CDMContext **ctx, const _IN_ wchar_t character, const _IN_ CDMLetterColor frontColor, const _IN_ CDMBackgroundColor backColor)
 Fills the context with a single color. Ignores drawn flags completely. Status: Working. More...
 
void CDMPoke (_INOUT_ CDMContext **ctx, const _IN_ CDMCoord coord, const _IN_ wchar_t character, const _IN_ CDMLetterColor frontColor, const _IN_ CDMBackgroundColor backColor)
 Pokes a pixel in the screen to a certain color. Ignores drawn flags. Status: Working. More...
 
void CDMDraw (_IN_ CDMContext **ctx)
 Draws the whole screen. Does a batch draw if things have been added to the context. Status: Working. More...
 
int CDMGetR (_IN_ CDMColorScheme *data, const _IN_ short position)
 Gets the red color of a certain color inside a ColorScheme. Status: Working. More...
 
int CDMGetG (_IN_ CDMColorScheme *data, const _IN_ short position)
 Gets the green color of a certain color inside a ColorScheme. Status: Working. More...
 
int CDMGetB (_IN_ CDMColorScheme *data, const _IN_ short position)
 Gets the blue color of a certain color inside a ColorScheme. Status: Working. More...
 
void CDMSetActiveScheme (_IN_ CDMColorScheme data, _INOUT_ CDMContext **ctx)
 Sets a color scheme inside a context, and thus changing every display color of it. This instruction does not require you to draw again for results to be shown, as such its extremely fast. Status: Working. More...
 
void CDMSetPixel (_INOUT_ CDMSurface **surface, _IN_ short x, _IN_ short y, _IN_ CDMColorSets pixelSet)
 Sets a pixel inside a surface. You must select from one of the five possible colors inside the surface. Status: Working. More...
 
CDMBool CDMCompareCHARINFO (_IN_ CHAR_INFO rhs, _IN_ CHAR_INFO lhs)
 Compares two CHAR_INFO structures, it's mainly used inside the API for certain operations. May not prove useful to the graphics programmer. Status: Working. More...
 
void CDMPollEvents (_IN_ CDMContext *ctx, _INOUT_ CDMEvent *event)
 Polls the console events, this function must be used in order to get key and mouse presses, as such it must be called at the beginning of every frame and before every function that requires a CDMEvent. Status: Working. More...
 
CDMBool CDMGetKeyPressed (_IN_ CDMEvent *event, const _IN_ CDMKey key)
 Checks if the key selected in the parameter was pressed. This is the only function that checks for mouse input too. Status: Working. More...
 
CDMBool CDMGetKeyDown (_IN_ CDMEvent *event, const _IN_ CDMKey key)
 Checks if the key selected in the parameter was pressed this frame. Status: Working. More...
 
CDMBool CDMGetKeyUp (_IN_ CDMEvent *event, const _IN_ CDMKey key)
 Checks if the key selected in the parameter stopped being pressed this frame. Status: Working. More...
 
CDMCoord CDMGetMousePos (_IN_ CDMEvent *event)
 Gets the mouse position inside the console window. Status: Working. More...
 
void CDMKeepScreenSize (_INOUT_ CDMContext **ctx, _IN_ CDMEvent *event)
 Keeps the screen size of the program. Might be useful if you want to limit screen resizing. Status: Working. More...
 
void CDMPrintf (_INOUT_ CDMContext **ctx, const _IN_ int startingLetter, _IN_ CDMRect initialPos, const _IN_ CDMLetterColor frontColor, const _IN_ CDMBackgroundColor backColor, const _IN_ wchar_t *txt,...)
 A printf implementation for CDM, made it as a replacement or alternative to the text object. It should be easier to manage, but a more expensive call, so use this for dynamic text only, and use Text objects for static text. More...
 
void CDMSetErrno (const _IN_ CDMErrno code)
 Sets an specific errno to a value. Status: Working. More...
 
CDMErrno CDMGetErrno ()
 Gets the value of errno and sets it to zero. Status: Working. More...
 
char * CDMGetErrorMessage ()
 Translates an error code to an error message, for a brief description. Status: Working. More...
 
void CDMClearErrno ()
 Sets errno back to 0. More...
 

Detailed Description

This file contains every definition, structure and function needed to use CDM.

Macro Definition Documentation

◆ _IN_

#define _IN_

Describes a parameter that will only be used for data input and is required.

< .

◆ _INOPT_

#define _INOPT_

Describes a parameter that will only be used for data input and is not required.

◆ _INOUT_

#define _INOUT_

Describes a parameter that will be used for data input and output and is required.

◆ _INOUTOPT_

#define _INOUTOPT_

Describes a parameter that will be used for data input and output and is not required.

◆ _OUT_

#define _OUT_

Describes a parameter that will only be used for data output and is required.

◆ _OUTOPT_

#define _OUTOPT_

Describes a parameter that will only be used for data output and is not required.

Typedef Documentation

◆ CDMCoord

COORD CDMCoord

Defines an alias representing the CDM coordinate, contains an X and a Y property.

◆ CDMEnum

char CDMEnum

Defines an alias representing the CDM enum, this type is completely symbolic and describes a parameter that requires to be filled with an enumeration.

◆ CDMErrno

unsigned char CDMErrno

Defines an alias representing the CDM error number, a simple type for checking errors inside the API.

◆ CDMRect

SMALL_RECT CDMRect

Defines an alias representing the CDM rectangle, contains a left, right, top and bottom properties.

Enumeration Type Documentation

◆ CDMBackgroundColor

Describes a parameter that will be used for data input and output and it maps all the possible colors for the letters that can be used inside CDM.

Enumerator
BCLEAR 
BBLACK 
BDARKBLUE 
BDARKGREEN 
BDARKCYAN 
BDARKRED 
BDARKMAGENTA 
BDARKYELLOW 
BDARKGRAY 
BGRAY 
BBLUE 
BGREEN 
BCYAN 
BRED 
BMAGENTA 
BYELLOW 
BWHITE 
BCOLOR1 
BCOLOR2 
BCOLOR3 
BCOLOR4 
BCOLOR5 
BCOLOR6 
BCOLOR7 
BCOLOR8 
BCOLOR9 
BCOLOR10 
BCOLOR11 
BCOLOR12 
BCOLOR13 
BCOLOR14 
BCOLOR15 

◆ CDMBool

enum CDMBool

Boolean implementation.

Enumerator
CDMFalse 
CDMTrue 

◆ CDMColorSets

Values that represent the color sets to be used inside CDMSetPixel. Each one represents one combination of a background color, a letter color and a character.

Enumerator
Set1 
Set2 
Set3 
Set4 
SetAlpha 

◆ CDMExtraOptions

Values that represent extra options for coloring letters and backgrounds. Exclusive for advanced usage.

Enumerator
reverseColors 
underscore 
Alpha 

◆ CDMKey

enum CDMKey

Values that represent all possible inputs inside CDM.

Enumerator
mbleft 
mbright 
backspace 
tab 
clear 
returnK 
shift 
ctrl 
alt 
pause 
caps 
esc 
space 
pgup 
pgdown 
end 
left 
right 
up 
down 
print 
insert 
del 
zero 
one 
two 
three 
four 
five 
six 
seven 
eight 
nine 
add 
separator 
substract 
decimal 
divide 
f1 
f2 
f3 
f4 
f5 
f6 
f7 
f8 
f9 
f10 
f11 
f12 
lshift 
rshift 
lctrl 
rctrl 
lalt 
ralt 
KeysEnd 

◆ CDMLetterColor

Describes a parameter that will be used for data input and output and it maps all the possible colors for the letters that can be used inside CDM.

Enumerator
CLEAR 
BLACK 
DARKBLUE 
DARKGREEN 
DARKCYAN 
DARKRED 
DARKMAGENTA 
DARKYELLOW 
DARKGRAY 
GRAY 
BLUE 
GREEN 
CYAN 
RED 
MAGENTA 
YELLOW 
WHITE 
LCOLOR1 
LCOLOR2 
LCOLOR3 
LCOLOR4 
LCOLOR5 
LCOLOR6 
LCOLOR7 
LCOLOR8 
LCOLOR9 
LCOLOR10 
LCOLOR11 
LCOLOR12 
LCOLOR13 
LCOLOR14 
LCOLOR15 

◆ CDMMode

enum CDMMode

Values that represent the rendering mode of CDM, not to be used right now.

Enumerator
mode3d 
mode2d 

Function Documentation

◆ CDMActivateMouseInput()

void CDMActivateMouseInput ( _INOUT_ CDMContext **  ctx)

Activates mouse input recognition for the console. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.

◆ CDMAddSurfaceToContext()

void CDMAddSurfaceToContext ( _INOUT_ CDMContext **  ctx,
_IN_ CDMSurface surface 
)

Adds a surface to the context, and thus batching its draw with every other added object, the batch will be completely flushed once CDMDraw is called. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context in which the surface will be painted, must not be null.
[in,out]surfaceThe surface to be printed, must not be null.
Examples:
main.cpp.

◆ CDMAddTextToContext()

void CDMAddTextToContext ( _INOUT_ CDMContext **  ctx,
_IN_ CDMText txt 
)

Adds a text to the context, and thus batching its draw with every other added object, the batch will be completely flushed once CDMDraw is called. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context in which the text will be painted, must not be null.
[in,out]txtThe text that will be printed, must not be null.
Examples:
main.cpp.

◆ CDMChangeText()

void CDMChangeText ( CDMText **  txt,
const _IN_ wchar_t *  text 
)

Changes the text content of a CDMText. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]txtThe text object, must not be null.
[in]textThe text, null terminated.

◆ CDMChangeWindowSize()

void CDMChangeWindowSize ( _INOUT_ CDMContext **  ctx,
const _IN_ short  width,
const _IN_ short  height 
)

Changes the window size of a context. May be called at any time, however it will clear the screen once its done. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in]widthThe expected width in CDM pixels.
[in]heightThe expected height in CDM pixels.
Examples:
main.cpp.

◆ CDMClearErrno()

void CDMClearErrno ( )

Sets errno back to 0.

Author
Komo
Date
30/4/2018

◆ CDMClearScreen()

void CDMClearScreen ( _INOUT_ CDMContext **  ctx)

Clears the current buffer. It does not make the whole screen black. For that you may use CDMFillScreen.This function is implemented like this to reduce overhead on the program by reducing assignations and comparisons. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
Examples:
main.cpp.

◆ CDMCompareCHARINFO()

CDMBool CDMCompareCHARINFO ( _IN_ CHAR_INFO  rhs,
_IN_ CHAR_INFO  lhs 
)

Compares two CHAR_INFO structures, it's mainly used inside the API for certain operations. May not prove useful to the graphics programmer. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]rhsThe right hand side.
[in]lhsThe left hand side.
Returns
CDMTRUE if both structures are the same, else CDMFALSE.

◆ CDMCreateContext()

CDMContext * CDMCreateContext ( const _IN_ short  width,
const _IN_ short  height 
)

The setup function of CDM. Must be called before anything else. CDM requires a context to work, most of the functions here require a context to be used. Status: Working.

Warning
This might not be thread safe.
Author
Komo
Date
30/4/2018
Parameters
[in]widthThe expected width in CDM pixels.
[in]heightThe expected height in CDM pixels.
Returns
Null if it fails, else a pointer to a CDMContext.
Examples:
main.cpp.

◆ CDMCreateSurface()

CDMSurface * CDMCreateSurface ( const _IN_ short  posX,
const _IN_ short  posY,
const _IN_ short  sizeX,
const _IN_ short  sizeY 
)

Creates a surface. A surface is the base representation of an image in CDM Most every object used in CDM will most likely be a surface. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]posXThe position x coordinate of the surface, using screen coordinates.
[in]posYThe position y coordinate of the surface, using screen coordinates.
[in]sizeXThe width of the surface.
[in]sizeYThe height of the surface.
Returns
Null if it fails, else a pointer to a CDMSurface.
Examples:
main.cpp.

◆ CDMDraw()

void CDMDraw ( _IN_ CDMContext **  ctx)

Draws the whole screen. Does a batch draw if things have been added to the context. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]ctxcontext, must not be null.
Examples:
main.cpp.

◆ CDMDrawSurface()

void CDMDrawSurface ( _INOUT_ CDMContext **  ctx,
_IN_ CDMSurface surface 
)

Draws directly a surface in the context, instead of batching it with other draws. I highly recommend using the batch function (Add, then CDMDraw) over this one, to make the program run faster. Status: Partially works.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context in which the surface will be painted, must not be null.
[in,out]surfaceThe surface to be printed, must not be null.

◆ CDMDrawText()

void CDMDrawText ( _INOUT_ CDMContext **  ctx,
_IN_ CDMText txt 
)

Draws directly a text in the context, instead of batching it with other draws. I highly recommend using the batch function (Add, then CDMDraw) over this one, to make the program run faster. Status: Partially Works.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context in which the text will be painted, must not be null.
[in,out]txtThe text that will be printed, must not be null.

◆ CDMExportSrfcToImg()

void CDMExportSrfcToImg ( const _IN_ CDMContext ctx,
const _IN_ CDMSurface srfc,
const _IN_ char *  fileName,
const _IN_ size_t  nameSize 
)

Exports a surface to a .cdi image. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]ctxThe current context, must not be null.
[in]srfcThe surface intended to export, must not be null.
[in]fileNameFilename of the file.
[in]nameSizeSize of the name.

◆ CDMFillScreen()

void CDMFillScreen ( _INOUT_ CDMContext **  ctx,
const _IN_ wchar_t  character,
const _IN_ CDMLetterColor  frontColor,
const _IN_ CDMBackgroundColor  backColor 
)

Fills the context with a single color. Ignores drawn flags completely. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in]characterThe character to be printed.
[in]frontColorThe front color.
[in]backColorThe background color.

◆ CDMFreeContext()

void CDMFreeContext ( _INOUT_ CDMContext **  ctx)

Simple dynamic memory allocation free method. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null. Upon finishing, this function makes this parameter's value null.

◆ CDMFreeSurface()

void CDMFreeSurface ( _INOUT_ CDMSurface **  surface)

Simple dynamic memory allocation free method. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface, must not be null. Upon finishing this function makes this parameter's value null.
Examples:
main.cpp.

◆ CDMFreeText()

void CDMFreeText ( _INOUT_ CDMText **  txt)

Simple dynamic memory allocation free method. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]txtThe text, must not be null. Upon finishing, this function makes this parameter's value null.

◆ CDMGetB()

int CDMGetB ( _IN_ CDMColorScheme data,
const _IN_ short  position 
)

Gets the blue color of a certain color inside a ColorScheme. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]dataThe color scheme to check from.
[in]positionThe position of the color wanted.
Returns
The color's value in decimal.

◆ CDMGetErrno()

CDMErrno CDMGetErrno ( )

Gets the value of errno and sets it to zero. Status: Working.

Author
Komo
Date
30/4/2018
Returns
The value of errno.

◆ CDMGetErrorMessage()

char * CDMGetErrorMessage ( )

Translates an error code to an error message, for a brief description. Status: Working.

Author
Komo
Date
30/4/2018
Returns
Will always return a string of characters.

◆ CDMGetG()

int CDMGetG ( _IN_ CDMColorScheme data,
const _IN_ short  position 
)

Gets the green color of a certain color inside a ColorScheme. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]dataThe color scheme to check from.
[in]positionThe position of the color wanted.
Returns
The color's value in decimal.

◆ CDMGetKeyDown()

CDMBool CDMGetKeyDown ( _IN_ CDMEvent event,
const _IN_ CDMKey  key 
)

Checks if the key selected in the parameter was pressed this frame. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]eventAn event structure, must not be null.
[in]keyThe key to be checked.
Returns
Returns CDMTRUE if the key is pressed, but only if it was pressed in this frame, CDMFALSE if the key is not pressed.

◆ CDMGetKeyPressed()

CDMBool CDMGetKeyPressed ( _IN_ CDMEvent event,
const _IN_ CDMKey  key 
)

Checks if the key selected in the parameter was pressed. This is the only function that checks for mouse input too. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]eventAn event structure, must not be null.
[in]keyThe key to be checked.
Returns
Returns CDMTRUE if the key is pressed, regardless of how many frames it has been pressed, CDMFALSE if the key is not pressed.

◆ CDMGetKeyUp()

CDMBool CDMGetKeyUp ( _IN_ CDMEvent event,
const _IN_ CDMKey  key 
)

Checks if the key selected in the parameter stopped being pressed this frame. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]eventAn event structure, must not be null.
[in]keyThe key to be checked.
Returns
Returns CDMTRUE if the key is not pressed, but only if it was pressed in the last frame, CDMFALSE if the key is pressed.
Examples:
main.cpp.

◆ CDMGetMousePos()

CDMCoord CDMGetMousePos ( _IN_ CDMEvent event)

Gets the mouse position inside the console window. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]eventAn event structure, must not be null.
Returns
A CDMCoord containing the coordinates of the mouse inside the screen.

◆ CDMGetR()

int CDMGetR ( _IN_ CDMColorScheme data,
const _IN_ short  position 
)

Gets the red color of a certain color inside a ColorScheme. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]dataThe color scheme to check from.
[in]positionThe position of the color wanted.
Returns
The color's value in decimal.

◆ CDMKeepScreenSize()

void CDMKeepScreenSize ( _INOUT_ CDMContext **  ctx,
_IN_ CDMEvent event 
)

Keeps the screen size of the program. Might be useful if you want to limit screen resizing. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in,out]eventAn event structure to check for resize events, must not be null.
Examples:
main.cpp.

◆ CDMPoke()

void CDMPoke ( _INOUT_ CDMContext **  ctx,
const _IN_ CDMCoord  coord,
const _IN_ wchar_t  character,
const _IN_ CDMLetterColor  frontColor,
const _IN_ CDMBackgroundColor  backColor 
)

Pokes a pixel in the screen to a certain color. Ignores drawn flags. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in]coordThe coordinate of the pixel.
[in]characterThe character to be printed.
[in]frontColorThe front color.
[in]backColorThe background color.

◆ CDMPollEvents()

void CDMPollEvents ( _IN_ CDMContext ctx,
_INOUT_ CDMEvent event 
)

Polls the console events, this function must be used in order to get key and mouse presses, as such it must be called at the beginning of every frame and before every function that requires a CDMEvent. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in,out]eventAn event structure, must not be null.
Examples:
main.cpp.

◆ CDMPrepareSurface()

void CDMPrepareSurface ( _INOUT_ CDMSurface **  surface)

This should only be called each time the surface's contents were modified before calling a draw or add function. Internally this function converts the image's values to raw data that the console understands. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface, must not be null.
Examples:
main.cpp.

◆ CDMPrepareText()

void CDMPrepareText ( _INOUT_ CDMText **  txt)

This should only be called each time the text's contents were modified before calling a draw or add function. Internally this function converts the text's values to raw data that the console understands. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]txtThe text, must not be null.
Examples:
main.cpp.

◆ CDMPrintf()

void CDMPrintf ( _INOUT_ CDMContext **  ctx,
const _IN_ int  startingLetter,
_IN_ CDMRect  initialPos,
const _IN_ CDMLetterColor  frontColor,
const _IN_ CDMBackgroundColor  backColor,
const _IN_ wchar_t *  txt,
  ... 
)

A printf implementation for CDM, made it as a replacement or alternative to the text object. It should be easier to manage, but a more expensive call, so use this for dynamic text only, and use Text objects for static text.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
startingLetterThe letter index to start printing from.
[in]initialPosThe initial position of the text, it wraps around the initialPos parameter's right and bottom elements.
[in]frontColorThe front color of the text.
[in]backColorThe back color of the text.
[in]txtThe text, modes "%d,%i,%u,%f,%g,%x,%o,%c,%s" are working, the new line character is \n.
[in]...Variable arguments providing additional information.

◆ CDMReadImg()

CDMSurface * CDMReadImg ( const _IN_ char *  fileName,
_OUTOPT_ CDMColorScheme scheme 
)

Reads a .cdi image file into a CDMSurface. The file must be generated exactly the same as CDMExportSrfcToImg, for it to work using this function. The usage of the structure may be imperative. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]fileNameFilename of the file.
[in,out]schemeIf non-null, the scheme that will obtain the real scheme used in the image.
Returns
Null if it fails, else a pointer to a CDMSurface.

◆ CDMSetActiveScheme()

void CDMSetActiveScheme ( _IN_ CDMColorScheme  data,
_INOUT_ CDMContext **  ctx 
)

Sets a color scheme inside a context, and thus changing every display color of it. This instruction does not require you to draw again for results to be shown, as such its extremely fast. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in]dataThe color scheme to be set.
[in,out]ctxThe context to modify, must not be null.
Examples:
main.cpp.

◆ CDMSetBackgroundColor()

void CDMSetBackgroundColor ( _INOUT_ CDMSurface **  surface,
const _IN_ CDMBackgroundColor  c1,
const _IN_ CDMBackgroundColor  c2,
const _IN_ CDMBackgroundColor  c3,
const _IN_ CDMBackgroundColor  c4 
)

A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four background colors that the Surface will use from the color palette. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface, must not be null.
[in]c1The first CDMEnum using color macros.
[in]c2The second CDMEnum using color macros.
[in]c3The third CDMEnum using color macros.
[in]c4The fourth CDMEnum using color macros.
Examples:
main.cpp.

◆ CDMSetCharacters()

void CDMSetCharacters ( _INOUT_ CDMSurface **  surface,
const _IN_ wchar_t  c1,
const _IN_ wchar_t  c2,
const _IN_ wchar_t  c3,
const _IN_ wchar_t  c4 
)

A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four characters that the Surface will use. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface, must not be null.
[in]c1The first character to be used.
[in]c2The second character to be used.
[in]c3The third character to be used.
[in]c4The fourth character to be used.
Examples:
main.cpp.

◆ CDMSetColorBin()

void CDMSetColorBin ( _INOUT_ CDMColorScheme data,
_IN_ short  position,
const _IN_ DWORD  color 
)

Sets an RGB color inside a ColorScheme. This function accepts an already converted to binary RGB color. You may use Windows.h macro RGB(r,g,b) to get the data. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]dataThe color scheme, must not be null.
[in]positionThe position of the color inside the ColorScheme.
[in]colorThe binary RGB color.
Examples:
main.cpp.

◆ CDMSetColorRGB()

void CDMSetColorRGB ( _INOUT_ CDMColorScheme data,
_IN_ short  position,
_IN_ short  r,
_IN_ short  g,
_IN_ short  b 
)

Sets an RGB color inside a ColorScheme. Every color goes from 0 to 255, however every value passes through a modulo operation to assure no weird behavior will happen. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]dataThe color scheme, must not be null.
[in]positionThe position of the color inside the ColorScheme.
[in]rRed value.
[in]gGreen value.
[in]bBlue value.
Examples:
main.cpp.

◆ CDMSetCursorVisibility()

void CDMSetCursorVisibility ( _INOUT_ CDMContext **  ctx,
const _IN_ CDMBool  status 
)

Sets the visibility of the console's cursor. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxIf non-null, the context.
[in]statusBoolean value to set the status of the cursor.
Examples:
main.cpp.

◆ CDMSetErrno()

void CDMSetErrno ( const _IN_ CDMErrno  code)

Sets an specific errno to a value. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
codeThe code to be set.

◆ CDMSetFontAndSize()

void CDMSetFontAndSize ( _INOUT_ CDMContext **  ctx,
const _IN_ wchar_t *  fontName,
const _IN_ short  width,
const _IN_ short  height 
)

Sets the font and font size of the console. The recommended font name is L"Terminal" for its unique characteristic of allowing square pixels, however most fonts can be used. It's important to include L at the start of your string, since this function requires a wchar_t* instead of a regular char. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxThe context, must not be null.
[in]fontNameName of the font.
[in]widthThe width in regular pixels of the font.
[in]heightThe height in regular pixels of the font.
Examples:
main.cpp.

◆ CDMSetForegroundColor()

void CDMSetForegroundColor ( _INOUT_ CDMSurface **  surface,
const _IN_ CDMLetterColor  c1,
const _IN_ CDMLetterColor  c2,
const _IN_ CDMLetterColor  c3,
const _IN_ CDMLetterColor  c4 
)

A CDMSurface may only have 4 color sets at a time. Including background, foreground and character. Each combination of 3 of those elements makes a set. This function sets directly the four foreground colors that the Surface will use from the color palette. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface, must not be null.
[in]c1The first CDMEnum using color macros.
[in]c2The second CDMEnum using color macros.
[in]c3The third CDMEnum using color macros.
[in]c4The fourth CDMEnum using color macros.
Examples:
main.cpp.

◆ CDMSetPixel()

void CDMSetPixel ( _INOUT_ CDMSurface **  surface,
_IN_ short  x,
_IN_ short  y,
_IN_ CDMColorSets  pixelSet 
)

Sets a pixel inside a surface. You must select from one of the five possible colors inside the surface. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]surfaceThe surface to be modified, must not be null.
[in]xThe x coordinate of the pixel.
[in]yThe y coordinate of the pixel.
[in]pixelSetThe enumeration value of the data.
Examples:
main.cpp.

◆ CDMSetWindowTitle()

void CDMSetWindowTitle ( const _IN_ wchar_t *  title)

Sets the title of the console. Just a wrapper for a WINAPI functionality. Status: Working.

Author
Komo
Date
8/5/2018
Parameters
[in]titleThe title of the console.
Examples:
main.cpp.

◆ CDMTextWrapper()

CDMText * CDMTextWrapper ( _IN_ wchar_t *  text,
const _IN_ CDMLetterColor  color,
const _IN_ CDMBackgroundColor  background 
)

Since CDM basically hijacks the console, functions like printf are not enabled. No output will be shown using them, instead you must use the text as an object, this means you have much more control of the position and design of your text, at the expense of making a little bit harder to use. Moreover, repeated uses of the same text box will not require you to create a new object or call anything else other than adding this object to the context, or drawing it directly. All text begins in the ( 0 , 0 ) coordinate. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]textThe text string, must not be null, must be zero terminated.
[in]colorThe color of the text.
[in]backgroundThe background color of the text.
Returns
Null if it fails, else a pointer to a CDMText.
Examples:
main.cpp.

◆ CDMTextWrapper_s()

CDMText * CDMTextWrapper_s ( _IN_ wchar_t *  text,
const _IN_ size_t  textSize,
const _IN_ CDMLetterColor  color,
const _IN_ CDMBackgroundColor  background 
)

Since CDM basically hijacks the console, functions like printf are disabled. No output will be shown using them, instead you must use the text as an object, this means you have much more control of the position and design of your text, at the expense of making a little bit harder to use. Moreover, repeated uses of the same text box will not require you to create a new object or call anything else other than adding this object to the context, or drawing it directly. All text begins in the ( 0 , 0 ) coordinate. Status: Working.

Author
Komo
Date
30/4/2018
Parameters
[in,out]textThe text string, must not be null.
[in]textSizeSize of the text.
[in]colorThe color of the text.
[in]backgroundThe background color of the text.
Returns
Null if it fails, else a pointer to a CDMText.

◆ CDMToggleFullscreen()

void CDMToggleFullscreen ( CDMContext **_INOUT_  ctx,
const _IN_ CDMBool  val 
)

Toggles full screen mode. Status: May be working on older platforms.

Author
Komo
Date
30/4/2018
Parameters
[in,out]ctxIf non-null, the context.
[in]valBoolean value for the toggle.