home *** CD-ROM | disk | FTP | other *** search
/ MORE WinGames / WINGAMES.iso / winpool / ustick.c < prev    next >
C/C++ Source or Header  |  1992-08-09  |  4KB  |  178 lines

  1.  
  2.  
  3. /*
  4.  * I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400 Golden,    CO,   USA. 80401 
  5.  *
  6.  *
  7.  * Copyright (C) 1992 Ismail ARIT 
  8.  *
  9.  * This file  is distributed in the hope that it will be useful, but without any
  10.  * warranty.  No author or distributor accepts responsibility to anyone for
  11.  * the consequences of using it or for whether it serves any particular
  12.  * purpose or works at all. 
  13.  *
  14.  *
  15.  * Everyone is granted permission to copy, modify and redistribute this file
  16.  * under the following conditions: 
  17.  *
  18.  *
  19.  * Permission is granted to anyone to make or distribute copies of the source
  20.  * code, either as received or modified, in any medium, provided that all
  21.  * copyright notices, permission and nonwarranty notices are preserved, and
  22.  * that the distributor grants the recipient permission for further
  23.  * redistribution as permitted by this document. 
  24.  *
  25.  * No part of this program can be used in any commercial product. 
  26.  */
  27.  
  28.  
  29. #include <windows.h>
  30. #include <stdio.h>
  31. #include <malloc.h>
  32. #include <math.h>
  33. #include <stdlib.h>
  34.  
  35. #include "definiti.h"
  36.  
  37.  
  38.  
  39. extern char    *progname;
  40.  
  41. extern HPEN     StickPen;
  42. extern HPEN     TrajPen;
  43.  
  44.  
  45.  
  46. static void
  47. Stick_Show(Stick * this, HDC hdc)
  48. {
  49.     this->Visible = YES;
  50.     MoveTo(hdc, this->New.x, this->New.y);
  51.     LineTo(hdc, this->New.xx, this->New.yy);
  52.  
  53. };
  54.  
  55. static void
  56. Stick_Hide(Stick * this, HDC hdc)
  57. {
  58.     if (this->Visible) {
  59.         MoveTo(hdc, this->Old.x, this->Old.y);
  60.         LineTo(hdc, this->Old.xx, this->Old.yy);
  61.     }
  62.     this->Visible = NO;
  63. };
  64.  
  65. static void
  66. Stick_Delete(Stick * this, HDC hdc)
  67. {
  68.     HPEN            hpenOld;
  69.     int             mode;
  70.  
  71.     if (this->type == STICK)
  72.         hpenOld = SelectObject(hdc, StickPen);
  73.     else
  74.         hpenOld = SelectObject(hdc, TrajPen);
  75.  
  76.     mode = SetROP2(hdc, R2_XORPEN);
  77.  
  78.     this->Hide(this, hdc);
  79.  
  80.     SetROP2(hdc, mode);
  81.  
  82.     SelectObject(hdc, hpenOld);
  83.  
  84.  
  85. };
  86.  
  87. static void
  88. Stick_MoveTo(Stick * this, HDC hdc, int Button, int x, int y, int xx, int yy)
  89. {
  90.  
  91.     HPEN            hpenOld;
  92.     int             mode;
  93.  
  94.     this->New.x = x;
  95.     this->New.y = y;
  96.     this->New.xx = xx;
  97.     this->New.yy = yy;
  98.     if (this->type == STICK)
  99.         hpenOld = SelectObject(hdc, StickPen);
  100.     else
  101.         hpenOld = SelectObject(hdc, TrajPen);
  102.  
  103.     mode = SetROP2(hdc, R2_XORPEN);
  104.  
  105.     if (Button == TRUE) {
  106.         this->Hide(this, hdc);
  107.         this->Show(this, hdc);
  108.     } else
  109.         this->Hide(this, hdc);
  110.  
  111.  
  112.     SetROP2(hdc, mode);
  113.  
  114.     SelectObject(hdc, hpenOld);
  115.  
  116.  
  117.     this->Old.x = this->New.x;
  118.     this->Old.xx = this->New.xx;
  119.     this->Old.y = this->New.y;
  120.     this->Old.yy = this->New.yy;
  121.  
  122. };
  123.  
  124.  
  125.  
  126.  
  127. static void
  128. Stick_Status(Stick * this, int status)
  129. {
  130.     this->Done = status;
  131.     if (this->Done) {
  132.         this->Old.x = this->Old.y = 0;
  133.         this->Old.xx = this->Old.yy = 0;
  134.     }
  135. };
  136.  
  137. float
  138. Stick_Lenght(Stick * this)
  139. {
  140.     return (hypot((float) (this->New.xx - this->New.x), (float) (this->New.yy - this->New.y)));
  141.  
  142. };
  143.  
  144.  
  145. Stick          *
  146. new__Stick(int type)
  147. {
  148.  
  149.     Stick          *this;
  150.  
  151.     this = (Stick *) malloc(sizeof(Stick));
  152.     if (!this) {
  153.         printf("problem..\n");
  154.         exit(0);
  155.     }
  156.     /* this is default stick color */
  157.     this->Done = NO;
  158.     this->Visible = NO;
  159.     this->type = type;
  160.     this->Old.x = this->New.x = 0;
  161.     this->Old.xx = this->New.xx = 0;
  162.     this->Old.y = this->New.y = 0;
  163.     this->Old.yy = this->New.yy = 0;
  164.  
  165.  
  166.     this->Show = Stick_Show;
  167.     this->Hide = Stick_Hide;
  168.     this->MoveTo = Stick_MoveTo;
  169.     this->DoneWithTheStick = Stick_Status;
  170.     this->Lenght = Stick_Lenght;
  171.     this->Delete = Stick_Delete;
  172.  
  173.  
  174.     return (this);
  175.  
  176.  
  177. };
  178.