📄 widgets.h
字号:
/* * widgets.h - SDL widget set in C * * Copyright 2004 by Jeffery L. Post * theposts<AT>pacbell<DOT>net * Version 0.0.3 - 11/26/04 * * 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 * (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef _WIDGETS_H_#define _WIDGETS_H_#ifdef WIN32#include <windows.h>#endif#include <assert.h>#include <SDL/SDL.h>#define DEBUG#ifndef bool#define bool int#endif#ifndef FALSE#define FALSE 0#endif#ifndef TRUE#define TRUE 1#endif#ifdef WIN32#define strcasecmp(a,b) stricmp(a,b)#define lstat stat#endif#define FONT_WIDTH 6#define FONT_HEIGHT 13#define SLIDERSIZE 4 // minimum size of slider handle in pixels#define SLIDERBUTTONSIZE 10 // size of adjust buttons on sliders#define SLIDER_AUTO_CALLBACK (SDL_NUMEVENTS + 1)#define TIMER_EVENT (SDL_NUMEVENTS + 2)#define IBOX_INSERT_MODE 0#define IBOX_OVERWRITE_MODE 1// For Slider auto callbacks, slider->state tells where the// mouse is currently located by one of the following codes.enum SliderMouseCodes { MOUSE_NOT_IN_SLIDER, // mouse not positioned within slider MOUSE_IN_SLIDER_UPBUTTON, // mouse is in the up/left button MOUSE_IN_SLIDER_DOWNBUTTON, // mouse is in the down/right button MOUSE_IN_UPPER_SLIDER, // mouse within slider region above marker MOUSE_IN_LOWER_SLIDER, // mouse within slider region below marker MOUSE_ON_SLIDER // mouse is on the marker};// AlertBox responsesenum alertResponses { ALERT_NO_RESPONSE, ALERT_CANCEL, ALERT_OK};// Graphic characters#define UPPER_LEFT_CORNER 0xda#define UPPER_RIGHT_CORNER 0xbf#define LOWER_LEFT_CORNER 0xc0#define LOWER_RIGHT_CORNER 0xd9#define HORIZONTAL_LINE 0xc4#define VERTICAL_LINE 0xb3#define CHECK_MARK 0xfbenum WidgetType { // types of widgets WindowType, // 0 MenuType, // 1 VMenuType, // 2 ButtonType, // 3 CheckBoxType, // 4 LabelType, // 5 HLabelType, // 6 AlertType, // 7 NoticeType, // 8 TextBoxType, // 9 InputBoxType, // 10 VSliderType, // 11 HSliderType, // 12 MaxWidgetType // Invalid type};// Button widgettypedef struct { int type; // ButtonType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; bool border; // true = show left/right borders char *text; // text of button} BUTTON;// Checkbox widgettypedef struct { int type; // CheckBoxType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; bool border; // true = show left/right borders char *text; // text of checkbox bool *value;} CHECKBOX;// Label widgettypedef struct { int type; // LabelType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; bool border; // true = show left/right borders char *text; // text of button} LABEL;// Highlighted Label widgettypedef struct { int type; // HLabelType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; bool border; // true = show left/right borders char *text; // text of button bool hlflag; // TRUE = enable highlight text} HLABEL;union LISTMEMBER{ BUTTON *button; CHECKBOX *checkbox; LABEL *label; HLABEL *hlabel;};typedef struct buttonList { union LISTMEMBER thislist; struct buttonList *next;} BLIST;typedef BLIST CLIST;// Window widgettypedef struct { int type; // WindowType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; BLIST *list; // buttons attached to window} WINDOW;// Menu widgettypedef struct { int type; // MenuType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; BLIST *list; // buttons attached to window} MENU;// Vertical Menu widgettypedef struct { int type; // VMenuType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color int bg; // text background color int hi; // border highlight color int lo; // border lowlight color void *mdfunc; // function to call when mouse button down within window void *mufunc; // function to call when mouse button up within window void *mmfunc; // function to call when mouse button motion within window void *kdfunc; // function to call on keypress void *kufunc; // function to call on keyrelease void *parent; BLIST *list; // buttons attached to window} VMENU;// Alert box widgettypedef struct { int type; // AlertType int id; int x; // x location relative to parent int y; // y location relative to parent int w; // width int h; // height int fg; // text foreground color
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -