[haiku-commits] haiku: hrev46746 - src/add-ons/screen_savers/icons

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 23 Jan 2014 02:43:42 +0100 (CET)

hrev46746 adds 3 changesets to branch 'master'
old head: 000c26330bf4ec8be161a7dc2433981efd3d3e01
new head: 0def0b0d621f3c051375d11826b6143272dcc9b9
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0def0b0+%5E000c263

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

05cf63e: Icons Screensaver: Update copyright header and version
  
  Add myself to authors, assign copyright to Haiku, Inc.
  
  Bump version to 1.0.1-final, update short and long description

3cbb113: Icons Screensaver: Style fixes only

0def0b0: Icons Screensaver: Grab vector icons via query, fixes #10166
  
  Iterate through each BFS volume and find vector icon data in apps
  using a BFS query. Cap off at 128 total icons, we could get more if
  desired. Default install comes with ~100 at present.
  
  Make sure we have at least 20 icons (15 display at a time) before we
  start drawing icons.
  
  Rename VectorIcon to vector_icon and treat it like the POD struct that it is.
  Also add a type_code parame to vector_icon that should be set to
  B_VECTOR_ICON.
  
  Some style fixes also included, e.g. turned defines into static const int32’s.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

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

5 files changed, 162 insertions(+), 92 deletions(-)
src/add-ons/screen_savers/icons/IconDisplay.cpp |  13 +-
src/add-ons/screen_savers/icons/IconDisplay.h   |  48 +++---
src/add-ons/screen_savers/icons/Icons.rdef      |   8 +-
src/add-ons/screen_savers/icons/IconsSaver.cpp  | 156 +++++++++++++-------
src/add-ons/screen_savers/icons/IconsSaver.h    |  29 ++--

############################################################################

Commit:      05cf63e3a734264c6a7d2ba3ca1d2e8b80945f9b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=05cf63e
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Thu Jan 23 01:35:05 2014 UTC

Icons Screensaver: Update copyright header and version

Add myself to authors, assign copyright to Haiku, Inc.

Bump version to 1.0.1-final, update short and long description

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

diff --git a/src/add-ons/screen_savers/icons/IconDisplay.cpp 
b/src/add-ons/screen_savers/icons/IconDisplay.cpp
index 67cbdcb..52de1db 100644
--- a/src/add-ons/screen_savers/icons/IconDisplay.cpp
+++ b/src/add-ons/screen_savers/icons/IconDisplay.cpp
@@ -1,7 +1,12 @@
 /*
-       Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
-       All rights reserved. Distributed under the terms of the MIT License.
-*/
+ * Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
+ * Copyright 2014 Haiku, Inc. All rights reserved.
+ *
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             John Scipione, jscipione@xxxxxxxxx
+ */
 
 
 #include "IconDisplay.h"
diff --git a/src/add-ons/screen_savers/icons/IconDisplay.h 
b/src/add-ons/screen_savers/icons/IconDisplay.h
index f9441e6..43efa1c 100644
--- a/src/add-ons/screen_savers/icons/IconDisplay.h
+++ b/src/add-ons/screen_savers/icons/IconDisplay.h
@@ -1,7 +1,12 @@
 /*
-       Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
-       All rights reserved. Distributed under the terms of the MIT License.
-*/
+ * Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
+ * Copyright 2014 Haiku, Inc. All rights reserved.
+ *
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             John Scipione, jscipione@xxxxxxxxx
+ */
 #ifndef ICON_DISPLAY_H
 #define ICON_DISPLAY_H
 
diff --git a/src/add-ons/screen_savers/icons/Icons.rdef 
b/src/add-ons/screen_savers/icons/Icons.rdef
index cf87fb8..5e126ed 100644
--- a/src/add-ons/screen_savers/icons/Icons.rdef
+++ b/src/add-ons/screen_savers/icons/Icons.rdef
@@ -6,9 +6,9 @@ resource app_name_catalog_entry 
"x-vnd.Haiku-IconsScreensaver:System name:Icons"
 resource app_version {
        major  = 1,
        middle = 0,
-       minor  = 0,
-       variety = 0,
+       minor  = 1,
+       variety = 5,
        internal = 0,
-       short_info = "1.0.0",
-       long_info = "Screensaver Icons"
+       short_info = "Icons Screensaver",
+       long_info = "Icons Screensaver ©2009 Vincent Duvert, ©2014 Haiku, Inc."
 };
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.cpp 
b/src/add-ons/screen_savers/icons/IconsSaver.cpp
index 45c8127..6285bd7 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.cpp
+++ b/src/add-ons/screen_savers/icons/IconsSaver.cpp
@@ -1,7 +1,12 @@
 /*
-       Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
-       All rights reserved. Distributed under the terms of the MIT License.
-*/
+ * Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
+ * Copyright 2014 Haiku, Inc. All rights reserved.
+ *
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             John Scipione, jscipione@xxxxxxxxx
+ */
 
 
 #include "IconsSaver.h"
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.h 
b/src/add-ons/screen_savers/icons/IconsSaver.h
index b2ed86c..4e69c3f 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.h
+++ b/src/add-ons/screen_savers/icons/IconsSaver.h
@@ -1,7 +1,12 @@
 /*
-       Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
-       All rights reserved. Distributed under the terms of the MIT License.
-*/
+ * Copyright 2009 Vincent Duvert, vincent.duvert@xxxxxxx
+ * Copyright 2014 Haiku, Inc. All rights reserved.
+ *
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             John Scipione, jscipione@xxxxxxxxx
+ */
 #ifndef ICONS_SAVER_H
 #define ICONS_SAVER_H
 

############################################################################

Commit:      3cbb1132f803048060fed885dee47c96047b857f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3cbb113
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Thu Jan 23 01:39:37 2014 UTC

Icons Screensaver: Style fixes only

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

diff --git a/src/add-ons/screen_savers/icons/IconDisplay.h 
b/src/add-ons/screen_savers/icons/IconDisplay.h
index 43efa1c..67f8d3d 100644
--- a/src/add-ons/screen_savers/icons/IconDisplay.h
+++ b/src/add-ons/screen_savers/icons/IconDisplay.h
@@ -10,6 +10,7 @@
 #ifndef ICON_DISPLAY_H
 #define ICON_DISPLAY_H
 
+
 #include <Rect.h>
 #include <View.h>
 
@@ -35,14 +36,15 @@ public:
                        void                            DrawOn(BView* view, 
uint32 delta);
 
 private:
-       bool                                            fIsRunning;
-       uint8                                           fState;
-       
-       int32                                           fTicks;
-       int32                                           fDelay;
+                       bool                            fIsRunning;
+                       uint8                           fState;
 
-       BBitmap*                                        fBitmap;
-       BRect                                           fFrame;
+                       int32                           fTicks;
+                       int32                           fDelay;
+
+                       BBitmap*                        fBitmap;
+                       BRect                           fFrame;
 };
 
-#endif
+
+#endif // ICON_DISPLAY_H
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.cpp 
b/src/add-ons/screen_savers/icons/IconsSaver.cpp
index 6285bd7..a58e553 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.cpp
+++ b/src/add-ons/screen_savers/icons/IconsSaver.cpp
@@ -23,6 +23,7 @@
 
 #include "IconDisplay.h"
 
+
 #undef B_TRANSLATION_CONTEXT
 #define B_TRANSLATION_CONTEXT "Screensaver Icons"
 
@@ -36,16 +37,19 @@
 const rgb_color kBackgroundColor = ui_color(B_DESKTOP_COLOR);
 
 
+
 BScreenSaver* instantiate_screen_saver(BMessage* msg, image_id image)
 {
        return new IconsSaver(msg, image);
 }
 
 
-IconsSaver::IconsSaver(BMessage* msg, image_id image)
+//     #pragma mark - IconsSaver
+
+
+IconsSaver::IconsSaver(BMessage* archive, image_id image)
        :
-       BScreenSaver(msg, image),
-       fVectorIconsCount(0),
+       BScreenSaver(archive, image),
        fIcons(NULL),
        fBackBitmap(NULL),
        fBackView(NULL),
@@ -61,7 +65,7 @@ IconsSaver::~IconsSaver()
 
 
 status_t
-IconsSaver::StartSaver(BView *view, bool /*preview*/)
+IconsSaver::StartSaver(BView* view, bool /*preview*/)
 {
        if (fVectorIconsCount <= 0) {
                // Load the vector icons from the MIME types
@@ -138,11 +142,11 @@ IconsSaver::StopSaver()
 
 
 void
-IconsSaver::Draw(BView *view, int32 frame)
+IconsSaver::Draw(BView* view, int32 frame)
 {
        static int32 previousFrame = 0;
 
-       // Update drawing
+       // update drawing
        if (fBackBitmap->Lock()) {
                for (uint8 i = 0 ; i < MAX_ICONS ; i++) {
                        fIcons[i].ClearOn(fBackView);
@@ -157,7 +161,7 @@ IconsSaver::Draw(BView *view, int32 frame)
                fBackBitmap->Unlock();
        }
 
-       // Sync the view with the back buffer
+       // sync the view with the back buffer
        view->DrawBitmap(fBackBitmap);
        previousFrame = frame;
 
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.h 
b/src/add-ons/screen_savers/icons/IconsSaver.h
index 4e69c3f..82431ff 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.h
+++ b/src/add-ons/screen_savers/icons/IconsSaver.h
@@ -10,6 +10,7 @@
 #ifndef ICONS_SAVER_H
 #define ICONS_SAVER_H
 
+
 #include <List.h>
 #include <ScreenSaver.h>
 
@@ -37,7 +38,10 @@ private:
        BBitmap*                                        fBackBitmap;
        BView*                                          fBackView;
 
-       uint16                                          fMinSize, fMaxSize;
+
+                       uint16                          fMinSize;
+                       uint16                          fMaxSize;
 };
 
-#endif
+
+#endif // ICONS_SAVER_H

############################################################################

Revision:    hrev46746
Commit:      0def0b0d621f3c051375d11826b6143272dcc9b9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0def0b0
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Thu Jan 23 01:43:22 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/10166

Icons Screensaver: Grab vector icons via query, fixes #10166

Iterate through each BFS volume and find vector icon data in apps
using a BFS query. Cap off at 128 total icons, we could get more if
desired. Default install comes with ~100 at present.

Make sure we have at least 20 icons (15 display at a time) before we
start drawing icons.

Rename VectorIcon to vector_icon and treat it like the POD struct that it is.
Also add a type_code parame to vector_icon that should be set to
B_VECTOR_ICON.

Some style fixes also included, e.g. turned defines into static const int32’s.

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

diff --git a/src/add-ons/screen_savers/icons/IconDisplay.cpp 
b/src/add-ons/screen_savers/icons/IconDisplay.cpp
index 52de1db..3c3ca0b 100644
--- a/src/add-ons/screen_savers/icons/IconDisplay.cpp
+++ b/src/add-ons/screen_savers/icons/IconDisplay.cpp
@@ -42,7 +42,7 @@ IconDisplay::~IconDisplay()
 
 
 void
-IconDisplay::Run(VectorIcon* icon, BRect frame)
+IconDisplay::Run(vector_icon* icon, BRect frame)
 {
        delete fBitmap;
 
diff --git a/src/add-ons/screen_savers/icons/IconDisplay.h 
b/src/add-ons/screen_savers/icons/IconDisplay.h
index 67f8d3d..d077753 100644
--- a/src/add-ons/screen_savers/icons/IconDisplay.h
+++ b/src/add-ons/screen_savers/icons/IconDisplay.h
@@ -12,11 +12,14 @@
 
 
 #include <Rect.h>
+#include <SupportDefs.h>
 #include <View.h>
 
-struct VectorIcon {
-        uint8* data;
-        size_t size;
+
+struct vector_icon {
+       uint8* data;
+       size_t size;
+       type_code type;
 };
 
 
@@ -27,10 +30,10 @@ class IconDisplay {
 public:
                                                                IconDisplay();
                                                                ~IconDisplay();
-       
-                       void                            Run(VectorIcon* icon, 
BRect frame);
-       inline  bool                            IsRunning() { return 
fIsRunning; };
-       inline  BRect                           GetFrame() { return fFrame; };
+
+                       void                            Run(vector_icon* icon, 
BRect frame);
+       inline  bool                            IsRunning() const { return 
fIsRunning; };
+       inline  BRect                           GetFrame() const { return 
fFrame; };
 
                        void                            ClearOn(BView* view);
                        void                            DrawOn(BView* view, 
uint32 delta);
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.cpp 
b/src/add-ons/screen_savers/icons/IconsSaver.cpp
index a58e553..8f23d45 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.cpp
+++ b/src/add-ons/screen_savers/icons/IconsSaver.cpp
@@ -16,8 +16,14 @@
 
 #include <Bitmap.h>
 #include <Catalog.h>
+#include <Entry.h>
 #include <MimeType.h>
+#include <Node.h>
+#include <NodeInfo.h>
 #include <StringView.h>
+#include <Query.h>
+#include <Volume.h>
+#include <VolumeRoster.h>
 
 #include <BuildScreenSaverDefaultSettingsView.h>
 
@@ -28,12 +34,18 @@
 #define B_TRANSLATION_CONTEXT "Screensaver Icons"
 
 
-#define MAX_ICONS 15
-#define MAX_SIZE 20 // In percentage of the screen width
-#define MIN_SIZE 5 // Same here
 #define RAND_BETWEEN(a, b) ((rand() % ((b) - (a) + 1) + (a)))
 
 
+static const int32 kMaxConcurrentIcons = 15;
+static const int32 kMinIconWidthPercentage = 5;
+       // percentage of the screen width
+static const int32 kMaxIconWidthPercentage = 20;
+       // same here
+static const int32 kMinIconCount = 20;
+static const int32 kMaxIconCount = 128;
+
+
 const rgb_color kBackgroundColor = ui_color(B_DESKTOP_COLOR);
 
 
@@ -67,32 +79,8 @@ IconsSaver::~IconsSaver()
 status_t
 IconsSaver::StartSaver(BView* view, bool /*preview*/)
 {
-       if (fVectorIconsCount <= 0) {
-               // Load the vector icons from the MIME types
-               BMessage types;
-               BMimeType::GetInstalledTypes(&types);
-
-               for (int32 index = 0 ; ; index++) {
-                       const char* type;
-                       if (types.FindString("types", index, &type) != B_OK)
-                               break;
-
-                       BMimeType mimeType(type);
-                       uint8* vectorData = NULL;
-                       size_t size = 0;
-
-                       if (mimeType.GetIcon(&vectorData, &size) != B_OK || 
size == 0)
-                               continue;
-
-                       VectorIcon* icon = new VectorIcon;
-                       icon->data = vectorData;
-                       icon->size = size;
-
-                       fVectorIcons.AddItem(icon);
-               }
-
-               fVectorIconsCount = fVectorIcons.CountItems();
-       }
+       if (fVectorIcons.CountItems() < kMinIconCount)
+               _GetVectorIcons();
 
        srand(system_time() % INT_MAX);
 
@@ -117,10 +105,10 @@ IconsSaver::StartSaver(BView* view, bool /*preview*/)
                fBackBitmap->Unlock();
        }
 
-       fIcons = new IconDisplay[MAX_ICONS];
+       fIcons = new IconDisplay[kMaxConcurrentIcons];
 
-       fMaxSize = (screenRect.IntegerWidth() * MAX_SIZE) / 100;
-       fMinSize = (screenRect.IntegerWidth() * MIN_SIZE) / 100;
+       fMaxSize = (screenRect.IntegerWidth() * kMaxIconWidthPercentage) / 100;
+       fMinSize = (screenRect.IntegerWidth() * kMinIconWidthPercentage) / 100;
        if (fMaxSize > 255)
                fMaxSize = 255;
 
@@ -148,15 +136,13 @@ IconsSaver::Draw(BView* view, int32 frame)
 
        // update drawing
        if (fBackBitmap->Lock()) {
-               for (uint8 i = 0 ; i < MAX_ICONS ; i++) {
+               for (uint8 i = 0 ; i < kMaxConcurrentIcons ; i++)
                        fIcons[i].ClearOn(fBackView);
-               }
 
                int32 delta = frame - previousFrame;
-
-               for (uint8 i = 0 ; i < MAX_ICONS ; i++) {
+               for (uint8 i = 0 ; i < kMaxConcurrentIcons ; i++)
                        fIcons[i].DrawOn(fBackView, delta);
-               }
+
                fBackView->Sync();
                fBackBitmap->Unlock();
        }
@@ -165,11 +151,11 @@ IconsSaver::Draw(BView* view, int32 frame)
        view->DrawBitmap(fBackBitmap);
        previousFrame = frame;
 
-       if (fVectorIconsCount <= 0)
+       if (fVectorIcons.CountItems() < kMinIconCount)
                return;
 
-       // Restart one icon
-       for (uint8 i = 0 ; i < MAX_ICONS ; i++) {
+       // restart one icon
+       for (uint8 i = 0 ; i < kMaxConcurrentIcons ; i++) {
                if (!fIcons[i].IsRunning()) {
                        uint16 size = RAND_BETWEEN(fMinSize, fMaxSize);
                        uint16 maxX = view->Frame().IntegerWidth() - size;
@@ -179,16 +165,14 @@ IconsSaver::Draw(BView* view, int32 frame)
                        iconFrame.OffsetTo(RAND_BETWEEN(0, maxX), 
RAND_BETWEEN(0, maxY));
 
                        // Check that the icon doesn't overlap with others
-                       for (uint8 j = 0 ; j < MAX_ICONS ; j++) {
+                       for (uint8 j = 0 ; j < kMaxConcurrentIcons ; j++) {
                                if (fIcons[j].IsRunning() &&
                                        
iconFrame.Intersects(fIcons[j].GetFrame()))
                                        return;
                        }
 
-                       int32 index = RAND_BETWEEN(0, fVectorIconsCount - 1);
-
-                       fIcons[i].Run((VectorIcon*)fVectorIcons.ItemAt(index), 
iconFrame);
-
+                       int32 index = RAND_BETWEEN(0, fVectorIcons.CountItems() 
- 1);
+                       fIcons[i].Run((vector_icon*)fVectorIcons.ItemAt(index), 
iconFrame);
                        return;
                }
        }
@@ -202,3 +186,56 @@ IconsSaver::StartConfig(BView* view)
                B_TRANSLATE("by Vincent Duvert"));
 }
 
+
+//     #pragma mark - IconsSaver private methods
+
+
+void
+IconsSaver::_GetVectorIcons()
+{
+       BVolumeRoster volumeRoster;
+       BVolume volume;
+       while (volumeRoster.GetNextVolume(&volume) == B_OK) {
+               if (!volume.KnowsAttr() || !volume.KnowsMime() || 
!volume.KnowsQuery())
+                       continue;
+
+               BQuery query;
+               query.SetVolume(&volume);
+               query.SetPredicate("BEOS:APP_SIG=*");
+               query.Fetch();
+
+               entry_ref ref;
+               while (query.GetNextRef(&ref) == B_OK) {
+                       BFile file(&ref, B_READ_ONLY);
+                       if (file.InitCheck() != B_OK)
+                               continue;
+
+                       struct vector_icon* icon
+                               = (struct vector_icon*)malloc(sizeof(struct 
vector_icon));
+                       if (icon == NULL)
+                               continue;
+
+                       BNode node(&ref);
+                       BNodeInfo nodeInfo(&node);
+                       if (nodeInfo.InitCheck() != B_OK
+                               || nodeInfo.GetIcon(&icon->data, &icon->size, 
&icon->type)
+                                       != B_OK) {
+                               // didn't find an icon
+                               continue;
+                       }
+
+                       if (icon->type != B_VECTOR_ICON_TYPE) {
+                               // found an icon, but it's not a vector icon
+                               delete icon;
+                               continue;
+                       }
+
+                       // found a vector icon, add it to the list
+                       fVectorIcons.AddItem(icon);
+                       if (fVectorIcons.CountItems() >= kMaxIconCount) {
+                               // this is enough to choose from, stop eating 
memory...
+                               return;
+                       }
+               }
+       }
+}
diff --git a/src/add-ons/screen_savers/icons/IconsSaver.h 
b/src/add-ons/screen_savers/icons/IconsSaver.h
index 82431ff..6def51b 100644
--- a/src/add-ons/screen_savers/icons/IconsSaver.h
+++ b/src/add-ons/screen_savers/icons/IconsSaver.h
@@ -31,13 +31,13 @@ public:
        virtual void                            StartConfig(BView* view);
 
 private:
-       BList                                           fVectorIcons;
-       int32                                           fVectorIconsCount;
-       IconDisplay*                            fIcons;
+                       void                            _GetVectorIcons();
 
-       BBitmap*                                        fBackBitmap;
-       BView*                                          fBackView;
+                       BList                           fVectorIcons;
+                       IconDisplay*            fIcons;
 
+                       BBitmap*                        fBackBitmap;
+                       BView*                          fBackView;
 
                        uint16                          fMinSize;
                        uint16                          fMaxSize;


Other related posts: