source: abuse/tags/pd/imlib/port/dos4gw/mouse.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#include "video.hpp"
2#include "sprite.hpp"
3#include "image.hpp"
4#include "filter.hpp"
5#include "mdlread.hpp"
6#include "monoprnt.hpp"
7#include "mouse.hpp"
8#include "dprint.hpp"
9#include "doscall.hpp"
10#include "i86.h"
11
12unsigned char def_mouse[]=
13    { 0,2,0,0,0,0,0,0,
14      2,1,2,0,0,0,0,0,
15      2,1,1,2,0,0,0,0,
16      2,1,1,1,2,0,0,0,
17      2,1,1,1,1,2,0,0,
18      2,1,1,1,1,1,2,0,
19      0,2,1,1,2,2,0,0,
20      0,0,2,1,1,2,0,0,
21      0,0,2,1,1,2,0,0,
22      0,0,0,2,2,0,0,0 };    // 8x10
23
24static int Mbut,Mx,My;
25
26
27class mouse_detector
28{
29  public :
30  int detected;
31  mouse_detector()
32  {
33    union  REGS in,out;
34    memset(&in,0,sizeof(in));
35    in.w.ax=0;
36    int386(0x33,&in,&out);
37    detected=(((unsigned short)out.w.ax)==0xffff);
38  }
39} mouse_detect;
40
41void JCMouse::set_shape(image *im, int centerx, int centery)
42{
43  sp->change_visual(im,1);
44  cx=-centerx;
45  cy=-centery;
46}
47
48JCMouse::JCMouse(image *Screen, palette *pal)
49{
50  image *im;
51  int br,dr;
52  filter f;
53  but=0;
54  cx=cy=0;
55  sp=NULL;
56
57  union  REGS in,out;
58  memset(&in,0,sizeof(in));
59
60  here=mouse_detect.detected;
61
62  if (here)                     // is it here?
63  {
64    screen=Screen;
65    br=pal->brightest(1);
66    dr=pal->darkest(1);
67    f.set(1,br);
68    f.set(2,dr);
69    im=new image(8,10,def_mouse);
70    f.apply(im);
71    sp=new sprite(Screen,im,100,100);
72
73    memset(&in,0,sizeof(in));
74    in.w.ax=4;
75    in.w.cx=40;
76    in.w.dx=40;
77   
78    int386(0x33,&in,&out);
79
80  } else dprintf("mouse not detected\n");
81
82  mx=Screen->width()/2;
83  my=Screen->height()/2;
84
85}
86
87void JCMouse::update(int newx, int newy, int new_but)
88{
89
90  int butn,xx,yy;
91  if (newx<0)
92  {
93    if (here)
94    {
95      union REGS in,out;
96
97      in.w.ax=0x0b;
98      int386(0x33,&in,&out);    // get the mouse movement
99
100      xx=(signed short)out.w.cx;
101      yy=(signed short)out.w.dx;
102
103      in.w.ax=5;                 // get the button press info
104      in.w.bx=1|2|4;
105      int386(0x33,&in,&out);
106      butn=out.w.ax;
107     
108
109      lx=mx; ly=my; lbut=but;
110      but=butn;
111      mx+=xx;
112      my+=yy;
113      if (mx<0) mx=0;
114      if (my<0) my=0;
115      if (mx>=screen->width()) mx=screen->width()-1;
116      if (my>=screen->height()) my=screen->height()-1;
117    }
118  } else
119  { mx=newx; my=newy; but=new_but; }
120}
121
122
123
124JCMouse::~JCMouse()
125{
126  if (sp)
127  {
128    delete sp->visual;
129    delete sp;
130  }
131}
132
133
134
135void JCMouse::set_position(int new_mx, int new_my)
136{
137  mx=new_mx;
138  my=new_my;
139}
Note: See TracBrowser for help on using the repository browser.