home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
MODEL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-05
|
5KB
|
253 lines
/*
* メインルーチン
*
* 1996.1.6 T.Kobayashi
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <assert.h>
#include "lib.h"
#include "matrix.h"
#include "reader.h"
#include "matclass.h"
#include "ml.h"
#include "view.h"
#include "event.h"
#include "model.h"
#include "graph.h"
#include "input.h"
int QuitFlag ;
int InputKey, CursorMoveKey ;
int Argc ;
char **Argv ;
static int mainloop = FALSE ;
static jmp_buf env ;
static DataStruct *stacktop = NULL;
#ifndef WINDOWS
void main( argc, argv )
int argc ;
char *argv[] ;
#else
void ModelMain( int argc, char **argv )
#endif
{
int ident;
Argc = argc ;
Argv = argv ;
mainloop = FALSE ;
InputKey = LEFT_SWITCH ;
CursorMoveKey = RIGHT_SWITCH ;
ModelInit();
#ifndef WINDOWS
ViewFrame();
ViewLineAll( 0, 0, DISPLAY_X, DISPLAY_Y, TRUE );
DrawTitleBar();
DrawUserButtonAll();
DrawControlPanel();
#endif
MessageSet( InternalError, Message );
QuitFlag = FALSE ;
ExecSentenseAll();
ViewCursor( ON );
mainloop = TRUE ;
stacktop = StackTop();
if ( (ident = IdentSearch( IdentFunction, "main" ) ) >= 0 ) {
setjmp(env);
if (!QuitFlag) {
StackRelease( stacktop );
CallFunction( ident, 0, stacktop );
}
} else {
for(;;)
{
if ( QuitFlag )
break ;
if ( setjmp( env ) == 0 )
{
StackRelease( stacktop );
if ( WaitEvent() )
CallInputEvent();
else if ( KeyCode != 0 )
CallKeyEvent();
}
}
}
ViewCursor( OFF );
ModelExit();
exit( 0 );
}
/* 再表示 */
void RedrawAll()
{
/* ViewCursor( OFF );*/
ViewFrame();
ViewLineAll( 0, 0, DISPLAY_X, DISPLAY_Y, TRUE );
DrawTitleBar();
DrawUserButtonAll();
DrawControlPanel();
/* ViewCursor( ON );*/
}
/* イベント待ち */
int WaitEvent()
{
int mleft, mright;
mleft = MouseLeft;
mright = MouseRight;
WaitMouseOrKey();
if (QuitFlag) {
longjmp( env, 1 );
}
#ifdef WINDOWS
if (KEY_MENU_START <= KeyCode && KeyCode < KEY_MENU_START + KEY_MENU_STEP * MAX_MENU) {
int x, y;
x = (KeyCode - KEY_MENU_START)/KEY_MENU_STEP;
y = (KeyCode - KEY_MENU_START)%KEY_MENU_STEP;
ExecMenu(x, y);
KeyCode = 0;
return FALSE;
}
#endif
if (MouseLeft || MouseRight ) {
#ifndef WINDOWS
if (MouseY <= MENU_WIDTH) {
CallMenu( MouseX, MouseY );
return FALSE ;
}
#endif
if (MouseY >= DISPLAY_Y-STATUS_WIDTH) {
WaitMouseOff();
return FALSE ;
}
if (MouseX >= DISPLAY_X - CTRL_WIDTH )
{
ControlSelect( MouseX, MouseY );
return FALSE ;
}
if (MouseX >= DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth) {
CallButton( MouseX, MouseY );
return FALSE;
}
if (ScrollCheck(MouseX, MouseY)) {
#if 0
ViewCursorPos( MouseX, MouseY);
#else
#ifdef WINDOWS
extern unsigned long WinGetTimer(void);
unsigned long lasttime = WinGetTimer();
while ((MouseRight || MouseLeft) && ScrollCheck(MouseX,MouseY)
&& !QuitFlag) {
ViewCursorPos( MouseX, MouseY);
do {
PeekInput();
} while (lasttime + 66 > WinGetTimer()
&& !QuitFlag && (MouseRight || MouseLeft));
lasttime = WinGetTimer();
}
#else
while ((MouseRight || MouseLeft) && ScrollCheck(MouseX,MouseY)
&& !QuitFlag) {
ViewCursorPos( MouseX, MouseY);
PeekInput();
}
#endif
#endif
return FALSE;
}
}
if ( ( ( CursorMoveKey & 1 ) && MouseLeft ) || ( ( CursorMoveKey & 2 ) && MouseRight ) )
{
ViewCursorPos( MouseX, MouseY );
DrawCursorPos();
}
if ( InputKey == ' ' ) {
return KeyCode == ' ' ;
}
if ( InputKey == LEFT_SWITCH && (MouseLeft || (mleft && !MouseLeft)) )
{
WaitMouseOff();
return TRUE ;
}
if ( InputKey == RIGHT_SWITCH && (MouseRight || (mright && !MouseRight)) )
{
WaitMouseOff();
return TRUE ;
}
return FALSE ;
}
/* エラー処理ルーチン */
void InternalError( msg )
char *msg ;
{
Bell();
Message( msg );
if ( mainloop )
{
while( MenuStackPtr > 0 )
PopMenu();
DrawTitleBar();
longjmp( env, 1 );
}
else
{
ModelExit();
exit( 1 );
}
}
/* メッセージ表示 */
void Message( msg )
char *msg ;
{
static char str[1024];
static char *button_ok[2] = {"確認", NULL};
int lines;
char *p, *q;
strcpy(str, msg);
for (lines = 0, p = str; *p; p++) {
if (*p == '\n') lines++;
}
DlogOpen( "Message", lines + 1, button_ok );
for (lines = 0, p = q = str; *p; p++) {
if (*p == '\n') {
*p = '\0';
DlogMessage( lines++, q );
q = p + 1;
}
}
DlogMessage( lines, q );
/* DlogMessage( 0, msg );*/
DlogWait();
}
/* 警告音 */
void Warning()
{
Bell();
}