Súbor: [Platon] / games / _shared / menu.c (stiahnutie)
Revízia 1.6, Tue Apr 6 09:54:15 2004 UTC (21 years ago) by nepto
Zmeny od 1.5: +11 -3
[lines]
Headers update:
- switch to standard/classic Platon SDG source header
- bumped copyright year to 2004
- changelog dates reformatted to new format YYYY-MM-DD
|
/*
* games/_shared/ - shared routines for games
*
* menu.c - mouse driven highlighting graphical menu
* ____________________________________________________________
*
* Developed by Ondrej Jombik <nepto@platon.sk>
* Copyright (c) 1997-2000 Condy software inc.
* Copyright (c) 2001-2004 Platon SDG, http://platon.sk/
* All rights reserved.
*
* See README file for more information about this software.
* See COPYING file for license information.
*
* Download the latest version from
* http://platon.sk/projects/games/
*/
/* $Platon: games/_shared/menu.c,v 1.5 2003/08/12 20:50:59 nepto Exp $ */
#include <typedef.h>
#include <mouse.h>
#include <my-graph.h>
#include <string.h>
#include <stdlib.h>
/* getch() */
#if PLATON_SYSTEM_MSDOS
# include <conio.h>
#endif
#if PLATON_SYSTEM_WIN32
# include <dos2win32.h>
#endif
#if PLATON_SYSTEM_SVGALIB || PLATON_SYSTEM_X11
# include <dos2linux.h>
#endif
BYTE menu(char*s[],
WORD xx,
WORD yy,
int fnt,
int fntsize,
WORD fntrng,
int cnorm,
int cins)
{
register BYTE c,cold,but=0,k,lines=0;
WORD x,y;
struct textsettingstype textset;
gettextsettings(&textset);
/* while(strcmp(s[lines],NULL))lines++; */ /* Old 1998 code... strange. */
while (s[lines] != NULL)
lines++;
c=cold=lines;
settextstyle(fnt,0,fntsize);
settextjustify(CENTER_TEXT,TOP_TEXT);
setcolor(cnorm);
hidemouse();
for(k=0;k<lines;k++)outtextxy(xx,k*fntrng+yy,s[k]);
showmouse();
while(releasebutton(0,&x,&y));
while(1){
if(kbhit()&&((but=getch())==NUL)){
switch(getch()){
case SUP:
while(!strcmp(s[c=(!c?lines-1:c-1)],""));
setmousepos(xx,yy+textheight(s[c])/2+c*fntrng);
break;
case SDOWN:
while(!strcmp(s[c=(c==lines-1?0:(c==lines?0:c+1))],""));
setmousepos(xx,yy+textheight(s[c])/2+c*fntrng);
break;
}
}
if(but!=EOL){
but=releasebutton(0,&x,&y);
(void)getmousepos(&x,&y);
c=lines;
for(k=0;k<lines;k++)
if((x<xx+textwidth(s[k])/2)&&
(x>=xx-textwidth(s[k])/2)&&
(yy+k*fntrng<y)&&
(yy+k*fntrng+textheight(s[k])>=y)
)c=k;
}
if((but)&&(c<lines)){
setcolor(cnorm);
hidemouse();
outtextxy(xx,yy+c*fntrng,s[c]);
showmouse();
break;
}
else but=0;
if(cold!=c){
hidemouse();
if(cold<lines){
setcolor(cnorm);
outtextxy(xx,yy+cold*fntrng,s[cold]);
}
cold=c;
if(c<lines){
setcolor(cins);
outtextxy(xx,yy+c*fntrng,s[c]);
}
showmouse();
}
}
settextstyle(textset.font,textset.direction,textset.charsize);
settextjustify(textset.vert,textset.horiz);
return(c);
}
Platon Group <platon@platon.sk> http://platon.sk/
|