File: xcursor.cc

package info (click to toggle)
atom4 4.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 664 kB
  • ctags: 947
  • sloc: cpp: 4,451; makefile: 52; sh: 45; perl: 6
file content (72 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download | duplicates (7)
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
/*
 * Simple X11 client-side cursor
 * Implementation file
 *
 * $Id: xcursor.cc,v 1.2 2003/02/10 01:41:05 hsteoh Exp hsteoh $
 */

#include "exception.h"
#include "xcursor.h"


void xcursor::draw() {
  bckgnd.save(d, x-cursor->org_x(), y-cursor->org_y(),
              cursor->width(), cursor->height());
  cursor->draw(d,x,y);
}

xcursor::xcursor(xsprite_engine *engine, Drawable drw, xflatsprite *curs,
                 int max_wd, int max_ht) :
	eng(engine), d(drw), bckgnd(engine,d,max_wd,max_ht) {
  set_sprite(curs);
  visible=0;
  x=y=0;
}

xcursor::~xcursor() {
  if (visible) {
    bckgnd.restore();
  }
}

void xcursor::set_sprite(xflatsprite *curs) {
  if (curs->width() > bckgnd.max_width() ||
      curs->height() > bckgnd.max_height()) {
    throw exception("xcursor::set_sprite(): cursor sprite too big\n");
  } else {
    cursor=curs;
    if (visible) {			// redraw with new cursor image
      bckgnd.restore();
      draw();
    }
  }
}

void xcursor::on() {
  if (!visible) {
    visible=1;
    draw();
  }
}

void xcursor::off() {
  if (visible) {
    bckgnd.restore();
  }
  visible=0;
}

void xcursor::move(int new_x, int new_y) {
  if (visible) {
    if (new_x!=x || new_y!=y) {		// only update if coors changed
      bckgnd.restore();			// erase from last position
      x = new_x;
      y = new_y;
      draw();
    }
  } else {
    x = new_x;				// still update internal coor anyway
    y = new_y;
  }
}