📄 sdllabel.cpp
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLLabel.h
// This is a basic SDLGUI library that I've set up for use with the game demos
// I've used in the book.
// ============================================================================
#include "SDLLabel.h"
// -------------------------------------------------------
// Name: SDLLabel::SDLLabel
// Description: This constructs the label
// Arguments: - p_x: x coordinate
// - p_y: y coordinate
// - p_text: the text of the label
// - p_tforecol: the foreground color of the
// text
// - p_tbackcol: the background color of the
// text
// - p_font: the font of the label.
// -------------------------------------------------------
SDLLabel::SDLLabel( int p_x, int p_y,
const char* p_text,
SDL_Color p_tforecol,
SDL_Color p_tbackcol,
TTF_Font* p_font )
{
// load the text.
m_text = TTF_RenderText_Shaded( p_font, p_text, p_tforecol, p_tbackcol );
SDL_SetColorKey( m_text,
SDL_SRCCOLORKEY,
SDL_MapRGB( m_text->format,
p_tbackcol.r,
p_tbackcol.g,
p_tbackcol.b ) );
m_x = p_x;
m_y = p_y;
}
// ----------------------------------------------------------------
// Name: Draw
// Description: draws the item on a surface
// Arguments: p_dest: the destination surface
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::Draw( SDL_Surface* p_dest )
{
SDLBlit( m_text, p_dest, m_x, m_y );
}
// ----------------------------------------------------------------
// Name: ClickDown
// Description: Tells the item that it was clicked on.
// Arguments: None
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::ClickDown()
{
// do nothing
}
// ----------------------------------------------------------------
// Name: ClickUp
// Description: Tells the item that it a mouse was released
// on this item
// Arguments: None
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::ClickUp()
{
// do nothing
}
// ----------------------------------------------------------------
// Name: IsOver
// Description: determines if a set of coordinates is over this
// item
// Arguments: p_x, p_y: the coordinates
// Return Value: true if the coordinates are over this item
// ----------------------------------------------------------------
bool SDLLabel::IsOver( int p_x, int p_y )
{
if( p_x >= m_x && p_x < (m_x + m_text->w) )
{
if( p_y >= m_y && p_y < (m_y + m_text->h) )
{
return true;
}
}
return false;
}
// ----------------------------------------------------------------
// Name: ResetOnUp
// Description: This tells the item to reset itself because
// the user unclicked the mouse (only valid
// for some items)
// Arguments: None
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::ResetOnUp()
{
// do nothing
}
// -------------------------------------------------------
// Name: SDLLabel::CanGetFocus
// Description: determines if this object can get the
// focus of the GUI.
// Arguments: None.
// Return Value: True or False
// -------------------------------------------------------
bool SDLLabel::CanGetFocus()
{
// in our GUI, labels cannot get the focus.
return false;
}
// ----------------------------------------------------------------
// Name: GetFocus
// Description: tells the item to get the focus or not.
// Arguments: p_focus: true if the item gets the focus
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::GetFocus( bool p_focus )
{
// do nothing
return;
}
// ----------------------------------------------------------------
// Name: KeyPress
// Description: tells the GUI that a key was pressed when this
// item was in focus
// Arguments: p_key: the that was pressed
// p_mod: the keyboard modifier flag (shift, alt,
// control).
// p_char: the UNICODE representation of the key
// Return Value: None
// ----------------------------------------------------------------
void SDLLabel::KeyPress( SDLKey p_key, SDLMod p_mod, Uint16 p_char )
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -