2018-05-01 05:15:48 +00:00
|
|
|
/*{
|
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tui.h"
|
|
|
|
#include "btn.h"
|
|
|
|
|
2018-06-01 16:02:13 +00:00
|
|
|
void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol)
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
|
|
|
u32 cx, cy;
|
|
|
|
|
|
|
|
gfx_con_getpos(con, &cx, &cy);
|
|
|
|
|
|
|
|
gfx_con_setpos(con, x, y);
|
|
|
|
|
2018-06-03 06:07:03 +00:00
|
|
|
gfx_printf(con, "%k[%3d%%]%k", fgcol, val, 0xFFCCCCCC);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
x += 7 * 8;
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
2018-06-01 16:02:13 +00:00
|
|
|
gfx_line(con->gfx_ctxt, x, y + i + 1, x + 3 * val, y + i + 1, fgcol);
|
|
|
|
gfx_line(con->gfx_ctxt, x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, bgcol);
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx_con_setpos(con, cx, cy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *tui_do_menu(gfx_con_t *con, menu_t *menu)
|
|
|
|
{
|
2018-06-12 23:34:32 +00:00
|
|
|
int idx = 0, prev_idx = 0, cnt = 0x7FFFFFFF;
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2018-06-06 10:29:38 +00:00
|
|
|
gfx_clear_grey(con->gfx_ctxt, 0x1B);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2018-05-24 21:29:41 +00:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-05-01 05:15:48 +00:00
|
|
|
gfx_con_setpos(con, menu->x, menu->y);
|
|
|
|
gfx_printf(con, "[%s]\n\n", menu->caption);
|
|
|
|
|
2018-06-15 11:28:27 +00:00
|
|
|
// Skip caption or seperator lines selection.
|
2018-05-24 21:33:11 +00:00
|
|
|
while (menu->ents[idx].type == MENT_CAPTION ||
|
|
|
|
menu->ents[idx].type == MENT_CHGLINE)
|
|
|
|
{
|
2018-06-15 11:28:27 +00:00
|
|
|
if (prev_idx <= idx || (!idx && prev_idx == cnt - 1))
|
2018-06-12 23:34:32 +00:00
|
|
|
{
|
2018-05-24 21:33:11 +00:00
|
|
|
idx++;
|
|
|
|
if (idx > (cnt - 1))
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
prev_idx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx--;
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
idx = cnt - 1;
|
|
|
|
prev_idx = cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prev_idx = idx;
|
|
|
|
|
2018-06-15 11:28:27 +00:00
|
|
|
//Draw the menu.
|
2018-05-01 05:15:48 +00:00
|
|
|
for (cnt = 0; menu->ents[cnt].type != MENT_END; cnt++)
|
|
|
|
{
|
|
|
|
if (cnt == idx)
|
2018-05-24 21:29:41 +00:00
|
|
|
gfx_con_setcol(con, 0xFF1B1B1B, 1, 0xFFCCCCCC);
|
2018-05-01 05:15:48 +00:00
|
|
|
else
|
2018-05-24 21:29:41 +00:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-06-12 23:34:32 +00:00
|
|
|
if (menu->ents[cnt].type == MENT_CAPTION)
|
2018-05-24 21:33:11 +00:00
|
|
|
gfx_printf(con, "%k %s", menu->ents[cnt].color, menu->ents[cnt].caption);
|
2018-06-12 23:34:32 +00:00
|
|
|
else if (menu->ents[cnt].type != MENT_CHGLINE)
|
2018-05-24 21:33:11 +00:00
|
|
|
gfx_printf(con, " %s", menu->ents[cnt].caption);
|
2018-05-01 05:15:48 +00:00
|
|
|
if(menu->ents[cnt].type == MENT_MENU)
|
|
|
|
gfx_printf(con, "%k...", 0xFFEE9900);
|
2018-05-24 21:33:11 +00:00
|
|
|
gfx_printf(con, " \n");
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
2018-05-24 21:29:41 +00:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-05-01 05:15:48 +00:00
|
|
|
gfx_putc(con, '\n');
|
|
|
|
|
|
|
|
u32 btn = btn_wait();
|
|
|
|
|
2018-05-21 08:43:56 +00:00
|
|
|
if (btn & BTN_VOL_DOWN && idx < (cnt - 1))
|
2018-05-01 05:15:48 +00:00
|
|
|
idx++;
|
2018-05-21 08:43:56 +00:00
|
|
|
else if (btn & BTN_VOL_DOWN && idx == (cnt - 1))
|
|
|
|
idx = 0;
|
2018-05-01 05:15:48 +00:00
|
|
|
if (btn & BTN_VOL_UP && idx > 0)
|
|
|
|
idx--;
|
2018-05-21 08:43:56 +00:00
|
|
|
else if (btn & BTN_VOL_UP && idx == 0)
|
|
|
|
idx = cnt - 1;
|
2018-05-01 05:15:48 +00:00
|
|
|
if (btn & BTN_POWER)
|
|
|
|
{
|
|
|
|
ment_t *ent = &menu->ents[idx];
|
|
|
|
switch (ent->type)
|
|
|
|
{
|
|
|
|
case MENT_HANDLER:
|
|
|
|
ent->handler(ent->data);
|
|
|
|
break;
|
|
|
|
case MENT_MENU:
|
|
|
|
return tui_do_menu(con, ent->menu);
|
|
|
|
break;
|
|
|
|
case MENT_CHOICE:
|
|
|
|
return ent->data;
|
|
|
|
break;
|
|
|
|
case MENT_BACK:
|
|
|
|
return NULL;
|
|
|
|
break;
|
2018-05-24 21:33:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
2018-06-06 10:29:38 +00:00
|
|
|
gfx_clear_grey(con->gfx_ctxt, 0x1B);
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|