ShowImage: Use BControlLook::ComposeIconSize.

Also use BBitmap::ImportBits instead of a manual copy, while at it.
This commit is contained in:
Augustin Cavalier
2022-08-29 16:08:27 -04:00
parent fac73debbf
commit 87d8b1776f
2 changed files with 13 additions and 25 deletions
+4 -11
View File
@@ -28,6 +28,7 @@
#include <BitmapStream.h>
#include <Catalog.h>
#include <Clipboard.h>
#include <ControlLook.h>
#include <Cursor.h>
#include <Debug.h>
#include <Directory.h>
@@ -133,7 +134,7 @@ compose_checker_background(const BBitmap* bitmap)
blend_colors(p, kAlphaLow.red, kAlphaLow.green, kAlphaLow.blue, alpha);
else
blend_colors(p, kAlphaHigh.red, kAlphaHigh.green, kAlphaHigh.blue, alpha);
} else {
if (i % 10 >= 5)
blend_colors(p, kAlphaHigh.red, kAlphaHigh.green, kAlphaHigh.blue, alpha);
@@ -1105,7 +1106,7 @@ ShowImageView::MouseDown(BPoint position)
// Using clickCount >= 2 and the modulo 2 accounts for quickly repeated
// double-clicks
if (buttons == B_PRIMARY_MOUSE_BUTTON && clickCount >= 2 &&
if (buttons == B_PRIMARY_MOUSE_BUTTON && clickCount >= 2 &&
clickCount % 2 == 0) {
Window()->PostMessage(MSG_FULL_SCREEN);
return;
@@ -1752,15 +1753,7 @@ ShowImageView::ResizeImage(int w, int h)
void
ShowImageView::_SetIcon(bool clear, icon_size which)
{
int32 size;
switch (which) {
case B_MINI_ICON: size = 16;
break;
case B_LARGE_ICON: size = 32;
break;
default:
return;
}
const int32 size = be_control_look->ComposeIconSize(which).IntegerWidth() + 1;
BRect rect(fBitmap->Bounds());
float s;
+9 -14
View File
@@ -15,6 +15,7 @@
#include <string.h>
#include <Bitmap.h>
#include <ControlLook.h>
#include <IconUtils.h>
@@ -622,10 +623,10 @@ static IconData kIcons[] = {
status_t
init_tool_bar_icons()
{
const int32 toolBarIconsSize = 22;
const int32 iconRenderSize = max_c(toolBarIconsSize, 32);
const BSize toolBarIconsSize = be_control_look->ComposeIconSize(22);
const BSize iconRenderSize = be_control_look->ComposeIconSize(32);
BBitmap bitmap(BRect(0, 0, iconRenderSize - 1, iconRenderSize - 1),
BBitmap bitmap(BRect(BPoint(0, 0), iconRenderSize),
B_BITMAP_NO_SERVER_LINK, B_RGBA32);
for (uint32 i = 0; i < sizeof(kIcons) / sizeof(IconData); i++) {
@@ -633,22 +634,16 @@ init_tool_bar_icons()
kIcons[i].size, &bitmap);
if (ret != B_OK)
return ret;
kIcons[i].bitmap = new(std::nothrow) BBitmap(BRect(0, 0,
toolBarIconsSize - 1, toolBarIconsSize - 1), 0, B_RGBA32);
kIcons[i].bitmap = new(std::nothrow) BBitmap(BRect(BPoint(0, 0),
toolBarIconsSize), 0, B_RGBA32);
if (kIcons[i].bitmap == NULL)
return B_NO_MEMORY;
ret = kIcons[i].bitmap->InitCheck();
if (ret != B_OK)
return ret;
uint8* src = reinterpret_cast<uint8*>(bitmap.Bits());
uint32 srcBPR = bitmap.BytesPerRow();
uint8* dst = reinterpret_cast<uint8*>(kIcons[i].bitmap->Bits());
uint32 dstBPR = kIcons[i].bitmap->BytesPerRow();
for (int32 y = 0; y < toolBarIconsSize; y++) {
memcpy(dst, src, 4 * toolBarIconsSize);
src += srcBPR;
dst += dstBPR;
}
kIcons[i].bitmap->ImportBits(&bitmap, BPoint(0, 0), BPoint(0, 0),
toolBarIconsSize);
}
// Initializing 14 icons on startup takes about 10ms on a Core2Duo @ 2GHz.