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

📄 sdlguiitem.h

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



// ----------------------------------------------------------------
//  Name:           SDLGUIItem
//  Description:    The GUI Item class
// ----------------------------------------------------------------
class SDLGUIItem
{
public:

// ----------------------------------------------------------------
//  Name:           SDLGUIItem
//  Description:    constructor, creates a new item
//  Arguments:      None
//  Return Value:   None
// ----------------------------------------------------------------
    SDLGUIItem()
    {
        m_visible = true;
    }
    

// ----------------------------------------------------------------
//  Name:           Move
//  Description:    moves an item to new coordinates
//  Arguments:      x, y: The new coordinates
//  Return Value:   None
// ----------------------------------------------------------------
    void Move( int x, int y )
    {
        m_x = x;
        m_y = y;
    }

// ----------------------------------------------------------------
//  Name:           SetVisibility
//  Description:    Sets the visibility of the item
//  Arguments:      p_vis: if the item is visible or not
//  Return Value:   None
// ----------------------------------------------------------------
    void SetVisibility( bool p_vis )
    {
        m_visible = p_vis;
    }


// ----------------------------------------------------------------
//  Name:           Visible
//  Description:    determines if the item is visible or not
//  Arguments:      None
//  Return Value:   true if visible
// ----------------------------------------------------------------
    bool Visible()
    {
        return m_visible;
    }

// ----------------------------------------------------------------
//  Name:           Draw
//  Description:    draws the item on a surface
//  Arguments:      p_dest: the destination surface
//  Return Value:   None
// ----------------------------------------------------------------
    virtual void Draw( SDL_Surface* p_dest ) = 0;


// ----------------------------------------------------------------
//  Name:           ClickDown
//  Description:    Tells the item that it was clicked on.
//  Arguments:      None
//  Return Value:   None
// ----------------------------------------------------------------
    virtual void ClickDown() = 0;

// ----------------------------------------------------------------
//  Name:           ClickUp
//  Description:    Tells the item that it a mouse was released
//                  on this item
//  Arguments:      None
//  Return Value:   None
// ----------------------------------------------------------------
    virtual void ClickUp() = 0;


// ----------------------------------------------------------------
//  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
// ----------------------------------------------------------------
    virtual void KeyPress( SDLKey p_key, SDLMod p_mod, Uint16 p_char ) = 0;

    
// ----------------------------------------------------------------
//  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
// ----------------------------------------------------------------
    virtual bool IsOver( int p_x, int p_y ) = 0;


// ----------------------------------------------------------------
//  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
// ----------------------------------------------------------------
    virtual void ResetOnUp() = 0;


// ----------------------------------------------------------------
//  Name:           CanGetFocus
//  Description:    determines if the item can get the focus
//  Arguments:      None
//  Return Value:   true if the item can get the focus
// ----------------------------------------------------------------
    virtual bool CanGetFocus() = 0;


// ----------------------------------------------------------------
//  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
// ----------------------------------------------------------------
    virtual void GetFocus( bool p_focus ) = 0;

protected:

// ----------------------------------------------------------------
//  Name:           m_x, m_y
//  Description:    coordinates of the item
// ----------------------------------------------------------------
    int m_x;
    int m_y;

// ----------------------------------------------------------------
//  Name:           m_visible
//  Description:    is the item visible?
// ----------------------------------------------------------------
    bool m_visible;
};





#endif

⌨️ 快捷键说明

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