cosmetical changes and some bug fixes along the way, added another constructor to take on bitmap data from somewhere else
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12383 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
//
|
//
|
||||||
// File Name: ServerCursor.h
|
// File Name: ServerCursor.h
|
||||||
// Author: DarkWyrm <[email protected]>
|
// Author: DarkWyrm <[email protected]>
|
||||||
|
// Stephan Aßmus <[email protected]>
|
||||||
// Description: Glorified ServerBitmap used for cursor work.
|
// Description: Glorified ServerBitmap used for cursor work.
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
|
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include "ServerBitmap.h"
|
#include "ServerBitmap.h"
|
||||||
|
|
||||||
class ServerApp;
|
class ServerApp;
|
||||||
@@ -43,30 +45,43 @@ class CursorManager;
|
|||||||
R5, cursors can be any size or color space, and this class accomodates and
|
R5, cursors can be any size or color space, and this class accomodates and
|
||||||
expands the R5 API.
|
expands the R5 API.
|
||||||
*/
|
*/
|
||||||
class ServerCursor : public ServerBitmap
|
class ServerCursor : public ServerBitmap {
|
||||||
{
|
public:
|
||||||
public:
|
ServerCursor(BRect r, color_space space,
|
||||||
ServerCursor(BRect r, color_space cspace, int32 flags, BPoint hotspot, int32 bytesperrow=-1, screen_id screen=B_MAIN_SCREEN_ID);
|
int32 flags, BPoint hotspot,
|
||||||
ServerCursor(int8 *data);
|
int32 bytesperrow = -1,
|
||||||
ServerCursor(const ServerCursor *cursor);
|
screen_id screen = B_MAIN_SCREEN_ID);
|
||||||
~ServerCursor(void);
|
ServerCursor(const int8* cursorDataFromR5);
|
||||||
|
ServerCursor(const uint8* alreadyPaddedData,
|
||||||
|
uint32 width, uint32 height,
|
||||||
|
color_space format);
|
||||||
|
ServerCursor(const ServerCursor* cursor);
|
||||||
|
|
||||||
|
virtual ~ServerCursor(void);
|
||||||
|
|
||||||
//! Returns the cursor's hot spot
|
//! Returns the cursor's hot spot
|
||||||
BPoint GetHotSpot(void) { return fHotSpot; }
|
void SetHotSpot(BPoint pt);
|
||||||
void SetHotSpot(BPoint pt);
|
BPoint GetHotSpot(void)
|
||||||
const char *GetAppSignature(void) { return fAppSignature.String(); }
|
{ return fHotSpot; }
|
||||||
void SetAppSignature(const char *signature);
|
|
||||||
void SetOwningTeam(team_id tid) { fOwningTeam=tid; }
|
void SetAppSignature(const char* signature);
|
||||||
team_id OwningTeam(void) const { return fOwningTeam; }
|
const char* GetAppSignature() const
|
||||||
|
{ return fAppSignature.String(); }
|
||||||
|
|
||||||
|
void SetOwningTeam(team_id tid)
|
||||||
|
{ fOwningTeam=tid; }
|
||||||
|
team_id OwningTeam(void) const
|
||||||
|
{ return fOwningTeam; }
|
||||||
|
|
||||||
//! Returns the cursor's ID
|
//! Returns the cursor's ID
|
||||||
int32 ID(void) { return fToken; }
|
int32 ID()
|
||||||
private:
|
{ return fToken; }
|
||||||
|
private:
|
||||||
friend class CursorManager;
|
friend class CursorManager;
|
||||||
|
|
||||||
BPoint fHotSpot;
|
BPoint fHotSpot;
|
||||||
team_id fOwningTeam;
|
team_id fOwningTeam;
|
||||||
BString fAppSignature;
|
BString fAppSignature;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // SERVERCURSOR_H_
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
//
|
//
|
||||||
// File Name: ServerCursor.cpp
|
// File Name: ServerCursor.cpp
|
||||||
// Author: DarkWyrm <[email protected]>
|
// Author: DarkWyrm <[email protected]>
|
||||||
|
// Stephan Aßmus <[email protected]>
|
||||||
// Description: Glorified ServerBitmap used for cursor work.
|
// Description: Glorified ServerBitmap used for cursor work.
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -35,98 +36,121 @@
|
|||||||
\param bytesperline Bytes per row for the cursor. See ServerBitmap::ServerBitmap()
|
\param bytesperline Bytes per row for the cursor. See ServerBitmap::ServerBitmap()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ServerCursor::ServerCursor(BRect r, color_space cspace, int32 flags, BPoint hotspot, int32 bytesperrow, screen_id screen)
|
ServerCursor::ServerCursor(BRect r, color_space format,
|
||||||
: ServerBitmap(r,cspace,flags,bytesperrow,screen)
|
int32 flags, BPoint hotspot,
|
||||||
|
int32 bytesPerRow,
|
||||||
|
screen_id screen)
|
||||||
|
: ServerBitmap(r, format, flags, bytesPerRow, screen),
|
||||||
|
fHotSpot(hotspot),
|
||||||
|
fOwningTeam(-1)
|
||||||
{
|
{
|
||||||
fHotSpot=hotspot;
|
|
||||||
fHotSpot.ConstrainTo(Bounds());
|
fHotSpot.ConstrainTo(Bounds());
|
||||||
fOwningTeam=-1;
|
|
||||||
|
|
||||||
_AllocateBuffer();
|
_AllocateBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Constructor
|
\brief Constructor
|
||||||
\param data pointer to 68-byte cursor data array. See BeBook entry for BCursor for details
|
\param data Pointer to 68-byte cursor data array. See BeBook entry for BCursor for details
|
||||||
*/
|
*/
|
||||||
ServerCursor::ServerCursor(int8 *data)
|
ServerCursor::ServerCursor(const int8* data)
|
||||||
: ServerBitmap(BRect(0,0,15,15),B_RGBA32,0)
|
: ServerBitmap(BRect(0, 0, 15, 15), B_RGBA32, 0),
|
||||||
|
fHotSpot(0, 0),
|
||||||
|
fOwningTeam(-1)
|
||||||
{
|
{
|
||||||
// 68-byte array used in R5 for holding cursors.
|
// 68-byte array used in R5 for holding cursors.
|
||||||
// This API has serious problems and should be deprecated(but supported) in R2
|
// This API has serious problems and should be deprecated(but supported) in R2
|
||||||
|
|
||||||
// Now that we have all the setup, we're going to map (for now) the cursor
|
// Now that we have all the setup, we're going to map (for now) the cursor
|
||||||
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths
|
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths
|
||||||
if(data)
|
if (data) {
|
||||||
{
|
|
||||||
fInitialized=true;
|
|
||||||
fOwningTeam=-1;
|
|
||||||
uint32 black=0xFF000000,
|
|
||||||
white=0xFFFFFFFF,
|
|
||||||
*bmppos;
|
|
||||||
uint16 *cursorpos, *maskpos,cursorflip, maskflip,
|
|
||||||
cursorval, maskval,powval;
|
|
||||||
uint8 i,j;
|
|
||||||
|
|
||||||
cursorpos=(uint16*)(data+4);
|
|
||||||
maskpos=(uint16*)(data+36);
|
|
||||||
fHotSpot.Set(data[3],data[2]);
|
|
||||||
|
|
||||||
_AllocateBuffer();
|
_AllocateBuffer();
|
||||||
|
uint8* buffer = Bits();
|
||||||
|
if (!buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fInitialized = true;
|
||||||
|
uint32 black = 0xFF000000;
|
||||||
|
uint32 white = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
uint16* cursorpos = (uint16*)(data + 4);
|
||||||
|
uint16* maskpos = (uint16*)(data + 36);
|
||||||
|
fHotSpot.Set(data[3], data[2]);
|
||||||
|
|
||||||
|
uint32* bmppos;
|
||||||
|
uint16 cursorflip;
|
||||||
|
uint16 maskflip;
|
||||||
|
uint16 cursorval;
|
||||||
|
uint16 maskval;
|
||||||
|
uint16 powval;
|
||||||
|
|
||||||
// for each row in the cursor data
|
// for each row in the cursor data
|
||||||
for(j=0;j<16;j++)
|
for (int32 j = 0; j < 16; j++) {
|
||||||
{
|
bmppos = (uint32*)(buffer + (j * BytesPerRow()));
|
||||||
bmppos=(uint32*)(fBuffer+ (j*BytesPerRow()) );
|
|
||||||
|
|
||||||
// On intel, our bytes end up swapped, so we must swap them back
|
// On intel, our bytes end up swapped, so we must swap them back
|
||||||
cursorflip=(cursorpos[j] & 0xFF) << 8;
|
cursorflip = (cursorpos[j] & 0xFF) << 8;
|
||||||
cursorflip |= (cursorpos[j] & 0xFF00) >> 8;
|
cursorflip |= (cursorpos[j] & 0xFF00) >> 8;
|
||||||
|
|
||||||
maskflip=(maskpos[j] & 0xFF) << 8;
|
maskflip = (maskpos[j] & 0xFF) << 8;
|
||||||
maskflip |= (maskpos[j] & 0xFF00) >> 8;
|
maskflip |= (maskpos[j] & 0xFF00) >> 8;
|
||||||
|
|
||||||
// for each column in each row of cursor data
|
// for each column in each row of cursor data
|
||||||
for(i=0;i<16;i++)
|
for (int32 i = 0; i < 16; i++) {
|
||||||
{
|
|
||||||
// Get the values and dump them to the bitmap
|
// Get the values and dump them to the bitmap
|
||||||
powval=1 << (15-i);
|
powval = 1 << (15 - i);
|
||||||
cursorval=cursorflip & powval;
|
cursorval = cursorflip & powval;
|
||||||
maskval=maskflip & powval;
|
maskval = maskflip & powval;
|
||||||
bmppos[i]=((cursorval!=0)?black:white) & ((maskval>0)?0xFFFFFFFF:0x00FFFFFF);
|
bmppos[i] = ((cursorval != 0) ? black : white) &
|
||||||
|
((maskval > 0) ? 0xFFFFFFFF : 0x00FFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fWidth = 0;
|
||||||
|
fHeight = 0;
|
||||||
|
fBytesPerRow = 0;
|
||||||
|
fSpace = B_NO_COLOR_SPACE;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
fWidth=0;
|
/*!
|
||||||
fHeight=0;
|
\brief Constructor
|
||||||
fBytesPerRow=0;
|
\param data Pointer to bitmap data in memory, the padding bytes should be contained when format less than 32 bpp.
|
||||||
fSpace=B_NO_COLOR_SPACE;
|
*/
|
||||||
}
|
ServerCursor::ServerCursor(const uint8* alreadyPaddedData,
|
||||||
|
uint32 width, uint32 height,
|
||||||
|
color_space format)
|
||||||
|
: ServerBitmap(BRect(0, 0, width - 1, height - 1), format, 0),
|
||||||
|
fHotSpot(0, 0),
|
||||||
|
fOwningTeam(-1)
|
||||||
|
{
|
||||||
|
_AllocateBuffer();
|
||||||
|
if (Bits())
|
||||||
|
memcpy(Bits(), alreadyPaddedData, BitsLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Copy constructor
|
\brief Copy constructor
|
||||||
\param cursor cursor to copy
|
\param cursor cursor to copy
|
||||||
*/
|
*/
|
||||||
ServerCursor::ServerCursor(const ServerCursor *cursor)
|
ServerCursor::ServerCursor(const ServerCursor* cursor)
|
||||||
: ServerBitmap(cursor)
|
: ServerBitmap(cursor),
|
||||||
|
fHotSpot(0, 0),
|
||||||
|
fOwningTeam(-1)
|
||||||
{
|
{
|
||||||
|
// TODO: Hm. I don't move this into the if clause,
|
||||||
|
// because it might break code elsewhere.
|
||||||
_AllocateBuffer();
|
_AllocateBuffer();
|
||||||
fInitialized=true;
|
|
||||||
fOwningTeam=-1;
|
|
||||||
|
|
||||||
if(cursor)
|
if (cursor) {
|
||||||
{
|
fInitialized = true;
|
||||||
if(cursor->fBuffer)
|
if (Bits() && cursor->Bits())
|
||||||
memcpy(fBuffer, cursor->fBuffer, BitsLength());
|
memcpy(Bits(), cursor->Bits(), BitsLength());
|
||||||
fHotSpot=cursor->fHotSpot;
|
fHotSpot = cursor->fHotSpot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Frees the heap space allocated for the cursor's image data
|
//! Frees the heap space allocated for the cursor's image data
|
||||||
ServerCursor::~ServerCursor(void)
|
ServerCursor::~ServerCursor()
|
||||||
{
|
{
|
||||||
_FreeBuffer();
|
_FreeBuffer();
|
||||||
}
|
}
|
||||||
@@ -135,13 +159,16 @@ ServerCursor::~ServerCursor(void)
|
|||||||
\brief Sets the cursor's hotspot
|
\brief Sets the cursor's hotspot
|
||||||
\param pt New location of hotspot, constrained to the cursor's boundaries.
|
\param pt New location of hotspot, constrained to the cursor's boundaries.
|
||||||
*/
|
*/
|
||||||
void ServerCursor::SetHotSpot(BPoint pt)
|
void
|
||||||
|
ServerCursor::SetHotSpot(BPoint pt)
|
||||||
{
|
{
|
||||||
fHotSpot=pt;
|
fHotSpot = pt;
|
||||||
fHotSpot.ConstrainTo(Bounds());
|
fHotSpot.ConstrainTo(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerCursor::SetAppSignature(const char *signature)
|
// SetAppSignature
|
||||||
|
void
|
||||||
|
ServerCursor::SetAppSignature(const char* signature)
|
||||||
{
|
{
|
||||||
fAppSignature.SetTo( (signature)?signature:"" );
|
fAppSignature.SetTo((signature) ? signature : "");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user