2003-01-13 01:51:01 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2004-09-21 02:50:02 +04:00
|
|
|
// Copyright (c) 2001-2002, Haiku, Inc.
|
2003-01-13 01:51:01 +03:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
// File Name: ServerCursor.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: Glorified ServerBitmap used for cursor work.
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include "ServerCursor.h"
|
2003-02-22 23:23:22 +03:00
|
|
|
#include <stdio.h>
|
2003-01-18 23:32:45 +03:00
|
|
|
/*!
|
|
|
|
\brief Constructor
|
2003-01-20 02:04:58 +03:00
|
|
|
\param r Size of the cursor
|
|
|
|
\param cspace Color space of the cursor
|
|
|
|
\param flags ServerBitmap flags. See Bitmap.h.
|
|
|
|
\param hotspot Hotspot of the cursor
|
|
|
|
\param bytesperline Bytes per row for the cursor. See ServerBitmap::ServerBitmap()
|
2003-01-18 23:32:45 +03:00
|
|
|
|
|
|
|
*/
|
2003-06-23 06:54:52 +04:00
|
|
|
ServerCursor::ServerCursor(BRect r, color_space cspace, int32 flags, BPoint hotspot, int32 bytesperrow, screen_id screen)
|
2003-01-13 01:51:01 +03:00
|
|
|
: ServerBitmap(r,cspace,flags,bytesperrow,screen)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fHotSpot=hotspot;
|
|
|
|
fHotSpot.ConstrainTo(Bounds());
|
2004-10-06 03:00:47 +04:00
|
|
|
fOwningTeam=-1;
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
_AllocateBuffer();
|
|
|
|
}
|
|
|
|
|
2003-01-18 23:32:45 +03:00
|
|
|
/*!
|
|
|
|
\brief Constructor
|
2003-01-20 02:04:58 +03:00
|
|
|
\param data pointer to 68-byte cursor data array. See BeBook entry for BCursor for details
|
2003-01-18 23:32:45 +03:00
|
|
|
*/
|
2003-01-13 01:51:01 +03:00
|
|
|
ServerCursor::ServerCursor(int8 *data)
|
2003-02-22 23:23:22 +03:00
|
|
|
: ServerBitmap(BRect(0,0,15,15),B_RGBA32,0)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
|
|
|
// 68-byte array used in R5 for holding cursors.
|
|
|
|
// 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
|
|
|
|
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths
|
|
|
|
if(data)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fInitialized=true;
|
2004-10-06 03:00:47 +04:00
|
|
|
fOwningTeam=-1;
|
2003-01-13 01:51:01 +03:00
|
|
|
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);
|
2004-09-21 02:50:02 +04:00
|
|
|
fHotSpot.Set(data[3],data[2]);
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
_AllocateBuffer();
|
|
|
|
|
|
|
|
// for each row in the cursor data
|
|
|
|
for(j=0;j<16;j++)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
bmppos=(uint32*)(fBuffer+ (j*BytesPerRow()) );
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
// On intel, our bytes end up swapped, so we must swap them back
|
|
|
|
cursorflip=(cursorpos[j] & 0xFF) << 8;
|
|
|
|
cursorflip |= (cursorpos[j] & 0xFF00) >> 8;
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-01-13 01:51:01 +03:00
|
|
|
maskflip=(maskpos[j] & 0xFF) << 8;
|
|
|
|
maskflip |= (maskpos[j] & 0xFF00) >> 8;
|
|
|
|
|
|
|
|
// for each column in each row of cursor data
|
|
|
|
for(i=0;i<16;i++)
|
|
|
|
{
|
|
|
|
// Get the values and dump them to the bitmap
|
2003-02-22 23:23:22 +03:00
|
|
|
powval=1 << (15-i);
|
2003-01-13 01:51:01 +03:00
|
|
|
cursorval=cursorflip & powval;
|
|
|
|
maskval=maskflip & powval;
|
|
|
|
bmppos[i]=((cursorval!=0)?black:white) & ((maskval>0)?0xFFFFFFFF:0x00FFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fWidth=0;
|
|
|
|
fHeight=0;
|
|
|
|
fBytesPerRow=0;
|
|
|
|
fSpace=B_NO_COLOR_SPACE;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-18 23:32:45 +03:00
|
|
|
/*!
|
|
|
|
\brief Copy constructor
|
2003-01-20 02:04:58 +03:00
|
|
|
\param cursor cursor to copy
|
2003-01-18 23:32:45 +03:00
|
|
|
*/
|
2003-01-13 01:51:01 +03:00
|
|
|
ServerCursor::ServerCursor(const ServerCursor *cursor)
|
|
|
|
: ServerBitmap(cursor)
|
|
|
|
{
|
|
|
|
_AllocateBuffer();
|
2004-09-21 02:50:02 +04:00
|
|
|
fInitialized=true;
|
2004-10-06 03:00:47 +04:00
|
|
|
fOwningTeam=-1;
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
if(cursor)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(cursor->fBuffer)
|
|
|
|
memcpy(fBuffer, cursor->fBuffer, BitsLength());
|
|
|
|
fHotSpot=cursor->fHotSpot;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-18 23:32:45 +03:00
|
|
|
//! Frees the heap space allocated for the cursor's image data
|
2003-01-13 01:51:01 +03:00
|
|
|
ServerCursor::~ServerCursor(void)
|
|
|
|
{
|
|
|
|
_FreeBuffer();
|
|
|
|
}
|
|
|
|
|
2003-01-18 23:32:45 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the cursor's hotspot
|
2003-01-20 02:04:58 +03:00
|
|
|
\param pt New location of hotspot, constrained to the cursor's boundaries.
|
2003-01-18 23:32:45 +03:00
|
|
|
*/
|
2003-01-13 01:51:01 +03:00
|
|
|
void ServerCursor::SetHotSpot(BPoint pt)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fHotSpot=pt;
|
|
|
|
fHotSpot.ConstrainTo(Bounds());
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
2003-02-24 18:47:06 +03:00
|
|
|
|
|
|
|
void ServerCursor::SetAppSignature(const char *signature)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fAppSignature.SetTo( (signature)?signature:"" );
|
2003-02-24 18:47:06 +03:00
|
|
|
}
|