* Fixed BBox resizing when not attached.
* Less flickering when drawing the label: the area of the label is now clipped, so there is no need to fill the background again. * Consumed the last reserved member for the bounding box of the label. * More or less rewrote the header. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15747 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+56
-104
@@ -1,126 +1,78 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2005, Haiku, Inc. All Rights Reserved.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*/
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
|
||||||
// to deal in the Software without restriction, including without limitation
|
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: Box.h
|
|
||||||
// Author: Marc Flerackers ([email protected])
|
|
||||||
// Description: BBox objects group views together and draw a border
|
|
||||||
// around them.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _BOX_H
|
#ifndef _BOX_H
|
||||||
#define _BOX_H
|
#define _BOX_H
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
#include <BeBuild.h>
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
// BBox class ------------------------------------------------------------------
|
|
||||||
class BBox : public BView {
|
class BBox : public BView {
|
||||||
|
public:
|
||||||
|
BBox(BRect frame, const char *name = NULL,
|
||||||
|
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
||||||
|
| B_NAVIGABLE_JUMP,
|
||||||
|
border_style border = B_FANCY_BORDER);
|
||||||
|
virtual ~BBox();
|
||||||
|
|
||||||
public:
|
/* Archiving */
|
||||||
BBox(BRect frame,
|
BBox(BMessage* archive);
|
||||||
const char *name = NULL,
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS |
|
|
||||||
B_NAVIGABLE_JUMP,
|
|
||||||
border_style border = B_FANCY_BORDER);
|
|
||||||
virtual ~BBox();
|
|
||||||
|
|
||||||
/* Archiving */
|
virtual void SetBorder(border_style border);
|
||||||
BBox(BMessage *archive);
|
border_style Border() const;
|
||||||
static BArchivable *Instantiate(BMessage *archive);
|
|
||||||
virtual status_t Archive(BMessage *archive, bool deep = true) const;
|
|
||||||
|
|
||||||
virtual void SetBorder(border_style border);
|
void SetLabel(const char* string);
|
||||||
border_style Border() const;
|
status_t SetLabel(BView* viewLabel);
|
||||||
|
|
||||||
void SetLabel(const char *string);
|
const char* Label() const;
|
||||||
status_t SetLabel(BView *viewLabel);
|
BView* LabelView() const;
|
||||||
|
|
||||||
const char *Label() const;
|
virtual void Draw(BRect updateRect);
|
||||||
BView *LabelView() const;
|
virtual void AttachedToWindow();
|
||||||
|
virtual void DetachedFromWindow();
|
||||||
|
virtual void AllAttached();
|
||||||
|
virtual void AllDetached();
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
virtual void MouseDown(BPoint point);
|
||||||
|
virtual void MouseUp(BPoint point);
|
||||||
|
virtual void WindowActivated(bool active);
|
||||||
|
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||||
|
const BMessage* dragMessage);
|
||||||
|
virtual void FrameMoved(BPoint newLocation);
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual BHandler* ResolveSpecifier(BMessage* message,
|
||||||
virtual void AttachedToWindow();
|
int32 index, BMessage* specifier,
|
||||||
virtual void DetachedFromWindow();
|
int32 what, const char* property);
|
||||||
virtual void AllAttached();
|
|
||||||
virtual void AllDetached();
|
|
||||||
virtual void FrameResized(float width, float height);
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
|
||||||
virtual void MouseDown(BPoint point);
|
|
||||||
virtual void MouseUp(BPoint point);
|
|
||||||
virtual void WindowActivated(bool active);
|
|
||||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
|
||||||
const BMessage *message);
|
|
||||||
virtual void FrameMoved(BPoint newLocation);
|
|
||||||
|
|
||||||
virtual BHandler *ResolveSpecifier(BMessage *message,
|
virtual void ResizeToPreferred();
|
||||||
int32 index,
|
virtual void GetPreferredSize(float* _width, float* _height);
|
||||||
BMessage *specifier,
|
virtual void MakeFocus(bool focused = true);
|
||||||
int32 what,
|
virtual status_t GetSupportedSuites(BMessage* message);
|
||||||
const char *property);
|
|
||||||
|
|
||||||
virtual void ResizeToPreferred();
|
virtual status_t Perform(perform_code d, void* arg);
|
||||||
virtual void GetPreferredSize(float *width, float *height);
|
|
||||||
virtual void MakeFocus(bool focused = true);
|
|
||||||
virtual status_t GetSupportedSuites(BMessage *message);
|
|
||||||
|
|
||||||
virtual status_t Perform(perform_code d, void *arg);
|
private:
|
||||||
|
virtual void _ReservedBox1();
|
||||||
|
virtual void _ReservedBox2();
|
||||||
|
|
||||||
private:
|
BBox &operator=(const BBox &);
|
||||||
|
|
||||||
virtual void _ReservedBox1();
|
void _InitObject(BMessage* data = NULL);
|
||||||
virtual void _ReservedBox2();
|
void _DrawPlain(BRect labelBox);
|
||||||
|
void _DrawFancy(BRect labelBox);
|
||||||
|
void _ClearLabel();
|
||||||
|
|
||||||
BBox &operator=(const BBox &);
|
char* fLabel;
|
||||||
|
BRect fBounds;
|
||||||
void InitObject(BMessage *data = NULL);
|
border_style fStyle;
|
||||||
void DrawPlain();
|
BView* fLabelView;
|
||||||
void DrawFancy();
|
BRect* fLabelBox;
|
||||||
void ClearAnyLabel();
|
|
||||||
|
|
||||||
char *fLabel;
|
|
||||||
BRect fBounds;
|
|
||||||
border_style fStyle;
|
|
||||||
BView *fLabelView;
|
|
||||||
uint32 _reserved[1];
|
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // _BOX_H
|
#endif // _BOX_H
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|||||||
+69
-46
@@ -6,38 +6,35 @@
|
|||||||
* Marc Flerackers ([email protected])
|
* Marc Flerackers ([email protected])
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
* DarkWyrm <[email protected]>
|
* DarkWyrm <[email protected]>
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Region.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Box.h>
|
|
||||||
#include <Message.h>
|
|
||||||
|
|
||||||
|
|
||||||
BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
|
BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
|
||||||
border_style border)
|
border_style border)
|
||||||
: BView(frame, name, resizingMode, flags | B_FRAME_EVENTS),
|
: BView(frame, name, resizingMode, flags | B_FRAME_EVENTS),
|
||||||
fStyle(border)
|
fStyle(border)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
InitObject();
|
_InitObject();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BBox::~BBox()
|
|
||||||
{
|
|
||||||
ClearAnyLabel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BBox::BBox(BMessage *archive)
|
BBox::BBox(BMessage *archive)
|
||||||
: BView(archive)
|
: BView(archive)
|
||||||
{
|
{
|
||||||
InitObject(archive);
|
_InitObject(archive);
|
||||||
|
|
||||||
const char *string;
|
const char *string;
|
||||||
|
|
||||||
@@ -57,13 +54,19 @@ BBox::BBox(BMessage *archive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BBox::~BBox()
|
||||||
|
{
|
||||||
|
_ClearLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BArchivable *
|
BArchivable *
|
||||||
BBox::Instantiate(BMessage *archive)
|
BBox::Instantiate(BMessage *archive)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(archive, "BBox"))
|
if (validate_instantiation(archive, "BBox"))
|
||||||
return new BBox(archive);
|
return new BBox(archive);
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,17 +110,18 @@ BBox::Border() const
|
|||||||
void
|
void
|
||||||
BBox::SetLabel(const char *string)
|
BBox::SetLabel(const char *string)
|
||||||
{
|
{
|
||||||
ClearAnyLabel();
|
_ClearLabel();
|
||||||
|
|
||||||
if (string) {
|
if (string) {
|
||||||
// Update fBounds
|
font_height fontHeight;
|
||||||
fBounds = Bounds();
|
GetFontHeight(&fontHeight);
|
||||||
font_height fh;
|
|
||||||
GetFontHeight(&fh);
|
|
||||||
|
|
||||||
fBounds.top = (float)ceil((fh.ascent + fh.descent) / 2.0f);
|
|
||||||
|
|
||||||
fLabel = strdup(string);
|
fLabel = strdup(string);
|
||||||
|
|
||||||
|
// leave 6 pixels of the frame, and have a gap of 4 pixels between
|
||||||
|
// the frame and the text on both sides
|
||||||
|
fLabelBox = new BRect(6.0f, 0, StringWidth(string) + 14.0f,
|
||||||
|
ceilf(fontHeight.ascent + fontHeight.descent));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Window())
|
if (Window())
|
||||||
@@ -128,14 +132,9 @@ BBox::SetLabel(const char *string)
|
|||||||
status_t
|
status_t
|
||||||
BBox::SetLabel(BView *viewLabel)
|
BBox::SetLabel(BView *viewLabel)
|
||||||
{
|
{
|
||||||
ClearAnyLabel();
|
_ClearLabel();
|
||||||
|
|
||||||
if (viewLabel) {
|
if (viewLabel) {
|
||||||
// Update fBounds
|
|
||||||
fBounds = Bounds();
|
|
||||||
|
|
||||||
fBounds.top = ceilf(viewLabel->Bounds().Height() / 2.0f);
|
|
||||||
|
|
||||||
fLabelView = viewLabel;
|
fLabelView = viewLabel;
|
||||||
fLabelView->MoveTo(10.0f, 0.0f);
|
fLabelView->MoveTo(10.0f, 0.0f);
|
||||||
AddChild(fLabelView, ChildAt(0));
|
AddChild(fLabelView, ChildAt(0));
|
||||||
@@ -165,13 +164,25 @@ BBox::LabelView() const
|
|||||||
void
|
void
|
||||||
BBox::Draw(BRect updateRect)
|
BBox::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
PushState();
|
||||||
|
|
||||||
|
BRect labelBox = BRect(0, 0, 0, 0);
|
||||||
|
if (fLabel != NULL) {
|
||||||
|
labelBox = *fLabelBox;
|
||||||
|
BRegion update(updateRect);
|
||||||
|
update.Exclude(labelBox);
|
||||||
|
|
||||||
|
ConstrainClippingRegion(&update);
|
||||||
|
} else if (fLabelView != NULL)
|
||||||
|
labelBox = fLabelView->Bounds();
|
||||||
|
|
||||||
switch (fStyle) {
|
switch (fStyle) {
|
||||||
case B_FANCY_BORDER:
|
case B_FANCY_BORDER:
|
||||||
DrawFancy();
|
_DrawFancy(labelBox);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_PLAIN_BORDER:
|
case B_PLAIN_BORDER:
|
||||||
DrawPlain();
|
_DrawPlain(labelBox);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -179,27 +190,35 @@ BBox::Draw(BRect updateRect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fLabel) {
|
if (fLabel) {
|
||||||
font_height fh;
|
ConstrainClippingRegion(NULL);
|
||||||
GetFontHeight(&fh);
|
|
||||||
|
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
/*
|
||||||
SetHighColor(ViewColor());
|
SetHighColor(ViewColor());
|
||||||
|
|
||||||
FillRect(BRect(6.0f, 1.0f, 12.0f + StringWidth(fLabel),
|
FillRect(BRect(6.0f, 1.0f, 12.0f + StringWidth(fLabel),
|
||||||
(float)ceil(fh.ascent + fh.descent))/*, B_SOLID_LOW*/);
|
(float)ceil(fh.ascent + fh.descent)), B_SOLID_LOW);
|
||||||
|
*/
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
DrawString(fLabel, BPoint(10.0f, (float)ceil(fh.ascent - fh.descent)
|
DrawString(fLabel, BPoint(10.0f,
|
||||||
+ 1.0f));
|
ceilf(fontHeight.ascent - fontHeight.descent) + 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BBox::AttachedToWindow()
|
void
|
||||||
|
BBox::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent()) {
|
if (Parent()) {
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
SetLowColor(Parent()->ViewColor());
|
SetLowColor(Parent()->ViewColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The box could have been resized in the mean time
|
||||||
|
fBounds = Bounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -313,8 +332,8 @@ BBox::FrameMoved(BPoint newLocation)
|
|||||||
|
|
||||||
BHandler *
|
BHandler *
|
||||||
BBox::ResolveSpecifier(BMessage *message, int32 index,
|
BBox::ResolveSpecifier(BMessage *message, int32 index,
|
||||||
BMessage *specifier, int32 what,
|
BMessage *specifier, int32 what,
|
||||||
const char *property)
|
const char *property)
|
||||||
{
|
{
|
||||||
return BView::ResolveSpecifier(message, index, specifier, what, property);
|
return BView::ResolveSpecifier(message, index, specifier, what, property);
|
||||||
}
|
}
|
||||||
@@ -414,7 +433,7 @@ BBox::operator=(const BBox &)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BBox::InitObject(BMessage *data)
|
BBox::_InitObject(BMessage *data)
|
||||||
{
|
{
|
||||||
fLabel = NULL;
|
fLabel = NULL;
|
||||||
fBounds = Bounds();
|
fBounds = Bounds();
|
||||||
@@ -436,9 +455,10 @@ BBox::InitObject(BMessage *data)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BBox::DrawPlain()
|
BBox::_DrawPlain(BRect labelBox)
|
||||||
{
|
{
|
||||||
BRect r = fBounds;
|
BRect r = Bounds();
|
||||||
|
r.top += labelBox.Height() / 2.0f;
|
||||||
|
|
||||||
rgb_color light = tint_color(ViewColor(), B_LIGHTEN_MAX_TINT);
|
rgb_color light = tint_color(ViewColor(), B_LIGHTEN_MAX_TINT);
|
||||||
rgb_color shadow = tint_color(ViewColor(), B_DARKEN_3_TINT);
|
rgb_color shadow = tint_color(ViewColor(), B_DARKEN_3_TINT);
|
||||||
@@ -457,9 +477,10 @@ BBox::DrawPlain()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BBox::DrawFancy()
|
BBox::_DrawFancy(BRect labelBox)
|
||||||
{
|
{
|
||||||
BRect r = fBounds;
|
BRect r = Bounds();
|
||||||
|
r.top += labelBox.Height() / 2.0f;
|
||||||
|
|
||||||
rgb_color light = tint_color(ViewColor(), B_LIGHTEN_MAX_TINT);
|
rgb_color light = tint_color(ViewColor(), B_LIGHTEN_MAX_TINT);
|
||||||
rgb_color shadow = tint_color(ViewColor(), B_DARKEN_3_TINT);
|
rgb_color shadow = tint_color(ViewColor(), B_DARKEN_3_TINT);
|
||||||
@@ -489,13 +510,15 @@ BBox::DrawFancy()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BBox::ClearAnyLabel()
|
BBox::_ClearLabel()
|
||||||
{
|
{
|
||||||
fBounds.top = 0;
|
fBounds.top = 0;
|
||||||
|
|
||||||
if (fLabel) {
|
if (fLabel) {
|
||||||
|
delete fLabelBox;
|
||||||
free(fLabel);
|
free(fLabel);
|
||||||
fLabel = NULL;
|
fLabel = NULL;
|
||||||
|
fLabelBox = NULL;
|
||||||
} else if (fLabelView) {
|
} else if (fLabelView) {
|
||||||
fLabelView->RemoveSelf();
|
fLabelView->RemoveSelf();
|
||||||
delete fLabelView;
|
delete fLabelView;
|
||||||
|
|||||||
Reference in New Issue
Block a user