BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / accelerants / 3dfx / cursor.cpp
blobe4860fba5413262f423a0d6c722e482c72b3d979
1 /*
2 Copyright 1999, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
5 Other authors:
6 Gerald Zajac 2007-2010
7 */
9 #include "accelerant.h"
12 status_t
13 SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y,
14 uint8* andMask, uint8* xorMask)
16 // NOTE: Currently, for BeOS, cursor width and height must be equal to 16.
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.
25 SharedInfo& si = *gInfo.sharedInfo;
26 si.cursorHotX = hot_x;
27 si.cursorHotY = hot_y;
29 if ( ! TDFX_LoadCursorImage(width, height, andMask, xorMask))
30 return B_ERROR;
33 return B_OK;
37 void
38 MoveCursor(uint16 xPos, uint16 yPos)
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.
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
47 SharedInfo& si = *gInfo.sharedInfo;
48 DisplayModeEx& dm = si.displayMode;
50 uint16 hds = dm.h_display_start; // current horizontal starting pixel
51 uint16 vds = dm.v_display_start; // current vertical starting line
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;
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;
65 if (y >= (dm.timing.v_display + vds))
66 vds = y - dm.timing.v_display + 1;
67 else if (y < vds)
68 vds = y;
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);
74 // Put cursor in correct physical position.
75 x -= (hds + si.cursorHotX);
76 y -= (vds + si.cursorHotY);
78 // Position the cursor on the display.
79 TDFX_SetCursorPosition(x, y);