📄 sdlguiframe.cpp
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLGUIFrame.cpp
// A Basic Framework for using the SDLGUI library.
// ============================================================================
#include "SDLGUI.h"
// ============================================================================
// Global Constants
// ============================================================================
const char PROGRAM_NAME[] = "INSERT PROGRAM NAME HERE";
const int WIDTH = 640;
const int HEIGHT = 480;
const int ITEMS = 32;
// ============================================================================
// Global Variables
// ============================================================================
SDLGUI* g_gui;
int main( int argc, char* argv[] )
{
// declare coordinates.
int x, y;
// declare event holder
SDL_Event event;
// set our at exit function
atexit( SDL_Quit );
//initialize systems
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
TTF_Init();
// create the GUI and set the caption.
g_gui = new SDLGUI( WIDTH, HEIGHT, ITEMS, WHITE );
SDL_WM_SetCaption( PROGRAM_NAME, 0);
// add your GUI items here.
// main message loop.
while( 1 )
{
//look for an event
if( SDL_PollEvent( &event ) )
{
//an event was found
if( event.type == SDL_QUIT )
break;
if( event.type == SDL_MOUSEBUTTONDOWN )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
// tell the GUI that a button has been pressed
g_gui->MouseDown( x, y );
}
if( event.type == SDL_MOUSEBUTTONUP )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
// tell the GUI that a button has been released
g_gui->MouseUp( x, y );
}
if( event.type == SDL_KEYDOWN )
{
// a key was pressed.
if( event.key.keysym.sym == SDLK_ESCAPE )
{
// if ESC was pressed, quit the program.
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent( &quit );
}
// tell the GUI that a key was pressed.
g_gui->KeyDown( event.key.keysym.sym, event.key.keysym.mod );
}
} // end event loop.
// do all game-related stuff here.
// tell the GUI to redraw itself
g_gui->Draw();
// DO ALL YOUR RENDERING HERE
// tell the GUI to update itself
g_gui->Update();
}
// done
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -