File: mouse.c

package info (click to toggle)
abuse 2.00-12
  • links: PTS
  • area: main
  • in suites: slink
  • size: 12,708 kB
  • ctags: 15,389
  • sloc: ansic: 115,852; cpp: 6,792; lisp: 2,066; sh: 1,734; makefile: 1,601; asm: 264
file content (110 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "video.hpp"
#include "sprite.hpp"
#include "image.hpp"
#include "filter.hpp"
#include "mdlread.hpp"
#include "monoprnt.hpp"
#include "mouse.hpp"

unsigned char def_mouse[]=
    { 0,2,0,0,0,0,0,0,
      2,1,2,0,0,0,0,0,
      2,1,1,2,0,0,0,0,
      2,1,1,1,2,0,0,0,
      2,1,1,1,1,2,0,0,
      2,1,1,1,1,1,2,0,
      0,2,1,1,2,2,0,0,
      0,0,2,1,1,2,0,0,
      0,0,2,1,1,2,0,0,
      0,0,0,2,2,0,0,0 };    // 8x10

int Mbut,Mx,My;



void JCmouse::set_shape(image *im, int centerx=0, int centery=0)
{
  sp->change_visual(im,1);
  cx=-centerx;
  cy=-centery;
}



JCMouse::JCMouse(image *Screen, palette *pal)
{
  image *im;
  int br,dr,h;
  filter f;
  but=0;
  cx=cy=0;
#ifdef __DOS
  asm {
    mov ax, 0             // detect the mouse
    int 0x33
    mov h, ax
  }
  here=h;
#else 
  here=1;
#endif
  if (here)                     // is it here?
  {
    screen=Screen;
    br=pal->brightest(1);
    dr=pal->darkest(1);
    f.set(1,br);
    f.set(2,dr);
    im=new image(8,10,def_mouse);
    f.apply(im);
    sp=new sprite(Screen,im,100,100);
#ifdef __DOS
    asm {                // mouse the mouse pointer to 40,40
      mov ax, 4
      mov cx, 40
      mov dx, 40
      int 0x33
    }
#endif
  }
}

void JCMouse::update(int newx, int newy, int new_but)
{
  int butn,xx,yy;
  if (newx<0)
  {
#ifdef __DOS
    if (here)
    {
      asm {
        mov ax, 0x0b
        int 0x33            // get the mouse movement
        mov xx,cx
        mov yy,dx
        mov ax, 3
        int 0x33           // get the mouse button status
        mov butn,bx
      }
      lx=mx; ly=my; lbut=but;
      but=butn;
      mx+=xx;
      my+=yy;
      if (mx<0) mx=0;
      if (my<0) my=0;
      if (mx>=screen->width()) mx=screen->width()-1;
      if (my>=screen->height()) my=screen->height()-1;
    }
#else
    Window w1,w2;
    int j;
    unsigned int mask;
    lx=mx; ly=my; lbut=but;
    XQueryPointer(display,mainwin,&w1,&w2,&j,&j,&mx,&my,&mask);
    but=((mask&Button1Mask)!=0)|
         ((mask&Button2Mask)!=0)<<2|
         ((mask&Button3Mask)!=0)<<1;
#endif
  } else 
  { mx=newx; my=newy; but=new_but; }
}