brewpanel/dlgBrew.c

Sat, 14 Nov 2015 23:40:51 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 14 Nov 2015 23:40:51 +0100
changeset 422
13502d0dda65
parent 420
644a6106d712
child 425
c51265b518ce
permissions
-rw-r--r--

The brewpanel works, but still needs a lot more

/*****************************************************************************
 * Copyright (C) 2015
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of the mbsePi-apps
 *
 * The gui code is based on the gui from the emulator ARAnyM,
 * Copyright (c) 2004 Petr Stehlik of ARAnyM dev team
 *
 * mbsePi-apps 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, or (at your option) any
 * later version.
 *
 * mbsePi-apps 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 mbsePi-apps; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

#include "brewpanel.h"
#include "sockio.h"
#include "dlgBrew.h"
#include "sdlgui.h"
#include "slcd.h"


#ifdef HAVE_SDL_SDL_H

extern SDL_Surface	*PAN_surface;
extern int		my_shutdown;
extern uint16_t		keys;


#define	MAINDLG_B1	 2
#define MAINDLG_B2	 3
#define MAINDLG_B3	 4
#define MAINDLG_B4	 5
#define MAINDLG_QUIT     6


/* The main dialog: */
static SGOBJ maindlg[] =
{
/*        type      flags     state   x    y    w    h  txt  */
	{ SGBOX,    0,           0,   0,   0, 374, 470, NULL },
	{ SGLCD,    0,           0,  -1,  44,  20,   4, NULL },
	{ SGBUTTON, 0,           0,  80, 135,  30,  30, (char *)"1" },
	{ SGBUTTON, 0,           0, 140, 135,  30,  30, (char *)"2" },
	{ SGBUTTON, 0,           0, 200, 135,  30,  30, (char *)"3" },
	{ SGBUTTON, 0,           0, 260, 135,  30,  30, (char *)"4" },
	{ SGBUTTON, 0,           0, 147, 430,  80,  20, (char *)"Quit" },
	{ SGTTF,    0,           0,  85, 170,  20,  20, (char *)"Up" },
	{ SGTTF,    0,           0, 135, 170,  20,  20, (char *)"Down" },
	{ SGTTF,    0,           0, 203, 170,  20,  20, (char *)"Ret" },
	{ SGTTF,    0,           0, 258, 170,  20,  20, (char *)"Enter" },
	{ -1,       0,           0,   0,   0,   0,   0, NULL }
};



int Dialog_LCDinit(int *x, int *y, int *w, int *h, int *cols, int *rows, int index)
{
    int	retval;

    retval = SDLGui_LCDinit(maindlg, x, y, w, h, cols, rows, index);

    fprintf(stdout, "SDLGui_LCDinit(maindlg, %d, %d, %d, %d, %d, %d, %d) = %d\n", *x, *y, *w, *h, *cols, *rows, index, retval);
    return retval;
}



/*
 * This functions sets up the actual font and then displays the brew panel dialog.
 */
int Dialog_BrewDlg(void)
{
    int retbut;
    int bOldMouseVisibility;
    int nOldMouseX, nOldMouseY;
    int x, y, w, h, cols, rows, fd;

    if (SDLGui_SetScreen(PAN_surface)) {
	syslog(LOG_NOTICE, "SDLGui_SetScreen(PAN_surface) failed: %s", SDL_GetError());
	return FALSE;
    }

    SDL_GetMouseState(&nOldMouseX, &nOldMouseY);
    bOldMouseVisibility = SDL_ShowCursor(SDL_QUERY);
    SDL_ShowCursor(SDL_ENABLE);

    SDLGui_CenterDlg(maindlg);
    SDLGui_DoDialogInit(maindlg);
    fd = Dialog_LCDinit(&x, &y, &w, &h, &cols, &rows, 0);
    fprintf(stdout, "Dialog_LCDinit(%d, %d, %d, %d, %d, %d, 0) = %d\n", x, y, w, h, cols, rows, fd);
    socket_connect();
    slcdInit(fd, x, y, w, h, cols, rows);

    do {
	retbut = SDLGui_DoDialogLoop(maindlg);
	fprintf(stdout, "SDLGui_DoDialog retbut=%d\n", retbut);

	switch (retbut) {
	    case MAINDLG_B1 + 1000:
		    		keys |= 0x0008;
				break;
	    case MAINDLG_B1:	
				keys &= ~0x0008;
		    		break;
	    case MAINDLG_B2 + 1000:
				keys |= 0x0004;
				break;
	    case MAINDLG_B2:	
				keys &= ~0x0004;
				break;
	    case MAINDLG_B3 + 1000:
				keys |= 0x0002;
				break;
	    case MAINDLG_B3:
				keys &= ~0x0002;
				break;
	    case MAINDLG_B4 + 1000:
				keys |= 0x0001;
				break;
	    case MAINDLG_B4:
				keys &= ~0x0001;
				break;
	    case MAINDLG_QUIT:	my_shutdown = TRUE;
				break;
	}

    } while (retbut != SDLGUI_QUIT && retbut != SDLGUI_ERROR && !my_shutdown);

    SDLGui_DoDialogEnd();
    SDL_ShowCursor(bOldMouseVisibility);

    return TRUE;
}

#endif

mercurial