📄 sdltextbox.h
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLTextBox.h
// This is a basic SDLGUI library that I've set up for use with the game demos
// I've used in the book.
// ============================================================================
#ifndef SDLTEXTBOX_H
#define SDLTEXTBOX_H
#include "SDLHelpers.h"
#include "SDLGUIItem.h"
class SDLTextBox : public SDLGUIItem
{
public:
// -------------------------------------------------------
// Name: SDLTextBox::SDLTextBox
// Description: This constructs the text box
// Arguments: - p_x: x coordinate
// - p_y: y coordinate
// - p_w, p_h: the width and height.
// - p_string: a pointer to the string of
// the text box
// - p_size: the max size of the string.
// - p_tforecol: the foreground color of the
// text
// - p_tbackcol: the background color of the
// text
// - p_font: the font of the text.
// - p_func: the function this calls when
// enter is pressed.
// -------------------------------------------------------
SDLTextBox( int p_x, int p_y,
int p_w, int p_h,
char* p_string,
int p_size,
SDL_Color p_tforecol,
SDL_Color p_tbackcol,
TTF_Font* p_font,
bool p_enabled,
void (*p_func)(void) );
// ----------------------------------------------------------------
// Name: Draw
// Description: draws the item on a surface
// Arguments: p_dest: the destination surface
// Return Value: None
// ----------------------------------------------------------------
void Draw( SDL_Surface* p_dest );
// ----------------------------------------------------------------
// Name: ClickDown
// Description: Tells the item that it was clicked on.
// Arguments: None
// Return Value: None
// ----------------------------------------------------------------
void ClickDown();
// ----------------------------------------------------------------
// Name: ClickUp
// Description: Tells the item that it a mouse was released
// on this item
// Arguments: None
// Return Value: None
// ----------------------------------------------------------------
void ClickUp();
// ----------------------------------------------------------------
// 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 IsOver( int p_x, int p_y );
// ----------------------------------------------------------------
// 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 ResetOnUp();
// ----------------------------------------------------------------
// Name: CanGetFocus
// Description: determines if the item can get the focus
// Arguments: None
// Return Value: true if the item can get the focus
// ----------------------------------------------------------------
bool CanGetFocus();
// ----------------------------------------------------------------
// 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 GetFocus( bool p_focus );
// ----------------------------------------------------------------
// 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 KeyPress( SDLKey p_key, SDLMod p_mod, Uint16 p_char );
protected:
char* m_string;
int m_x, m_y, m_w, m_h;
int m_size;
SDL_Color m_tforecol, m_tbackcol;
TTF_Font* m_font;
bool m_hasFocus;
bool m_enabled;
void (*m_func)(void);
// this is to implement cursor blinking.
bool m_blink;
int m_timer;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -