home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
BUTTLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-28
|
4KB
|
172 lines
/*
* ユーザーボタン制御
*
* Copyright M.Takatsu 1996.1.24
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "ml.h"
#include "strclass.h"
#include "view.h"
#include "button.h"
static char *SysConstName[] = {
"BUTTON_WIDTH",
"BUTTON_HEIGHT",
"BUTTON_DISABLE",
"BUTTON_ENABLE",
"BUTTON_NOREPEAT",
"BUTTON_REPEAT",
NULL
};
static IntData SysConst[] = {
{ TYPE_INT, 0, BUTTON_WIDTH, },
{ TYPE_INT, 0, BUTTON_HEIGHT, },
{ TYPE_INT, 0, BUTTON_DISABLE, },
{ TYPE_INT, 0, BUTTON_ENABLE, },
{ TYPE_INT, 0, BUTTON_NOREPEAT, },
{ TYPE_INT, 0, BUTTON_REPEAT, },
};
static int StringClassID;
static int FuncCreateButton( int, int, DataStruct* );
static int FuncUpdateButton( int, int, DataStruct* );
static int FuncClearButton( int, int, DataStruct* );
static int FuncButtonArea( int, int, DataStruct* );
static int FuncButtonEnable( int, int, DataStruct* );
/* 初期化 */
void ButtonLibInit()
{
int i;
StringClassID = ClassName( "String" );
for( i = 0 ; SysConstName[i] != NULL ; i++ )
{
NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
}
NewFunction( 0, "CreateButton", FuncCreateButton );
NewFunction( 0, "UpdateButton", FuncUpdateButton );
NewFunction( 0, "ClearButton", FuncClearButton );
NewFunction( 0, "ButtonArea", FuncButtonArea );
NewFunction( 0, "ButtonEnable", FuncButtonEnable );
}
static int ConvertStringToBitmap(char *dst, char *src)
{
int i, j;
unsigned short data, *p;
p = (unsigned short *)dst;
for (i = ((BUTTON_BITMAP_WIDTH-1)/16+1)*BUTTON_BITMAP_HEIGHT; i > 0; --i) {
data = 0;
for (j = 4; j > 0; --j, src++) {
data *= 16;
while (*src != '\0' && !isxdigit(*src)) {
src++;
}
if (*src == '\0') {
return FALSE;
}
if (isdigit(*src)) {
data += (*src - '0');
} else if ('A' <= *src && *src <= 'F') {
data += (*src - 'A' + 10);
} else if ('a' <= *src && *src <= 'a') {
data += (*src - 'a' + 10);
}
}
*p++ = data;
}
return TRUE;
}
static int FuncCreateButton(int ident, int args, DataStruct *buf)
{
int x, y, exec;
int id, enable;
char *str, bitmap[((BUTTON_BITMAP_WIDTH-1)/16+1)*2*BUTTON_BITMAP_HEIGHT];
id = -1;
enable = BUTTON_ENABLE;
if (args > 4) {
ArgCheck( "CreateButton", args, buf, TYPE_INT, TYPE_INT, TYPE_OBJECT, TYPE_FUNC, TYPE_INT, TYPE_NOASN );
enable = buf[4].id.i;
} else {
ArgCheck( "CreateButton", args, buf, TYPE_INT, TYPE_INT, TYPE_OBJECT, TYPE_FUNC, TYPE_NOASN );
}
if (ObjectCheck(&buf[2], StringClassID) == FALSE) {
ExecError("SetButtonArea:3番目の引数の型が異なる\n");
}
x = buf[0].id.i;
y = buf[1].id.i;
exec = buf[3].funcd.ident ;
str = ((StringClass*)buf[2].od.ptr)->str;
if (ConvertStringToBitmap(bitmap, str)) {
id = CreateButton(x, y, bitmap, BUTTON_BITMAP, exec, enable);
} else {
id = CreateButton(x, y, str, BUTTON_STRING, exec, enable);
}
StackPushInt(id);
return RETURN_RETURN;
}
static int FuncUpdateButton(int ident, int args, DataStruct *buf)
{
if (args > 0) {
ArgCheck( "SetButtonArea", args, buf, TYPE_INT, TYPE_NOASN);
DrawUserButton(buf[0].id.i);
} else {
DrawUserButtonAll();
}
return RETURN_VOID;
}
static int FuncClearButton(int ident, int args, DataStruct *buf)
{
int i;
for (i = 0; i < MAX_BUTTON; ++i) {
UserButton[i].type = BUTTON_UNUSED;
}
return RETURN_VOID;
}
static int FuncButtonArea(int ident, int args, DataStruct *buf)
{
int w;
w = ButtonAreaWidth;
if (args > 0) {
ArgCheck( "SetButtonArea", args, buf, TYPE_INT, TYPE_NOASN );
ViewCursor( OFF );
SetButtonArea(buf[0].id.i);
ViewFrame();
ViewLineAll( 0, 0, 4096, 4096, TRUE );
ViewCursor( ON );
}
StackPushInt( w );
return RETURN_RETURN ;
}
static int FuncButtonEnable(int ident, int args, DataStruct *buf)
{
int id, enable = -1;
if (args > 1) {
ArgCheck( "ButtonEnable", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
enable = buf[1].id.i;
} else {
ArgCheck( "ButtonEnable", args, buf, TYPE_INT, TYPE_NOASN );
}
id = buf[0].id.i;
if (0 <= id && id < MAX_BUTTON && UserButton[id].type != BUTTON_UNUSED) {
if (enable < 0) {
enable = UserButton[id].enable;
} else {
UserButton[id].enable = enable;
}
}
StackPushInt( enable );
return RETURN_RETURN ;
}