[haiku-commits] haiku: hrev54087 - src/add-ons/screen_savers/message

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 24 Apr 2020 18:34:11 -0400 (EDT)

hrev54087 adds 1 changeset to branch 'master'
old head: 6d31c23459cd520a2a291ae30ddb6a21aaf33c44
new head: 3ed66cafbac12eda5b64864aa80478fb7d73e2c1
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=3ed66cafbac1+%5E6d31c23459cd

----------------------------------------------------------------------------

3ed66cafbac1: 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 <waddlesplash@xxxxxxxxx>

                                              [ X512 <danger_mail@xxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev54087
Commit:      3ed66cafbac12eda5b64864aa80478fb7d73e2c1
URL:         https://git.haiku-os.org/haiku/commit/?id=3ed66cafbac1
Author:      X512 <danger_mail@xxxxxxx>
Date:        Mon Mar 23 00:46:50 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Apr 24 22:34:07 2020 UTC

----------------------------------------------------------------------------

1 file changed, 23 insertions(+), 20 deletions(-)
src/add-ons/screen_savers/message/Message.cpp | 43 ++++++++++++-----------

----------------------------------------------------------------------------

diff --git a/src/add-ons/screen_savers/message/Message.cpp 
b/src/add-ons/screen_savers/message/Message.cpp
index 50e6640343..a17af0b7a9 100644
--- a/src/add-ons/screen_savers/message/Message.cpp
+++ b/src/add-ons/screen_savers/message/Message.cpp
@@ -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);


Other related posts:

  • » [haiku-commits] haiku: hrev54087 - src/add-ons/screen_savers/message - waddlesplash