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

📄 sdlcheckbox.cpp

📁 游戏开发数据结构-Data.Structures.for.Game.Programmers
💻 CPP
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLCheckBox.cpp
// This is a basic SDLGUI library that I've set up for use with the game demos
// I've used in the book.
// ============================================================================
#include "SDLCheckBox.h"


// -------------------------------------------------------
// Name:        SDLCheckBox::SDLCheckBox
// 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.
// -------------------------------------------------------
SDLCheckBox::SDLCheckBox( 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) )
    : SDLButton( p_up, p_down, p_x, p_y, p_text,
                 p_tforecol, p_tbackcol, p_font, p_func )
{
}


// -------------------------------------------------------
// Name:        SDLButton::draw
// Description: draws the button.
// Arguments:   - p_dest: destination surface.
// -------------------------------------------------------
void SDLCheckBox::Draw( SDL_Surface* p_dest )
{
    SDLBlit( m_current, p_dest, m_x, m_y );
    SDLBlit( m_text, p_dest, 
             m_x + m_current->w,
             m_y + ((m_current->h - m_text->h) / 2));
}


// -------------------------------------------------------
// 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 SDLCheckBox::IsOver( int p_x, int p_y )
{
    // check if cursor is over checkbox.
    if( p_x >= m_x && 
        p_x < (m_x + m_current->w) &&
        p_y >= m_y && 
        p_y < (m_y + m_current->h) )
    {
        return true;
    }
    // check if cursor is over text label.
    if( p_x >= m_x + m_current->w && 
        p_x < m_x + m_current->w + m_text->w &&
        p_y >= m_y && 
        p_y < (m_y + m_current->h) )
    {
        return true;
    }
    return false;
}


// -------------------------------------------------------
// Name:        SDLCheckBox::ClickDown
// Description: sets the down state of the button
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
void SDLCheckBox::ClickDown()
{
    // do nothing.
}
 

// -------------------------------------------------------
// Name:        SDLCheckBox::ClickUp
// Description: sets the up state of the button
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
void SDLCheckBox::ClickUp()
{
    Toggle();
    if( m_func != 0 )
    {
        m_func();
    }
}


// -------------------------------------------------------
// Name:        SDLCheckBox::ResetOnUp
// Description: resets the button state if needed.
// Arguments:   None.
// Return Value: None.
// -------------------------------------------------------
void SDLCheckBox::ResetOnUp()
{
    // do nothing.
}


// -------------------------------------------------------
// Name:        SDLCheckBox::CanGetFocus
// Description: determines if this object can get the 
//              focus of the GUI.
// Arguments:   None.
// Return Value: True or False
// -------------------------------------------------------
bool SDLCheckBox::CanGetFocus()
{
    // in our GUI, checkboxes 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 SDLCheckBox::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 SDLCheckBox::KeyPress( SDLKey p_key, SDLMod p_mod, Uint16 p_char )
{
    return;
}

⌨️ 快捷键说明

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