home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xpool-10.zip / Xpool / stick.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  3KB  |  134 lines

  1.  
  2.  
  3. /* I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400
  4.                 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,
  10.   but without any warranty.  No author or distributor accepts
  11.   responsibility to anyone for the consequences of using it or for
  12.   whether it serves any particular purpose or works at all.
  13.  
  14.  
  15.   Everyone is granted permission to copy, modify and redistribute
  16.   this file under the following conditions:
  17.  
  18.  
  19.      Permission is granted to anyone to make or distribute copies
  20.      of the source code, either as received or modified, in any
  21.      medium, provided that all copyright notices, permission and
  22.      nonwarranty notices are preserved, and that the distributor
  23.      grants the recipient permission for further redistribution as
  24.      permitted by this document.
  25.      No part of this program can be used in any commercial product.
  26.  
  27.  
  28. */
  29.  
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <malloc.h>
  34. #include <math.h>
  35. #include <stdlib.h>
  36. #include    <X11/Xlib.h>
  37. #include    <X11/Xutil.h>
  38.  
  39. #include "definition.h"
  40.  
  41.  
  42.  
  43. extern char *progname;
  44. extern  Display disp;
  45. extern  Window Pane;
  46. extern  GC gc;
  47. extern  GC XorGc;
  48.  
  49.  
  50. extern void RubberLineOnPane(int type,int x, int y, int xx, int yy, int color);
  51. extern int  get_color (char *name);
  52.  
  53.  
  54. static  void Stick_Show (Stick * this) {
  55.             RubberLineOnPane (this->type,this -> New.x, this -> New.y, this -> New.xx, this -> New.yy, this -> color);
  56.     this -> Visible = YES;
  57.  
  58. };
  59.  
  60. static  void Stick_Hide (Stick * this) {
  61.             RubberLineOnPane (this->type,this -> Old.x, this -> Old.y, this -> Old.xx, this -> Old.yy, this -> color);
  62.  
  63. };
  64.  
  65. static  void Stick_MoveTo (Stick * this, int x, int y, int xx, int yy) {
  66.             this -> New.x = x;
  67.     this -> New.y = y;
  68.     this -> New.xx = xx;
  69.     this -> New.yy = yy;
  70.     this -> Hide (this);
  71.     this -> Show (this);
  72.     this -> Old.x = this -> New.x;
  73.     this -> Old.xx = this -> New.xx;
  74.     this -> Old.y = this -> New.y;
  75.     this -> Old.yy = this -> New.yy;
  76.  
  77. };
  78.  
  79. static  void Stick_GetColor (Stick * this, int color) {
  80.             this -> color = color;
  81. };
  82. static  void Stick_Status (Stick * this, int status) {
  83.             this -> Done = status;
  84.     if (this -> Done) {
  85.     this -> Old.x = this -> Old.y = 0;
  86.     this -> Old.xx = this -> Old.yy = 0;
  87.     }
  88. };
  89.  
  90. float   Stick_Lenght (Stick * this) {
  91.             return (sqrt ((float) ((this -> New.xx - this -> New.x) * (this -> New.xx - this -> New.x)
  92.         +
  93.                 (this -> New.yy - this -> New.y) * (this -> New.yy - this -> New.y)
  94.         )));
  95. };
  96.  
  97.  
  98. Stick * new__Stick (int type) {
  99.  
  100.     Stick * this;
  101.  
  102.     this = (Stick *) malloc (sizeof (Stick));
  103.     if (!this) {
  104.     printf ("problem..\n");
  105.     exit (0);
  106.     }
  107.     /* this is default stick color */
  108.     this -> color = get_color ("red");
  109.     this -> Done = NO;
  110.     this -> Visible = NO;
  111.     this->type = type;
  112.     this -> Old.x = this -> New.x = 0;
  113.     this -> Old.xx = this -> New.xx = 0;
  114.     this -> Old.y = this -> New.y = 0;
  115.     this -> Old.yy = this -> New.yy = 0;
  116.  
  117.  
  118.     this -> Show = Stick_Show;
  119.     this -> Hide = Stick_Hide;
  120.     this -> MoveTo = Stick_MoveTo;
  121.     this -> GetColor = Stick_GetColor;
  122.     this -> DoneWithTheStick = Stick_Status;
  123.     this -> Lenght = Stick_Lenght;
  124.  
  125.  
  126.     return (this);
  127.  
  128.  
  129. };
  130.  
  131.  
  132.  
  133.  
  134.