[Haiku-commits] r31137 - in haiku/trunk: headers/os/interface src/kits/interface
stippi at mail.berlios.de
stippi at mail.berlios.de
Sat Jun 20 17:03:36 CEST 2009
Author: stippi
Date: 2009-06-20 17:03:33 +0200 (Sat, 20 Jun 2009)
New Revision: 31137
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31137&view=rev
Modified:
haiku/trunk/headers/os/interface/ControlLook.h
haiku/trunk/headers/os/interface/SplitView.h
haiku/trunk/src/kits/interface/ControlLook.cpp
haiku/trunk/src/kits/interface/SplitLayout.cpp
haiku/trunk/src/kits/interface/SplitLayout.h
haiku/trunk/src/kits/interface/SplitView.cpp
Log:
* Added BSplitView drawing code to ControlLook.
* BSplitView uses ControlLook to draw itself.
* Small refactoring in SplitLayout to implement IsAboveSplitter(BPoint).
* BSplitView updates the view cursor when the mouse is above a splitter.
* Standard splitter size is now 6 pixels, which is a bit easer to hit.
Modified: haiku/trunk/headers/os/interface/ControlLook.h
===================================================================
--- haiku/trunk/headers/os/interface/ControlLook.h 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/headers/os/interface/ControlLook.h 2009-06-20 15:03:33 UTC (rev 31137)
@@ -208,6 +208,13 @@
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS);
+ /*virtual*/ void DrawSplitter(BView* view, BRect& rect,
+ const BRect& updateRect,
+ const rgb_color& base,
+ enum orientation orientation,
+ uint32 flags = 0,
+ uint32 borders = B_ALL_BORDERS);
+
// various borders
virtual void DrawBorder(BView* view, BRect& rect,
Modified: haiku/trunk/headers/os/interface/SplitView.h
===================================================================
--- haiku/trunk/headers/os/interface/SplitView.h 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/headers/os/interface/SplitView.h 2009-06-20 15:03:33 UTC (rev 31137)
@@ -55,10 +55,12 @@
protected:
virtual void DrawSplitter(BRect frame,
+ const BRect& updateRect,
enum orientation orientation, bool pressed);
private:
static void _DrawDefaultSplitter(BView* view, BRect frame,
+ const BRect& updateRect,
enum orientation orientation, bool pressed);
private:
Modified: haiku/trunk/src/kits/interface/ControlLook.cpp
===================================================================
--- haiku/trunk/src/kits/interface/ControlLook.cpp 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/src/kits/interface/ControlLook.cpp 2009-06-20 15:03:33 UTC (rev 31137)
@@ -239,7 +239,7 @@
if (popupIndicator) {
BRect leftRect(rect);
leftRect.right -= 10;
-
+
BRect rightRect(rect);
rightRect.left = rightRect.right - 9;
@@ -272,7 +272,7 @@
view->SetHighColor(markColor);
view->FillTriangle(triangle[0], triangle[1], triangle[2]);
-
+
view->SetFlags(viewFlags);
rect = leftRect;
@@ -424,7 +424,7 @@
_DrawOuterResessedFrame(view, rect, base, 0.6);
- // colors
+ // colors
rgb_color dark1BorderColor = tint_color(base, 1.3);
rgb_color dark2BorderColor = tint_color(base, 1.2);
rgb_color dark1FilledBorderColor = tint_color(barColor, 1.20);
@@ -869,7 +869,7 @@
rightBarSide.top = sliderPosition;
}
- // fill the background for the corners, exclude the middle bar for now
+ // fill the background for the corners, exclude the middle bar for now
BRegion region(rect);
region.Exclude(rightBarSide);
view->ConstrainClippingRegion(®ion);
@@ -879,7 +879,7 @@
DrawSliderBar(view, rect, updateRect, base, leftFillColor, flags,
orientation);
- view->PopState();
+ view->PopState();
region.Set(rect);
region.Exclude(leftBarSide);
@@ -890,7 +890,7 @@
DrawSliderBar(view, rect, updateRect, base, rightFillColor, flags,
orientation);
- view->PopState();
+ view->PopState();
view->ConstrainClippingRegion(NULL);
}
@@ -921,7 +921,7 @@
barRect.bottom -= ceilf(barRect.Width() / 2);
}
- // fill the background for the corners, exclude the middle bar for now
+ // fill the background for the corners, exclude the middle bar for now
BRegion region(rect);
region.Exclude(barRect);
view->ConstrainClippingRegion(®ion);
@@ -968,7 +968,7 @@
_DrawRoundBarCorner(view, leftCorner, updateRect, edgeLightColor,
edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor,
fillShadowColor, 1.0, 1.0, 0.0, -1.0, orientation);
-
+
_DrawRoundBarCorner(view, rightCorner, updateRect, edgeLightColor,
edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor,
fillShadowColor, 0.0, 1.0, -1.0, -1.0, orientation);
@@ -976,7 +976,7 @@
_DrawRoundBarCorner(view, leftCorner, updateRect, edgeLightColor,
edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor,
fillShadowColor, 1.0, 1.0, -1.0, 0.0, orientation);
-
+
_DrawRoundBarCorner(view, rightCorner, updateRect, edgeLightColor,
edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor,
fillShadowColor, 1.0, 0.0, -1.0, -1.0, orientation);
@@ -1031,7 +1031,7 @@
// figure out the tints to be used
float frameLightTint;
float frameShadowTint;
-
+
if (flags & B_DISABLED) {
frameLightTint = 1.30;
frameShadowTint = 1.35;
@@ -1040,7 +1040,7 @@
frameLightTint = 1.6;
frameShadowTint = 1.65;
}
-
+
frameLightColor = tint_color(base, frameLightTint);
frameShadowColor = tint_color(base, frameShadowTint);
}
@@ -1143,7 +1143,7 @@
// figure out the tints to be used
float frameLightTint;
float frameShadowTint;
-
+
if (flags & B_DISABLED) {
frameLightTint = 1.30;
frameShadowTint = 1.35;
@@ -1152,7 +1152,7 @@
frameLightTint = 1.6;
frameShadowTint = 1.65;
}
-
+
frameLightColor = tint_color(base, frameLightTint);
frameShadowColor = tint_color(base, frameShadowTint);
}
@@ -1440,6 +1440,113 @@
}
+void
+BControlLook::DrawSplitter(BView* view, BRect& rect, const BRect& updateRect,
+ const rgb_color& base, enum orientation orientation, uint32 flags,
+ uint32 borders)
+{
+ rgb_color background;
+ if ((flags & (B_CLICKED | B_ACTIVATED)) != 0)
+ background = tint_color(base, B_DARKEN_1_TINT);
+ else
+ background = base;
+
+ rgb_color light = tint_color(background, 0.6);
+ rgb_color shadow = tint_color(background, 1.21);
+
+ // frame
+ if (borders != 0 && rect.Width() > 3 && rect.Height() > 3)
+ DrawRaisedBorder(view, rect, updateRect, background, flags, borders);
+
+ // dots and rest of background
+ if (orientation == B_HORIZONTAL) {
+ if (rect.Width() > 2) {
+ // background on left/right
+ BRegion region(rect);
+ rect.left = floorf((rect.left + rect.right) / 2.0 - 0.5);
+ rect.right = rect.left + 1;
+ region.Exclude(rect);
+ view->SetHighColor(background);
+ view->FillRegion(®ion);
+ }
+
+ BPoint dot = rect.LeftTop();
+ BPoint stop = rect.LeftBottom();
+ int32 num = 1;
+ while (dot.y <= stop.y) {
+ rgb_color col1;
+ rgb_color col2;
+ switch (num) {
+ case 1:
+ col1 = background;
+ col2 = background;
+ break;
+ case 2:
+ col1 = shadow;
+ col2 = background;
+ break;
+ case 3:
+ col1 = background;
+ col2 = light;
+ num = 0;
+ break;
+ }
+ view->SetHighColor(col1);
+ view->StrokeLine(dot, dot, B_SOLID_HIGH);
+ view->SetHighColor(col2);
+ dot.x++;
+ view->StrokeLine(dot, dot, B_SOLID_HIGH);
+ dot.x -= 1.0;
+ // next pixel
+ num++;
+ dot.y++;
+ }
+ } else {
+ if (rect.Height() > 2) {
+ // background on left/right
+ BRegion region(rect);
+ rect.top = floorf((rect.top + rect.bottom) / 2.0 - 0.5);
+ rect.bottom = rect.top + 1;
+ region.Exclude(rect);
+ view->SetHighColor(background);
+ view->FillRegion(®ion);
+ }
+
+ BPoint dot = rect.LeftTop();
+ BPoint stop = rect.RightTop();
+ int32 num = 1;
+ while (dot.x <= stop.x) {
+ rgb_color col1;
+ rgb_color col2;
+ switch (num) {
+ case 1:
+ col1 = background;
+ col2 = background;
+ break;
+ case 2:
+ col1 = shadow;
+ col2 = background;
+ break;
+ case 3:
+ col1 = background;
+ col2 = light;
+ num = 0;
+ break;
+ }
+ view->SetHighColor(col1);
+ view->StrokeLine(dot, dot, B_SOLID_HIGH);
+ view->SetHighColor(col2);
+ dot.y++;
+ view->StrokeLine(dot, dot, B_SOLID_HIGH);
+ dot.y -= 1.0;
+ // next pixel
+ num++;
+ dot.x++;
+ }
+ }
+}
+
+
// #pragma mark -
@@ -1601,7 +1708,7 @@
// truncate the label if necessary and get the width and height
BString truncatedLabel(label);
-
+
BFont font;
view->GetFont(&font);
@@ -1765,7 +1872,7 @@
// colors
float tintLight = kEdgeBevelLightTint;
float tintShadow = kEdgeBevelShadowTint;
-
+
if (contrast == 0.0) {
tintLight = B_NO_TINT;
tintShadow = B_NO_TINT;
@@ -1773,10 +1880,10 @@
tintLight = B_NO_TINT + (tintLight - B_NO_TINT) * contrast;
tintShadow = B_NO_TINT + (tintShadow - B_NO_TINT) * contrast;
}
-
+
rgb_color borderBevelShadow = tint_color(base, tintShadow);
rgb_color borderBevelLight = tint_color(base, tintLight);
-
+
if (brightness < 1.0) {
borderBevelShadow.red = uint8(borderBevelShadow.red * brightness);
borderBevelShadow.green = uint8(borderBevelShadow.green * brightness);
@@ -1785,7 +1892,7 @@
borderBevelLight.green = uint8(borderBevelLight.green * brightness);
borderBevelLight.blue = uint8(borderBevelLight.blue * brightness);
}
-
+
_DrawFrame(view, rect, borderBevelShadow, borderBevelShadow,
borderBevelLight, borderBevelLight, borders);
}
Modified: haiku/trunk/src/kits/interface/SplitLayout.cpp
===================================================================
--- haiku/trunk/src/kits/interface/SplitLayout.cpp 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/src/kits/interface/SplitLayout.cpp 2009-06-20 15:03:33 UTC (rev 31137)
@@ -140,7 +140,7 @@
fRightInset(0),
fTopInset(0),
fBottomInset(0),
- fSplitterSize(3),
+ fSplitterSize(6),
fSpacing(spacing),
fSplitterItems(),
@@ -153,7 +153,7 @@
fVerticalLayouter(NULL),
fHorizontalLayoutInfo(NULL),
fVerticalLayoutInfo(NULL),
-
+
fHeightForWidthItems(),
fHeightForWidthVerticalLayouter(NULL),
fHeightForWidthHorizontalLayoutInfo(NULL),
@@ -165,7 +165,7 @@
fCachedMinHeightForWidth(-1),
fCachedMaxHeightForWidth(-1),
fCachedPreferredHeightForWidth(-1),
-
+
fDraggingStartPoint(),
fDraggingStartValue(0),
fDraggingCurrentValue(0),
@@ -482,7 +482,7 @@
verticalLayouter = fHeightForWidthVerticalLayouter;
} else
verticalLayouter = fVerticalLayouter;
-
+
verticalLayouter->Layout(fVerticalLayoutInfo, size.height);
float xOffset = fLeftInset;
@@ -551,6 +551,13 @@
return BRect();
}
+// IsAboveSplitter
+bool
+BSplitLayout::IsAboveSplitter(const BPoint& point) const
+{
+ return _SplitterItemAt(point) != NULL;
+}
+
// StartDraggingSplitter
bool
BSplitLayout::StartDraggingSplitter(BPoint point)
@@ -568,18 +575,14 @@
return false;
}
- int32 splitterCount = fSplitterItems.CountItems();
- for (int32 i = 0; i < splitterCount; i++) {
- SplitterItem* splitItem = _SplitterItemAt(i);
- BRect frame = splitItem->Frame();
- if (frame.Contains(point)) {
- fDraggingStartPoint = View()->ConvertToScreen(point);
- fDraggingStartValue = _SplitterValue(i);
- fDraggingCurrentValue = fDraggingStartValue;
- fDraggingSplitterIndex = i;
+ int32 index;
+ if (SplitterItem* splitItem = _SplitterItemAt(point, &index)) {
+ fDraggingStartPoint = View()->ConvertToScreen(point);
+ fDraggingStartValue = _SplitterValue(index);
+ fDraggingCurrentValue = fDraggingStartValue;
+ fDraggingSplitterIndex = index;
- return true;
- }
+ return true;
}
return false;
@@ -692,6 +695,23 @@
// _SplitterItemAt
BSplitLayout::SplitterItem*
+BSplitLayout::_SplitterItemAt(const BPoint& point, int32* index) const
+{
+ int32 splitterCount = fSplitterItems.CountItems();
+ for (int32 i = 0; i < splitterCount; i++) {
+ SplitterItem* splitItem = _SplitterItemAt(i);
+ BRect frame = splitItem->Frame();
+ if (frame.Contains(point)) {
+ if (index != NULL)
+ *index = i;
+ return splitItem;
+ }
+ }
+ return NULL;
+}
+
+// _SplitterItemAt
+BSplitLayout::SplitterItem*
BSplitLayout::_SplitterItemAt(int32 index) const
{
return (SplitterItem*)fSplitterItems.ItemAt(index);
@@ -778,7 +798,7 @@
bool visibilityChanged = (info->isVisible != isVisible);
if (visibilityChanged)
item->SetVisible(info->isVisible);
-
+
// nothing more to do, if the item is not visible
if (!info->isVisible)
return;
@@ -1070,7 +1090,7 @@
fHeightForWidthItems.MakeEmpty();
_InvalidateCachedHeightForWidth();
-
+
// filter the visible items
int32 itemCount = CountItems();
for (int32 i = 0; i < itemCount; i++) {
@@ -1084,7 +1104,7 @@
if (item->HasHeightForWidth())
fHeightForWidthItems.AddItem(item);
}
- itemCount = fVisibleItems.CountItems();
+ itemCount = fVisibleItems.CountItems();
// create the layouters
Layouter* itemLayouter = new SimpleLayouter(itemCount, 0);
@@ -1161,7 +1181,7 @@
}
horizontalLayoutInfo = fHeightForWidthHorizontalLayoutInfo;
}
-
+
// do the horizontal layout (already done when doing this for the real
// layout)
if (!realLayout)
@@ -1223,7 +1243,7 @@
float spacing = _SplitterSpace();
if (fOrientation == B_HORIZONTAL)
size.width = BLayoutUtils::AddDistances(size.width, spacing - 1);
- else
+ else
size.height = BLayoutUtils::AddDistances(size.height, spacing - 1);
return size;
@@ -1257,7 +1277,7 @@
float spacing = _SplitterSpace();
if (fOrientation == B_HORIZONTAL)
size.width = BLayoutUtils::SubtractDistances(size.width, spacing - 1);
- else
+ else
size.height = BLayoutUtils::SubtractDistances(size.height, spacing - 1);
return size;
Modified: haiku/trunk/src/kits/interface/SplitLayout.h
===================================================================
--- haiku/trunk/src/kits/interface/SplitLayout.h 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/src/kits/interface/SplitLayout.h 2009-06-20 15:03:33 UTC (rev 31137)
@@ -80,13 +80,14 @@
// interface for BSplitView
BRect SplitterItemFrame(int32 index) const;
+ bool IsAboveSplitter(const BPoint& point) const;
bool StartDraggingSplitter(BPoint point);
bool DragSplitter(BPoint point);
bool StopDraggingSplitter();
int32 DraggedSplitter() const;
-protected:
+protected:
virtual void ItemAdded(BLayoutItem* item);
virtual void ItemRemoved(BLayoutItem* item);
@@ -98,6 +99,8 @@
void _InvalidateLayout(bool invalidateView);
void _InvalidateCachedHeightForWidth();
+ SplitterItem* _SplitterItemAt(const BPoint& point,
+ int32* index = NULL) const;
SplitterItem* _SplitterItemAt(int32 index) const;
void _GetSplitterValueRange(int32 index,
@@ -150,7 +153,7 @@
LayoutInfo* fHorizontalLayoutInfo;
LayoutInfo* fVerticalLayoutInfo;
-
+
BList fHeightForWidthItems;
// Incorporates the children's height for width constraints for a
// concrete width. Cloned lazily from fVerticalLayout when needed.
@@ -165,7 +168,7 @@
float fCachedMinHeightForWidth;
float fCachedMaxHeightForWidth;
float fCachedPreferredHeightForWidth;
-
+
BPoint fDraggingStartPoint;
int32 fDraggingStartValue;
int32 fDraggingCurrentValue;
Modified: haiku/trunk/src/kits/interface/SplitView.cpp
===================================================================
--- haiku/trunk/src/kits/interface/SplitView.cpp 2009-06-20 15:00:33 UTC (rev 31136)
+++ haiku/trunk/src/kits/interface/SplitView.cpp 2009-06-20 15:03:33 UTC (rev 31137)
@@ -5,12 +5,45 @@
#include <SplitView.h>
+#include <stdio.h>
+
+#include <ControlLook.h>
+#include <Cursor.h>
+
#include "SplitLayout.h"
+static const unsigned char kHSplitterCursor[] = {
+ 16, 1, 8, 8,
+ 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
+ 0x1a, 0x58, 0x2a, 0x54, 0x4a, 0x52, 0x8a, 0x51,
+ 0x8a, 0x51, 0x4a, 0x52, 0x2a, 0x54, 0x1a, 0x58,
+ 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0,
+
+ 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0,
+ 0x1b, 0xd8, 0x3b, 0xdc, 0x7b, 0xde, 0xfb, 0xdf,
+ 0xfb, 0xdf, 0x7b, 0xde, 0x3b, 0xdc, 0x1b, 0xd8,
+ 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0
+};
+
+static const unsigned char kVSplitterCursor[] = {
+ 16, 1, 8, 8,
+ 0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x08, 0x10,
+ 0x0f, 0xf0, 0x00, 0x00, 0xff, 0xff, 0x80, 0x01,
+ 0x80, 0x01, 0xff, 0xff, 0x00, 0x00, 0x0f, 0xf0,
+ 0x08, 0x10, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80,
+
+ 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0,
+ 0x0f, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x0f, 0xf0,
+ 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80
+};
+
+
// constructor
BSplitView::BSplitView(enum orientation orientation, float spacing)
- : BView(NULL,
+ :
+ BView(NULL,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INVALIDATE_AFTER_LAYOUT,
fSplitLayout = new BSplitLayout(orientation, spacing))
{
@@ -136,7 +169,8 @@
int32 count = fSplitLayout->CountItems();
for (int32 i = 0; i < count - 1; i++) {
BRect frame = fSplitLayout->SplitterItemFrame(i);
- DrawSplitter(frame, Orientation(), draggedSplitterIndex == i);
+ DrawSplitter(frame, updateRect, Orientation(),
+ draggedSplitterIndex == i);
}
}
@@ -144,7 +178,8 @@
void
BSplitView::MouseDown(BPoint where)
{
- SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
+ SetMouseEventMask(B_POINTER_EVENTS,
+ B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS);
if (fSplitLayout->StartDraggingSplitter(where))
Invalidate();
@@ -164,7 +199,17 @@
void
BSplitView::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
{
+ BCursor cursor(B_CURSOR_SYSTEM_DEFAULT);
+
int32 splitterIndex = fSplitLayout->DraggedSplitter();
+
+ if (splitterIndex >= 0 || fSplitLayout->IsAboveSplitter(where)) {
+ if (Orientation() == B_VERTICAL)
+ cursor = BCursor(kVSplitterCursor);
+ else
+ cursor = BCursor(kHSplitterCursor);
+ }
+
if (splitterIndex >= 0) {
BRect oldFrame = fSplitLayout->SplitterItemFrame(splitterIndex);
if (fSplitLayout->DragSplitter(where)) {
@@ -172,6 +217,8 @@
Invalidate(fSplitLayout->SplitterItemFrame(splitterIndex));
}
}
+
+ SetViewCursor(&cursor, true);
}
// SetLayout
@@ -183,13 +230,18 @@
// DrawSplitter
void
-BSplitView::DrawSplitter(BRect frame, enum orientation orientation,
- bool pressed)
+BSplitView::DrawSplitter(BRect frame, const BRect& updateRect,
+ enum orientation orientation, bool pressed)
{
- rgb_color black = { 0, 0, 0, 255 };
- rgb_color white = { 255, 255, 255, 255 };
+ _DrawDefaultSplitter(this, frame, updateRect, orientation, pressed);
+}
- SetHighColor(pressed ? white : black);
-
- FillRect(frame);
+// _DrawDefaultSplitter
+void
+BSplitView::_DrawDefaultSplitter(BView* view, BRect frame,
+ const BRect& updateRect, enum orientation orientation, bool pressed)
+{
+ uint32 flags = pressed ? BControlLook::B_ACTIVATED : 0;
+ be_control_look->DrawSplitter(view, frame, updateRect, view->ViewColor(),
+ orientation, flags, 0);
}
More information about the Haiku-commits
mailing list