⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdlbutton.h

📁 游戏开发数据结构Data Structures for Game Programmers
💻 H
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLButton.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 SDLBUTTON_H
#define SDLBUTTON_H

#include "SDLHelpers.h"
#include "SDLGUIItem.h"



enum BUTTONSTATE
{
    BUTTONDOWN,
    BUTTONUP
};


class SDLButton : public SDLGUIItem
{
public:
// -------------------------------------------------------
// Name:        SDLButton::SDLButton
// Description: This constructs the button
// Arguments:   - p_up: the up bitmap name
//              - p_down: the down bitmap name
//              - 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.
//              - p_func: the function this calls when
//                        pressed.
// -------------------------------------------------------
    SDLButton( const char* p_up, const char* p_down,
               int p_x, int p_y,
               const char* p_text, 
               SDL_Color p_tforecol,
               SDL_Color p_tbackcol,
               TTF_Font* p_font,
               void (*p_func)(void) );


// -------------------------------------------------------
// Name:        SDLButton::~SDLButton
// Description: This destructs the button
// Arguments:   None.
// -------------------------------------------------------
    ~SDLButton();

    
// -------------------------------------------------------
// Name:        SDLButton::Draw
// Description: draws the button.
// Arguments:   - p_dest: destination surface.
// -------------------------------------------------------
    void Draw( SDL_Surface* p_dest );


// -------------------------------------------------------
// Name:        SDLButton::IsOver
// Description: determines if a position is over the button
// Arguments:   - p_x: x coordinate
//              - p_y: y coordinate
// Return Value: true if the position is over the button.
// -------------------------------------------------------
    bool IsOver( int p_x, int p_y );


// -------------------------------------------------------
// Name:        SDLButton::State
// Description: gets the state of the button
// Arguments:   None.
// Return Value: BUTTONSTATE
// -------------------------------------------------------
    BUTTONSTATE State();


// -------------------------------------------------------
// Name:        SDLButton::ClickDown
// Description: sets the down state of the button
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
    void ClickDown();
 

// -------------------------------------------------------
// Name:        SDLButton::ClickUp
// Description: sets the up state of the button
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
    void ClickUp();


// -------------------------------------------------------
// Name:        SDLButton::ResetOnUp
// Description: resets the button state if needed.
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
    void ResetOnUp();


// -------------------------------------------------------
// Name:        SDLButton::Toggle
// Description: toggles the state of the button
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
    void Toggle();


// -------------------------------------------------------
// Name:        SDLButton::CanGetFocus
// Description: determines if this object can get the 
//              focus of the GUI.
// Arguments:   None.
// Return Value: True or False
// -------------------------------------------------------
    bool CanGetFocus();


// ----------------------------------------------------------------
//  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 );

// ----------------------------------------------------------------
//  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 );


protected:
 SDL_Surface* m_up;
 SDL_Surface* m_down;
 SDL_Surface* m_current;
 SDL_Surface* m_text;

 bool m_state;
 void (*m_func)(void);

};



#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -