home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
BUTTON.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-21
|
5KB
|
194 lines
/*
* ユーザーボタン管理
*
* Copyright M.Takatsu 1996.1.24
*/
#include <stdio.h>
#include <string.h>
#include "poly.h"
#include "view.h"
#include "menu.h"
#include "event.h"
#include "button.h"
#include "ml.h"
#include "graph.h"
#include "input.h"
#include "model.h"
ButtonData UserButton[MAX_BUTTON];
int ButtonAreaWidth;
void ButtonInit( void )
{
int i;
ButtonAreaWidth = 0;
for (i = 0; i < MAX_BUTTON; ++i) {
UserButton[i].type = BUTTON_UNUSED;
}
}
void DrawUserButton( int pos )
{
int x, y;
int fg;
int len;
if (ButtonAreaWidth <= 0 || pos < 0 || pos >=MAX_BUTTON
|| UserButton[pos].type == BUTTON_UNUSED
|| UserButton[pos].x < 0 || UserButton[pos].x > ButtonAreaWidth-BUTTON_WIDTH
|| UserButton[pos].y < 0 || UserButton[pos].y > DISPLAY_Y-MENU_WIDTH-STATUS_WIDTH-BUTTON_HEIGHT) {
return;
}
x = DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth + UserButton[pos].x;
y = MENU_WIDTH + UserButton[pos].y;
if (UserButton[pos].enable & BUTTON_ENABLE) {
fg = 0;
} else {
fg = BG_COLOR;
}
if (UserButton[pos].type == BUTTON_STRING) {
len = strlen((char*)UserButton[pos].bitmap);
graph_puts((char*)UserButton[pos].bitmap,
x + (BUTTON_WIDTH - FontH*len)/2,
y + (BUTTON_HEIGHT- FontV)/2,
fg | (FRAME_COLOR<<4));
} else {
graph_pattern(
x + (BUTTON_WIDTH - BUTTON_BITMAP_WIDTH )/2,
y + (BUTTON_HEIGHT - BUTTON_BITMAP_HEIGHT)/2,
(fg << 4) | FRAME_COLOR, (short*)UserButton[pos].bitmap,
BUTTON_BITMAP_WIDTH, BUTTON_BITMAP_HEIGHT );
}
graph_box( x, y, x + BUTTON_WIDTH-1, y + BUTTON_HEIGHT-1, TRUE );
}
void DrawUserButtonAll( void )
{
int i, x, y1, y2;
if (ButtonAreaWidth == 0) {
return;
}
x = DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth;
y1 = MENU_WIDTH;
y2 = DISPLAY_Y - STATUS_WIDTH - 1;
graph_fill( x, y1, x + ButtonAreaWidth-1, y2, FRAME_COLOR );
for (i = 0; i < MAX_BUTTON; ++i) {
DrawUserButton(i);
}
}
void SetButtonArea(int width)
{
if (width >= 0 && width <= BUTTON_WIDTH*4) {
ButtonAreaWidth = width;
ViewSetDisplay(DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth, DISPLAY_Y);
}
}
void CallButton( int x, int y )
{
int i, sx, sy, exec;
if (ButtonAreaWidth == 0) {
return;
}
sx = DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth;
sy = MENU_WIDTH;
for (i = 0; i < MAX_BUTTON; ++i) {
if (UserButton[i].type != BUTTON_UNUSED
&& (UserButton[i].enable & BUTTON_ENABLE)
&& sx + UserButton[i].x <= x && x < sx + UserButton[i].x + BUTTON_WIDTH
&& sy + UserButton[i].y <= y && y < sy + UserButton[i].y + BUTTON_HEIGHT) {
int x1 = sx + UserButton[i].x;
int y1 = sy + UserButton[i].y;
#if 0
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, FALSE );
WaitMouseOff();
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, TRUE );
exec = UserButton[i].exec;
if ( exec >= 0 )
{
DataStruct *top = StackTop();
StackPushInt( i );
CallFunction( exec, 1, top+1 );
StackRelease( top );
}
#else
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, FALSE );
exec = UserButton[i].exec;
if ( exec >= 0 )
{
DataStruct *top = StackTop();
if (UserButton[i].enable & BUTTON_REPEAT) {
#ifdef WINDOWS
extern unsigned long WinGetTimer(void);
unsigned long lasttime = WinGetTimer();
#endif
do {
StackPushInt( i );
CallFunction( exec, 1, top+1 );
StackRelease( top );
#ifdef WINDOWS
do {
PeekInput();
} while (lasttime + 66 > WinGetTimer()
&& !QuitFlag && (MouseRight || MouseLeft));
lasttime = WinGetTimer();
#else
PeekInput();
#endif
} while ((MouseRight || MouseLeft));
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, TRUE );
} else {
WaitMouseOff();
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, TRUE );
StackPushInt( i );
CallFunction( exec, 1, top+1 );
StackRelease( top );
}
} else {
WaitMouseOff();
graph_box( x1, y1, x1+BUTTON_WIDTH-1, y1+BUTTON_HEIGHT-1, TRUE );
}
#endif
return;
}
}
WaitMouseOff();
}
int CreateButton(int x, int y, char *bitmap, int type, int exec, int enable)
{
int i;
for (i = 0; i < MAX_BUTTON; ++i) {
if (x-BUTTON_WIDTH < UserButton[i].x && UserButton[i].x < x + BUTTON_WIDTH
&& y-BUTTON_HEIGHT < UserButton[i].y && UserButton[i].y < y + BUTTON_HEIGHT) {
UserButton[i].type = BUTTON_UNUSED;
}
}
for (i = 0; i < MAX_BUTTON; ++i) {
if (UserButton[i].type == BUTTON_UNUSED) {
break;
}
}
if (i == MAX_BUTTON) {
return -1;
}
UserButton[i].type = type;
UserButton[i].x = x;
UserButton[i].y = y;
UserButton[i].exec = exec;
UserButton[i].enable = enable;
if (type == BUTTON_STRING) {
strncpy((char *)UserButton[i].bitmap, bitmap, 6);
UserButton[i].bitmap[7] = '\0';
} else {
memcpy(UserButton[i].bitmap, bitmap, ((BUTTON_BITMAP_WIDTH-1)/16+1)*2*BUTTON_BITMAP_HEIGHT);
}
return i;
}