|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: menu.c,v 1.39 2004/02/05 22:59:04 stpohle Exp $
|
|
|
|
/* $Id: menu.c,v 1.40 2004/02/07 11:47:10 stpohle Exp $
|
|
|
|
* Menuhandling */
|
|
|
|
* Menuhandling */
|
|
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
#include "basic.h"
|
|
|
@ -8,15 +8,21 @@
|
|
|
|
#include "network.h"
|
|
|
|
#include "network.h"
|
|
|
|
#include "ogcache-client.h"
|
|
|
|
#include "ogcache-client.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MENU_MESSAGES_MAXLINES 5
|
|
|
|
|
|
|
|
#define MENU_MESSAGES_MAXLINELEN 50
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_menuitem menuitems[MENU_MAXENTRYS];
|
|
|
|
_menuitem menuitems[MENU_MAXENTRYS];
|
|
|
|
_menu menu;
|
|
|
|
_menu menu;
|
|
|
|
int menu_looprunning = 0;
|
|
|
|
int menu_looprunning = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* delete all informations and create a totally new menuscreen */
|
|
|
|
/* delete all informations and create a totally new menuscreen */
|
|
|
|
void menu_new (char *title, int x, int y) {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_new (char *title, int x, int y)
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
if (menu.oldscreen != NULL)
|
|
|
|
if (menu.oldscreen != NULL)
|
|
|
|
menu_delete();
|
|
|
|
menu_delete ();
|
|
|
|
|
|
|
|
|
|
|
|
strncpy (menu.title, title, MENU_TITLELEN);
|
|
|
|
strncpy (menu.title, title, MENU_TITLELEN);
|
|
|
|
menu.items = NULL;
|
|
|
|
menu.items = NULL;
|
|
|
@ -28,12 +34,12 @@ void menu_new (char *title, int x, int y) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* save the old background screen */
|
|
|
|
/* save the old background screen */
|
|
|
|
x = (1 + (int)(x / menu.images[1]->w)) * menu.images[1]->w;
|
|
|
|
x = (1 + (int) (x / menu.images[1]->w)) * menu.images[1]->w;
|
|
|
|
y = (1 + (int)(y / menu.images[3]->h)) * menu.images[3]->h;
|
|
|
|
y = (1 + (int) (y / menu.images[3]->h)) * menu.images[3]->h;
|
|
|
|
menu.oldscreenpos.x = ((gfx.res.x - (x + 2*menu.images[0]->w)) / 2);
|
|
|
|
menu.oldscreenpos.x = ((gfx.res.x - (x + 2 * menu.images[0]->w)) / 2);
|
|
|
|
menu.oldscreenpos.y = ((gfx.res.y - (y + 2*menu.images[0]->h)) / 2);
|
|
|
|
menu.oldscreenpos.y = ((gfx.res.y - (y + 2 * menu.images[0]->h)) / 2);
|
|
|
|
menu.oldscreenpos.w = x + 2*menu.images[0]->w;
|
|
|
|
menu.oldscreenpos.w = x + 2 * menu.images[0]->w;
|
|
|
|
menu.oldscreenpos.h = y + 2*menu.images[0]->h;
|
|
|
|
menu.oldscreenpos.h = y + 2 * menu.images[0]->h;
|
|
|
|
menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos);
|
|
|
|
menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos);
|
|
|
|
menu.focus = NULL;
|
|
|
|
menu.focus = NULL;
|
|
|
|
menu_looprunning = 0;
|
|
|
|
menu_looprunning = 0;
|
|
|
@ -41,7 +47,9 @@ void menu_new (char *title, int x, int y) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* restore the screen and reset all needed informations, free the old screen */
|
|
|
|
/* restore the screen and reset all needed informations, free the old screen */
|
|
|
|
void menu_delete () {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_delete ()
|
|
|
|
|
|
|
|
{
|
|
|
|
gfx_restorescreen (menu.oldscreen, &menu.oldscreenpos);
|
|
|
|
gfx_restorescreen (menu.oldscreen, &menu.oldscreenpos);
|
|
|
|
gfx_blitdraw ();
|
|
|
|
gfx_blitdraw ();
|
|
|
|
SDL_FreeSurface (menu.oldscreen);
|
|
|
|
SDL_FreeSurface (menu.oldscreen);
|
|
|
@ -56,33 +64,45 @@ void menu_delete () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* draw only a part of the Screen */
|
|
|
|
/* draw only a part of the Screen */
|
|
|
|
void menu_draw_background (SDL_Rect *updaterect) {
|
|
|
|
void
|
|
|
|
int x,y, dx, dy;
|
|
|
|
menu_draw_background (SDL_Rect * updaterect)
|
|
|
|
SDL_Rect dest, cdest, src, csrc, window;
|
|
|
|
{
|
|
|
|
|
|
|
|
int x,
|
|
|
|
|
|
|
|
y,
|
|
|
|
|
|
|
|
dx,
|
|
|
|
|
|
|
|
dy;
|
|
|
|
|
|
|
|
SDL_Rect dest,
|
|
|
|
|
|
|
|
cdest,
|
|
|
|
|
|
|
|
src,
|
|
|
|
|
|
|
|
csrc,
|
|
|
|
|
|
|
|
window;
|
|
|
|
|
|
|
|
|
|
|
|
y = 0; // start at the updaterect. start pos
|
|
|
|
y = 0; // start at the updaterect. start pos
|
|
|
|
for (; y <= (menu.oldscreenpos.h - 2*menu.images[0]->h - 1)/menu.images[4]->h; y++) {
|
|
|
|
for (; y <= (menu.oldscreenpos.h - 2 * menu.images[0]->h - 1) / menu.images[4]->h; y++) {
|
|
|
|
x = 0; // start at the updaterect. start pos
|
|
|
|
x = 0; // start at the updaterect. start pos
|
|
|
|
for (; x <= (menu.oldscreenpos.w - 2*menu.images[0]->w - 1)/menu.images[4]->w; x++) {
|
|
|
|
for (; x <= (menu.oldscreenpos.w - 2 * menu.images[0]->w - 1) / menu.images[4]->w; x++) {
|
|
|
|
dest.x = x * menu.images[4]->w; // start pos
|
|
|
|
dest.x = x * menu.images[4]->w; // start pos
|
|
|
|
dest.y = y * menu.images[4]->h;
|
|
|
|
dest.y = y * menu.images[4]->h;
|
|
|
|
|
|
|
|
|
|
|
|
dx = (1+x) * menu.images[4]->w; // end pos
|
|
|
|
dx = (1 + x) * menu.images[4]->w; // end pos
|
|
|
|
if (dx >= (menu.oldscreenpos.w - 2*menu.images[0]->w))
|
|
|
|
if (dx >= (menu.oldscreenpos.w - 2 * menu.images[0]->w))
|
|
|
|
dest.w = menu.images[4]->w - (dx - (menu.oldscreenpos.w - 2*menu.images[0]->w));
|
|
|
|
dest.w = menu.images[4]->w - (dx - (menu.oldscreenpos.w - 2 * menu.images[0]->w));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
dest.w = menu.images[4]->w;
|
|
|
|
dest.w = menu.images[4]->w;
|
|
|
|
|
|
|
|
|
|
|
|
dy = (1+y) * menu.images[4]->h;
|
|
|
|
dy = (1 + y) * menu.images[4]->h;
|
|
|
|
if (dy >= (menu.oldscreenpos.h - 2*menu.images[0]->h))
|
|
|
|
if (dy >= (menu.oldscreenpos.h - 2 * menu.images[0]->h))
|
|
|
|
dest.h = menu.images[4]->h - (dy - (menu.oldscreenpos.h - 2*menu.images[0]->h));
|
|
|
|
dest.h = menu.images[4]->h - (dy - (menu.oldscreenpos.h - 2 * menu.images[0]->h));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
dest.h = menu.images[4]->h;
|
|
|
|
dest.h = menu.images[4]->h;
|
|
|
|
|
|
|
|
|
|
|
|
if (dest.w > 0 || dest.h > 0) {
|
|
|
|
if (dest.w > 0 || dest.h > 0) {
|
|
|
|
dest.x += MENUOFFSET_X;
|
|
|
|
dest.x += MENUOFFSET_X;
|
|
|
|
dest.y += MENUOFFSET_Y;
|
|
|
|
dest.y += MENUOFFSET_Y;
|
|
|
|
src.x = 0; src.y = 0; src.h = dest.h; src.w = dest.w;
|
|
|
|
src.x = 0;
|
|
|
|
|
|
|
|
src.y = 0;
|
|
|
|
|
|
|
|
src.h = dest.h;
|
|
|
|
|
|
|
|
src.w = dest.w;
|
|
|
|
|
|
|
|
|
|
|
|
if (updaterect == NULL)
|
|
|
|
if (updaterect == NULL)
|
|
|
|
gfx_blit (menu.images[4], &src, gfx.screen, &dest, 10000);
|
|
|
|
gfx_blit (menu.images[4], &src, gfx.screen, &dest, 10000);
|
|
|
@ -91,7 +111,8 @@ void menu_draw_background (SDL_Rect *updaterect) {
|
|
|
|
window.x += MENUOFFSET_X;
|
|
|
|
window.x += MENUOFFSET_X;
|
|
|
|
window.y += MENUOFFSET_Y;
|
|
|
|
window.y += MENUOFFSET_Y;
|
|
|
|
rect_clipping (&src, &dest, &window, &csrc, &cdest);
|
|
|
|
rect_clipping (&src, &dest, &window, &csrc, &cdest);
|
|
|
|
if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF && cdest.h < UINT16_HALF)
|
|
|
|
if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF
|
|
|
|
|
|
|
|
&& cdest.h < UINT16_HALF)
|
|
|
|
gfx_blit (menu.images[4], &csrc, gfx.screen, &cdest, 10000);
|
|
|
|
gfx_blit (menu.images[4], &csrc, gfx.screen, &cdest, 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,9 +122,12 @@ void menu_draw_background (SDL_Rect *updaterect) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* draws the menuborders, this function does not save the background */
|
|
|
|
/* draws the menuborders, this function does not save the background */
|
|
|
|
void menu_draw_border () {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_draw_border ()
|
|
|
|
|
|
|
|
{
|
|
|
|
SDL_Rect dest;
|
|
|
|
SDL_Rect dest;
|
|
|
|
int i, dx;
|
|
|
|
int i,
|
|
|
|
|
|
|
|
dx;
|
|
|
|
|
|
|
|
|
|
|
|
// draw top left
|
|
|
|
// draw top left
|
|
|
|
dest.x = menu.oldscreenpos.x;
|
|
|
|
dest.x = menu.oldscreenpos.x;
|
|
|
@ -113,7 +137,7 @@ void menu_draw_border () {
|
|
|
|
gfx_blit (menu.images[0], NULL, gfx.screen, &dest, 10000);
|
|
|
|
gfx_blit (menu.images[0], NULL, gfx.screen, &dest, 10000);
|
|
|
|
|
|
|
|
|
|
|
|
// draw top and below
|
|
|
|
// draw top and below
|
|
|
|
for (i = 0; i < ((menu.oldscreenpos.w - (2*menu.images[0]->w)) / menu.images[1]->w); i++) {
|
|
|
|
for (i = 0; i < ((menu.oldscreenpos.w - (2 * menu.images[0]->w)) / menu.images[1]->w); i++) {
|
|
|
|
dest.x = menu.oldscreenpos.x + menu.images[0]->w + (i * menu.images[1]->w);
|
|
|
|
dest.x = menu.oldscreenpos.x + menu.images[0]->w + (i * menu.images[1]->w);
|
|
|
|
dest.y = menu.oldscreenpos.y;
|
|
|
|
dest.y = menu.oldscreenpos.y;
|
|
|
|
dest.w = menu.images[1]->w;
|
|
|
|
dest.w = menu.images[1]->w;
|
|
|
@ -131,7 +155,7 @@ void menu_draw_border () {
|
|
|
|
gfx_blit (menu.images[2], NULL, gfx.screen, &dest, 10000);
|
|
|
|
gfx_blit (menu.images[2], NULL, gfx.screen, &dest, 10000);
|
|
|
|
|
|
|
|
|
|
|
|
// draw left and right
|
|
|
|
// draw left and right
|
|
|
|
for (i = 0; i < ((menu.oldscreenpos.h - (2*menu.images[0]->h)) / menu.images[3]->h); i++) {
|
|
|
|
for (i = 0; i < ((menu.oldscreenpos.h - (2 * menu.images[0]->h)) / menu.images[3]->h); i++) {
|
|
|
|
dest.x = menu.oldscreenpos.x;
|
|
|
|
dest.x = menu.oldscreenpos.x;
|
|
|
|
dest.y = menu.oldscreenpos.y + menu.images[0]->h + menu.images[3]->h * i;
|
|
|
|
dest.y = menu.oldscreenpos.y + menu.images[0]->h + menu.images[3]->h * i;
|
|
|
|
dest.w = menu.images[1]->w;
|
|
|
|
dest.w = menu.images[1]->w;
|
|
|
@ -157,17 +181,22 @@ void menu_draw_border () {
|
|
|
|
|
|
|
|
|
|
|
|
menu_draw_background (NULL);
|
|
|
|
menu_draw_background (NULL);
|
|
|
|
// draw title
|
|
|
|
// draw title
|
|
|
|
dx = menu.oldscreenpos.x + (menu.oldscreenpos.w - font[2].size.x*strlen (menu.title)) / 2;
|
|
|
|
dx = menu.oldscreenpos.x + (menu.oldscreenpos.w - font[2].size.x * strlen (menu.title)) / 2;
|
|
|
|
font_gfxdrawbold (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_brown, 2, 10000);
|
|
|
|
font_gfxdrawbold (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_brown,
|
|
|
|
font_gfxdraw (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_yellow, 10000);
|
|
|
|
2, 10000);
|
|
|
|
|
|
|
|
font_gfxdraw (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_yellow,
|
|
|
|
|
|
|
|
10000);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* draw the menu, even it is only put into the gfx_blitlist. gfx_blitdraw needs
|
|
|
|
/* draw the menu, even it is only put into the gfx_blitlist. gfx_blitdraw needs
|
|
|
|
* to be called before the menu is drawed on the screen */
|
|
|
|
* to be called before the menu is drawed on the screen */
|
|
|
|
void menu_draw () {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_draw ()
|
|
|
|
|
|
|
|
{
|
|
|
|
_menuitem *m;
|
|
|
|
_menuitem *m;
|
|
|
|
if (!menu_looprunning) return;
|
|
|
|
if (!menu_looprunning)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
menu_draw_border ();
|
|
|
|
menu_draw_border ();
|
|
|
|
|
|
|
|
|
|
|
@ -178,8 +207,11 @@ void menu_draw () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* draw an item on the screen */
|
|
|
|
/* draw an item on the screen */
|
|
|
|
inline void menu_draw_menuitem (_menuitem *m) {
|
|
|
|
inline void
|
|
|
|
if (!menu_looprunning) return;
|
|
|
|
menu_draw_menuitem (_menuitem * m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!menu_looprunning)
|
|
|
|
|
|
|
|
return;
|
|
|
|
switch (m->type) {
|
|
|
|
switch (m->type) {
|
|
|
|
case (MENU_label):
|
|
|
|
case (MENU_label):
|
|
|
|
menu_draw_label (m);
|
|
|
|
menu_draw_label (m);
|
|
|
@ -204,7 +236,9 @@ inline void menu_draw_menuitem (_menuitem *m) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* reload all variables into all menuelements */
|
|
|
|
/* reload all variables into all menuelements */
|
|
|
|
void menu_reload () {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_reload ()
|
|
|
|
|
|
|
|
{
|
|
|
|
_menuitem *m;
|
|
|
|
_menuitem *m;
|
|
|
|
|
|
|
|
|
|
|
|
for (m = menu.items; m != NULL; m = m->next)
|
|
|
|
for (m = menu.items; m != NULL; m = m->next)
|
|
|
@ -214,7 +248,9 @@ void menu_reload () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* reload variable into menuelement */
|
|
|
|
/* reload variable into menuelement */
|
|
|
|
inline void menu_reload_menuitem (_menuitem *m) {
|
|
|
|
inline void
|
|
|
|
|
|
|
|
menu_reload_menuitem (_menuitem * m)
|
|
|
|
|
|
|
|
{
|
|
|
|
switch (m->type) {
|
|
|
|
switch (m->type) {
|
|
|
|
case (MENU_entrytext):
|
|
|
|
case (MENU_entrytext):
|
|
|
|
case (MENU_entryint16):
|
|
|
|
case (MENU_entryint16):
|
|
|
@ -230,14 +266,16 @@ inline void menu_reload_menuitem (_menuitem *m) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* find the last menuitem in the list. */
|
|
|
|
/* find the last menuitem in the list. */
|
|
|
|
int menu_getlastitem (_menuitem *first) {
|
|
|
|
int
|
|
|
|
|
|
|
|
menu_getlastitem (_menuitem * first)
|
|
|
|
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int i = 0;
|
|
|
|
_menuitem *result = first;
|
|
|
|
_menuitem *result = first;
|
|
|
|
|
|
|
|
|
|
|
|
if (first == NULL) // no first item there
|
|
|
|
if (first == NULL) // no first item there
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
for (;result->next != NULL; result = result->next)
|
|
|
|
for (; result->next != NULL; result = result->next)
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
return i;
|
|
|
@ -245,15 +283,21 @@ int menu_getlastitem (_menuitem *first) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get the last and the first id number */
|
|
|
|
/* get the last and the first id number */
|
|
|
|
_menuitem *menu_get_firstid () {
|
|
|
|
_menuitem *
|
|
|
|
_menuitem *result = NULL, *mi = menu.items;
|
|
|
|
menu_get_firstid ()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_menuitem *result = NULL,
|
|
|
|
|
|
|
|
*mi = menu.items;
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
if ((result == NULL || mi->id < result->id) && mi->id != -1)
|
|
|
|
if ((result == NULL || mi->id < result->id) && mi->id != -1)
|
|
|
|
result = mi;
|
|
|
|
result = mi;
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
_menuitem *menu_get_lastid () {
|
|
|
|
_menuitem *
|
|
|
|
_menuitem *result = NULL, *mi = menu.items;
|
|
|
|
menu_get_lastid ()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_menuitem *result = NULL,
|
|
|
|
|
|
|
|
*mi = menu.items;
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
if ((result == NULL || mi->id > result->id) && mi->id != -1)
|
|
|
|
if ((result == NULL || mi->id > result->id) && mi->id != -1)
|
|
|
|
result = mi;
|
|
|
|
result = mi;
|
|
|
@ -263,7 +307,9 @@ _menuitem *menu_get_lastid () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* change the focus to the givin element */
|
|
|
|
/* change the focus to the givin element */
|
|
|
|
void menu_change_focus (_menuitem *newfocus) {
|
|
|
|
void
|
|
|
|
|
|
|
|
menu_change_focus (_menuitem * newfocus)
|
|
|
|
|
|
|
|
{
|
|
|
|
_menuitem *oldmi;
|
|
|
|
_menuitem *oldmi;
|
|
|
|
|
|
|
|
|
|
|
|
if (newfocus == menu.focus) // no focus change
|
|
|
|
if (newfocus == menu.focus) // no focus change
|
|
|
@ -295,36 +341,49 @@ void menu_change_focus (_menuitem *newfocus) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* focus next element, order by ID */
|
|
|
|
/* focus next element, order by ID */
|
|
|
|
void menu_focus_next () {
|
|
|
|
void
|
|
|
|
_menuitem *newmi = menu.focus, *mi, *oldmi = menu.focus;
|
|
|
|
menu_focus_next ()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_menuitem *newmi = menu.focus,
|
|
|
|
|
|
|
|
*mi,
|
|
|
|
|
|
|
|
*oldmi = menu.focus;
|
|
|
|
|
|
|
|
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
if (mi->id != oldmi->id && mi->id > menu.focus->id && (mi->id < newmi->id || newmi == oldmi))
|
|
|
|
if (mi->id != oldmi->id && mi->id > menu.focus->id
|
|
|
|
|
|
|
|
&& (mi->id < newmi->id || newmi == oldmi))
|
|
|
|
newmi = mi;
|
|
|
|
newmi = mi;
|
|
|
|
if (newmi == oldmi)
|
|
|
|
if (newmi == oldmi)
|
|
|
|
menu_change_focus (menu_get_firstid());
|
|
|
|
menu_change_focus (menu_get_firstid ());
|
|
|
|
else
|
|
|
|
else
|
|
|
|
menu_change_focus (newmi);
|
|
|
|
menu_change_focus (newmi);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* focus previous element, order by ID */
|
|
|
|
/* focus previous element, order by ID */
|
|
|
|
void menu_focus_prev () {
|
|
|
|
void
|
|
|
|
_menuitem *newmi = menu.focus, *mi, *oldmi = menu.focus;
|
|
|
|
menu_focus_prev ()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_menuitem *newmi = menu.focus,
|
|
|
|
|
|
|
|
*mi,
|
|
|
|
|
|
|
|
*oldmi = menu.focus;
|
|
|
|
|
|
|
|
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
if (mi->id != -1 && mi->id != oldmi->id && mi->id < oldmi->id && (mi->id > newmi->id || newmi == oldmi))
|
|
|
|
if (mi->id != -1 && mi->id != oldmi->id && mi->id < oldmi->id
|
|
|
|
|
|
|
|
&& (mi->id > newmi->id || newmi == oldmi))
|
|
|
|
newmi = mi;
|
|
|
|
newmi = mi;
|
|
|
|
if (newmi == oldmi)
|
|
|
|
if (newmi == oldmi)
|
|
|
|
menu_change_focus (menu_get_lastid());
|
|
|
|
menu_change_focus (menu_get_lastid ());
|
|
|
|
else
|
|
|
|
else
|
|
|
|
menu_change_focus (newmi);
|
|
|
|
menu_change_focus (newmi);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* focus element with id ID */
|
|
|
|
/* focus element with id ID */
|
|
|
|
void menu_focus_id (int id) {
|
|
|
|
void
|
|
|
|
_menuitem *mi, *oldmi = menu.focus;
|
|
|
|
menu_focus_id (int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_menuitem *mi,
|
|
|
|
|
|
|
|
*oldmi = menu.focus;
|
|
|
|
|
|
|
|
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
for (mi = menu.items; mi != NULL; mi = mi->next)
|
|
|
|
if (mi->id == id)
|
|
|
|
if (mi->id == id)
|
|
|
@ -338,10 +397,15 @@ void menu_focus_id (int id) {
|
|
|
|
|
|
|
|
|
|
|
|
/* menu loop, programm will stay in here as long as no ESCAPE is pressed
|
|
|
|
/* menu loop, programm will stay in here as long as no ESCAPE is pressed
|
|
|
|
* and as long as no Button is clicked. Return of -2 means something needs to reordered */
|
|
|
|
* and as long as no Button is clicked. Return of -2 means something needs to reordered */
|
|
|
|
int menu_loop () {
|
|
|
|
int
|
|
|
|
|
|
|
|
menu_loop ()
|
|
|
|
|
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
SDL_Event event;
|
|
|
|
Uint8 *keys;
|
|
|
|
Uint8 *keys;
|
|
|
|
int keypressed = 0, done = 0, eventstate = 0, reorder = 0;
|
|
|
|
int keypressed = 0,
|
|
|
|
|
|
|
|
done = 0,
|
|
|
|
|
|
|
|
eventstate = 0,
|
|
|
|
|
|
|
|
reorder = 0;
|
|
|
|
|
|
|
|
|
|
|
|
menu_looprunning = 1;
|
|
|
|
menu_looprunning = 1;
|
|
|
|
|
|
|
|
|
|
|
@ -363,7 +427,7 @@ int menu_loop () {
|
|
|
|
|
|
|
|
|
|
|
|
timestamp = SDL_GetTicks (); // needed for time sync.
|
|
|
|
timestamp = SDL_GetTicks (); // needed for time sync.
|
|
|
|
|
|
|
|
|
|
|
|
menu_draw();
|
|
|
|
menu_draw ();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reorder && !done && bman.state != GS_quit) {
|
|
|
|
while (!reorder && !done && bman.state != GS_quit) {
|
|
|
|
gfx_blitdraw ();
|
|
|
|
gfx_blitdraw ();
|
|
|
@ -435,7 +499,7 @@ int menu_loop () {
|
|
|
|
menu_looprunning = 0;
|
|
|
|
menu_looprunning = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (reorder) {
|
|
|
|
if (reorder) {
|
|
|
|
menu.focus->changed=1;
|
|
|
|
menu.focus->changed = 1;
|
|
|
|
return -2;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return menu.focus->id;
|
|
|
|
return menu.focus->id;
|
|
|
@ -445,16 +509,19 @@ int menu_loop () {
|
|
|
|
/* create a list with all directory entrys,
|
|
|
|
/* create a list with all directory entrys,
|
|
|
|
* except we can't put everything in the list because the list is too smal.
|
|
|
|
* except we can't put everything in the list because the list is too smal.
|
|
|
|
* Return: number of entrys, Pointers will be set*/
|
|
|
|
* Return: number of entrys, Pointers will be set*/
|
|
|
|
int menu_create_dirlist (char *path, signed char dirflags, _charlist *cl, int maxentry) {
|
|
|
|
int
|
|
|
|
|
|
|
|
menu_create_dirlist (char *path, signed char dirflags, _charlist * cl, int maxentry)
|
|
|
|
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
int cnt;
|
|
|
|
_direntry *destart, *de;
|
|
|
|
_direntry *destart,
|
|
|
|
|
|
|
|
*de;
|
|
|
|
|
|
|
|
|
|
|
|
destart = s_getdir (path);
|
|
|
|
destart = s_getdir (path);
|
|
|
|
destart = s_dirfilter (destart, dirflags);
|
|
|
|
destart = s_dirfilter (destart, dirflags);
|
|
|
|
for (cnt = 0, de = destart; (de != NULL && cnt < maxentry); de = de->next) {
|
|
|
|
for (cnt = 0, de = destart; (de != NULL && cnt < maxentry); de = de->next) {
|
|
|
|
strncpy (cl[cnt].text, de->name, 255);
|
|
|
|
strncpy (cl[cnt].text, de->name, 255);
|
|
|
|
if (de->next != NULL)
|
|
|
|
if (de->next != NULL)
|
|
|
|
cl[cnt].next = &cl[cnt+1];
|
|
|
|
cl[cnt].next = &cl[cnt + 1];
|
|
|
|
else
|
|
|
|
else
|
|
|
|
cl[cnt].next = NULL;
|
|
|
|
cl[cnt].next = NULL;
|
|
|
|
cnt++;
|
|
|
|
cnt++;
|
|
|
@ -468,9 +535,11 @@ int menu_create_dirlist (char *path, signed char dirflags, _charlist *cl, int ma
|
|
|
|
* returns the name of the file */
|
|
|
|
* returns the name of the file */
|
|
|
|
static char menu_dir_name[LEN_PATHFILENAME];
|
|
|
|
static char menu_dir_name[LEN_PATHFILENAME];
|
|
|
|
char *
|
|
|
|
char *
|
|
|
|
menu_dir_select (char *title, char *path, signed char dirflags) {
|
|
|
|
menu_dir_select (char *title, char *path, signed char dirflags)
|
|
|
|
|
|
|
|
{
|
|
|
|
_charlist flist[MAX_DIRENTRYS];
|
|
|
|
_charlist flist[MAX_DIRENTRYS];
|
|
|
|
int flcnt, menuselect;
|
|
|
|
int flcnt,
|
|
|
|
|
|
|
|
menuselect;
|
|
|
|
_charlist *selfile = NULL;
|
|
|
|
_charlist *selfile = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
flcnt = menu_create_dirlist (path, dirflags, flist, MAX_DIRENTRYS);
|
|
|
|
flcnt = menu_create_dirlist (path, dirflags, flist, MAX_DIRENTRYS);
|
|
|
@ -481,7 +550,7 @@ menu_dir_select (char *title, char *path, signed char dirflags) {
|
|
|
|
menuselect = menu_loop ();
|
|
|
|
menuselect = menu_loop ();
|
|
|
|
menu_delete ();
|
|
|
|
menu_delete ();
|
|
|
|
|
|
|
|
|
|
|
|
if (menuselect < 0 || selfile-&flist[0] < 0 || selfile-&flist[0] >= flcnt)
|
|
|
|
if (menuselect < 0 || selfile - &flist[0] < 0 || selfile - &flist[0] >= flcnt)
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
strncpy (menu_dir_name, selfile->text, LEN_PATHFILENAME);
|
|
|
|
strncpy (menu_dir_name, selfile->text, LEN_PATHFILENAME);
|
|
|
@ -490,24 +559,111 @@ menu_dir_select (char *title, char *path, signed char dirflags) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* display a message on the screen and wait untill ESC is pressed */
|
|
|
|
/* display a message on the screen and wait untill ESC is pressed */
|
|
|
|
void menu_displaymessage (char *title, char *line1, char *line2, char *line3, char *line4) {
|
|
|
|
void
|
|
|
|
menu_new (title, 500, 150);
|
|
|
|
menu_displaymessage (char *title, char *fmt,...)
|
|
|
|
if (line1 != NULL) menu_create_label (line1, -1, 55, 0);
|
|
|
|
{
|
|
|
|
if (line2 != NULL) menu_create_label (line2, -1, 75, 0);
|
|
|
|
va_list args;
|
|
|
|
if (line3 != NULL) menu_create_label (line3, -1, 95, 0);
|
|
|
|
|
|
|
|
if (line4 != NULL) menu_create_label (line4, -1, 115, 0);
|
|
|
|
int maxlinelen = 0, // max y size for the window
|
|
|
|
|
|
|
|
i,
|
|
|
|
|
|
|
|
linenr;
|
|
|
|
|
|
|
|
char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)];
|
|
|
|
|
|
|
|
char *lines[MENU_MESSAGES_MAXLINES+1]; // textlines for the screen
|
|
|
|
|
|
|
|
char text[512];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* read the whole text and convert it to a normal char text */
|
|
|
|
|
|
|
|
memset (text, 0, sizeof (text));
|
|
|
|
|
|
|
|
memset (out, 0, sizeof (out));
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
vsprintf (text, fmt, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu_formattext (text, out, lines, &linenr, &maxlinelen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = maxlinelen * font[0].size.x + 32;
|
|
|
|
|
|
|
|
if (i < (strlen (title) * font[2].size.x + 16))
|
|
|
|
|
|
|
|
i = strlen (title) * font[2].size.x + 16;
|
|
|
|
|
|
|
|
menu_new (title, i , linenr * font[0].size.y + 75);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++)
|
|
|
|
|
|
|
|
menu_create_label (lines[i], -1, 55 + i * font[0].size.y, 0);
|
|
|
|
menu_loop ();
|
|
|
|
menu_loop ();
|
|
|
|
menu_delete ();
|
|
|
|
menu_delete ();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* format display messages */
|
|
|
|
|
|
|
|
void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen) {
|
|
|
|
|
|
|
|
int i, pos, outpos;
|
|
|
|
|
|
|
|
char *tmpchar1, *tmpchar2;
|
|
|
|
|
|
|
|
*maxlinelen = i = pos = outpos = *lines = 0;
|
|
|
|
|
|
|
|
start[0] = out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* create all lines and do some word wrapping */
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
if (input[i] == ' ') { // new word check if there is still space left for another word
|
|
|
|
|
|
|
|
/* check what will be found first #13 or space */
|
|
|
|
|
|
|
|
tmpchar1 = strchr (&input[i+1], ' ');
|
|
|
|
|
|
|
|
tmpchar2 = strchr (&input[i+1], '\n');
|
|
|
|
|
|
|
|
if (tmpchar2 != NULL && tmpchar2 < tmpchar1)
|
|
|
|
|
|
|
|
tmpchar1 = tmpchar2;
|
|
|
|
|
|
|
|
if (tmpchar1 == NULL)
|
|
|
|
|
|
|
|
tmpchar1 = input + strlen (input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tmpchar1 - (&input[i] - pos) >= MENU_MESSAGES_MAXLINELEN) { /* new line */
|
|
|
|
|
|
|
|
out[outpos++] = 0;
|
|
|
|
|
|
|
|
start[++(*lines)] = &out[outpos];
|
|
|
|
|
|
|
|
if (pos > *maxlinelen)
|
|
|
|
|
|
|
|
*maxlinelen = pos;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else /* add this to the line */
|
|
|
|
|
|
|
|
out[outpos++] = input[i];
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (input[i] == '\n') {
|
|
|
|
|
|
|
|
out[outpos++] = 0;
|
|
|
|
|
|
|
|
start[++(*lines)] = &out[outpos];
|
|
|
|
|
|
|
|
if (pos > *maxlinelen)
|
|
|
|
|
|
|
|
*maxlinelen = pos;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else { /* copy the text */
|
|
|
|
|
|
|
|
out[outpos++] = input[i];
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
} while (i < strlen (input) && i < MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1) && *lines < MENU_MESSAGES_MAXLINES);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* display a text on the screen and return */
|
|
|
|
/* display a text on the screen and return */
|
|
|
|
void menu_displaytext (char *title, char *line1, char *line2, char *line3, char *line4) {
|
|
|
|
void
|
|
|
|
menu_new (title, 500, 150);
|
|
|
|
menu_displaytext (char *title, char *fmt,...)
|
|
|
|
if (line1 != NULL) menu_create_label (line1, -1, 55, 0);
|
|
|
|
{
|
|
|
|
if (line2 != NULL) menu_create_label (line2, -1, 75, 0);
|
|
|
|
va_list args;
|
|
|
|
if (line3 != NULL) menu_create_label (line3, -1, 95, 0);
|
|
|
|
|
|
|
|
if (line4 != NULL) menu_create_label (line4, -1, 115, 0);
|
|
|
|
int maxlinelen = 0, // max y size for the window
|
|
|
|
|
|
|
|
i,
|
|
|
|
|
|
|
|
linenr;
|
|
|
|
|
|
|
|
char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)];
|
|
|
|
|
|
|
|
char *lines[MENU_MESSAGES_MAXLINES+1]; // textlines for the screen
|
|
|
|
|
|
|
|
char text[512];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* read the whole text and convert it to a normal char text */
|
|
|
|
|
|
|
|
memset (text, 0, sizeof (text));
|
|
|
|
|
|
|
|
memset (out, 0, sizeof (out));
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
vsprintf (text, fmt, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu_formattext (text, out, lines, &linenr, &maxlinelen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = maxlinelen * font[0].size.x + 32;
|
|
|
|
|
|
|
|
if (i < (strlen (title) * font[2].size.x + 16))
|
|
|
|
|
|
|
|
i = strlen (title) * font[2].size.x + 16;
|
|
|
|
|
|
|
|
menu_new (title, i , linenr * font[0].size.y + 75);
|
|
|
|
|
|
|
|
for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++)
|
|
|
|
|
|
|
|
menu_create_label (lines[i], -1, 55 + i * font[0].size.y, 0);
|
|
|
|
menu_looprunning = 1;
|
|
|
|
menu_looprunning = 1;
|
|
|
|
menu_draw ();
|
|
|
|
menu_draw ();
|
|
|
|
gfx_blitdraw ();
|
|
|
|
gfx_blitdraw ();
|
|
|
|