1/*
2	Copyright 1999, Be Incorporated.   All Rights Reserved.
3	This file may be used under the terms of the Be Sample Code License.
4
5	Other authors:
6	Gerald Zajac 2007-2008
7*/
8
9#include "accelerant.h"
10
11
12status_t
13SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y,
14				uint8* andMask, uint8* xorMask)
15{
16	// NOTE: Currently, for BeOS, cursor width and height must be equal to 16.
17
18	if ((width != 16) || (height != 16)) {
19		return B_ERROR;
20	} else if ((hot_x >= width) || (hot_y >= height)) {
21		return B_ERROR;
22	} else {
23		// Update cursor variables appropriately.
24
25		SharedInfo& si = *gInfo.sharedInfo;
26		si.cursorHotX = hot_x;
27		si.cursorHotY = hot_y;
28
29		if ( ! gInfo.LoadCursorImage(width, height, andMask, xorMask))
30			return B_ERROR;
31	}
32
33	return B_OK;
34}
35
36
37void
38MoveCursor(uint16 xPos, uint16 yPos)
39{
40	// Move the cursor to the specified position on the desktop.  If we're
41	// using some kind of virtual desktop, adjust the display start position
42	// accordingly and position the cursor in the proper "virtual" location.
43
44	int x = xPos;		// use signed int's since chip specific functions
45	int y = yPos;		// need signed int to determine if cursor off screen
46
47	SharedInfo& si = *gInfo.sharedInfo;
48	DisplayModeEx& dm = si.displayMode;
49
50	uint16 hds = dm.h_display_start;	// current horizontal starting pixel
51	uint16 vds = dm.v_display_start;	// current vertical starting line
52
53	// Clamp cursor to virtual display.
54	if (x >= dm.virtual_width)
55		x = dm.virtual_width - 1;
56	if (y >= dm.virtual_height)
57		y = dm.virtual_height - 1;
58
59	// Adjust h/v display start to move cursor onto screen.
60	if (x >= (dm.timing.h_display + hds))
61		hds = x - dm.timing.h_display + 1;
62	else if (x < hds)
63		hds = x;
64
65	if (y >= (dm.timing.v_display + vds))
66		vds = y - dm.timing.v_display + 1;
67	else if (y < vds)
68		vds = y;
69
70	// Reposition the desktop on the display if required.
71	if (hds != dm.h_display_start || vds != dm.v_display_start)
72		MoveDisplay(hds, vds);
73
74	// Put cursor in correct physical position.
75	x -= (hds + si.cursorHotX);
76	y -= (vds + si.cursorHotY);
77
78	// Position the cursor on the display.
79	gInfo.SetCursorPosition(x, y);
80}
81
82