Cursor frame can be expressed using IntRect. Saves a few lines of code too.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24099 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -162,12 +162,12 @@ HWInterface::SetCursorVisible(bool visible)
|
|||||||
if (visible) {
|
if (visible) {
|
||||||
fCursorVisible = visible;
|
fCursorVisible = visible;
|
||||||
fCursorObscured = false;
|
fCursorObscured = false;
|
||||||
BRect r = _CursorFrame();
|
IntRect r = _CursorFrame();
|
||||||
|
|
||||||
_DrawCursor(r);
|
_DrawCursor(r);
|
||||||
Invalidate(r);
|
Invalidate(r);
|
||||||
} else {
|
} else {
|
||||||
BRect r = _CursorFrame();
|
IntRect r = _CursorFrame();
|
||||||
fCursorVisible = visible;
|
fCursorVisible = visible;
|
||||||
|
|
||||||
_RestoreCursorArea();
|
_RestoreCursorArea();
|
||||||
@@ -313,7 +313,7 @@ HWInterface::CopyBackToFront(const BRect& frame)
|
|||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
// we need to mess with the area, but it is const
|
// we need to mess with the area, but it is const
|
||||||
BRect area(frame);
|
IntRect area(frame);
|
||||||
BRect bufferClip(backBuffer->Bounds());
|
BRect bufferClip(backBuffer->Bounds());
|
||||||
|
|
||||||
if (area.IsValid() && area.Intersects(bufferClip)) {
|
if (area.IsValid() && area.Intersects(bufferClip)) {
|
||||||
@@ -471,13 +471,13 @@ HWInterface::RemoveListener(HWInterfaceListener* listener)
|
|||||||
// * area is where we potentially draw the cursor, the cursor
|
// * area is where we potentially draw the cursor, the cursor
|
||||||
// might be somewhere else, in which case this function does nothing
|
// might be somewhere else, in which case this function does nothing
|
||||||
void
|
void
|
||||||
HWInterface::_DrawCursor(BRect area) const
|
HWInterface::_DrawCursor(IntRect area) const
|
||||||
{
|
{
|
||||||
RenderingBuffer* backBuffer = DrawingBuffer();
|
RenderingBuffer* backBuffer = DrawingBuffer();
|
||||||
if (!backBuffer || !area.IsValid())
|
if (!backBuffer || !area.IsValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BRect cf = _CursorFrame();
|
IntRect cf = _CursorFrame();
|
||||||
|
|
||||||
// make sure we don't copy out of bounds
|
// make sure we don't copy out of bounds
|
||||||
area = backBuffer->Bounds() & area;
|
area = backBuffer->Bounds() & area;
|
||||||
@@ -487,12 +487,8 @@ HWInterface::_DrawCursor(BRect area) const
|
|||||||
// clip to common area
|
// clip to common area
|
||||||
area = area & cf;
|
area = area & cf;
|
||||||
|
|
||||||
int32 left = (int32)area.left;
|
int32 width = area.right - area.left + 1;
|
||||||
int32 top = (int32)area.top;
|
int32 height = area.bottom - area.top + 1;
|
||||||
int32 right = (int32)area.right;
|
|
||||||
int32 bottom = (int32)area.bottom;
|
|
||||||
int32 width = right - left + 1;
|
|
||||||
int32 height = bottom - top + 1;
|
|
||||||
|
|
||||||
// make a bitmap from the backbuffer
|
// make a bitmap from the backbuffer
|
||||||
// that has the cursor blended on top of it
|
// that has the cursor blended on top of it
|
||||||
@@ -503,16 +499,16 @@ HWInterface::_DrawCursor(BRect area) const
|
|||||||
// offset into back buffer
|
// offset into back buffer
|
||||||
uint8* src = (uint8*)backBuffer->Bits();
|
uint8* src = (uint8*)backBuffer->Bits();
|
||||||
uint32 srcBPR = backBuffer->BytesPerRow();
|
uint32 srcBPR = backBuffer->BytesPerRow();
|
||||||
src += top * srcBPR + left * 4;
|
src += area.top * srcBPR + area.left * 4;
|
||||||
|
|
||||||
// offset into cursor bitmap
|
// offset into cursor bitmap
|
||||||
uint8* crs = (uint8*)fCursorAndDragBitmap->Bits();
|
uint8* crs = (uint8*)fCursorAndDragBitmap->Bits();
|
||||||
uint32 crsBPR = fCursorAndDragBitmap->BytesPerRow();
|
uint32 crsBPR = fCursorAndDragBitmap->BytesPerRow();
|
||||||
// since area is clipped to cf,
|
// since area is clipped to cf,
|
||||||
// the diff between top and cf.top is always positive,
|
// the diff between area.top and cf.top is always positive,
|
||||||
// same for diff between left and cf.left
|
// same for diff between area.left and cf.left
|
||||||
crs += (top - (int32)floorf(cf.top)) * crsBPR
|
crs += (area.top - (int32)floorf(cf.top)) * crsBPR
|
||||||
+ (left - (int32)floorf(cf.left)) * 4;
|
+ (area.left - (int32)floorf(cf.left)) * 4;
|
||||||
|
|
||||||
uint8* dst = buffer;
|
uint8* dst = buffer;
|
||||||
|
|
||||||
@@ -520,21 +516,21 @@ HWInterface::_DrawCursor(BRect area) const
|
|||||||
&& fFloatingOverlaysLock.Lock()) {
|
&& fFloatingOverlaysLock.Lock()) {
|
||||||
fCursorAreaBackup->cursor_hidden = false;
|
fCursorAreaBackup->cursor_hidden = false;
|
||||||
// remember which area the backup contains
|
// remember which area the backup contains
|
||||||
fCursorAreaBackup->left = left;
|
fCursorAreaBackup->left = area.left;
|
||||||
fCursorAreaBackup->top = top;
|
fCursorAreaBackup->top = area.top;
|
||||||
fCursorAreaBackup->right = right;
|
fCursorAreaBackup->right = area.right;
|
||||||
fCursorAreaBackup->bottom = bottom;
|
fCursorAreaBackup->bottom = area.bottom;
|
||||||
uint8* bup = fCursorAreaBackup->buffer;
|
uint8* bup = fCursorAreaBackup->buffer;
|
||||||
uint32 bupBPR = fCursorAreaBackup->bpr;
|
uint32 bupBPR = fCursorAreaBackup->bpr;
|
||||||
|
|
||||||
// blending and backup of drawing buffer
|
// blending and backup of drawing buffer
|
||||||
for (int32 y = top; y <= bottom; y++) {
|
for (int32 y = area.top; y <= area.bottom; y++) {
|
||||||
uint8* s = src;
|
uint8* s = src;
|
||||||
uint8* c = crs;
|
uint8* c = crs;
|
||||||
uint8* d = dst;
|
uint8* d = dst;
|
||||||
uint8* b = bup;
|
uint8* b = bup;
|
||||||
|
|
||||||
for (int32 x = left; x <= right; x++) {
|
for (int32 x = area.left; x <= area.right; x++) {
|
||||||
*(uint32*)b = *(uint32*)s;
|
*(uint32*)b = *(uint32*)s;
|
||||||
// assumes backbuffer alpha = 255
|
// assumes backbuffer alpha = 255
|
||||||
// assuming pre-multiplied cursor bitmap
|
// assuming pre-multiplied cursor bitmap
|
||||||
@@ -556,11 +552,11 @@ HWInterface::_DrawCursor(BRect area) const
|
|||||||
fFloatingOverlaysLock.Unlock();
|
fFloatingOverlaysLock.Unlock();
|
||||||
} else {
|
} else {
|
||||||
// blending
|
// blending
|
||||||
for (int32 y = top; y <= bottom; y++) {
|
for (int32 y = area.top; y <= area.bottom; y++) {
|
||||||
uint8* s = src;
|
uint8* s = src;
|
||||||
uint8* c = crs;
|
uint8* c = crs;
|
||||||
uint8* d = dst;
|
uint8* d = dst;
|
||||||
for (int32 x = left; x <= right; x++) {
|
for (int32 x = area.left; x <= area.right; x++) {
|
||||||
// assumes backbuffer alpha = 255
|
// assumes backbuffer alpha = 255
|
||||||
// assuming pre-multiplied cursor bitmap
|
// assuming pre-multiplied cursor bitmap
|
||||||
uint8 a = 255 - c[3];
|
uint8 a = 255 - c[3];
|
||||||
@@ -578,7 +574,8 @@ HWInterface::_DrawCursor(BRect area) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copy result to front buffer
|
// copy result to front buffer
|
||||||
_CopyToFront(buffer, width * 4, left, top, right, bottom);
|
_CopyToFront(buffer, width * 4, area.left, area.top, area.right,
|
||||||
|
area.bottom);
|
||||||
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
@@ -786,10 +783,10 @@ HWInterface::_CopyToFront(uint8* src, uint32 srcBPR,
|
|||||||
|
|
||||||
|
|
||||||
// PRE: the object must be locked
|
// PRE: the object must be locked
|
||||||
BRect
|
IntRect
|
||||||
HWInterface::_CursorFrame() const
|
HWInterface::_CursorFrame() const
|
||||||
{
|
{
|
||||||
BRect frame(0.0, 0.0, -1.0, -1.0);
|
IntRect frame(0, 0, -1, -1);
|
||||||
if (fCursorAndDragBitmap && fCursorVisible) {
|
if (fCursorAndDragBitmap && fCursorVisible) {
|
||||||
frame = fCursorAndDragBitmap->Bounds();
|
frame = fCursorAndDragBitmap->Bounds();
|
||||||
frame.OffsetTo(fCursorLocation - fCursorAndDragBitmap->GetHotSpot());
|
frame.OffsetTo(fCursorLocation - fCursorAndDragBitmap->GetHotSpot());
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
|
|
||||||
|
#include "IntRect.h"
|
||||||
|
|
||||||
|
|
||||||
class Overlay;
|
class Overlay;
|
||||||
class RenderingBuffer;
|
class RenderingBuffer;
|
||||||
@@ -169,14 +171,14 @@ class HWInterface : protected MultiLocker {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// implement this in derived classes
|
// implement this in derived classes
|
||||||
virtual void _DrawCursor(BRect area) const;
|
virtual void _DrawCursor(IntRect area) const;
|
||||||
|
|
||||||
// does the actual transfer and handles color space conversion
|
// does the actual transfer and handles color space conversion
|
||||||
void _CopyToFront(uint8* src, uint32 srcBPR,
|
void _CopyToFront(uint8* src, uint32 srcBPR,
|
||||||
int32 x, int32 y,
|
int32 x, int32 y,
|
||||||
int32 right, int32 bottom) const;
|
int32 right, int32 bottom) const;
|
||||||
|
|
||||||
BRect _CursorFrame() const;
|
IntRect _CursorFrame() const;
|
||||||
void _RestoreCursorArea() const;
|
void _RestoreCursorArea() const;
|
||||||
void _AdoptDragBitmap(const ServerBitmap* bitmap,
|
void _AdoptDragBitmap(const ServerBitmap* bitmap,
|
||||||
const BPoint& offset);
|
const BPoint& offset);
|
||||||
|
|||||||
Reference in New Issue
Block a user