Skip to content
Snippets Groups Projects
game.h 3.5 KiB
Newer Older
Jin Zijun's avatar
Jin Zijun committed

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>

typedef union SDL_Event
{
  Uint8 type; //事件类型
  SDL_ActiveEvent active; //窗口焦点、输入焦点及鼠标焦点的失去和得到事件
  SDL_KeyboardEvent key; //键盘事件,键盘按下和释放
  SDL_MouseMotionEvent motion; //鼠标移动事件
  SDL_MouseButtonEvent button; //鼠标按键事件
  SDL_QuitEvent quit; //退出事件
  SDL_SysWMEvent syswm; //平台相关的系统事件
} SDL_Event;

typedef enum {
  SDL_NOEVENT = 0, /* 未使用 */
  SDL_ACTIVEEVENT, /* 应用程序失去焦点或得到焦点*/
  SDL_KEYDOWN, /* 按下某键 */
  SDL_KEYUP, /* 松开某键 */
  SDL_MOUSEMOTION, /* 鼠标移动 */
  SDL_MOUSEBUTTONDOWN, /* 鼠标键按下 */
  SDL_MOUSEBUTTONUP, /* 鼠标键松开 */
  SDL_QUIT, /*离开 */
  SDL_SYSWMEVENT, /* 系统事件 */
  SDL_EVENT_RESERVEDA, /* 保留 */
  SDL_EVENT_RESERVEDB, /* 保留 */
  SDL_VIDEORESIZE, /* 用户改变视频模式 */
  SDL_VIDEOEXPOSE, /* 屏幕重画 */
  SDL_EVENT_RESERVED2, /* 保留*/
  SDL_EVENT_RESERVED3, /* 保留 */
  SDL_EVENT_RESERVED4, /* 保留 */
  SDL_EVENT_RESERVED5, /* 保留 */
  SDL_EVENT_RESERVED6, /* 保留*/
  SDL_EVENT_RESERVED7, /* 保留 */
  SDL_USEREVENT = 24, /* 用户自定义事件 */
  SDL_NUMEVENTS = 32
} SDL_EventType;

typedef struct SDL_MouseButtonEvent {
    Uint8 type;    /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
    Uint8 which;    /* The mouse device index */
    Uint8 button;    /* 鼠标按键,左、右、中三个键*/
    Uint8 state;    /* SDL_PRESSED按下 or SDL_RELEASED松开 */
    Uint16 x, y;    /* 鼠标按下时的坐标 */
} SDL_MouseButtonEvent;

typedef struct SDL_MouseMotionEvent {
    Uint8 type;    /* SDL_MOUSEMOTION */
    Uint8 which;    /* The mouse device index */
    Uint8 state;    /* 鼠标状态 */
    Uint16 x, y;    /* 鼠标当前坐标 */
    Sint16 xrel;    /* 鼠标在x方向的位移 */
    Sint16 yrel;    /* 鼠标在y方向的位移*/
} SDL_MouseMotionEvent;


#ifndef FONT_H
#define FONT_H

typedef  int BOOL;
#define TRUE  1
#define FALSE 0

//表面声明
extern SDL_Surface *gpBackground; //背景表面
extern SDL_Surface *gpScreen; //显示表面
extern SDL_Surface *gpMessage[1]; //文字表面

//事件声明
extern SDL_Event myEvent;

// 字体声明
extern TTF_Font *font;

extern const SDL_Color RGB_Black;
extern const SDL_Color RGB_Red;
extern const SDL_Color RGB_Green;
extern const SDL_Color RGB_Blue;
extern const SDL_Color RGB_Cyan;
extern const SDL_Color RGB_Magenta;
extern const SDL_Color RGB_Yellow;
extern const SDL_Color RGB_White;
extern const SDL_Color RGB_Gray;
extern const SDL_Color RGB_Grey;
extern const SDL_Color RGB_Maroon ;
extern const SDL_Color RGB_Darkgreen;
extern const SDL_Color RGB_Navy;
extern const SDL_Color RGB_Teal;
extern const SDL_Color RGB_Purple;
extern const SDL_Color RGB_Olive;
extern const SDL_Color RGB_Noname;


int isOnButton(int aX,int aY, int aIndex);
void changeButton(BUTTONPOS aPos,int aNo,SDL_Rect *aDst);
BOOL init(char* aCaption,char * aIcon);
SDL_Surface *loadImage( char * filename );
void applySurface( int x, int y, SDL_Surface* source, SDL_Surface* destination );
void cleanup();
char *localeToUTF8(char *src);
wchar_t* cstringToUnicode(char * aSrc);
void handle_input(char *str, SDL_Surface *text);
void show_centered(SDL_Surface *text);

#endif