mgsLib  1.3
Mermaja's Graphic Screen. A simple C library to build Windows graphic applications from console programs.
mrmNumPad.c File Reference

NumPad for the MrMWidgets. More...

Functions

Numeric Pad management functions

These functions create and handle the Numeric Pad.

int mrmNPInit (int bgCol, int nChar, void(*callBack)(void))
 Creates the NumPad. More...
 
void mrmNPDelete (void)
 Delete the NumPad if exists. More...
 
int mrmNPExists (void)
 Check the existence of the NumPad. More...
 
void mrmNPMove (int x, int y)
 Moves the NumPad to a new position. More...
 
void mrmNPSetColors (int colKeyNum, int colKeyEsp, int colScr, int colKeyTxt, int colScrTxt, int colDisTxt)
 Sets the colors for the NumPad. More...
 
void mrmNPGetText (char *res, int n, int *blocked)
 Gets the value on the NumPad as text. More...
 
double mrmNPGetVal (int *blocked)
 Gets the value on the NumPad as floating point value. More...
 

Detailed Description

Author
Germán Fabregat
Date
October 2017

Function Documentation

◆ mrmNPInit()

int mrmNPInit ( int  bgCol,
int  nChar,
void(*)(void)  callBack 
)

This function is used to create the NumPad. Only one can be present in the system, so the call will fail if one already exists. The function sets the background color and max. number of characters accepted by the NumPad. It also sets a callback function to be invoked when Ok is pressed.

Parameters
[in]bgColColor for the background of the NumPad window. Use a negative value for the default color.
[in]nCharMaximum number of characters to be accepted by the NumPad.
[in]callBackFunction to be called when the text is completed -*Ok* is pressed-. If NULL no function is invoked.
Returns
The function returns a 0 or positive integer that references the NumPad screen, or a negative value if an error occurred.

◆ mrmNPDelete()

void mrmNPDelete ( void  )

This functions deletes the NumPad from the system. A new one can then be created if desired.

◆ mrmNPExists()

int mrmNPExists ( void  )

Only one NumPad can be present in the system. This function returns true if the NumPad exists, false if not.

Returns
The function returns 1 if the NumPad exists, 0 if not.

◆ mrmNPMove()

void mrmNPMove ( int  x,
int  y 
)

This functions places the NumPad -top left corner- to the indicated position, without altering proportion nor contents. No bounding checks are performed.

Parameters
[in]xCoordinate of the leftmost position.
[in]yCoordinate of the top position.

◆ mrmNPSetColors()

void mrmNPSetColors ( int  colKeyNum,
int  colKeyEsp,
int  colScr,
int  colKeyTxt,
int  colScrTxt,
int  colDisTxt 
)

When the NumPad is created default system colors are assigned for its texts and keys. This function allows the user to change them during execution.

Parameters
[in]colKeyNumColor for numeric keys.
[in]colKeyEspColor for the special keys.
[in]colScrColor for the display screen.
[in]colKeyTxtColor for text on the keys.
[in]colScrTxtColor for text on the display.
[in]colDisTxtColor for the text on the display when it is blocked, that is, from the moment when Ok is pressed until the NumPad value is read.

◆ mrmNPGetText()

void mrmNPGetText ( char *  res,
int  n,
int *  blocked 
)

This function can be called any time while the NumPad exists, and gets its contents as text. It can also read the bloked flag to verifiy if the user has pressed Ok. If the NumPad is blocked, reading its value deletes its contents and resets it to normal state.

Parameters
[out]resBuffer to read the characters. Has to hold at least n + 1 bytes.
[in]nMaximum number of characters to be read.
[out]blockedPointer to an integer to retrieve the blocked flag. Ignored if NULL.

◆ mrmNPGetVal()

double mrmNPGetVal ( int *  blocked)

This function can be called any time while the NumPad exists, and gets its contents as a double. Please notice that there can be precission loses if the number of characters is high. It can also read the bloked flag to verifiy if the user has pressed Ok. If the NumPad is blocked, reading its value deletes its contents and resets it to normal state.

Parameters
[out]blockedPointer to an integer to retrieve the blocked flag. Ignored if NULL.
Returns
Floating point value of the contents of the NumPad.