Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005-2014 Simon Howard
// Copyright(C) 2021-2022 Graham Sanderson
//
// 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.
//
// DESCRIPTION:
// The status bar widget code.
//
#include <stdio.h>
#include <ctype.h>
#include "deh_main.h"
#include "doomdef.h"
#include "z_zone.h"
#include "v_video.h"
#include "i_swap.h"
#include "i_system.h"
#include "w_wad.h"
#include "st_stuff.h"
#include "st_lib.h"
#include "r_local.h"
// in AM_map.c
extern boolean automapactive;
//
// Hack display negative frags.
// Loads and store the stminus lump.
//
vpatch_handle_small_t sttminus;
void STlib_init(void)
{
sttminus = VPATCH_HANDLE(VPATCH_NAME(STTMINUS));
}
// ?
void
STlib_initNum
( st_number_t* n,
int x,
int y,
vpatch_sequence_t pl,
int* num,
boolean* on,
int width )
{
n->x = x;
n->y = y;
#if !DOOM_TINY
n->oldnum = 0;
#else
n->cached = 9999;
#endif
n->width = width;
n->num = num;
n->on = on;
n->p = pl;
}
//
// A fairly efficient way to draw a number
// based on differences from the old number.
// Note: worth the trouble?
//
void
STlib_drawNum
( st_number_t* n,
boolean refresh )
{
int numdigits = n->width;
int num = *n->num;
int w = vpatch_width(resolve_vpatch_handle(vpatch_n(n->p, 0)));
int h = vpatch_height(resolve_vpatch_handle(vpatch_n(n->p, 0)));
int x = n->x;
int neg;
#if !DOOM_TINY
n->oldnum = *n->num;
#else
// stbar wipe support - we need to be able to redraw and old status bar value
if (refresh || n->cached == 9999) n->cached = (int16_t)num;
else num = n->cached;
#endif
neg = num < 0;
if (neg)
{
if (numdigits == 2 && num < -9)
num = -9;
else if (numdigits == 3 && num < -99)
num = -99;
num = -num;
}
// clear the area
x = n->x - numdigits*w;
#if !DOOM_TINY
if (n->y - ST_Y < 0)
I_Error("drawNum: n->y - ST_Y < 0");
V_CopyRect(x, n->y - ST_Y, st_backing_screen, w*numdigits, h, x, n->y);
#endif
// if non-number, do not draw it
if (num == 1994)
return;
x = n->x;
// in the special case of 0, you draw 0
if (!num)
V_DrawPatch(x - w, n->y, vpatch_n(n->p, 00));
// draw the new number
while (num && numdigits--)
{
x -= w;
V_DrawPatch(x, n->y, vpatch_n(n->p, num % 10));
num /= 10;
}
// draw a minus sign if necessary
if (neg)
V_DrawPatch(x - 8, n->y, sttminus);
}
//
void
STlib_updateNum
( st_number_t* n,
boolean refresh )
{
if (*n->on) STlib_drawNum(n, refresh);
}
//
void
STlib_initPercent
( st_percent_t* p,
int x,
int y,
vpatch_sequence_t pl,
int* num,
boolean* on,
vpatch_handle_small_t percent )
{
STlib_initNum(&p->n, x, y, pl, num, on, 3);
p->p = percent;
}
void
STlib_updatePercent
( st_percent_t* per,
int refresh )
{
#if !DOOM_TINY
if (refresh && *per->n.on)
V_DrawPatch(per->n.x, per->n.y, per->p);
#else
if (*per->n.on)
V_DrawPatch(per->n.x, per->n.y, per->p);
#endif
STlib_updateNum(&per->n, refresh);
}
void
STlib_initMultIcon
( st_multicon_t* i,
int x,
int y,
vpatch_handle_small_t* il,
isb_int8_t * inum,
boolean* on )
{
i->x = x;
i->y = y;
#if !DOOM_TINY
i->oldinum = -1;
#else
i->cached = -1;
#endif
i->inum = inum;
i->on = on;
i->p = il;
}
void
STlib_updateMultIcon
( st_multicon_t* mi,
boolean refresh )
{
int w;
int h;
int x;
int y;
#if !DOOM_TINY
if (*mi->on
&& (mi->oldinum != *mi->inum || refresh)
&& (*mi->inum!=-1))
{
if (mi->oldinum != -1)
{
x = mi->x - patch_leftoffset(mi->p[mi->oldinum]);
y = mi->y - patch_topoffset(mi->p[mi->oldinum]);
w = vpatch_width(resolve_vpatch_handle(mi->p[mi->oldinum]));
h = vpatch_height(resolve_vpatch_handle(mi->p[mi->oldinum]));
if (y - ST_Y < 0)
I_Error("updateMultIcon: y - ST_Y < 0");
V_CopyRect(x, y-ST_Y, st_backing_screen, w, h, x, y);
}
V_DrawPatch(mi->x, mi->y, mi->p[*mi->inum]);
mi->oldinum = *mi->inum;
}
#else
int8_t inum = *mi->inum;
// stbar wipe support - we need to be able to redraw and old status bar value
if (refresh || mi->cached==-1) mi->cached = (int8_t)*mi->inum;
else inum = mi->cached;
if (*mi->on && inum!=-1)
V_DrawPatch(mi->x, mi->y, mi->p[inum]);
#endif
}
void
STlib_initBinIcon
( st_binicon_t* b,
int x,
int y,
vpatch_handle_small_t i,
boolean* val,
boolean* on )
{
b->x = x;
b->y = y;
#if !DOOM_TINY
b->oldval = false;
#else
b->cached = -1;
#endif
b->val = val;
b->on = on;
b->p = i;
}
void
STlib_updateBinIcon
( st_binicon_t* bi,
boolean refresh )
{
int x;
int y;
int w;
int h;
#if !DOOM_TINY
if (*bi->on
&& (bi->oldval != *bi->val || refresh))
{
x = bi->x - patch_leftoffset(bi->p);
y = bi->y - patch_topoffset(bi->p);
w = patch_width(bi->p);
h = patch_height(bi->p);
if (y - ST_Y < 0)
I_Error("updateBinIcon: y - ST_Y < 0");
if (*bi->val)
V_DrawPatch(bi->x, bi->y, bi->p);
else
V_CopyRect(x, y-ST_Y, st_backing_screen, w, h, x, y);
bi->oldval = *bi->val;
}
#else
boolean val = *bi->val;
// stbar wipe support - we need to be able to redraw and old status bar value
if (refresh || bi->cached==-1) bi->cached = (int8_t)*bi->val;
else val = bi->cached;
if (*bi->on && val) {
V_DrawPatch(bi->x, bi->y, bi->p);
}
#endif
}