📄 aihomesdk.cpp
字号:
/* * CChess Copyright (C) 2006 wesley.wang lily.ru * wq1977@gmail.com rujingli@163.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */#include "aihomesdk.h"#ifndef WIN32typedef struct{ const char *CmdStr; int KeyCode;}IrCmdBufStru;IrCmdBufStru AllCmdBuf[]={ {"RETURN",KEY_ENTER}, {"LEFT",KEY_LEFT}, {"RIGHT",KEY_RIGHT}, {"UP",KEY_UP}, {"DOWN",KEY_DOWN}, {"EXIT",KEY_ESC},};int CmpCmdBuf(const void *p, const void*q){ IrCmdBufStru *m,*n; m=(IrCmdBufStru *)p; n=(IrCmdBufStru *)q; return strcmp(m->CmdStr,n->CmdStr);}void *QueryIrQ(void *nouse){ int irsock; struct lirc_config *config; char *code; char *c; int ret; irsock=lirc_init("sdk",1); if (irsock==-1){ printf("lirc_init fail!"); return NULL; } if (lirc_readconfig("sdklircrc",&config,NULL)!=0){ printf("read config fail!"); return NULL; } qsort(AllCmdBuf,sizeof(AllCmdBuf)/sizeof(IrCmdBufStru),sizeof(IrCmdBufStru), CmpCmdBuf); while (lirc_nextcode(&code)==0){ if (code){ while ((ret=lirc_code2char(config,code,&c))==0 && c!=NULL){ IrCmdBufStru stCmdBuf,*pstRet; stCmdBuf.CmdStr = c; pstRet = (IrCmdBufStru*)bsearch(&stCmdBuf,AllCmdBuf,sizeof(AllCmdBuf)/sizeof(IrCmdBufStru),sizeof(IrCmdBufStru),CmpCmdBuf); if (pstRet){ simulate_keypress(pstRet->KeyCode << 8); } } free(code); } } if (config) lirc_freeconfig(config); lirc_deinit(); return NULL;}#endifvoid aihomegame::CommonProcInput(int keycode){ if (ProcInput(keycode)) return; switch (keycode >> 8){ case KEY_ESC: Done(); break; }}bool aihomegame::CommonInit(){ if (allegro_init() != 0) return false; install_keyboard(); install_timer(); if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0) { allegro_message("Error initialising sound system\n%s\n", allegro_error); return false; }#ifndef WIN32 pthread_t pid; pthread_create(&pid,NULL,QueryIrQ,NULL);#endif set_color_depth(16); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, HEIGHT*2) != 0) { if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, WIDTH, HEIGHT, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return false; } } } set_palette(desktop_palette); page1 = create_video_bitmap(SCREEN_W, SCREEN_H); page2 = create_video_bitmap(SCREEN_W, SCREEN_H); if (page1 && page2){ UseFlip = true; active_page = page2; } else { if (page1) { destroy_bitmap(page1); page1=NULL; } if (page2) { destroy_bitmap(page2); page2=NULL; } buffer = create_bitmap(SCREEN_W, SCREEN_H); active_page = buffer; } return Init();}void aihomegame::CommonDraw(){ Draw(); if (UseFlip){ show_video_bitmap(active_page); if (active_page == page1) active_page = page2; else active_page = page1; } else{ vsync(); blit(active_page, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } }void aihomegame::CommonQuit(){ Quit(); if (page1) destroy_bitmap(page1); if (page2) destroy_bitmap(page2); if (buffer) destroy_bitmap(buffer); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -