app_server: Add tiled bitmap drawing routines
Change-Id: I9a7bd967f2cc95d815a66707b764cf5e33b3f8ed Reviewed-on: https://review.haiku-os.org/c/haiku/+/1962 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
4dcc9761a7
commit
c67dde0f2c
@@ -2706,8 +2706,13 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
otherwise stated. Notes on specific methods are provided below:
|
otherwise stated. Notes on specific methods are provided below:
|
||||||
|
|
||||||
DrawBitmap()
|
DrawBitmap()
|
||||||
|
DrawTiledBitmap()
|
||||||
|
|
||||||
If the the image is bigger than the destination rectangle, it is scaled to fit.
|
DrawBitmap() scales the image to fit if the image has different size than
|
||||||
|
the destination rectangle.
|
||||||
|
|
||||||
|
DrawTiledBitmap() fills the destination rectangle with copies of the source
|
||||||
|
image, without changing its size.
|
||||||
|
|
||||||
The asynchronous versions pass the image to Application Server and return
|
The asynchronous versions pass the image to Application Server and return
|
||||||
immediately.
|
immediately.
|
||||||
@@ -2752,6 +2757,7 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect,
|
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect,
|
||||||
BRect viewRect, uint32 options)
|
BRect viewRect, uint32 options)
|
||||||
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
||||||
|
\a bitmap portion is scaled to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
||||||
@@ -2768,6 +2774,7 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect,
|
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect,
|
||||||
BRect viewRect)
|
BRect viewRect)
|
||||||
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
||||||
|
\a bitmap portion is scaled to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
||||||
@@ -2782,6 +2789,7 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
/*!
|
/*!
|
||||||
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect viewRect)
|
\fn void BView::DrawBitmapAsync(const BBitmap* bitmap, BRect viewRect)
|
||||||
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
||||||
|
\a bitmap is scaled to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param viewRect The area in the view's coordinate system to draw the
|
\param viewRect The area in the view's coordinate system to draw the
|
||||||
@@ -2815,7 +2823,8 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
/*!
|
/*!
|
||||||
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect,
|
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect,
|
||||||
BRect viewRect, uint32 options)
|
BRect viewRect, uint32 options)
|
||||||
\brief brief Draws \a bitmap on the view within \a viewRect.
|
\brief Draws \a bitmap on the view within \a viewRect. \a bitmap portion
|
||||||
|
is scaled to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
||||||
@@ -2831,7 +2840,8 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
/*!
|
/*!
|
||||||
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect,
|
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect,
|
||||||
BRect viewRect)
|
BRect viewRect)
|
||||||
\brief Draws \a bitmap on the view within \a viewRect.
|
\brief Draws \a bitmap on the view within \a viewRect. \a bitmap portion
|
||||||
|
is scaled to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
\param bitmapRect The portion of the bitmap to draw in the bitmap's
|
||||||
@@ -2845,7 +2855,8 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect viewRect)
|
\fn void BView::DrawBitmap(const BBitmap* bitmap, BRect viewRect)
|
||||||
\brief Draws \a bitmap on the view within \a viewRect.
|
\brief Draws \a bitmap on the view within \a viewRect. \a bitmap is scaled
|
||||||
|
to fit \a viewRect.
|
||||||
|
|
||||||
\param bitmap The bitmap to draw onto the view.
|
\param bitmap The bitmap to draw onto the view.
|
||||||
\param viewRect The area in the view's coordinate system to draw the
|
\param viewRect The area in the view's coordinate system to draw the
|
||||||
@@ -2876,6 +2887,37 @@ SetViewColor(Parent()->ViewColor());
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void BView::DrawTiledBitmapAsync(const BBitmap* bitmap, BRect viewRect,
|
||||||
|
BPoint phase = B_ORIGIN)
|
||||||
|
\brief Draws \a bitmap on the view within \a viewRect asynchronously.
|
||||||
|
If \a bitmap is smaller, it is cloned to fill remaining space
|
||||||
|
in \a viewRect.
|
||||||
|
|
||||||
|
\param bitmap The bitmap to draw onto the view.
|
||||||
|
\param viewRect The area in the view's coordinate system to draw the
|
||||||
|
bitmap in.
|
||||||
|
\param phase Source bitmap offset used as starting point for drawing.
|
||||||
|
|
||||||
|
\since Haiku R1
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void BView::DrawTiledBitmap(const BBitmap* bitmap, BRect viewRect,
|
||||||
|
BPoint phase = B_ORIGIN)
|
||||||
|
\brief Draws \a bitmap on the view within \a viewRect. If \a bitmap is
|
||||||
|
smaller, it is cloned to fill remaining space in \a viewRect.
|
||||||
|
|
||||||
|
\param bitmap The bitmap to draw onto the view.
|
||||||
|
\param viewRect The area in the view's coordinate system to draw the
|
||||||
|
bitmap in.
|
||||||
|
\param phase Source bitmap offset used as starting point for drawing.
|
||||||
|
|
||||||
|
\since Haiku R1
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void BView::DrawChar(char c)
|
\fn void BView::DrawChar(char c)
|
||||||
\brief Draws character \a c onto to the view at the current pen position.
|
\brief Draws character \a c onto to the view at the current pen position.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015 Haiku, Inc. All rights reserved.
|
* Copyright 2001-2019 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _VIEW_H
|
#ifndef _VIEW_H
|
||||||
@@ -472,6 +472,12 @@ public:
|
|||||||
BPoint where);
|
BPoint where);
|
||||||
void DrawBitmap(const BBitmap* aBitmap);
|
void DrawBitmap(const BBitmap* aBitmap);
|
||||||
|
|
||||||
|
void DrawTiledBitmapAsync(const BBitmap* aBitmap,
|
||||||
|
BRect viewRect, BPoint phase = B_ORIGIN);
|
||||||
|
|
||||||
|
void DrawTiledBitmap(const BBitmap* aBitmap,
|
||||||
|
BRect viewRect, BPoint phase = B_ORIGIN);
|
||||||
|
|
||||||
void DrawChar(char aChar);
|
void DrawChar(char aChar);
|
||||||
void DrawChar(char aChar, BPoint location);
|
void DrawChar(char aChar, BPoint location);
|
||||||
void DrawString(const char* string,
|
void DrawString(const char* string,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2017 Haiku, Inc. All rights reserved.
|
* Copyright 2001-2019 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -3120,6 +3120,38 @@ BView::DrawBitmap(const BBitmap* bitmap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BView::DrawTiledBitmapAsync(const BBitmap* bitmap, BRect viewRect,
|
||||||
|
BPoint phase)
|
||||||
|
{
|
||||||
|
if (bitmap == NULL || fOwner == NULL || !viewRect.IsValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
_CheckLockAndSwitchCurrent();
|
||||||
|
|
||||||
|
ViewDrawBitmapInfo info;
|
||||||
|
info.bitmapToken = bitmap->_ServerToken();
|
||||||
|
info.options = B_TILE_BITMAP;
|
||||||
|
info.viewRect = viewRect;
|
||||||
|
info.bitmapRect = bitmap->Bounds().OffsetToCopy(phase);
|
||||||
|
|
||||||
|
fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP);
|
||||||
|
fOwner->fLink->Attach<ViewDrawBitmapInfo>(info);
|
||||||
|
|
||||||
|
_FlushIfNotInTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BView::DrawTiledBitmap(const BBitmap* bitmap, BRect viewRect, BPoint phase)
|
||||||
|
{
|
||||||
|
if (fOwner) {
|
||||||
|
DrawTiledBitmapAsync(bitmap, viewRect, phase);
|
||||||
|
Sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BView::DrawChar(char c)
|
BView::DrawChar(char c)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ Painter::BitmapPainter::Draw(const BRect& sourceRect,
|
|||||||
|
|
||||||
TRACE("BitmapPainter::Draw()\n");
|
TRACE("BitmapPainter::Draw()\n");
|
||||||
TRACE(" bitmapBounds = (%.1f, %.1f) - (%.1f, %.1f)\n",
|
TRACE(" bitmapBounds = (%.1f, %.1f) - (%.1f, %.1f)\n",
|
||||||
bitmapBounds.left, bitmapBounds.top,
|
fBitmapBounds.left, fBitmapBounds.top,
|
||||||
bitmapBounds.right, bitmapBounds.bottom);
|
fBitmapBounds.right, fBitmapBounds.bottom);
|
||||||
TRACE(" sourceRect = (%.1f, %.1f) - (%.1f, %.1f)\n",
|
TRACE(" sourceRect = (%.1f, %.1f) - (%.1f, %.1f)\n",
|
||||||
sourceRect.left, sourceRect.top,
|
sourceRect.left, sourceRect.top,
|
||||||
sourceRect.right, sourceRect.bottom);
|
sourceRect.right, sourceRect.bottom);
|
||||||
@@ -78,27 +78,29 @@ Painter::BitmapPainter::Draw(const BRect& sourceRect,
|
|||||||
if (!success)
|
if (!success)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// optimized version for no scale in CMAP8 or RGB32 OP_OVER
|
if ((fOptions & B_TILE_BITMAP) == 0) {
|
||||||
if (!_HasScale() && !_HasAffineTransform() && !_HasAlphaMask()) {
|
// optimized version for no scale in CMAP8 or RGB32 OP_OVER
|
||||||
if (fColorSpace == B_CMAP8) {
|
if (!_HasScale() && !_HasAffineTransform() && !_HasAlphaMask()) {
|
||||||
if (fPainter->fDrawingMode == B_OP_COPY) {
|
if (fColorSpace == B_CMAP8) {
|
||||||
DrawBitmapNoScale<CMap8Copy> drawNoScale;
|
if (fPainter->fDrawingMode == B_OP_COPY) {
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 1, fOffset,
|
DrawBitmapNoScale<CMap8Copy> drawNoScale;
|
||||||
fDestinationRect);
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 1, fOffset,
|
||||||
return;
|
fDestinationRect);
|
||||||
}
|
return;
|
||||||
if (fPainter->fDrawingMode == B_OP_OVER) {
|
}
|
||||||
DrawBitmapNoScale<CMap8Over> drawNoScale;
|
if (fPainter->fDrawingMode == B_OP_OVER) {
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 1, fOffset,
|
DrawBitmapNoScale<CMap8Over> drawNoScale;
|
||||||
fDestinationRect);
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 1, fOffset,
|
||||||
return;
|
fDestinationRect);
|
||||||
}
|
return;
|
||||||
} else if (fColorSpace == B_RGB32) {
|
}
|
||||||
if (fPainter->fDrawingMode == B_OP_OVER) {
|
} else if (fColorSpace == B_RGB32) {
|
||||||
DrawBitmapNoScale<Bgr32Over> drawNoScale;
|
if (fPainter->fDrawingMode == B_OP_OVER) {
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
DrawBitmapNoScale<Bgr32Over> drawNoScale;
|
||||||
fDestinationRect);
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
||||||
return;
|
fDestinationRect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,62 +108,69 @@ Painter::BitmapPainter::Draw(const BRect& sourceRect,
|
|||||||
ObjectDeleter<BBitmap> convertedBitmapDeleter;
|
ObjectDeleter<BBitmap> convertedBitmapDeleter;
|
||||||
_ConvertColorSpace(convertedBitmapDeleter);
|
_ConvertColorSpace(convertedBitmapDeleter);
|
||||||
|
|
||||||
// optimized version if there is no scale
|
if ((fOptions & B_TILE_BITMAP) == 0) {
|
||||||
if (!_HasScale() && !_HasAffineTransform() && !_HasAlphaMask()) {
|
// optimized version if there is no scale
|
||||||
if (fPainter->fDrawingMode == B_OP_COPY) {
|
if (!_HasScale() && !_HasAffineTransform() && !_HasAlphaMask()) {
|
||||||
DrawBitmapNoScale<Bgr32Copy> drawNoScale;
|
if (fPainter->fDrawingMode == B_OP_COPY) {
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
DrawBitmapNoScale<Bgr32Copy> drawNoScale;
|
||||||
fDestinationRect);
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
||||||
return;
|
fDestinationRect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fPainter->fDrawingMode == B_OP_OVER
|
||||||
|
|| (fPainter->fDrawingMode == B_OP_ALPHA
|
||||||
|
&& fPainter->fAlphaSrcMode == B_PIXEL_ALPHA
|
||||||
|
&& fPainter->fAlphaFncMode == B_ALPHA_OVERLAY)) {
|
||||||
|
DrawBitmapNoScale<Bgr32Alpha> drawNoScale;
|
||||||
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
||||||
|
fDestinationRect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fPainter->fDrawingMode == B_OP_OVER
|
|
||||||
|| (fPainter->fDrawingMode == B_OP_ALPHA
|
|
||||||
&& fPainter->fAlphaSrcMode == B_PIXEL_ALPHA
|
|
||||||
&& fPainter->fAlphaFncMode == B_ALPHA_OVERLAY)) {
|
|
||||||
DrawBitmapNoScale<Bgr32Alpha> drawNoScale;
|
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
|
||||||
fDestinationRect);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_HasScale() && !_HasAffineTransform() && _HasAlphaMask()) {
|
if (!_HasScale() && !_HasAffineTransform() && _HasAlphaMask()) {
|
||||||
if (fPainter->fDrawingMode == B_OP_COPY) {
|
if (fPainter->fDrawingMode == B_OP_COPY) {
|
||||||
DrawBitmapNoScale<Bgr32CopyMasked> drawNoScale;
|
DrawBitmapNoScale<Bgr32CopyMasked> drawNoScale;
|
||||||
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
drawNoScale.Draw(fPainter->fInternal, fBitmap, 4, fOffset,
|
||||||
fDestinationRect);
|
fDestinationRect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bilinear and nearest-neighbor scaled, OP_COPY only
|
||||||
|
if (fPainter->fDrawingMode == B_OP_COPY
|
||||||
|
&& !_HasAffineTransform() && !_HasAlphaMask()) {
|
||||||
|
if ((fOptions & B_FILTER_BITMAP_BILINEAR) != 0) {
|
||||||
|
DrawBitmapBilinear<ColorTypeRgb, DrawModeCopy> drawBilinear;
|
||||||
|
drawBilinear.Draw(fPainter, fPainter->fInternal,
|
||||||
|
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
||||||
|
} else {
|
||||||
|
DrawBitmapNearestNeighborCopy::Draw(fPainter, fPainter->fInternal,
|
||||||
|
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// bilinear and nearest-neighbor scaled, OP_COPY only
|
if (fPainter->fDrawingMode == B_OP_ALPHA
|
||||||
if (fPainter->fDrawingMode == B_OP_COPY
|
&& fPainter->fAlphaSrcMode == B_PIXEL_ALPHA
|
||||||
&& !_HasAffineTransform() && !_HasAlphaMask()) {
|
&& fPainter->fAlphaFncMode == B_ALPHA_OVERLAY
|
||||||
if ((fOptions & B_FILTER_BITMAP_BILINEAR) != 0) {
|
&& !_HasAffineTransform() && !_HasAlphaMask()
|
||||||
DrawBitmapBilinear<ColorTypeRgb, DrawModeCopy> drawBilinear;
|
&& (fOptions & B_FILTER_BITMAP_BILINEAR) != 0) {
|
||||||
|
DrawBitmapBilinear<ColorTypeRgba, DrawModeAlphaOverlay> drawBilinear;
|
||||||
drawBilinear.Draw(fPainter, fPainter->fInternal,
|
drawBilinear.Draw(fPainter, fPainter->fInternal,
|
||||||
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
||||||
} else {
|
return;
|
||||||
DrawBitmapNearestNeighborCopy::Draw(fPainter, fPainter->fInternal,
|
|
||||||
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fPainter->fDrawingMode == B_OP_ALPHA
|
if ((fOptions & B_TILE_BITMAP) != 0) {
|
||||||
&& fPainter->fAlphaSrcMode == B_PIXEL_ALPHA
|
DrawBitmapGeneric<Tile>::Draw(fPainter, fPainter->fInternal, fBitmap,
|
||||||
&& fPainter->fAlphaFncMode == B_ALPHA_OVERLAY
|
fOffset, fScaleX, fScaleY, fDestinationRect, fOptions);
|
||||||
&& !_HasAffineTransform() && !_HasAlphaMask()
|
} else {
|
||||||
&& (fOptions & B_FILTER_BITMAP_BILINEAR) != 0) {
|
// for all other cases (non-optimized drawing mode or scaled drawing)
|
||||||
DrawBitmapBilinear<ColorTypeRgba, DrawModeAlphaOverlay> drawBilinear;
|
DrawBitmapGeneric<Fill>::Draw(fPainter, fPainter->fInternal, fBitmap,
|
||||||
drawBilinear.Draw(fPainter, fPainter->fInternal,
|
fOffset, fScaleX, fScaleY, fDestinationRect, fOptions);
|
||||||
fBitmap, fOffset, fScaleX, fScaleY, fDestinationRect);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for all other cases (non-optimized drawing mode or scaled drawing)
|
|
||||||
DrawBitmapGeneric::Draw(fPainter, fPainter->fInternal, fBitmap, fOffset,
|
|
||||||
fScaleX, fScaleY, fDestinationRect, fOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -183,33 +192,38 @@ Painter::BitmapPainter::_DetermineTransform(BRect sourceRect,
|
|||||||
align_rect_to_pixels(&fDestinationRect);
|
align_rect_to_pixels(&fDestinationRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
fScaleX = (fDestinationRect.Width() + 1) / (sourceRect.Width() + 1);
|
if((fOptions & B_TILE_BITMAP) == 0) {
|
||||||
fScaleY = (fDestinationRect.Height() + 1) / (sourceRect.Height() + 1);
|
fScaleX = (fDestinationRect.Width() + 1) / (sourceRect.Width() + 1);
|
||||||
|
fScaleY = (fDestinationRect.Height() + 1) / (sourceRect.Height() + 1);
|
||||||
|
|
||||||
if (fScaleX == 0.0 || fScaleY == 0.0)
|
if (fScaleX == 0.0 || fScaleY == 0.0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// constrain source rect to bitmap bounds and transfer the changes to
|
// constrain source rect to bitmap bounds and transfer the changes to
|
||||||
// the destination rect with the right scale
|
// the destination rect with the right scale
|
||||||
if (sourceRect.left < fBitmapBounds.left) {
|
if (sourceRect.left < fBitmapBounds.left) {
|
||||||
float diff = fBitmapBounds.left - sourceRect.left;
|
float diff = fBitmapBounds.left - sourceRect.left;
|
||||||
fDestinationRect.left += diff * fScaleX;
|
fDestinationRect.left += diff * fScaleX;
|
||||||
sourceRect.left = fBitmapBounds.left;
|
sourceRect.left = fBitmapBounds.left;
|
||||||
}
|
}
|
||||||
if (sourceRect.top < fBitmapBounds.top) {
|
if (sourceRect.top < fBitmapBounds.top) {
|
||||||
float diff = fBitmapBounds.top - sourceRect.top;
|
float diff = fBitmapBounds.top - sourceRect.top;
|
||||||
fDestinationRect.top += diff * fScaleY;
|
fDestinationRect.top += diff * fScaleY;
|
||||||
sourceRect.top = fBitmapBounds.top;
|
sourceRect.top = fBitmapBounds.top;
|
||||||
}
|
}
|
||||||
if (sourceRect.right > fBitmapBounds.right) {
|
if (sourceRect.right > fBitmapBounds.right) {
|
||||||
float diff = sourceRect.right - fBitmapBounds.right;
|
float diff = sourceRect.right - fBitmapBounds.right;
|
||||||
fDestinationRect.right -= diff * fScaleX;
|
fDestinationRect.right -= diff * fScaleX;
|
||||||
sourceRect.right = fBitmapBounds.right;
|
sourceRect.right = fBitmapBounds.right;
|
||||||
}
|
}
|
||||||
if (sourceRect.bottom > fBitmapBounds.bottom) {
|
if (sourceRect.bottom > fBitmapBounds.bottom) {
|
||||||
float diff = sourceRect.bottom - fBitmapBounds.bottom;
|
float diff = sourceRect.bottom - fBitmapBounds.bottom;
|
||||||
fDestinationRect.bottom -= diff * fScaleY;
|
fDestinationRect.bottom -= diff * fScaleY;
|
||||||
sourceRect.bottom = fBitmapBounds.bottom;
|
sourceRect.bottom = fBitmapBounds.bottom;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fScaleX = 1.0;
|
||||||
|
fScaleY = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fOffset.x = fDestinationRect.left - sourceRect.left;
|
fOffset.x = fDestinationRect.left - sourceRect.left;
|
||||||
|
|||||||
@@ -11,6 +11,25 @@
|
|||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct Fill {};
|
||||||
|
struct Tile {};
|
||||||
|
|
||||||
|
template<typename PixFmt, typename Mode>
|
||||||
|
struct ImageAccessor {};
|
||||||
|
|
||||||
|
template<typename PixFmt>
|
||||||
|
struct ImageAccessor<PixFmt, Fill> {
|
||||||
|
typedef agg::image_accessor_clone<PixFmt> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename PixFmt>
|
||||||
|
struct ImageAccessor<PixFmt, Tile> {
|
||||||
|
typedef agg::image_accessor_wrap<PixFmt,
|
||||||
|
agg::wrap_mode_repeat, agg::wrap_mode_repeat> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename FillMode>
|
||||||
struct DrawBitmapGeneric {
|
struct DrawBitmapGeneric {
|
||||||
static void
|
static void
|
||||||
Draw(const Painter* painter, PainterAggInterface& aggInterface,
|
Draw(const Painter* painter, PainterAggInterface& aggInterface,
|
||||||
@@ -44,7 +63,8 @@ struct DrawBitmapGeneric {
|
|||||||
agg::span_allocator<pixfmt_image::color_type> spanAllocator;
|
agg::span_allocator<pixfmt_image::color_type> spanAllocator;
|
||||||
|
|
||||||
// image accessor attached to pixel format of bitmap
|
// image accessor attached to pixel format of bitmap
|
||||||
typedef agg::image_accessor_clone<pixfmt_image> source_type;
|
typedef
|
||||||
|
typename ImageAccessor<pixfmt_image, FillMode>::type source_type;
|
||||||
source_type source(pixf_img);
|
source_type source(pixf_img);
|
||||||
|
|
||||||
// clip to the current clipping region's frame
|
// clip to the current clipping region's frame
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ SubInclude HAIKU_TOP src tests servers app statusbar ;
|
|||||||
SubInclude HAIKU_TOP src tests servers app stress_test ;
|
SubInclude HAIKU_TOP src tests servers app stress_test ;
|
||||||
SubInclude HAIKU_TOP src tests servers app text_rendering ;
|
SubInclude HAIKU_TOP src tests servers app text_rendering ;
|
||||||
SubInclude HAIKU_TOP src tests servers app textview ;
|
SubInclude HAIKU_TOP src tests servers app textview ;
|
||||||
|
SubInclude HAIKU_TOP src tests servers app tiled_bitmap_test ;
|
||||||
SubInclude HAIKU_TOP src tests servers app transformation ;
|
SubInclude HAIKU_TOP src tests servers app transformation ;
|
||||||
SubInclude HAIKU_TOP src tests servers app unit_tests ;
|
SubInclude HAIKU_TOP src tests servers app unit_tests ;
|
||||||
SubInclude HAIKU_TOP src tests servers app view_state ;
|
SubInclude HAIKU_TOP src tests servers app view_state ;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
SubDir HAIKU_TOP src tests servers app tiled_bitmap_test ;
|
||||||
|
|
||||||
|
AddSubDirSupportedPlatforms libbe_test ;
|
||||||
|
|
||||||
|
UseHeaders [ FDirName os app ] ;
|
||||||
|
UseHeaders [ FDirName os interface ] ;
|
||||||
|
|
||||||
|
Application TiledBitmapTest :
|
||||||
|
TiledBitmapTest.cpp
|
||||||
|
: be [ TargetLibstdc++ ] [ TargetLibsupc++ ]
|
||||||
|
;
|
||||||
|
|
||||||
|
if $(TARGET_PLATFORM) = libbe_test {
|
||||||
|
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : TiledBitmapTest
|
||||||
|
: tests!apps ;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, Haiku Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Kacper Kasper, kacperkasper@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <GradientRadial.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <View.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
class View : public BView {
|
||||||
|
public:
|
||||||
|
View(BRect rect);
|
||||||
|
virtual ~View();
|
||||||
|
|
||||||
|
virtual void Draw(BRect);
|
||||||
|
BBitmap* fBitmap;
|
||||||
|
};
|
||||||
|
|
||||||
|
View::View(BRect rect)
|
||||||
|
: BView(rect, "tiledBitmaps", B_FOLLOW_ALL, B_WILL_DRAW)
|
||||||
|
{
|
||||||
|
SetViewColor(make_color(255, 0, 0));
|
||||||
|
fBitmap = new BBitmap(BRect(0, 0, 5, 5), B_RGBA32);
|
||||||
|
uint32 data[] = {
|
||||||
|
0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000,
|
||||||
|
0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
|
||||||
|
0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
|
||||||
|
0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
|
||||||
|
0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
|
||||||
|
0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000,
|
||||||
|
};
|
||||||
|
/*uint32 data[] = {
|
||||||
|
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
};*/
|
||||||
|
fBitmap->SetBits((void*)data, sizeof(data), 0, B_RGBA32);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
View::~View()
|
||||||
|
{
|
||||||
|
delete fBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
View::Draw(BRect)
|
||||||
|
{
|
||||||
|
DrawTiledBitmap(fBitmap, BRect(10, 10, 60, 60), BPoint(1, 1));
|
||||||
|
DrawTiledBitmap(fBitmap, BRect(10, 60, 60, 110), BPoint(3, 3));
|
||||||
|
DrawTiledBitmap(fBitmap, BRect(10, 110, 60, 160));
|
||||||
|
DrawBitmap(fBitmap, fBitmap->Bounds(), BRect(60, 10, 110, 60));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
class Window : public BWindow {
|
||||||
|
public:
|
||||||
|
Window();
|
||||||
|
virtual ~Window();
|
||||||
|
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Window::Window()
|
||||||
|
: BWindow(BRect(100, 100, 300, 300), "TiledBitmap-Test",
|
||||||
|
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
{
|
||||||
|
BView *view = new View(Bounds());
|
||||||
|
AddChild(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Window::~Window()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Window::QuitRequested()
|
||||||
|
{
|
||||||
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
class Application : public BApplication {
|
||||||
|
public:
|
||||||
|
Application();
|
||||||
|
|
||||||
|
virtual void ReadyToRun();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Application::Application()
|
||||||
|
: BApplication("application/x-vnd.haiku-tiled_bitmap_test")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Application::ReadyToRun()
|
||||||
|
{
|
||||||
|
Window *window = new Window();
|
||||||
|
window->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
Application app;
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user