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

Buttons for the MrMWidgets. More...

Functions

Buttons management functions

These functions create and handle buttons.

int mrmButtonInit (int scr, int width, int height, void(*callBack)(int, int), char *label, int nCol, int pCol, int dCol)
 Creates a new button with the given size and colors. More...
 
int mrmButtonDelete (int idx)
 Delete the button whose reference number is given. More...
 
int mrmButtonSetEnabled (int idx, int enabled)
 Enable or disable button. More...
 
int mrmButtonSetPos (int idx, int x, int y)
 Places the button at the given position on the screen. More...
 
int mrmButtonSetSize (int idx, int w, int h)
 Resizes the button. More...
 
int mrmButtonSetColor (int idx, int nCol, int pCol, int dCol)
 Sets the colors for the button. More...
 
int mrmButtonSetFont (int idx, int sz, int a, char *fn, int s)
 Sets the font for the button label. More...
 
int mrmButtonSetFontColor (int idx, int nCol, int pCol, int dCol)
 Sets the colors for the button label. More...
 
int mrmButtonSetLabel (int idx, char *label)
 Sets the label of the button. More...
 
int mrmButtonSetCounter (int idx, unsigned int val)
 Sets the counter for the button to a given value. More...
 
int mrmButtonGetCounter (int idx)
 Reads the counter of the button. More...
 

Detailed Description

Author
Germán Fabregat
Date
October 2017

Function Documentation

◆ mrmButtonInit()

int mrmButtonInit ( int  scr,
int  width,
int  height,
void(*)(int, int)  callBack,
char *  label,
int  nCol,
int  pCol,
int  dCol 
)

This function is used to create a button of the given width and height on the given screen. If a label is specified it will be printed centered on the button. Three colors are also given; the released and pressed color, and the color to be used when the button is disabled. The button is enabled after creation, but it is not placed on screen -and thus visible and usable- until its position is set using the corresponding function. A callback function can be specified to be called when the button is clicked. This function will receive two integer parameters: the button reference and the screen index.

Parameters
[in]scrGraphic screen where the button is placed.
[in]widthWidth in pixels of the button.
[in]heightHeight in pixels of the button.
[in]callBackFunction to be called when the button is clicked. If NULL no function is invoked.
[in]labelText to appear centered on the button. It can be the empty string or NULL if no text is wanted.
[in]nColColor for the button when not pressed.
[in]pColColor for the button when pressed.
[in]dColColor for the button when disabled.
Returns
The function returns a 0 or positive integer that references the created button, or a negative value if an error occurred.
Examples:
colorSelect.c, and colorStar.c.

◆ mrmButtonDelete()

int mrmButtonDelete ( int  idx)

This functions deletes from the system the button whose reference number is given, releasing all associated resources. The reference number and button slot are released for further use.

Parameters
[in]idxButton reference number.
Returns
A negative value in case of error, positive otherwise.

◆ mrmButtonSetEnabled()

int mrmButtonSetEnabled ( int  idx,
int  enabled 
)

This functions sets the enabled state of the button. When a button is disabled it appears with the disabled colors and cannot be cliked.

Parameters
[in]idxButton reference number.
[in]enabled0 to disable the button, nonzero to enable.
Returns
A negative value in case of error, positive otherwise.

◆ mrmButtonSetPos()

int mrmButtonSetPos ( int  idx,
int  x,
int  y 
)

For a button to be displayed on its screen it has to be placed on a given position. This function has to be used to place the button at the desired x,y position on the screen.

Parameters
[in]idxButton reference number.
[in]xHorizontal coordinate of the top left corner of the button.
[in]yVertical coordinate of the top left corner of the button.
Returns
A negative value in case of error, positive otherwise.
Examples:
colorSelect.c, and colorStar.c.

◆ mrmButtonSetSize()

int mrmButtonSetSize ( int  idx,
int  w,
int  h 
)

This function changes the height, the width of the button or both.

Parameters
[in]idxButton reference number.
[in]wNew width of the button. If 0 let it unchanged.
[in]hNew height of the button. If 0 let it unchanged.
Returns
A negative value in case of error, positive otherwise.

◆ mrmButtonSetColor()

int mrmButtonSetColor ( int  idx,
int  nCol,
int  pCol,
int  dCol 
)

When a button is created it is given some colors. This function allows the user to change them during execution.

Parameters
[in]idxButton reference number.
[in]nColColor for the button when not pressed.
[in]pColColor for the button when pressed.
[in]dColColor for the button when disabled.
Returns
A negative value in case of error, positive otherwise.

◆ mrmButtonSetFont()

int mrmButtonSetFont ( int  idx,
int  sz,
int  a,
char *  fn,
int  s 
)

When a button is created its label is assigned default font and colors. This function allows to set the font for the label.

Parameters
[in]idxButton reference number.
[in]szSize of the font.
[in]aRotation angle in degrees.
[in]fnPointer to a string containing the font name. If it is NULL the standard font is used.
[in]sStyle of the font. The three lower bits mean from 0 to 2 italic, underline and strikeout. The higher bits a weight ranging from 0 to 1000. The constants MGS_ITALIC, MGS_UNDERLINE and MGS_STRIKEOUT can be ored to form the lower three bits. MGS_LIGHT, MGS_BOLD and MGS_HEAVY are three predefined values for the weight that can also be ored.
Returns
A negative value in case of error, positive otherwise.
Examples:
colorSelect.c, and colorStar.c.

◆ mrmButtonSetFontColor()

int mrmButtonSetFontColor ( int  idx,
int  nCol,
int  pCol,
int  dCol 
)

When a button is created its label is assigned default font and colors. This function allows to set colors for the label.

Parameters
[in]idxButton reference number.
[in]nColColor for the button label when not pressed.
[in]pColColor for the button label when pressed.
[in]dColColor for the button label when disabled.
Returns
A negative value in case of error, positive otherwise.
Examples:
colorSelect.c, and colorStar.c.

◆ mrmButtonSetLabel()

int mrmButtonSetLabel ( int  idx,
char *  label 
)

When a button is created it is given a label. This function allows the user to change it during execution.

Parameters
[in]idxButton reference number.
[in]labelText to appear centered on the button. It can be the empty string or NULL if no text is wanted.
Returns
A negative value in case of error, positive otherwise.

◆ mrmButtonSetCounter()

int mrmButtonSetCounter ( int  idx,
unsigned int  val 
)

Each button holds an internal counter that is increased with each click. This function sets the couter value and returns the previous one.

Parameters
[in]idxButton reference number.
[in]valNew value for the counter.
Returns
The old value of the counter or MGS_ERRRESNOEXIST in case the button does not exist.

◆ mrmButtonGetCounter()

int mrmButtonGetCounter ( int  idx)

Each button holds an internal counter that is increased with each click. This function returns the value of this counter.

Parameters
[in]idxButton reference number.
Returns
The value of the counter or MGS_ERRRESNOEXIST in case the button does not exist.
Examples:
colorSelect.c, and colorStar.c.