[haiku-commits] haiku: hrev47437 - src/preferences/filetypes

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 28 Jun 2014 01:09:34 +0200 (CEST)

hrev47437 adds 3 changesets to branch 'master'
old head: 6f742d85f9f907e6c2f69fffca89d029e3fc247b
new head: e23f93739b311bfb52a81390ea80e0c5317a4f2d
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e23f937+%5E6f742d8

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

ada54af: FileTypes: Style fixes

c35a9fd: FileTypes: make middle bar darker
  
  ... matching the rest of the list view borders.
  
  * Don't draw the middle bar in DrawItem(), that already happens in
    owner->Draw(), no reason to draw it twice.
  * Update copyright header.

e23f937: FileTypes: Use list view color constants
  
  ...instead of hardcoding black.
  
  Only you can prevent hard-coded colors.
  
  Make sure to set both high color and low color so we don't get
  anti-aliasing glitches.
  
  Also, use be_control_look->DefaultLabelSpacing() instead of 5.0f.
  
  Only you can prevent hard-coded label spacings.
  
  Also return early if text is NULL (not set).
  
  Fixes a small part of #10840

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

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

1 file changed, 74 insertions(+), 43 deletions(-)
src/preferences/filetypes/AttributeListView.cpp | 117 +++++++++++++-------

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

Commit:      ada54af0c94b0d013efb469c7ef9ed7e52367f89
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ada54af
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jun 27 22:46:33 2014 UTC

FileTypes: Style fixes

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

diff --git a/src/preferences/filetypes/AttributeListView.cpp 
b/src/preferences/filetypes/AttributeListView.cpp
index 9c53183..67cacef 100644
--- a/src/preferences/filetypes/AttributeListView.cpp
+++ b/src/preferences/filetypes/AttributeListView.cpp
@@ -12,33 +12,43 @@
 #include <Locale.h>
 #include <ObjectList.h>
 
+
 #undef B_TRANSLATION_CONTEXT
 #define B_TRANSLATION_CONTEXT "Attribute ListView"
 
+
 const struct type_map kTypeMap[] = {
-       {B_TRANSLATE("String"),         B_STRING_TYPE},
-       {B_TRANSLATE("Boolean"),                B_BOOL_TYPE},
-       {B_TRANSLATE("Integer 8 bit"),  B_INT8_TYPE},
-       {B_TRANSLATE("Integer 16 bit"), B_INT16_TYPE},
-       {B_TRANSLATE("Integer 32 bit"), B_INT32_TYPE},
-       {B_TRANSLATE("Integer 64 bit"), B_INT64_TYPE},
-       {B_TRANSLATE("Float"),                  B_FLOAT_TYPE},
-       {B_TRANSLATE("Double"),                 B_DOUBLE_TYPE},
-       {B_TRANSLATE("Time"),                   B_TIME_TYPE},
-       {NULL,                                                  0}
+       { B_TRANSLATE("String"),         B_STRING_TYPE },
+       { B_TRANSLATE("Boolean"),        B_BOOL_TYPE   },
+       { B_TRANSLATE("Integer 8 bit"),  B_INT8_TYPE   },
+       { B_TRANSLATE("Integer 16 bit"), B_INT16_TYPE  },
+       { B_TRANSLATE("Integer 32 bit"), B_INT32_TYPE  },
+       { B_TRANSLATE("Integer 64 bit"), B_INT64_TYPE  },
+       { B_TRANSLATE("Float"),          B_FLOAT_TYPE  },
+       { B_TRANSLATE("Double"),         B_DOUBLE_TYPE },
+       { B_TRANSLATE("Time"),           B_TIME_TYPE   },
+       { NULL,                          0             }
 };
 
+
 // TODO: in the future, have a (private) Tracker API that exports these
 //     as well as a nice GUI for them.
 const struct display_as_map kDisplayAsMap[] = {
-       {B_TRANSLATE("Default"),        NULL,           {}},
-       {B_TRANSLATE("Checkbox"),       B_TRANSLATE("checkbox"),
-               {B_BOOL_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE}},
-       {B_TRANSLATE("Duration"),       B_TRANSLATE("duration"),
-               {B_TIME_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE, 
B_INT64_TYPE}},
-       {B_TRANSLATE("Rating"),         B_TRANSLATE("rating"),
-               {B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE}},
-       {NULL,                  NULL,           {}}
+       { B_TRANSLATE("Default"),       NULL,
+               {}
+       },
+       { B_TRANSLATE("Checkbox"),      B_TRANSLATE("checkbox"),
+               { B_BOOL_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE }
+       },
+       { B_TRANSLATE("Duration"),      B_TRANSLATE("duration"),
+               { B_TIME_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE, 
B_INT64_TYPE }
+       },
+       { B_TRANSLATE("Rating"),        B_TRANSLATE("rating"),
+               { B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE }
+       },
+       { NULL,                                         NULL,
+               {}
+       }
 };
 
 
@@ -131,12 +141,12 @@ create_attribute_item(BMessage& attributes, int32 index)
 }
 
 
-//     #pragma mark -
+//     #pragma mark - AttributeItem
 
 
 AttributeItem::AttributeItem(const char* name, const char* publicName,
-               type_code type, const char* displayAs, int32 alignment,
-               int32 width, bool visible, bool editable)
+       type_code type, const char* displayAs, int32 alignment,
+       int32 width, bool visible, bool editable)
        :
        BStringItem(publicName),
        fName(name),
@@ -247,11 +257,12 @@ AttributeItem::operator!=(const AttributeItem& other) 
const
 }
 
 
-//     #pragma mark -
+//     #pragma mark - AttributeListView
 
 
 AttributeListView::AttributeListView(const char* name)
-       : BListView(name, B_SINGLE_SELECTION_LIST,
+       :
+       BListView(name, B_SINGLE_SELECTION_LIST,
                B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE | 
B_FRAME_EVENTS)
 {
 }
@@ -266,9 +277,9 @@ AttributeListView::~AttributeListView()
 void
 AttributeListView::_DeleteItems()
 {
-       for (int32 i = CountItems(); i-- > 0;) {
+       for (int32 i = CountItems() - 1; i >= 0; i--)
                delete ItemAt(i);
-       }
+
        MakeEmpty();
 }
 
@@ -367,4 +378,3 @@ AttributeListView::Draw(BRect updateRect)
        float middle = Bounds().Width() / 2.0f;
        StrokeLine(BPoint(middle, 0.0f), BPoint(middle, Bounds().bottom));
 }
-

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

Commit:      c35a9fd0a7c56ed052938684886cbbbb80c5e378
URL:         http://cgit.haiku-os.org/haiku/commit/?id=c35a9fd
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jun 27 22:51:11 2014 UTC

FileTypes: make middle bar darker

... matching the rest of the list view borders.

* Don't draw the middle bar in DrawItem(), that already happens in
  owner->Draw(), no reason to draw it twice.
* Update copyright header.

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

diff --git a/src/preferences/filetypes/AttributeListView.cpp 
b/src/preferences/filetypes/AttributeListView.cpp
index 67cacef..b40525e 100644
--- a/src/preferences/filetypes/AttributeListView.cpp
+++ b/src/preferences/filetypes/AttributeListView.cpp
@@ -1,6 +1,12 @@
 /*
  * Copyright 2006-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2014 Haiku, Inc. All rights reserved.
+ *
  * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ *             John Scipione, jscipione@xxxxxxxxx
  */
 
 
@@ -212,9 +218,6 @@ AttributeItem::DrawItem(BView* owner, BRect frame, bool 
drawEverything)
 
        owner->SetHighColor(tint_color(owner->ViewColor(), B_DARKEN_1_TINT));
 
-       float middle = frame.left + frame.Width() / 2.0f;
-       owner->StrokeLine(BPoint(middle, 0.0f), BPoint(middle, frame.bottom));
-
        owner->SetHighColor(highColor);
        owner->SetLowColor(lowColor);
 }
@@ -373,7 +376,8 @@ AttributeListView::Draw(BRect updateRect)
 {
        BListView::Draw(updateRect);
 
-       SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
+       SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
+               B_DARKEN_2_TINT));
 
        float middle = Bounds().Width() / 2.0f;
        StrokeLine(BPoint(middle, 0.0f), BPoint(middle, Bounds().bottom));

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

Revision:    hrev47437
Commit:      e23f93739b311bfb52a81390ea80e0c5317a4f2d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e23f937
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jun 27 23:06:34 2014 UTC

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

FileTypes: Use list view color constants

...instead of hardcoding black.

Only you can prevent hard-coded colors.

Make sure to set both high color and low color so we don't get
anti-aliasing glitches.

Also, use be_control_look->DefaultLabelSpacing() instead of 5.0f.

Only you can prevent hard-coded label spacings.

Also return early if text is NULL (not set).

Fixes a small part of #10840

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

diff --git a/src/preferences/filetypes/AttributeListView.cpp 
b/src/preferences/filetypes/AttributeListView.cpp
index b40525e..fce417a 100644
--- a/src/preferences/filetypes/AttributeListView.cpp
+++ b/src/preferences/filetypes/AttributeListView.cpp
@@ -15,6 +15,7 @@
 #include <stdio.h>
 
 #include <Catalog.h>
+#include <ControlLook.h>
 #include <Locale.h>
 #include <ObjectList.h>
 
@@ -196,28 +197,44 @@ AttributeItem::DrawItem(BView* owner, BRect frame, bool 
drawEverything)
 {
        BStringItem::DrawItem(owner, frame, drawEverything);
 
+       BString type;
+       name_for_type(type, fType, fDisplayAs.String());
+       const char* typeString = type.String();
+       if (typeString == NULL)
+               return;
+
        rgb_color highColor = owner->HighColor();
        rgb_color lowColor = owner->LowColor();
 
+       // set the low color
        if (IsSelected())
-               owner->SetLowColor(tint_color(lowColor, B_DARKEN_2_TINT));
-
-       rgb_color black = {0, 0, 0, 255};
-
-       if (!IsEnabled())
-               owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
+               owner->SetLowColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR));
        else
-               owner->SetHighColor(black);
+               owner->SetLowColor(ui_color(B_LIST_BACKGROUND_COLOR));
+
+       // set the high color
+       if (!IsEnabled()) {
+               rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
+               if (textColor.red + textColor.green + textColor.blue > 128 * 3)
+                       owner->SetHighColor(tint_color(textColor, 
B_DARKEN_2_TINT));
+               else
+                       owner->SetHighColor(tint_color(textColor, 
B_LIGHTEN_2_TINT));
+       } else {
+               if (IsSelected())
+                       
owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
+               else
+                       owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR));
+       }
 
-       owner->MovePenTo(frame.left + frame.Width() / 2.0f + 5.0f,
+       // move the pen into position
+       owner->MovePenTo(frame.left + frame.Width() / 2.0f
+                       + be_control_look->DefaultLabelSpacing(),
                owner->PenLocation().y);
 
-       BString type;
-       name_for_type(type, fType, fDisplayAs.String());
-       owner->DrawString(type.String());
-
-       owner->SetHighColor(tint_color(owner->ViewColor(), B_DARKEN_1_TINT));
+       // draw the type string
+       owner->DrawString(typeString);
 
+       // set the high color and low color back to the original
        owner->SetHighColor(highColor);
        owner->SetLowColor(lowColor);
 }


Other related posts:

  • » [haiku-commits] haiku: hrev47437 - src/preferences/filetypes - jscipione