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;
}
}
|