Message screensaver: fix array delete[] problem on clang, style fixes

Change-Id: Ic0182e81e9267c69b92ed60a85026eb45cda3a2d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2407
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
X512
2020-04-24 22:34:07 +00:00
committed by waddlesplash
parent 6d31c23459
commit 3ed66cafba
+23 -20
View File
@@ -88,18 +88,21 @@ class Message : public BScreenSaver
void Draw(BView *view, int32 frame);
void StartConfig(BView *view);
status_t StartSaver(BView *view, bool preview);
private:
BObjectList<font_family> fFontFamilies;
struct font_family_wrapper {
font_family val;
};
BObjectList<font_family_wrapper> fFontFamilies;
float fScaleFactor;
bool fPreview;
};
BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id image)
{
BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id image)
{
return new Message(msg, image);
}
}
Message::Message(BMessage *archive, image_id id)
@@ -112,20 +115,20 @@ Message::~Message()
{
for (int32 i = 0; i < fFontFamilies.CountItems(); i++) {
if (fFontFamilies.ItemAt(i))
delete[] fFontFamilies.ItemAt(i);
delete fFontFamilies.ItemAt(i);
}
}
void
Message::StartConfig(BView *view)
{
void
Message::StartConfig(BView *view)
{
BPrivate::BuildDefaultSettingsView(view, "Message",
B_TRANSLATE("by Ryan Leavengood"));
}
}
status_t
status_t
Message::StartSaver(BView *view, bool preview)
{
fPreview = preview;
@@ -136,14 +139,14 @@ Message::StartSaver(BView *view, bool preview)
// Get font families
int numFamilies = count_font_families();
for (int32 i = 0; i < numFamilies; i++) {
font_family* family = new font_family[1];
font_family_wrapper* family = new font_family_wrapper;
uint32 flags;
if (get_font_family(i, family, &flags) == B_OK
if (get_font_family(i, &(family->val), &flags) == B_OK
&& (flags & B_IS_FIXED) == 0) {
// Do not add fixed fonts
fFontFamilies.AddItem(family);
} else
delete[] family;
delete family;
}
// Seed the random number generator
@@ -151,12 +154,12 @@ Message::StartSaver(BView *view, bool preview)
// Set tick size to 30,000,000 microseconds = 30 seconds
SetTickSize(30000000);
return B_OK;
}
void
void
Message::Draw(BView *view, int32 frame)
{
if (view == NULL || view->Window() == NULL || !view->Window()->IsLocked())
@@ -178,7 +181,7 @@ Message::Draw(BView *view, int32 frame)
// Set up the colors
rgb_color base_color = {(uint8)(rand() % 25), (uint8)(rand() % 25),
(uint8)(rand() % 25)};
offscreen.SetHighColor(base_color);
offscreen.SetHighColor(base_color);
offscreen.SetLowColor(tint_color(base_color, 0.815F));
offscreen.FillRect(offscreen.Bounds(), kCheckered);
rgb_color colors[8] = {
@@ -198,7 +201,7 @@ Message::Draw(BView *view, int32 frame)
BFont font;
offscreen.GetFont(&font);
font.SetFace(B_BOLD_FACE);
font.SetFamilyAndStyle(*(fFontFamilies.ItemAt(rand() % fFontFamilies.CountItems())), NULL);
font.SetFamilyAndStyle(fFontFamilies.ItemAt(rand() % fFontFamilies.CountItems())->val, NULL);
offscreen.SetFont(&font);
// Get the message
@@ -252,13 +255,13 @@ Message::Draw(BView *view, int32 frame)
// if this isn't preview mode
if (!fPreview) {
BFont font(be_fixed_font);
font.SetSize(14.0);
font.SetSize(14.0);
offscreen.SetFont(&font);
font_height fontHeight;
font.GetHeight(&fontHeight);
float lineHeight = fontHeight.ascent + fontHeight.descent
+ fontHeight.leading;
BStringList lines;
int longestLine = 0;
int32 count = get_lines(origMessage, lines, &longestLine);