1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
* file mi_toggle.c - checkbuttons for menus
*
* $Id: mi_toggle.c,v 1.5 2006/02/09 21:21:24 fzago Exp $
*
* Program XBLAST
* (C) by Oliver Vogel (e-mail: m.vogel@ndh.net)
*
* 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; or (at your option)
* any later version
*
* This program is distributed in the hope that it will be entertaining,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILTY 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 "xblast.h"
/*
* local macors
*/
#define FF_TOGGLE_FOCUS (FF_Small | FF_Black | FF_Left | FF_Outlined)
#define FF_TOGGLE_NO_FOCUS (FF_Small | FF_White | FF_Left)
/*
* local types
*/
typedef struct
{
XBMenuItem item;
const char *text;
Sprite *textSprite;
Sprite *ledSprite;
XBBool *pState;
XBBool state;
} XBMenuToggleItem;
/*
* a toggle item receives the focus
*/
static void
MenuToggleFocus (XBMenuItem * ptr, XBBool flag)
{
XBMenuToggleItem *toggle = (XBMenuToggleItem *) ptr;
assert (toggle != NULL);
assert (toggle->textSprite != NULL);
SetSpriteAnime (toggle->textSprite, flag ? FF_TOGGLE_FOCUS : FF_TOGGLE_NO_FOCUS);
} /* MenuToggleFocus */
/*
* a toggle is selected
*/
static void
MenuToggleSelect (XBMenuItem * ptr)
{
XBMenuToggleItem *toggle = (XBMenuToggleItem *) ptr;
assert (toggle != NULL);
if (NULL != toggle->pState) {
*toggle->pState = !*toggle->pState;
}
} /* MenuToggleSelect */
/*
* mouse click
*/
static void
MenuToggleMouse (XBMenuItem * ptr, XBEventCode code)
{
if (code == XBE_MOUSE_1) {
MenuToggleSelect (ptr);
}
} /* MenuToggleMouse */
/*
* polling a toggle item
*/
static void
MenuTogglePoll (XBMenuItem * ptr)
{
XBMenuToggleItem *toggle = (XBMenuToggleItem *) ptr;
assert (toggle != NULL);
assert (toggle->ledSprite != NULL);
if (*toggle->pState != toggle->state) {
toggle->state = *toggle->pState;
SetSpriteAnime (toggle->ledSprite, toggle->state ? ISA_LedOn : ISA_LedOff);
}
} /* MenuTogglePoll */
/*
*
*/
XBMenuItem *
MenuCreateToggle (int x, int y, int w, const char *text, XBBool * pState)
{
/* create item */
XBMenuToggleItem *toggle = calloc (1, sizeof (*toggle));
assert (NULL != toggle);
MenuSetItem (&toggle->item, MIT_Toggle, x, y, w, CELL_H / 2, MenuToggleFocus, MenuToggleSelect,
MenuToggleMouse, MenuTogglePoll);
/* set toggle specific data */
toggle->text = text;
toggle->pState = pState;
toggle->state = (NULL != pState) ? *pState : XBFalse;
/* sprite with text label */
toggle->textSprite =
CreateTextSprite (text, (x + 3) * BASE_X, y * BASE_Y, (w - 4) * BASE_X,
(CELL_H / 2) * BASE_Y, FF_TOGGLE_NO_FOCUS, SPM_MAPPED);
/* sprite with marker */
toggle->ledSprite =
CreateIconSprite ((x - 2) * BASE_X, (y - CELL_H / 4) * BASE_Y,
toggle->state ? ISA_LedOn : ISA_LedOff, SPM_MAPPED);
/* graphics */
MenuAddSmallFrame (x / CELL_W, (x + w - 1) / CELL_W, y / CELL_H);
return &toggle->item;
} /* CreateMenuToggle */
/*
* delete a toggle
*/
void
MenuDeleteToggle (XBMenuItem * item)
{
XBMenuToggleItem *toggle = (XBMenuToggleItem *) item;
assert (toggle->textSprite != NULL);
assert (toggle->ledSprite != NULL);
DeleteSprite (toggle->textSprite);
DeleteSprite (toggle->ledSprite);
} /* DeleteButtonItem */
/*
* end of file mi_toggle.c
*/
|