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

📄 stb_hello.cc

📁 Linux嵌入式设计配套光盘,学习嵌入式设计可参考
💻 CC
字号:
/**************************************************************************** * stb_hello.cc * * A simple demonstration UI using STBmenu and SDL. ****************************************************************************/#include <stdio.h>#include <stdlib.h>#include "SDL.h"                /* All SDL App's need this */#include "STBmenu.h"#define BLACK      0x000000#define LIGHT_BLUE 0x8080FF#define CYAN       0x00FFFF#define YELLOW     0xFFFF00int enableQuit = 0;/**************************************************************************** * callbacks ****************************************************************************/static void Hello(InputClass* const widget){  printf("Hello, world!\n");}static void QuitApplication(InputClass* const widget){  enableQuit = 1;}/**************************************************************************** * main ****************************************************************************/int main(int argc, char *argv[]) {  SDL_Event event;  // Allocate the persistent (static) objects required for the menu.  Always  // allocate the Menu first, since this initializes the video context.  // Menu: Provide number of pages, as well as width, height, bpp, and flags.  Menu* menu = new Menu(1, 640, 480, 8);  // A single page: Provide number rows, columns, background surface  Surface background(640,480,BLACK);  Page page(2, 1, background);  menu->AttachPage(0, page); // Provide page number and page  // The Hello button widget  Font font("/usr/local/share/fonts/bitstream/VeraBI.ttf",42);  Surface nfHello(font,CYAN,  "Hello");  Surface fHello (font,YELLOW,"Hello <");  Button helloButton(nfHello,fHello);  WButton wHello(helloButton,Hello,NULL);  page.AttachWidget(0,0,250,200,wHello); // Provide row, col, x, and y  // The Exit button widget  Surface nfExit (font,CYAN,  "Exit");  Surface fExit  (font,YELLOW,"Exit <");  Button exitButton (nfExit, fExit);  WButton wExit (exitButton, QuitApplication,NULL);  page.AttachWidget(1,0,250,260,wExit);  // Select the starting cursor position on each page. Finish with the first  // page to display, then display it.  menu->SetCursor(0, 0, 0);  menu->DisplayCurrentPage();  enableQuit = 0;  while(!enableQuit){    SDL_WaitEvent(&event);    switch(event.type){      case SDL_KEYDOWN:        switch(event.key.keysym.sym){          // A fallback for a graceful exit          case SDLK_ESCAPE:            enableQuit = 1;            break;          case SDLK_LEFT:            menu->CursorLeft();            break;          case SDLK_RIGHT:            menu->CursorRight();            break;          case SDLK_UP:            menu->CursorUp();            break;          case SDLK_DOWN:            menu->CursorDown();            break;          case SDLK_RETURN:            menu->Activate();            break;        }        break;    }    menu->Update();  }}

⌨️ 快捷键说明

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