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

📄 test.c

📁 一个很好的SDL建立应用程序界面的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * SDL Simple C widget set test * Copyright 2004 by * Jeffery L. Post * theposts@pacbell.net * * test.c - Main File - 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 * */#include	<stdio.h>#include	<stdlib.h>#include	<ctype.h>#include	<string.h>#ifndef WIN32#include	<SDL/SDL_syswm.h>#else#include <windows.h>#endif#define	DEBUG#include	"test.h"#include	"widgets.h"#include	"fileselect.h"#ifdef DEBUGextern void dump_widget_list(void);	// for test only#endif// Constants#define	VERNO		0#define	MAJORREV	0#define	MINORREV	3#define	WINDOW_X_POSITION		20#define	WINDOW_Y_POSITION		20#define	KB_DELAY					250	// key repeat start delay#define	KB_INTERVAL				50		// key repeat interval// Prototypes/* none */// Global variablesSDL_Surface	*screen = NULL;MENU		*menu = NULL;			// main menuMENU		*options = NULL;		// options bar (checkboxes)MENU		*filename = NULL;		// current file name menuLABEL		*filelabel = NULL;	// current file name labelchar		filestr[128];			// the current file namebool		fileButtonActive = FALSE;bool		fileSelectionActive = FALSE;VMENU		*file_menu = NULL;	// file sub-menubool		helpButtonActive = FALSE;VMENU		*help_menu = NULL;	// help screenbool		aboutButtonActive = FALSE;VMENU		*about_menu = NULL;	// about screenTEXTBOX	*tbox_test = NULL;bool		tboxActive = FALSE;ALERT		*testAlert = NULL;bool		quit = FALSE;bool		checkflag = FALSE;bool		anotherflag = FALSE;bool		toggleflag = TRUE;HSLIDER	*hSlider = NULL;VSLIDER	*vSlider = NULL;LABEL		*vSliderLabel = NULL;LABEL		*hSliderLabel = NULL;INPUTBOX	*ibox_test = NULL;bool		iboxActive = FALSE;INPUTBOX	*mibox_test = NULL;LABEL		*mibox_label = NULL;char		vSliderText[] = "Vertical Slider:   0%";char		hSliderText[] = "Horizontal Slider:   0%";char		caption[] = "Simple C Widgets for SDL - Version x.xx";char		font_set[16][17];char		fileNameInput[128];char		lineone[128];char		linetwo[128];char		linethree[128];char		linefour[128];////		Code//void hSliderCB(SDL_Event *event, HSLIDER *hs){	sprintf(hSliderText, "Horizontal Slider: %3d%%", hs->pc);//	if (event->type == SDL_MOUSEBUTTONUP)//		removeCallBack(hs, SDL_MOUSEMOTION);}void hSliderAutoCB(void){	hSliderCB(NULL, hSlider);	showWidget(hSliderLabel);}void vSliderCB(SDL_Event *event, VSLIDER *vs){	sprintf(vSliderText, "Vertical Slider: %3d%%", vs->pc);//	if (event->type == SDL_MOUSEBUTTONUP)//		removeCallBack(vs, SDL_MOUSEMOTION);}void vSliderAutoCB(void){	vSliderCB(NULL, vSlider);	showWidget(vSliderLabel);}void fileButtonCB(SDL_Event *event){	if (fileSelectionActive)		return;	fileButtonActive ^= TRUE;	if (fileButtonActive)		popUpWidget(file_menu);	else		pushDownWidget(file_menu);}void editButtonCB(SDL_Event *event){	popUpWidget(testAlert);}void configButtonCB(SDL_Event *event){	if (fileSelectionActive)		return;	tboxActive ^= TRUE;	if (tboxActive)		popUpWidget(tbox_test);	else		pushDownWidget(tbox_test);}void helpButtonCB(SDL_Event *event){	if (fileSelectionActive)		return;	helpButtonActive ^= TRUE;	if (helpButtonActive)		popUpWidget(help_menu);	else		pushDownWidget(help_menu);}void helpMenuCB(SDL_Event *event, BUTTON *b){	if (fileSelectionActive || !helpButtonActive)		return;	if (helpButtonActive)		popUpWidget(help_menu);}void aboutButtonCB(SDL_Event *event){	if (fileSelectionActive)		return;	aboutButtonActive ^= TRUE;	if (aboutButtonActive)		popUpWidget(about_menu);	else		pushDownWidget(about_menu);}void aboutMenuCB(SDL_Event *event, BUTTON *b){	if (fileSelectionActive || !aboutButtonActive)		return;	if (aboutButtonActive)		popUpWidget(about_menu);}void openButtonCB(SDL_Event *event, MENU *m){	char	*cptr;	if (!fileButtonActive || fileSelectionActive)		return;	if (event->type == SDL_MOUSEBUTTONDOWN)	{		fileSelectionActive = TRUE;		cptr = fileSelect(NULL, NULL);		fileSelectionActive = FALSE;		if (cptr == (char *) -1)		{			quit = TRUE;		}		else if (cptr)		{			strcpy(filestr, cptr);			filelabel->text = (char *) &filestr;		}		fileButtonActive = FALSE;		pushDownWidget(file_menu);	}}void saveButtonCB(SDL_Event *event, MENU *m){	if (!fileButtonActive || fileSelectionActive)		return;	if (event->type == SDL_MOUSEBUTTONDOWN && !iboxActive)	{		iboxActive = TRUE;		ibox_test->cursorx = 0;		ibox_test->text->str[0] = '\0';		popUpWidget(ibox_test);	}}void closeButtonCB(SDL_Event *event, MENU *m){	if (!fileButtonActive || fileSelectionActive)		return;	if (event->type == SDL_MOUSEBUTTONDOWN)	{		fileButtonActive = FALSE;		pushDownWidget(file_menu);	}}void alertCB(SDL_Event *event, ALERT *ab){	bool	remove = FALSE;	if (ab->response == ALERT_CANCEL)		remove = TRUE;	else if (ab->response == ALERT_OK)		remove = TRUE;	if (remove)		pushDownWidget(testAlert);}void tboxCB(SDL_Event *event, BUTTON *b){	if (fileSelectionActive)		return;	if (tboxActive)		popUpWidget(tbox_test);}void iboxCB(SDL_Event *event, INPUTBOX *b){	int	i;	char	chr;	if (iboxActive)	{		if (event->type == SDL_KEYDOWN)		{			chr = event->key.keysym.unicode;			if (chr == SDLK_RETURN)			{				b->cursorx = 0;				b->cursory = 0;				iboxActive = FALSE;				pushDownWidget(ibox_test);// user input is in fileNameInput, do something with it...				for (i=0; i<64; i++)				// clear out file name input for next time					fileNameInput[i] = '\0';			}		}	}}void miboxCB(SDL_Event *event, INPUTBOX *b){	if (b != topWidget)		popUpWidget(b);	// Do whatever needs to be done with the input}void exitButtonCB(SDL_Event *event, MENU *m){	if (!fileButtonActive || fileSelectionActive)		return;	quit = TRUE;	fileButtonActive = FALSE;	pushDownWidget(file_menu);}void checkBoxCB(SDL_Event *event, CHECKBOX *cb){	int	x, y, mx, my;	if (fileButtonActive || fileSelectionActive)		return;	if (event->type == SDL_MOUSEBUTTONDOWN)	{		mx = event->button.x;		my = event->button.y;		x = cb->x + 4;		y = cb->y;		if (mx > x && mx < x + FONT_WIDTH * 3 && my > y && my < y + FONT_HEIGHT)		{			*cb->value ^= TRUE;			if (*cb->value)				drawChar(x + FONT_WIDTH, y, cb->fg, cb->bg, (char) 0xfb);			else				drawChar(x + FONT_WIDTH, y, cb->fg, cb->bg, ' ');		}	}}void textboxCB(SDL_Event *event, TEXTBOX *tbox){	if (topWidget == tbox_test)	{		switch (event->key.keysym.sym)		{			case SDLK_UP:				decTListEntry(tbox_test, 1);				break;

⌨️ 快捷键说明

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