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:
@@ -88,18 +88,21 @@ class Message : public BScreenSaver
|
|||||||
void Draw(BView *view, int32 frame);
|
void Draw(BView *view, int32 frame);
|
||||||
void StartConfig(BView *view);
|
void StartConfig(BView *view);
|
||||||
status_t StartSaver(BView *view, bool preview);
|
status_t StartSaver(BView *view, bool preview);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BObjectList<font_family> fFontFamilies;
|
struct font_family_wrapper {
|
||||||
|
font_family val;
|
||||||
|
};
|
||||||
|
BObjectList<font_family_wrapper> fFontFamilies;
|
||||||
float fScaleFactor;
|
float fScaleFactor;
|
||||||
bool fPreview;
|
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);
|
return new Message(msg, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Message::Message(BMessage *archive, image_id id)
|
Message::Message(BMessage *archive, image_id id)
|
||||||
@@ -112,20 +115,20 @@ Message::~Message()
|
|||||||
{
|
{
|
||||||
for (int32 i = 0; i < fFontFamilies.CountItems(); i++) {
|
for (int32 i = 0; i < fFontFamilies.CountItems(); i++) {
|
||||||
if (fFontFamilies.ItemAt(i))
|
if (fFontFamilies.ItemAt(i))
|
||||||
delete[] fFontFamilies.ItemAt(i);
|
delete fFontFamilies.ItemAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Message::StartConfig(BView *view)
|
Message::StartConfig(BView *view)
|
||||||
{
|
{
|
||||||
BPrivate::BuildDefaultSettingsView(view, "Message",
|
BPrivate::BuildDefaultSettingsView(view, "Message",
|
||||||
B_TRANSLATE("by Ryan Leavengood"));
|
B_TRANSLATE("by Ryan Leavengood"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Message::StartSaver(BView *view, bool preview)
|
Message::StartSaver(BView *view, bool preview)
|
||||||
{
|
{
|
||||||
fPreview = preview;
|
fPreview = preview;
|
||||||
@@ -136,14 +139,14 @@ Message::StartSaver(BView *view, bool preview)
|
|||||||
// Get font families
|
// Get font families
|
||||||
int numFamilies = count_font_families();
|
int numFamilies = count_font_families();
|
||||||
for (int32 i = 0; i < numFamilies; i++) {
|
for (int32 i = 0; i < numFamilies; i++) {
|
||||||
font_family* family = new font_family[1];
|
font_family_wrapper* family = new font_family_wrapper;
|
||||||
uint32 flags;
|
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) {
|
&& (flags & B_IS_FIXED) == 0) {
|
||||||
// Do not add fixed fonts
|
// Do not add fixed fonts
|
||||||
fFontFamilies.AddItem(family);
|
fFontFamilies.AddItem(family);
|
||||||
} else
|
} else
|
||||||
delete[] family;
|
delete family;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed the random number generator
|
// 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
|
// Set tick size to 30,000,000 microseconds = 30 seconds
|
||||||
SetTickSize(30000000);
|
SetTickSize(30000000);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Message::Draw(BView *view, int32 frame)
|
Message::Draw(BView *view, int32 frame)
|
||||||
{
|
{
|
||||||
if (view == NULL || view->Window() == NULL || !view->Window()->IsLocked())
|
if (view == NULL || view->Window() == NULL || !view->Window()->IsLocked())
|
||||||
@@ -178,7 +181,7 @@ Message::Draw(BView *view, int32 frame)
|
|||||||
// Set up the colors
|
// Set up the colors
|
||||||
rgb_color base_color = {(uint8)(rand() % 25), (uint8)(rand() % 25),
|
rgb_color base_color = {(uint8)(rand() % 25), (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.SetLowColor(tint_color(base_color, 0.815F));
|
||||||
offscreen.FillRect(offscreen.Bounds(), kCheckered);
|
offscreen.FillRect(offscreen.Bounds(), kCheckered);
|
||||||
rgb_color colors[8] = {
|
rgb_color colors[8] = {
|
||||||
@@ -198,7 +201,7 @@ Message::Draw(BView *view, int32 frame)
|
|||||||
BFont font;
|
BFont font;
|
||||||
offscreen.GetFont(&font);
|
offscreen.GetFont(&font);
|
||||||
font.SetFace(B_BOLD_FACE);
|
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);
|
offscreen.SetFont(&font);
|
||||||
|
|
||||||
// Get the message
|
// Get the message
|
||||||
@@ -252,13 +255,13 @@ Message::Draw(BView *view, int32 frame)
|
|||||||
// if this isn't preview mode
|
// if this isn't preview mode
|
||||||
if (!fPreview) {
|
if (!fPreview) {
|
||||||
BFont font(be_fixed_font);
|
BFont font(be_fixed_font);
|
||||||
font.SetSize(14.0);
|
font.SetSize(14.0);
|
||||||
offscreen.SetFont(&font);
|
offscreen.SetFont(&font);
|
||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
font.GetHeight(&fontHeight);
|
font.GetHeight(&fontHeight);
|
||||||
float lineHeight = fontHeight.ascent + fontHeight.descent
|
float lineHeight = fontHeight.ascent + fontHeight.descent
|
||||||
+ fontHeight.leading;
|
+ fontHeight.leading;
|
||||||
|
|
||||||
BStringList lines;
|
BStringList lines;
|
||||||
int longestLine = 0;
|
int longestLine = 0;
|
||||||
int32 count = get_lines(origMessage, lines, &longestLine);
|
int32 count = get_lines(origMessage, lines, &longestLine);
|
||||||
|
|||||||
Reference in New Issue
Block a user