home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
201 Games 4 You
/
PILOT_2895.img
/
wingame
/
sonstige
/
winpool
/
ustick.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-09
|
4KB
|
178 lines
/*
* I. ARIT 1992 Hidirbeyli,AYDIN,TR. 09400 Golden, CO, USA. 80401
*
*
* Copyright (C) 1992 Ismail ARIT
*
* This file is distributed in the hope that it will be useful, but without any
* warranty. No author or distributor accepts responsibility to anyone for
* the consequences of using it or for whether it serves any particular
* purpose or works at all.
*
*
* Everyone is granted permission to copy, modify and redistribute this file
* under the following conditions:
*
*
* Permission is granted to anyone to make or distribute copies of the source
* code, either as received or modified, in any medium, provided that all
* copyright notices, permission and nonwarranty notices are preserved, and
* that the distributor grants the recipient permission for further
* redistribution as permitted by this document.
*
* No part of this program can be used in any commercial product.
*/
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include "definiti.h"
extern char *progname;
extern HPEN StickPen;
extern HPEN TrajPen;
static void
Stick_Show(Stick * this, HDC hdc)
{
this->Visible = YES;
MoveTo(hdc, this->New.x, this->New.y);
LineTo(hdc, this->New.xx, this->New.yy);
};
static void
Stick_Hide(Stick * this, HDC hdc)
{
if (this->Visible) {
MoveTo(hdc, this->Old.x, this->Old.y);
LineTo(hdc, this->Old.xx, this->Old.yy);
}
this->Visible = NO;
};
static void
Stick_Delete(Stick * this, HDC hdc)
{
HPEN hpenOld;
int mode;
if (this->type == STICK)
hpenOld = SelectObject(hdc, StickPen);
else
hpenOld = SelectObject(hdc, TrajPen);
mode = SetROP2(hdc, R2_XORPEN);
this->Hide(this, hdc);
SetROP2(hdc, mode);
SelectObject(hdc, hpenOld);
};
static void
Stick_MoveTo(Stick * this, HDC hdc, int Button, int x, int y, int xx, int yy)
{
HPEN hpenOld;
int mode;
this->New.x = x;
this->New.y = y;
this->New.xx = xx;
this->New.yy = yy;
if (this->type == STICK)
hpenOld = SelectObject(hdc, StickPen);
else
hpenOld = SelectObject(hdc, TrajPen);
mode = SetROP2(hdc, R2_XORPEN);
if (Button == TRUE) {
this->Hide(this, hdc);
this->Show(this, hdc);
} else
this->Hide(this, hdc);
SetROP2(hdc, mode);
SelectObject(hdc, hpenOld);
this->Old.x = this->New.x;
this->Old.xx = this->New.xx;
this->Old.y = this->New.y;
this->Old.yy = this->New.yy;
};
static void
Stick_Status(Stick * this, int status)
{
this->Done = status;
if (this->Done) {
this->Old.x = this->Old.y = 0;
this->Old.xx = this->Old.yy = 0;
}
};
float
Stick_Lenght(Stick * this)
{
return (hypot((float) (this->New.xx - this->New.x), (float) (this->New.yy - this->New.y)));
};
Stick *
new__Stick(int type)
{
Stick *this;
this = (Stick *) malloc(sizeof(Stick));
if (!this) {
printf("problem..\n");
exit(0);
}
/* this is default stick color */
this->Done = NO;
this->Visible = NO;
this->type = type;
this->Old.x = this->New.x = 0;
this->Old.xx = this->New.xx = 0;
this->Old.y = this->New.y = 0;
this->Old.yy = this->New.yy = 0;
this->Show = Stick_Show;
this->Hide = Stick_Hide;
this->MoveTo = Stick_MoveTo;
this->DoneWithTheStick = Stick_Status;
this->Lenght = Stick_Lenght;
this->Delete = Stick_Delete;
return (this);
};