[haiku-commits] BRANCH looncraz-github.setviewuicolor [9ba036ea48a7] src/kits/interface headers/os/interface

  • From: looncraz-github.setviewuicolor <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 15 Oct 2015 02:17:03 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/looncraz-github/setviewuicolor'
old head: a23ee539ac57a8cfcc304b994ba64ca966abc6e0
new head: 9ba036ea48a797987aaa3e9a380a78100e67edae
overview: https://github.com/looncraz/haiku/compare/a23ee539ac57...9ba036ea48a7

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

9ba036ea48a7: BColorSet - BMessage Optimization

Optimized BMessage storage to enable rapid-lookup without a BColorSet
object.

Created BColorSet::Get() static method to enable:

rgb_color color;
if (BColorSet::Get(message, B_PANEL_TEXT_COLOR, &color) == B_OK) {
...
}

BWindow will still forward a ready-made object, but this is useful for
several other scenarios.

[ looncraz <looncraz@xxxxxxxxxxxx> ]

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

Commit: 9ba036ea48a797987aaa3e9a380a78100e67edae
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Oct 15 01:00:33 2015 UTC

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

2 files changed, 52 insertions(+), 15 deletions(-)
headers/os/interface/ColorSet.h | 9 ++++--
src/kits/interface/ColorSet.cpp | 58 ++++++++++++++++++++++++++++---------

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

diff --git a/headers/os/interface/ColorSet.h b/headers/os/interface/ColorSet.h
index b8e9811..3ba90c2 100644
--- a/headers/os/interface/ColorSet.h
+++ b/headers/os/interface/ColorSet.h
@@ -32,10 +32,14 @@ public:
virtual status_t Archive(BMessage* into, bool
deep = true) const;
static BArchivable* Instantiate(BMessage* archive);

+ // Static methods
+
static const BColorSet* DefaultColorSet();
static const BColorSet* CurrentColorSet();
-
- status_t InitCheck() const;
+ static status_t Get(const BMessage* message,
int32 key,
+
rgb_color* color);
+ static status_t Get(const BMessage* message,
color_which which,
+
rgb_color* color);

// Adding and removing colors.
// Will fail if key currently in use
@@ -70,6 +74,7 @@ public:
BColorPair* Find(color_which which);

// Query
+ status_t InitCheck() const;
bool HasKey(int32 key) const;
int32 CountColors() const;
bool IsEmpty() const;
diff --git a/src/kits/interface/ColorSet.cpp b/src/kits/interface/ColorSet.cpp
index 789e453..465bf6f 100644
--- a/src/kits/interface/ColorSet.cpp
+++ b/src/kits/interface/ColorSet.cpp
@@ -6,11 +6,13 @@
* Joseph Groover <looncraz@xxxxxxxxxxxx>
*/
#include <stdio.h>
+#include <stdlib.h>

#include <Application.h>
#include <Autolock.h>
#include <ColorSet.h>
#include <Locker.h>
+#include <StringList.h>

#include <ColorSetPrivate.h>
#include <DefaultColors.h>
@@ -90,24 +92,27 @@ BColorSet::Archive(BMessage* into, bool deep) const
if (into == NULL)
return B_BAD_VALUE;

- into->AddInt32("_count", CountColors());
-
status_t error = B_OK;
const BColorPair* pair;
int32 intColor;
+ BString name;
+ BStringList storeNames;

for (int32 index = 0; index < CountColors(); ++index) {
pair = ColorPairAt(index);
intColor = B_BENDIAN_TO_HOST_INT32(*(int32*)&pair->color);

- error = into->AddInt32("_key", pair->key);
- if (error == B_OK)
- error = into->AddInt32("_color", intColor);
+ name.Truncate(0);
+ name << pair->key;
+ storeNames.Add(name);
+
+ error = into->AddInt32(name.String(), intColor);

if (error != B_OK)
break;
}

+ error = into->AddStrings("_keyList", storeNames);
return error;
}

@@ -182,9 +187,28 @@ BColorSet::CurrentColorSet()


status_t
-BColorSet::InitCheck() const
+BColorSet::Get(const BMessage* message, int32 key, rgb_color* color)
{
- return fInitStatus;
+ if (message == NULL)
+ return B_BAD_VALUE;
+
+ BString name;
+ name << key;
+ int32 intColor = 0;
+
+ status_t error = message->FindInt32(name.String(), &intColor);
+
+ if (error == B_OK && color != NULL)
+ *color = *(rgb_color*)&intColor;
+
+ return error;
+}
+
+
+status_t
+BColorSet::Get(const BMessage* message, color_which which, rgb_color* color)
+{
+ return BColorSet::Get(message, (int32)which, color);
}


@@ -487,6 +511,13 @@ BColorSet::Find(color_which which)
// #pragma mark Query


+status_t
+BColorSet::InitCheck() const
+{
+ return fInitStatus;
+}
+
+
bool
BColorSet::HasKey(int32 key) const
{
@@ -560,7 +591,6 @@ BColorSet::_Init(BMessage* from)
return;
}

- int32 count;
int32 key;
rgb_color color;
int32 intColor;
@@ -577,13 +607,15 @@ BColorSet::_Init(BMessage* from)
return;
}

- if (from->FindInt32("_count", &count) == B_OK
- && count > 0) {
+ BStringList nameList;
+ if (from->FindStrings("_keyList", &nameList) == B_OK
+ && nameList.CountStrings() > 0) {

- for (int32 index = 0; index < count; ++index) {
- if (from->FindInt32("_key", index, &key) == B_OK
- && from->FindInt32("_color", index, &intColor)
== B_OK) {
+ for (int32 index = 0; index < nameList.CountStrings(); ++index)
{
+ BString name = nameList.StringAt(index);

+ if (from->FindInt32(name.String(), &intColor) == B_OK) {
+ key = atoi(name.String());
intColor = B_HOST_TO_BENDIAN_INT32(intColor);
color = *(rgb_color*)&intColor;
Add(key, color);


Other related posts: