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

Last change on this file since 49 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 2.5 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 <vgamouse.h>
10#include <vga.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
24int Mbut,Mx,My;
25
26void JCMouse::set_shape(image *im, int centerx, int centery)
27{
28  sp->change_visual(im,1);
29  cx=-centerx;
30  cy=-centery;
31}
32
33
34JCMouse::JCMouse(image *Screen, palette *pal)
35{
36  image *im;
37  int br,dr;
38  filter f;
39  but=0;
40  cx=cy=0;
41  vga_setmousesupport(1);
42  long mtype=MOUSE_MICROSOFT;
43  char *mtype_str=getenv("MOUSE_TYPE");
44  if (mtype_str)
45  {
46    if (!strcmp(mtype_str,"MOUSESYSTEMS"))
47      mtype=MOUSE_MOUSESYSTEMS;
48    else if (!strcmp(mtype_str,"MMSERIES"))
49      mtype=MOUSE_MMSERIES;
50    else if (!strcmp(mtype_str,"LOGITECH"))
51      mtype=MOUSE_LOGITECH;
52    else if (!strcmp(mtype_str,"BUSMOUSE"))
53      mtype=MOUSE_BUSMOUSE;
54    else if (!strcmp(mtype_str,"PS2"))
55      mtype=MOUSE_PS2;
56    else dprintf("Unknown mouse type %s\n",mtype_str);
57  } else
58  {
59    dprintf("Warning : env variable MOUSE_TYPE not defined, set to :\n"
60            "  MMSERIES, LOGITECH, BUSMOUSE, or PS2\n"
61            "  *if* you do not have a MS compatiable mouse\n");
62   
63  }
64
65
66  here=!(mouse_init("/dev/mouse",mtype,MOUSE_DEFAULTSAMPLERATE));
67  here=1;
68
69  if (here)                     // is it here?
70  {
71    screen=Screen;
72    br=pal->brightest(1);
73    dr=pal->darkest(1);
74    f.set(1,br);
75    f.set(2,dr);
76    im=new image(8,10,def_mouse);
77    f.apply(im);
78    sp=new sprite(Screen,im,100,100);
79    mouse_setxrange(0,Screen->width()-1);
80    mouse_setyrange(0,Screen->height()-1);
81    mouse_setwrap(MOUSE_NOWRAP);
82    mouse_update();
83    update();
84    update();
85  }
86  mx=Screen->width()/2;
87  my=Screen->height()/2;
88
89}
90
91void JCMouse::update(int newx, int newy, int new_but)
92{
93  int l,r,m;
94  if (newx<0)
95  {
96    lbut=but; lx=mx; ly=my;
97    mouse_update();
98    mx=mouse_getx();
99    my=mouse_gety();
100    but=mouse_getbutton();
101    l=but&4; r=but&1; m=but&2;
102    but=but&(0xff-7);
103    if (l) but+=1;
104    if (r) but+=2;
105    if (m) but+=4;
106  } else
107  { mx=newx; my=newy; but=new_but; }
108}
109
110void JCMouse::set_position(int new_mx, int new_my)
111{
112  mx=new_mx;
113  my=new_my;
114  mouse_setposition(new_mx,new_my);
115}
116
117
118JCMouse::~JCMouse()
119{
120  mouse_close();
121}
122
Note: See TracBrowser for help on using the repository browser.