2002-08-16 21:54:21 +00:00
|
|
|
/*
|
|
|
|
options_util.qc
|
|
|
|
|
|
|
|
Utilities for the options menu
|
|
|
|
|
|
|
|
Copyright (C) 2002 Robin Redeker <elmex@x-paste.de>
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "draw.h"
|
|
|
|
#include "string.h"
|
2010-11-24 05:43:16 +00:00
|
|
|
#include "system.h"
|
2002-08-16 21:54:21 +00:00
|
|
|
|
2004-02-04 02:35:57 +00:00
|
|
|
#include "options_util.h"
|
|
|
|
|
2002-08-16 21:54:21 +00:00
|
|
|
/*
|
|
|
|
opt_cursor
|
|
|
|
|
|
|
|
function for drawing the cursor
|
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
void (int x, int y)
|
2002-08-16 21:54:21 +00:00
|
|
|
opt_cursor =
|
|
|
|
{
|
|
|
|
// use time becaus we want a nice rotaing cursor
|
2011-03-25 07:46:32 +00:00
|
|
|
Draw_Character (x, y, 12 + ((int) (time * 4) & 1));
|
2002-08-16 21:54:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
draw_item
|
2011-03-25 07:46:32 +00:00
|
|
|
|
2003-03-03 05:24:45 +00:00
|
|
|
Draws a item with a specific spacing between label and value to
|
|
|
|
position x, y.
|
2002-08-16 21:54:21 +00:00
|
|
|
Used as helper function for draw_val_item.
|
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
void (int x, int y, int spacing, string spacechar,
|
2003-03-03 05:24:45 +00:00
|
|
|
string label, string valstr)
|
2002-08-16 21:54:21 +00:00
|
|
|
draw_item =
|
|
|
|
{
|
2011-03-25 07:46:32 +00:00
|
|
|
local int i;
|
2003-03-03 05:24:45 +00:00
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
Draw_String (x, y, label);
|
|
|
|
for (i = x + (int) strlen (label) * 8; i < (x+spacing); i += 8) {
|
2002-08-16 21:54:21 +00:00
|
|
|
Draw_String (i, y, spacechar);
|
|
|
|
}
|
|
|
|
Draw_String (x + spacing, y, valstr);
|
|
|
|
};
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
/*
|
2002-08-16 21:54:21 +00:00
|
|
|
draw_val_item
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
Draws a nice menu item.
|
2002-08-16 21:54:21 +00:00
|
|
|
Use this function for a consistent look of menu items!
|
|
|
|
Example:
|
|
|
|
<Label>.....:<valstr>
|
|
|
|
spacing are the number of the points to put
|
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
void (int x, int y, int spacing, string label, string valstr)
|
2002-08-16 21:54:21 +00:00
|
|
|
draw_val_item =
|
|
|
|
{
|
|
|
|
draw_item (x, y, spacing, ".", label, ":" + valstr);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
to_percentage
|
|
|
|
|
|
|
|
Calculates the percentage of a value relative
|
|
|
|
to a min and max value.
|
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
int (float min, float max, float val)
|
2002-08-16 21:54:21 +00:00
|
|
|
to_percentage =
|
|
|
|
{
|
2003-03-03 05:24:45 +00:00
|
|
|
local float max_v = (max - min);
|
2011-03-25 07:46:32 +00:00
|
|
|
local int perc;
|
2003-03-03 05:24:45 +00:00
|
|
|
|
2002-08-16 21:54:21 +00:00
|
|
|
val -= min;
|
|
|
|
|
2003-03-03 05:24:45 +00:00
|
|
|
if (val > max_v) {
|
2002-08-16 21:54:21 +00:00
|
|
|
val = max_v;
|
|
|
|
}
|
2003-03-03 05:24:45 +00:00
|
|
|
if (val < 0) {
|
2002-08-16 21:54:21 +00:00
|
|
|
val = 0;
|
|
|
|
}
|
2011-03-25 07:46:32 +00:00
|
|
|
perc = (int) ((val / max_v) * 100);
|
2002-08-16 21:54:21 +00:00
|
|
|
|
|
|
|
return perc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
min_max_cnt
|
|
|
|
|
2003-03-03 05:24:45 +00:00
|
|
|
Increases or decreases a value by take care of the bordervalues.
|
2002-08-16 21:54:21 +00:00
|
|
|
min, max are the borders.
|
|
|
|
step is the step by in-/de-creasing.
|
2003-03-03 05:24:45 +00:00
|
|
|
cntflag should be true for increasing and false for decreasing
|
2002-08-16 21:54:21 +00:00
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
float (float min, float max, float step, float val, int cntflag)
|
2002-08-16 21:54:21 +00:00
|
|
|
min_max_cnt =
|
|
|
|
{
|
2003-03-03 05:24:45 +00:00
|
|
|
if (cntflag) {
|
2002-08-16 21:54:21 +00:00
|
|
|
val += step;
|
|
|
|
} else {
|
|
|
|
val -= step;
|
|
|
|
}
|
|
|
|
|
2003-03-03 05:24:45 +00:00
|
|
|
if (val > max) {
|
2002-08-16 21:54:21 +00:00
|
|
|
val = max;
|
2003-03-03 05:24:45 +00:00
|
|
|
} else if (val < min) {
|
2002-08-16 21:54:21 +00:00
|
|
|
val = min;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
};
|