HUD - ZenXChaos/MapleStorySDLCPP GitHub Wiki
HUD
HUD.h // HUD.cpp : Heads up display! GUI Elements.
HUDObject
The actual sprite/spritesheet which is displayed.
private members:
public members:
int row = 0;
int column = 0;
AnimatedSprite* sprites;
row: Row number to be displayed at
column: Column number to be displayed at
sprites: Sprite anim-sheet.
HUD_GridPanel
A grid that displays all attached HUDObjects. All rows share a fixed height. All columns share a fixed height.
private members:
public members:
int columns = 0;
int rows = 0;
int width = 0;
int height = 0;
std::map<std::string, HUDObject> elements;
void AddObject(std::string elem_name, HUDObject obj);
void DrawPanel(int x, int y);
columns: Number of columns.
rows: Number of rows.
width: Grid Width.
height: Grid Height.
elements: HUDObject container.
void AddObject: Add an HUDObject to the container.
void Draw: Draws the grid and it's elements.
HUD_FlowPanel
A flow panel that displays all attached HUDObjects. Relative based layout.
private members:
public members:
int width = 0;
int height = 0;
int spacingY = 5;
int spacingX = 5;
std::map<std::string, HUDObject> elements;
void AddObject(std::string elem_name, HUDObject obj);
void DrawPanel(int x, int y);
columns: Number of columns.
rows: Number of rows.
spacingX: Padding along x-axis.
spacingY: Padding along y-axis
width: Grid Width.
height: Grid Height.
elements: HUDObject container.
void AddObject: Add an HUDObject to the container.
void Draw: Draws the grid and it's elements.
Example: RelativeLayout
HUD_FlowPanel hudgrid2;
hudgrid2.height = 100;
hudgrid2.width = 10;
//hudgrid.columns = 5;
//hudgrid.rows = 1;
AnimatedSprite as1;
as1.LoadTexture("content\\misc\\itemNo\\ItemNo.1.png", gRenderer);
as1.BuildAnimation(0, 1, 8, 11, 0.1f);
AnimatedSprite as2;
as2.LoadTexture("content\\misc\\itemNo\\ItemNo.2.png", gRenderer);
as2.BuildAnimation(0, 1, 8, 11, 0.1f);
HUDObject hob1;
hob1.sprites = &as1;
hob1.column = 0;
hob1.row = 0;
HUDObject hob2;
hob2.sprites = &as2;
hob2.column = 1;
hob2.row = 0;
hudgrid2.AddObject("1", hob1);
hudgrid2.AddObject("2", hob2);
Example: GridLayout
Displaying a grid with two columns and one row.
//Our HUD Grid
HUD_GridPanel hudgrid;
hudgrid.height = 100;
hudgrid.width = 100;
hudgrid.columns = 2;
hudgrid.rows = 1;
//Create Sprites
AnimatedSprite as1;
as1.LoadTexture("content\\misc\\itemNo\\ItemNo.1.png", gRenderer);
as1.BuildAnimation(0, 1, 8, 11, 0.1f);
AnimatedSprite as2;
as2.LoadTexture("content\\misc\\itemNo\\ItemNo.2.png", gRenderer);
as2.BuildAnimation(0, 1, 8, 11, 0.1f);
//Bind Objects | Set row/column
HUDObject hob1;
hob1.sprites = &as1;
hob1.column = 0;
hob1.row = 0;
HUDObject hob2;
hob2.sprites = &as2;
hob2.column = 1;
hob2.row = 0;
The example above would result in the following:

See the "1" & "2" sprites? :)
Make sure to call .DrawPanel() in your main loop!