home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Zone
/
VRZONE.ISO
/
mac
/
PC
/
PCGLOVE
/
GLOVE
/
OBJGLV.ZIP
/
SRC
/
WINGLOVE.CPP
< prev
Wrap
C/C++ Source or Header
|
1993-05-12
|
8KB
|
303 lines
//
// WinGlove.cpp:
// Implementation of classes TDemoWindow and TGloveApp.
// Example use of Object Glove.
//
// Purpose:
// Sets up the Windows glove application.
//
// Compatibility:
// Windows only!
//
// Copyright 1993 Mark Thomas Pflaging
//
// Date: 3/22/93 (Release 3.0)
//
#include "winglove.hpp"
#include "winactor.hpp"
#include "gestsys.hpp"
TDemoWindow::TDemoWindow(PTWindowsObject AParent, LPSTR ATitle)
: TWindow(AParent, ATitle)
{
/****
HDC DC = GetDC(HWindow);
COLORREF bkcolor = GetBkColor(DC);
ReleaseDC(HWindow, DC);
****/
// ButtonDown = FALSE;
BrushData.lbStyle = BS_SOLID;
BrushData.lbColor = 0; // Ignored
// BrushData.lbHatch = HS_CROSS; // Ignored
// ClearBrush = CreateBrushIndirect(& BrushData);
BrushData.lbStyle = BS_HOLLOW; // BS_HATCHED;
BrushData.lbColor = 0;
// BrushData.lbHatch = HS_CROSS;
PenSize = 1;
ThePen = CreatePen(PS_SOLID, PenSize, 0);
// ClearPen = CreatePen(PS_NULL, PenSize, 0);
TheBrush = CreateBrushIndirect(& BrushData);
hGloveIcon = NULL;
// Attr.Style = WS_MINIMIZE;
}
void TDemoWindow::GetWindowClass(WNDCLASS & AWndClass)
{
TWindow::GetWindowClass( AWndClass );
AWndClass.hIcon = hGloveIcon = LoadIcon(GetApplication()->hInstance, MAKEINTRESOURCE(GLOVE_ICON));
}
void TDemoWindow::SetupWindow()
{
((PTGloveApp)GetApplication())->Setup();
TWindow::SetupWindow();
}
TDemoWindow::~TDemoWindow()
{
DeleteObject(ThePen);
// DeleteObject(ClearPen);
DeleteObject(TheBrush);
// DeleteObject(ClearBrush);
if (hGloveIcon) DestroyIcon(hGloveIcon);
}
BOOL TDemoWindow::CanClose()
{
return TRUE;
}
#include <strstream.h>
void TDemoWindow::SetPenSize(int NewSize)
{
DeleteObject(ThePen);
ThePen = CreatePen(PS_SOLID, NewSize, 0);
PenSize = NewSize;
}
void TDemoWindow::SetPenColor(COLORREF NewColor)
{
DeleteObject(ThePen);
ThePen = CreatePen(PS_SOLID, PenSize, NewColor);
PenColor = NewColor;
}
HGDIOBJ TDemoWindow::oldPen;
HGDIOBJ TDemoWindow::oldBrush;
void TDemoWindow::setupHDC(HDC DC, int currentColor)
{
SetPenColor(currentColor);
oldPen = SelectObject(DC, ThePen);
oldBrush = SelectObject(DC, TheBrush);
}
void TDemoWindow::releaseHDC(HDC DC)
{
SelectObject(DC, oldPen);
SelectObject(DC, oldBrush);
}
void TDemoWindow::Paint(HDC DC, PAINTSTRUCT&)
{
winGraphicsActor * graph = (((PTGloveApp)GetApplication())->getGlvGrph());
if (graph) graph->Paint(DC);
graph = (((PTGloveApp)GetApplication())->getGlvGrph2());
if (graph) graph->Paint(DC);
}
TGloveApp::~TGloveApp() {
if (GLOVE2) delete GLOVE2;
if (GLOVE1) delete GLOVE1;
if (gloveGraph1) delete gloveGraph1;
if (gloveGraph2) {
gloveGraph2->killAssociatedGestures();
delete gloveGraph2;
}
// if (gloveSound1) delete gloveSound1;
if (gloveGesture1) {
gloveGesture1->killAssociatedGestures();
delete gloveGesture1;
}
if (gloveGesture2) {
gloveGesture2->killAssociatedGestures();
delete gloveGesture2;
}
if (gestSys) delete gestSys;
if (gestSys2) delete gestSys2;
}
void TGloveApp::Setup()
{
if (GLOVE1) {
gloveGraph1->Setup();
if (gloveGesture1) gloveGesture1->Setup();
if (gloveGesture2) gloveGesture2->Setup();
}
if (GLOVE2) {
gloveGraph2->Setup();
}
}
void TGloveApp::IdleAction()
{
if (GLOVE1) rawGlove::winRun();
else {
PostMessage(MainWindow->HWindow, WM_CLOSE, 0, 0L);
}
}
void TGloveApp::InitMainWindow()
{
MainWindow = new TDemoWindow(NULL, Name);
if (GLOVE1) {
gloveGraph1 = new winGraphicsActor(*gloveIni, *((TDemoWindow *)MainWindow), *gloveGesture1);
(*gestSys) + gloveGraph1;
gestSys->turnOn();
if (GLOVE2) {
gloveGraph2 = new winGraphicsActor(*gloveIni, *((TDemoWindow *)MainWindow), *gloveGraph1, *gloveGesture2);
gloveGraph2->turnOn();
(*gestSys2) + gloveGraph2;
gestSys2->turnOn();
}
gloveGraph1->turnOn();
// gloveSound1 = new soundActor(0 /*MIDI_MAPPER*/);
if (gloveGesture1) gloveGesture1->setWindow(*((TDemoWindow *)MainWindow));
if (gloveGesture2) gloveGesture2->setWindow(*((TDemoWindow *)MainWindow));
gloveIni->write();
delete gloveIni;
}
}
void TGloveApp::InitInstance()
{
TApplication::InitInstance();
// Only allow one instance of this App. (for now.)
/****
if (hPrevInstance || !GLOVE1) {
Status = EM_INVALIDMAINWINDOW;
return;
}
****/
}
void TGloveApp::graphicsOutput(gloveDriver & gd, void * app)
{
TGloveApp & here = *((TGloveApp *)app);
// TDemoWindow & where = *((TDemoWindow *)(here.MainWindow));
gd.checkGestures();
(here.gloveGraph1)->Process(gd);
// (here.gloveSound1)->test(gd);
}
void TGloveApp::graphicsOutput2(gloveDriver & gd, void * app)
{
TGloveApp & here = *((TGloveApp *)app);
// TDemoWindow & where = *((TDemoWindow *)(here.MainWindow));
gd.checkGestures();
(here.gloveGraph2)->Process(gd);
// (here.gloveSound2)->test(gd);
}
Boolean quit_func()
{
return False; // look forever...
}
void TGloveApp::InitApplication()
{
gloveIni = new InitFile("glove.ini");
if (gloveIni->getStatus() == Key::FileDidNotExist)
MessageBox(NULL,
"Cannot open \"glove.ini\". Using defaults and "
"creating new \"glove.ini\".",
"Warning",
MB_ICONEXCLAMATION | MB_OK);
if (gloveIni->getStatus() == Key::ErrorReadingFile)
MessageBox(NULL,
"Error in \"glove.ini\". Using defaults and "
"perhaps modifying \"glove.ini\".",
"Warning",
MB_ICONEXCLAMATION | MB_OK);
gestSys = new GestureSystem;
gloveGesture1 = new winGestureActor(*gloveIni, "1.Gestures", "Sounds");
gloveGesture1->turnOn();
(*gestSys) + gloveGesture1;
// gloveIni->dump(cout);
if (!strcmp(gloveIni->find("1.Smoothing", "smoothingEnabled", "True"),
"True"))
GLOVE1 = new smoothGlove(*gloveIni, gestSys, quit_func);
else
GLOVE1 = new rawGlove(*gloveIni, gestSys, quit_func);
GLOVE1->test();
if ((GLOVE1->driverStatus() == gloveDriver::EverythingOK) && (howMany > 1)) {
gestSys2 = new GestureSystem;
gloveGesture2 = new winGestureActor(*gloveIni, "2.Gestures", "Sounds");
gloveGesture2->turnOn();
(*gestSys2) + gloveGesture2;
if (!strcmp(gloveIni->find("2.Smoothing", "smoothingEnabled", "True"),
"True"))
GLOVE2 = new smoothGlove(*gloveIni, gestSys2, quit_func);
else
GLOVE2 = new rawGlove(*gloveIni, gestSys2, quit_func);
if (GLOVE2->driverStatus() == gloveDriver::EverythingOK) {
GLOVE2->initFunction(graphicsOutput2, this);
}
else {
delete GLOVE2;
delete gestSys2;
GLOVE2 = NULL;
gestSys2 = NULL;
}
GLOVE1->initFunction(graphicsOutput, this);
GLOVE1->Start(strcmp(gloveIni->find(
gloveDriver::getTitle(),
"PolledOperation", "False"),
"True") ? True : False);
}
else {
if (GLOVE1->driverStatus() != gloveDriver::EverythingOK) {
MessageBox(NULL,
"Delay values are not specified in \"glove.ini\"."
" Please EXIT WINDOWS and run \"INITGLOV.EXE\""
" while you are in the same directory as GLOVE.INI.",
"Warning",
MB_ICONEXCLAMATION | MB_OK);
gloveIni->write();
delete gloveIni;
delete GLOVE1;
delete gestSys;
GLOVE1 = NULL;
gestSys = NULL;
}
else {
GLOVE1->initFunction(graphicsOutput, this);
GLOVE1->Start(strcmp(gloveIni->find(
gloveDriver::getTitle(),
"PolledOperation", "False"),
"True") ? True : False);
}
}
}
BOOL TGloveApp::CanClose()
{
if (GLOVE1) ExecDialog(new TDialog(MainWindow, GLOVEDEMO_INFO));
return (MainWindow->CanClose());
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
TGloveApp MyApp("WinGlove", hInstance, hPrevInstance,
lpCmdLine, nCmdShow);
MyApp.Run();
return MyApp.Status;
}