@@ -379,20 +379,15 @@ Brush::delete_all_data()
379
379
float
380
380
Brush::PreviewBrush (BBitmap* preview_bitmap)
381
381
{
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 ) ;
384
384
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 ;
387
387
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_);
393
389
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);
396
391
397
392
uint32* bits = (uint32*)preview_bitmap->Bits ();
398
393
int32 bpr = preview_bitmap->BytesPerRow () / 4 ;
@@ -413,11 +408,22 @@ Brush::PreviewBrush(BBitmap* preview_bitmap)
413
408
uint32 brush_bpr = brush_bmap->BytesPerRow () / 4 ;
414
409
brush_bmap->Unlock ();
415
410
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
+
416
417
// Here we draw the brush to the bitmap.
417
418
for (int32 y = 0 ; y < preview_height; ++y) {
419
+ if (ceil (y * scale) > brush_bmap->Bounds ().Height ())
420
+ break ;
418
421
for (int32 x = 0 ; x < preview_width; ++x) {
422
+ if (ceil (x * scale) > brush_bpr)
423
+ break ;
424
+
419
425
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));
421
427
color.bytes [0 ] = 255 - color.bytes [0 ];
422
428
color.bytes [1 ] = 255 - color.bytes [1 ];
423
429
color.bytes [2 ] = 255 - color.bytes [2 ];
@@ -428,22 +434,37 @@ Brush::PreviewBrush(BBitmap* preview_bitmap)
428
434
}
429
435
}
430
436
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;
447
468
}
448
469
449
470
0 commit comments