Skip to content

Commit 3e1d654

Browse files
committed
BrushEditor: size preview based on max dimension to avoid jumping
- Removed red line - Added size number to preview when it's larger than the preview bitmap
1 parent addb47e commit 3e1d654

File tree

4 files changed

+59
-47
lines changed

4 files changed

+59
-47
lines changed

artpaint/paintwindow/StatusView.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ CurrentBrushView::CurrentBrushView(BRect frame)
395395

396396
SetToolTip(B_TRANSLATE("Brush"));
397397

398-
frame.InsetBy(1.0, 1.0);
399-
fBrushPreview = new BBitmap(BRect(0.0, 0.0, frame.Width(), frame.Height()), B_RGBA32);
398+
fBrushPreview = new BBitmap(BRect(0.0, 0.0, frame.Width(), frame.Height()), B_RGBA32, true);
400399
BitmapUtilities::ClearBitmap(fBrushPreview, 0xFFFFFFFF);
401400

402401
list_of_views.AddItem(this);
@@ -412,11 +411,7 @@ CurrentBrushView::~CurrentBrushView()
412411

413412
void CurrentBrushView::Draw(BRect)
414413
{
415-
DrawBitmap(fBrushPreview, BPoint(1.0, 1.0));
416-
417-
SetPenSize(1);
418-
SetHighColor(0, 0, 0, 255);
419-
StrokeRect(Bounds());
414+
DrawBitmap(fBrushPreview, BPoint(0.0, 0.0));
420415
}
421416

422417

artpaint/tools/Brush.cpp

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,15 @@ Brush::delete_all_data()
379379
float
380380
Brush::PreviewBrush(BBitmap* preview_bitmap)
381381
{
382-
float preview_width = width_;
383-
float preview_height = height_;
382+
float bmap_width = (preview_bitmap->Bounds().Width() + 1);
383+
float bmap_height = (preview_bitmap->Bounds().Height() + 1);
384384

385-
float bmap_width = preview_bitmap->Bounds().Width() + 1;
386-
float bmap_height = preview_bitmap->Bounds().Height() + 1;
385+
float preview_width = 0.9 * bmap_width;
386+
float preview_height = 0.9 * bmap_height;
387387

388-
while ((preview_width > bmap_width) || (preview_height > bmap_height)) {
389-
preview_width /= 2.0;
390-
preview_height /= 2.0;
391-
}
392-
int32 scale = (int32)(width_ / preview_width);
388+
float max_dim = max_c(width_, height_);
393389

394-
int32 top = (int32)((bmap_height - preview_height) / 2.0);
395-
int32 left = (int32)((bmap_width - preview_width) / 2.0);
390+
float scale = max_c(1.0, max_dim / preview_width);
396391

397392
uint32* bits = (uint32*)preview_bitmap->Bits();
398393
int32 bpr = preview_bitmap->BytesPerRow() / 4;
@@ -413,11 +408,22 @@ Brush::PreviewBrush(BBitmap* preview_bitmap)
413408
uint32 brush_bpr = brush_bmap->BytesPerRow() / 4;
414409
brush_bmap->Unlock();
415410

411+
int32 draw_width = brush_bpr / scale;
412+
int32 draw_height = brush_bmap->Bounds().Height() / scale;
413+
414+
int32 top = (int32)((bmap_height - draw_height) / 2.0);
415+
int32 left = (int32)((bmap_width - draw_width) / 2.0);
416+
416417
// Here we draw the brush to the bitmap.
417418
for (int32 y = 0; y < preview_height; ++y) {
419+
if (ceil(y * scale) > brush_bmap->Bounds().Height())
420+
break;
418421
for (int32 x = 0; x < preview_width; ++x) {
422+
if (ceil(x * scale) > brush_bpr)
423+
break;
424+
419425
union color_conversion color;
420-
color.word = *(brush_bits + (x * scale) + (y * scale * brush_bpr));
426+
color.word = *(brush_bits + (int32)ceil(x * scale) + ((int32)ceil(y * scale) * brush_bpr));
421427
color.bytes[0] = 255 - color.bytes[0];
422428
color.bytes[1] = 255 - color.bytes[1];
423429
color.bytes[2] = 255 - color.bytes[2];
@@ -428,22 +434,37 @@ Brush::PreviewBrush(BBitmap* preview_bitmap)
428434
}
429435
}
430436

431-
// Here we draw a line indicating the relative size of the brush
432-
color.bytes[0] = 0x00;
433-
color.bytes[1] = 0x00;
434-
color.bytes[2] = 0xFF;
435-
color.bytes[3] = 0xFF;
436-
bits = (uint32*)preview_bitmap->Bits();
437-
bits += bpr * (int32)(bmap_height - 5) + 1;
438-
*(bits - bpr) = color.word;
439-
*(bits + bpr) = color.word;
440-
for (int32 i = 0; i < bmap_width * (preview_width / width_) - 3; i++)
441-
*bits++ = color.word;
442-
bits--;
443-
*(bits - bpr) = color.word;
444-
*(bits + bpr) = color.word;
445-
446-
return preview_width / width_;
437+
// Add the brush size to the bottom of the preview
438+
BFont font;
439+
font.SetSize(bmap_width / 6);
440+
BString brushSizeString;
441+
brushSizeString.SetToFormat("%d", (int32)max_dim - 2);
442+
443+
int32 strWidth = font.StringWidth("000");
444+
font_height strHeight;
445+
font.GetHeight(&strHeight);
446+
int32 strX = 0;
447+
int32 strY = (int32)(bmap_height - 1);
448+
BRect fontBGRect(strX - 1, strY - strHeight.ascent + 2,
449+
strX + strWidth + 2, bmap_height);
450+
451+
preview_bitmap->Lock();
452+
BView* numView = new BView(preview_bitmap->Bounds(), "", B_FOLLOW_NONE, B_WILL_DRAW);
453+
preview_bitmap->AddChild(numView);
454+
rgb_color highColor = numView->HighColor();
455+
numView->StrokeRect(preview_bitmap->Bounds(), B_SOLID_HIGH);
456+
numView->StrokeRect(fontBGRect.OffsetByCopy(1.0, -1.0), B_SOLID_HIGH);
457+
numView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
458+
numView->FillRect(fontBGRect, B_SOLID_HIGH);
459+
numView->MovePenTo(BPoint(strX, strY));
460+
numView->SetHighColor(highColor);
461+
numView->SetFont(&font);
462+
numView->DrawString(brushSizeString);
463+
464+
numView->Sync();
465+
preview_bitmap->Unlock();
466+
467+
return preview_width / max_dim;
447468
}
448469

449470

artpaint/tools/BrushEditor.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ BrushView::BrushView(BRect frame, Brush* brush)
374374

375375
SetToolTip(B_TRANSLATE("Hold SHIFT to snap to 45° angles"));
376376

377-
frame.InsetBy(1.0, 1.0);
378377
fBrushPreview
379-
= new BBitmap(BRect(0.0, 0.0, frame.Width() - 1.0, frame.Height() - 1.0), B_RGBA32);
378+
= new BBitmap(BRect(0.0, 0.0, frame.Width(), frame.Height()), B_RGBA32, true);
380379
fBrush->PreviewBrush(fBrushPreview);
381380
}
382381

@@ -389,11 +388,7 @@ BrushView::~BrushView()
389388

390389
void BrushView::Draw(BRect)
391390
{
392-
DrawBitmap(fBrushPreview, BPoint(1.0, 1.0));
393-
394-
SetPenSize(1);
395-
SetHighColor(0, 0, 0, 255);
396-
StrokeRect(Bounds());
391+
DrawBitmap(fBrushPreview, BPoint(0.0, 0.0));
397392

398393
if (fDrawControls) {
399394
float r1 = Bounds().Width() / 2;

artpaint/windows/BrushStoreWindow.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,18 @@ BrushStoreView::Draw(BRect area)
310310
SetPenSize(1.0);
311311
for (int32 i = 0; i < brush_images->CountItems(); i++) {
312312
if ((area & get_bitmap_frame(i)).IsValid() == TRUE) {
313-
DrawBitmapAsync((BBitmap*)brush_images->ItemAt(i), get_bitmap_frame(i));
313+
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
314314
BRect outer_frame = get_bitmap_frame(i);
315-
outer_frame.InsetBy(-1, -1);
316-
StrokeRect(outer_frame);
315+
DrawBitmap((BBitmap*)brush_images->ItemAt(i), get_bitmap_frame(i));
316+
StrokeRect(outer_frame.InsetByCopy(-1, -1));
317+
StrokeRect(outer_frame.InsetByCopy(-2, -2));
317318
}
318319
}
319320
if (IsFocus() && (brush_data->CountItems() > 0)) {
320321
SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
321322
BRect outer_frame = get_bitmap_frame(selected_brush_index);
322323
SetPenSize(1.5);
323-
StrokeRect(outer_frame);
324+
StrokeRect(outer_frame.InsetByCopy(-1, -1));
324325
}
325326
Sync();
326327
}
@@ -483,7 +484,7 @@ BrushStoreView::AddBrush(Brush* brush)
483484
bool added = false;
484485

485486
BBitmap* a_bitmap
486-
= new BBitmap(BRect(0, 0, BRUSH_PREVIEW_WIDTH - 1, BRUSH_PREVIEW_HEIGHT - 1), B_RGB_32_BIT);
487+
= new BBitmap(BRect(0, 0, BRUSH_PREVIEW_WIDTH, BRUSH_PREVIEW_HEIGHT), B_RGB_32_BIT, true);
487488

488489
brush_info new_brush_info = brush->GetInfo();
489490

0 commit comments

Comments
 (0)