Next row of Cortex style updates, courtesy of Vasilis Kaoutsis - thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21137 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-05-14 14:15:34 +00:00
parent b0d9cd6f66
commit 595c89bcdc
16 changed files with 1406 additions and 1601 deletions
+24 -24
View File
@@ -39,11 +39,11 @@ DiagramBox::~DiagramBox()
// derived from DiagramItemGroup (public)
bool
DiagramBox::addItem(DiagramItem *item)
DiagramBox::AddItem(DiagramItem *item)
{
D_METHOD(("DiagramBox::addItem()\n"));
D_METHOD(("DiagramBox::AddItem()\n"));
if (item) {
if (DiagramItemGroup::addItem(item)) {
if (DiagramItemGroup::AddItem(item)) {
if (m_view) {
item->_setOwner(m_view);
item->attachedToDiagram();
@@ -56,12 +56,12 @@ DiagramBox::addItem(DiagramItem *item)
bool
DiagramBox::removeItem(DiagramItem *item)
DiagramBox::RemoveItem(DiagramItem *item)
{
D_METHOD(("DiagramBox::removeItem()\n"));
D_METHOD(("DiagramBox::RemoveItem()\n"));
if (item) {
item->detachedFromDiagram();
if (DiagramItemGroup::removeItem(item)) {
if (DiagramItemGroup::RemoveItem(item)) {
item->_setOwner(0);
return true;
}
@@ -81,22 +81,22 @@ DiagramBox::draw(BRect updateRect)
if (m_flags & M_DRAW_UNDER_ENDPOINTS) {
BRegion region, clipping;
region.Include(frame());
if (group()->getClippingAbove(this, &clipping))
if (group()->GetClippingAbove(this, &clipping))
region.Exclude(&clipping);
view()->ConstrainClippingRegion(&region);
drawBox();
for (uint32 i = 0; i < countItems(); i++) {
DiagramItem *item = itemAt(i);
for (uint32 i = 0; i < CountItems(); i++) {
DiagramItem *item = ItemAt(i);
if (region.Intersects(item->frame()))
item->draw(item->frame());
}
} else {
BRegion region, clipping;
region.Include(frame());
if (view()->getClippingAbove(this, &clipping))
if (view()->GetClippingAbove(this, &clipping))
region.Exclude(&clipping);
for (uint32 i = 0; i < countItems(); i++) {
DiagramItem *item = itemAt(i);
for (uint32 i = 0; i < CountItems(); i++) {
DiagramItem *item = ItemAt(i);
BRect r;
if (region.Intersects(r = item->frame())) {
item->draw(r);
@@ -116,7 +116,7 @@ void
DiagramBox::mouseDown(BPoint point, uint32 buttons, uint32 clicks)
{
D_MOUSE(("DiagramBox::mouseDown()\n"));
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item)
item->mouseDown(point, buttons, clicks);
else if (clicks == 1) {
@@ -144,12 +144,12 @@ void
DiagramBox::mouseOver(BPoint point, uint32 transit)
{
D_MOUSE(("DiagramBox::mouseOver()\n"));
DiagramItem *last = lastItemUnder();
DiagramItem *last = _LastItemUnder();
if (last && (transit == B_EXITED_VIEW)) {
last->mouseOver(point, B_EXITED_VIEW);
resetItemUnder();
_ResetItemUnder();
} else {
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item) {
if (item != last) {
if (last)
@@ -168,12 +168,12 @@ void
DiagramBox::messageDragged(BPoint point, uint32 transit, const BMessage *message)
{
D_MOUSE(("DiagramBox::messageDragged()\n"));
DiagramItem *last = lastItemUnder();
DiagramItem *last = _LastItemUnder();
if (last && (transit == B_EXITED_VIEW)) {
last->messageDragged(point, B_EXITED_VIEW, message);
resetItemUnder();
_ResetItemUnder();
} else {
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item) {
if (item != last) {
if (last)
@@ -194,7 +194,7 @@ void
DiagramBox::messageDropped(BPoint point, BMessage *message)
{
D_METHOD(("DiagramBox::messageDropped()\n"));
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item) {
item->messageDropped(point, message);
return;
@@ -210,8 +210,8 @@ DiagramBox::moveBy(float x, float y, BRegion *wireRegion)
if (view()) {
view()->PushState();
{
for (uint32 i = 0; i < countItems(); i++) {
DiagramEndPoint *endPoint = dynamic_cast<DiagramEndPoint *>(itemAt(i));
for (uint32 i = 0; i < CountItems(); i++) {
DiagramEndPoint *endPoint = dynamic_cast<DiagramEndPoint *>(ItemAt(i));
if (endPoint)
endPoint->moveBy(x, y, wireRegion);
}
@@ -243,8 +243,8 @@ DiagramBox::_setOwner(DiagramView *owner)
{
D_METHOD(("DiagramBox::_setOwner()\n"));
m_view = owner;
for (uint32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++) {
DiagramItem *item = itemAt(i);
for (uint32 i = 0; i < CountItems(DiagramItem::M_ENDPOINT); i++) {
DiagramItem *item = ItemAt(i);
item->_setOwner(m_view);
if (m_view)
item->attachedToDiagram();
+2 -2
View File
@@ -42,11 +42,11 @@ class DiagramBox : public DiagramItem, public DiagramItemGroup {
// extends the DiagramItemGroup implementation by setting
// the items owner and calling the attachedToDiagram() hook
// on it
virtual bool addItem(DiagramItem *item);
virtual bool AddItem(DiagramItem *item);
// extends the DiagramItemGroup implementation by calling
// the detachedToDiagram() hook on the item
virtual bool removeItem(DiagramItem *item);
virtual bool RemoveItem(DiagramItem *item);
public: // derived from DiagramItem
+355 -396
View File
@@ -1,5 +1,13 @@
// DiagramItemGroup.cpp
/*! \class DiagramItemGroup.
\brief Basic class for managing and accessing DiagramItem objects.
Objects of this class can manage one or more of the DiagramItem
type M_BOX, M_WIRE and M_ENDPOINT. Many methods let you specify
which type of item you want to deal with.
*/
#include "DiagramItemGroup.h"
#include "DiagramItem.h"
@@ -10,397 +18,341 @@ __USE_CORTEX_NAMESPACE
#include <Debug.h>
#define D_METHOD(x) //PRINT (x)
// -------------------------------------------------------- //
// *** ctor/dtor
// -------------------------------------------------------- //
DiagramItemGroup::DiagramItemGroup(
uint32 acceptedTypes,
bool multiSelection)
: m_boxes(0),
m_wires(0),
m_endPoints(0),
m_selection(0),
m_types(acceptedTypes),
m_itemAlignment(1.0, 1.0),
m_multiSelection(multiSelection),
m_lastItemUnder(0)
DiagramItemGroup::DiagramItemGroup(uint32 acceptedTypes, bool multiSelection)
: fBoxes(0),
fWires(0),
fEndPoints(0),
fSelection(0),
fTypes(acceptedTypes),
fItemAlignment(1.0, 1.0),
fMultiSelection(multiSelection),
fLastItemUnder(0)
{
D_METHOD(("DiagramItemGroup::DiagramItemGroup()\n"));
m_selection = new BList(1);
fSelection = new BList(1);
}
DiagramItemGroup::~DiagramItemGroup()
{
D_METHOD(("DiagramItemGroup::~DiagramItemGroup()\n"));
if (m_selection)
{
m_selection->MakeEmpty();
delete m_selection;
if (fSelection) {
fSelection->MakeEmpty();
delete fSelection;
}
if (m_boxes && (m_types & DiagramItem::M_BOX))
{
while (countItems(DiagramItem::M_BOX) > 0)
{
DiagramItem *item = itemAt(0, DiagramItem::M_BOX);
if (removeItem(item))
if (fBoxes && (fTypes & DiagramItem::M_BOX)) {
while (CountItems(DiagramItem::M_BOX) > 0) {
DiagramItem *item = ItemAt(0, DiagramItem::M_BOX);
if (RemoveItem(item))
delete item;
}
delete m_boxes;
delete fBoxes;
}
if (m_wires && (m_types & DiagramItem::M_WIRE))
{
while (countItems(DiagramItem::M_WIRE) > 0)
{
DiagramItem *item = itemAt(0, DiagramItem::M_WIRE);
if (removeItem(item))
if (fWires && (fTypes & DiagramItem::M_WIRE)) {
while (CountItems(DiagramItem::M_WIRE) > 0) {
DiagramItem *item = ItemAt(0, DiagramItem::M_WIRE);
if (RemoveItem(item))
delete item;
}
delete m_wires;
delete fWires;
}
if (m_endPoints && (m_types & DiagramItem::M_ENDPOINT))
{
while (countItems(DiagramItem::M_ENDPOINT) > 0)
{
DiagramItem *item = itemAt(0, DiagramItem::M_ENDPOINT);
if (removeItem(item))
if (fEndPoints && (fTypes & DiagramItem::M_ENDPOINT)) {
while (CountItems(DiagramItem::M_ENDPOINT) > 0) {
DiagramItem *item = ItemAt(0, DiagramItem::M_ENDPOINT);
if (RemoveItem(item))
delete item;
}
delete m_endPoints;
delete fEndPoints;
}
}
// -------------------------------------------------------- //
// *** item accessors
// -------------------------------------------------------- //
uint32 DiagramItemGroup::countItems(
uint32 whichType) const
// #pragma mark - item accessors
//! Returns the number of items in the group (optionally only those
// of the given type \param whichType)
uint32
DiagramItemGroup::CountItems(uint32 whichType) const
{
D_METHOD(("DiagramItemGroup::countItems()\n"));
D_METHOD(("DiagramItemGroup::CountItems()\n"));
uint32 count = 0;
if (whichType & m_types)
{
if (whichType & DiagramItem::M_BOX)
{
if (m_boxes)
{
count += m_boxes->CountItems();
}
if (whichType & fTypes) {
if (whichType & DiagramItem::M_BOX) {
if (fBoxes)
count += fBoxes->CountItems();
}
if (whichType & DiagramItem::M_WIRE)
{
if (m_wires)
{
count += m_wires->CountItems();
}
if (whichType & DiagramItem::M_WIRE) {
if (fWires)
count += fWires->CountItems();
}
if (whichType & DiagramItem::M_ENDPOINT)
{
if (m_endPoints)
{
count += m_endPoints->CountItems();
}
if (whichType & DiagramItem::M_ENDPOINT) {
if (fEndPoints)
count += fEndPoints->CountItems();
}
}
return count;
}
DiagramItem *DiagramItemGroup::itemAt(
uint32 index,
uint32 whichType) const
/*! Returns a pointer to the item in the lists which is
at the given index; if none is found, this function
returns 0
*/
DiagramItem*
DiagramItemGroup::ItemAt(uint32 index, uint32 whichType) const
{
D_METHOD(("DiagramItemGroup::itemAt()\n"));
if (m_types & whichType)
{
if (whichType & DiagramItem::M_BOX)
{
if (m_boxes && (index < countItems(DiagramItem::M_BOX)))
{
return static_cast<DiagramItem *>(m_boxes->ItemAt(index));
}
D_METHOD(("DiagramItemGroup::ItemAt()\n"));
if (fTypes & whichType) {
if (whichType & DiagramItem::M_BOX) {
if (fBoxes && (index < CountItems(DiagramItem::M_BOX)))
return static_cast<DiagramItem *>(fBoxes->ItemAt(index));
else
{
index -= countItems(DiagramItem::M_BOX);
}
index -= CountItems(DiagramItem::M_BOX);
}
if (whichType & DiagramItem::M_WIRE)
{
if (m_wires && (index < countItems(DiagramItem::M_WIRE)))
{
return static_cast<DiagramItem *>(m_wires->ItemAt(index));
}
if (whichType & DiagramItem::M_WIRE) {
if (fWires && (index < CountItems(DiagramItem::M_WIRE)))
return static_cast<DiagramItem *>(fWires->ItemAt(index));
else
{
index -= countItems(DiagramItem::M_WIRE);
}
index -= CountItems(DiagramItem::M_WIRE);
}
if (whichType & DiagramItem::M_ENDPOINT)
{
if (m_endPoints && (index < countItems(DiagramItem::M_ENDPOINT)))
{
return static_cast<DiagramItem *>(m_endPoints->ItemAt(index));
}
if (whichType & DiagramItem::M_ENDPOINT) {
if (fEndPoints && (index < CountItems(DiagramItem::M_ENDPOINT)))
return static_cast<DiagramItem *>(fEndPoints->ItemAt(index));
}
}
return 0;
}
// This function returns the first box or endpoint found that
// contains the given point. For connections it looks at all
// wires that 'might' contain the point and calls their method
// howCloseTo() to find the one closest to the point.
// The lists should be sorted by selection time for proper results!
DiagramItem *DiagramItemGroup::itemUnder(
BPoint point)
/*! This function returns the first box or endpoint found that
contains the given \param point. For connections it looks at all
wires that 'might' contain the point and calls their method
howCloseTo() to find the one closest to the point.
The lists should be sorted by selection time for proper results!
*/
DiagramItem*
DiagramItemGroup::ItemUnder(BPoint point)
{
D_METHOD(("DiagramItemGroup::itemUnder()\n"));
if (m_types & DiagramItem::M_BOX)
{
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
{
DiagramItem *item = itemAt(i, DiagramItem::M_BOX);
if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0))
{
// DiagramItemGroup *group = dynamic_cast<DiagramItemGroup *>(item);
return (m_lastItemUnder = item);
D_METHOD(("DiagramItemGroup::ItemUnder()\n"));
if (fTypes & DiagramItem::M_BOX) {
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) {
DiagramItem *item = ItemAt(i, DiagramItem::M_BOX);
if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0)) {
// DiagramItemGroup *group = dynamic_cast<DiagramItemGroup *>(item);
return (fLastItemUnder = item);
}
}
}
if (m_types & DiagramItem::M_WIRE)
{
if (fTypes & DiagramItem::M_WIRE) {
float closest = 0.0;
DiagramItem *closestItem = 0;
for (uint32 i = 0; i < countItems(DiagramItem::M_WIRE); i++)
{
DiagramItem *item = itemAt(i, DiagramItem::M_WIRE);
if (item->frame().Contains(point))
{
for (uint32 i = 0; i < CountItems(DiagramItem::M_WIRE); i++) {
DiagramItem *item = ItemAt(i, DiagramItem::M_WIRE);
if (item->frame().Contains(point)) {
float howClose = item->howCloseTo(point);
if (howClose > closest)
{
if (howClose > closest) {
closestItem = item;
if (howClose == 1.0)
return (m_lastItemUnder = item);
return (fLastItemUnder = item);
closest = howClose;
}
}
}
if (closest > 0.5)
{
return (m_lastItemUnder = closestItem);
}
return (fLastItemUnder = closestItem);
}
if (m_types & DiagramItem::M_ENDPOINT)
{
for (uint32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++)
{
DiagramItem *item = itemAt(i, DiagramItem::M_ENDPOINT);
if (fTypes & DiagramItem::M_ENDPOINT) {
for (uint32 i = 0; i < CountItems(DiagramItem::M_ENDPOINT); i++) {
DiagramItem *item = ItemAt(i, DiagramItem::M_ENDPOINT);
if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0))
{
return (m_lastItemUnder = item);
}
return (fLastItemUnder = item);
}
}
return (m_lastItemUnder = 0); // no item was found!
return (fLastItemUnder = 0); // no item was found!
}
// -------------------------------------------------------- //
// *** item operations
// -------------------------------------------------------- //
bool DiagramItemGroup::addItem(
DiagramItem *item)
// #pragma mark - item operations
//! Adds an \param item to the group; returns true on success.
bool
DiagramItemGroup::AddItem(DiagramItem *item)
{
D_METHOD(("DiagramItemGroup::addItem()\n"));
if (item && (m_types & item->type()))
{
switch (item->type())
{
D_METHOD(("DiagramItemGroup::AddItem()\n"));
if (item && (fTypes & item->type())) {
switch (item->type()) {
case DiagramItem::M_BOX:
{
if (!m_boxes)
{
m_boxes = new BList();
}
if (!fBoxes)
fBoxes = new BList();
item->m_group = this;
return m_boxes->AddItem(static_cast<void *>(item));
}
return fBoxes->AddItem(static_cast<void *>(item));
case DiagramItem::M_WIRE:
{
if (!m_wires)
{
m_wires = new BList();
}
if (!fWires)
fWires = new BList();
item->m_group = this;
return m_wires->AddItem(static_cast<void *>(item));
}
return fWires->AddItem(static_cast<void *>(item));
case DiagramItem::M_ENDPOINT:
{
if (!m_endPoints)
{
m_endPoints = new BList();
}
if (!fEndPoints)
fEndPoints = new BList();
item->m_group = this;
return m_endPoints->AddItem(static_cast<void *>(item));
}
return fEndPoints->AddItem(static_cast<void *>(item));
}
}
return false;
}
bool DiagramItemGroup::removeItem(
DiagramItem *item)
//! Removes an \param item from the group; returns true on success.
bool
DiagramItemGroup::RemoveItem(DiagramItem* item)
{
D_METHOD(("DiagramItemGroup::removeItem()\n"));
if (item && (m_types & item->type()))
{
D_METHOD(("DiagramItemGroup::RemoveItem()\n"));
if (item && (fTypes & item->type())) {
// reset the lastItemUnder-pointer if it pointed to this item
if (m_lastItemUnder == item)
{
m_lastItemUnder = 0;
}
if (fLastItemUnder == item)
fLastItemUnder = 0;
// remove it from the selection list if it was selected
if (item->isSelected())
{
m_selection->RemoveItem(static_cast<void *>(item));
}
fSelection->RemoveItem(static_cast<void *>(item));
// try to remove the item from its list
switch (item->type())
{
switch (item->type()) {
case DiagramItem::M_BOX:
{
if (m_boxes)
{
if (fBoxes) {
item->m_group = 0;
return m_boxes->RemoveItem(static_cast<void *>(item));
return fBoxes->RemoveItem(static_cast<void *>(item));
}
}
break;
case DiagramItem::M_WIRE:
{
if (m_wires)
{
if (fWires) {
item->m_group = 0;
return m_wires->RemoveItem(static_cast<void *>(item));
return fWires->RemoveItem(static_cast<void *>(item));
}
}
break;
case DiagramItem::M_ENDPOINT:
{
if (m_endPoints)
{
if (fEndPoints) {
item->m_group = 0;
return m_endPoints->RemoveItem(static_cast<void *>(item));
return fEndPoints->RemoveItem(static_cast<void *>(item));
}
}
}
}
return false;
}
void DiagramItemGroup::sortItems(
uint32 whichType,
/*! Performs a quicksort on a list of items with the provided
compare function (one is already defined in the DiagramItem
implementation); can't handle more than one item type at a
time!
*/
void
DiagramItemGroup::SortItems(uint32 whichType,
int (*compareFunc)(const void *, const void *))
{
D_METHOD(("DiagramItemGroup::sortItems()\n"));
if ((whichType != DiagramItem::M_ANY) && (m_types & whichType))
{
switch (whichType)
{
D_METHOD(("DiagramItemGroup::SortItems()\n"));
if ((whichType != DiagramItem::M_ANY) && (fTypes & whichType)) {
switch (whichType) {
case DiagramItem::M_BOX:
{
if (m_boxes)
{
m_boxes->SortItems(compareFunc);
}
if (fBoxes)
fBoxes->SortItems(compareFunc);
break;
}
case DiagramItem::M_WIRE:
{
if (m_wires)
{
m_wires->SortItems(compareFunc);
}
if (fWires)
fWires->SortItems(compareFunc);
break;
}
case DiagramItem::M_ENDPOINT:
{
if (m_endPoints)
{
m_endPoints->SortItems(compareFunc);
}
if (fEndPoints)
fEndPoints->SortItems(compareFunc);
break;
}
}
}
}
// items are drawn in reverse order; they should be sorted by
// selection time before this function gets called, so that
// the more recently selected item are drawn above others
void DiagramItemGroup::drawItems(
BRect updateRect,
uint32 whichType,
BRegion *updateRegion)
/*! Fires a draw() command at all items of a specific type that
intersect with the \param updateRect;
items are drawn in reverse order; they should be sorted by
selection time before this function gets called, so that
the more recently selected item are drawn above others.
*/
void
DiagramItemGroup::DrawItems(BRect updateRect, uint32 whichType, BRegion* updateRegion)
{
D_METHOD(("DiagramItemGroup::drawItems()\n"));
if (whichType & DiagramItem::M_WIRE)
{
for (int32 i = countItems(DiagramItem::M_WIRE) - 1; i >= 0; i--)
{
DiagramItem *item = itemAt(i, DiagramItem::M_WIRE);
D_METHOD(("DiagramItemGroup::DrawItems()\n"));
if (whichType & DiagramItem::M_WIRE) {
for (int32 i = CountItems(DiagramItem::M_WIRE) - 1; i >= 0; i--) {
DiagramItem *item = ItemAt(i, DiagramItem::M_WIRE);
if (item->frame().Intersects(updateRect))
{
item->draw(updateRect);
}
}
}
if (whichType & DiagramItem::M_BOX)
{
for (int32 i = countItems(DiagramItem::M_BOX) - 1; i >= 0; i--)
{
DiagramItem *item = itemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(updateRect))
{
if (whichType & DiagramItem::M_BOX) {
for (int32 i = CountItems(DiagramItem::M_BOX) - 1; i >= 0; i--) {
DiagramItem *item = ItemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(updateRect)) {
item->draw(updateRect);
if (updateRegion)
updateRegion->Exclude(item->frame());
}
}
}
if (whichType & DiagramItem::M_ENDPOINT)
{
for (int32 i = countItems(DiagramItem::M_ENDPOINT) - 1; i >= 0; i--)
{
DiagramItem *item = itemAt(i, DiagramItem::M_ENDPOINT);
if (whichType & DiagramItem::M_ENDPOINT) {
for (int32 i = CountItems(DiagramItem::M_ENDPOINT) - 1; i >= 0; i--) {
DiagramItem *item = ItemAt(i, DiagramItem::M_ENDPOINT);
if (item && item->frame().Intersects(updateRect))
{
item->draw(updateRect);
}
}
}
}
bool DiagramItemGroup::getClippingAbove(
DiagramItem *which,
BRegion *region)
/*! Returns in outRegion the \param region of items that lay "over" the given
DiagramItem in \param which; returns false if no items are above or the item
doesn't exist.
*/
bool
DiagramItemGroup::GetClippingAbove(DiagramItem *which, BRegion *region)
{
D_METHOD(("DiagramItemGroup::getClippingAbove()\n"));
D_METHOD(("DiagramItemGroup::GetClippingAbove()\n"));
bool found = false;
if (which && region)
{
switch (which->type())
{
if (which && region) {
switch (which->type()) {
case DiagramItem::M_BOX:
{
int32 index = m_boxes->IndexOf(which);
if (index >= 0) // the item was found
{
int32 index = fBoxes->IndexOf(which);
if (index >= 0) { // the item was found
BRect r = which->frame();
for (int32 i = 0; i < index; i++)
{
DiagramItem *item = itemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(r))
{
for (int32 i = 0; i < index; i++) {
DiagramItem *item = ItemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(r)) {
region->Include(item->frame() & r);
found = true;
}
@@ -408,14 +360,13 @@ bool DiagramItemGroup::getClippingAbove(
}
break;
}
case DiagramItem::M_WIRE:
{
BRect r = which->frame();
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
{
DiagramItem *item = itemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(r))
{
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) {
DiagramItem *item = ItemAt(i, DiagramItem::M_BOX);
if (item && item->frame().Intersects(r)) {
region->Include(item->frame() & r);
found = true;
}
@@ -424,219 +375,227 @@ bool DiagramItemGroup::getClippingAbove(
}
}
}
return found;
}
// -------------------------------------------------------- //
// *** selection accessors
// -------------------------------------------------------- //
uint32 DiagramItemGroup::selectedType() const
// #pragma mark - selection accessors
/*! Returns the type of DiagramItems in the current selection
(currently only one type at a time is supported!)
*/
uint32
DiagramItemGroup::SelectedType() const
{
D_METHOD(("DiagramItemGroup::selectedType()\n"));
if (countSelectedItems() > 0)
{
return selectedItemAt(0)->type();
}
D_METHOD(("DiagramItemGroup::SelectedType()\n"));
if (CountSelectedItems() > 0)
return SelectedItemAt(0)->type();
return 0;
}
uint32 DiagramItemGroup::countSelectedItems() const
//! Returns the number of items in the current selection
uint32
DiagramItemGroup::CountSelectedItems() const
{
D_METHOD(("DiagramItemGroup::countSelectedItems()\n"));
if (m_selection)
{
return m_selection->CountItems();
}
D_METHOD(("DiagramItemGroup::CountSelectedItems()\n"));
if (fSelection)
return fSelection->CountItems();
return 0;
}
DiagramItem *DiagramItemGroup::selectedItemAt(
uint32 index) const
/*! Returns a pointer to the item in the list which is
at the given \param index; if none is found, this function
returns 0
*/
DiagramItem*
DiagramItemGroup::SelectedItemAt(uint32 index) const
{
D_METHOD(("DiagramItemGroup::selectedItemAt()\n"));
if (m_selection)
{
return static_cast<DiagramItem *>(m_selection->ItemAt(index));
}
D_METHOD(("DiagramItemGroup::SelectedItemAt()\n"));
if (fSelection)
return static_cast<DiagramItem *>(fSelection->ItemAt(index));
return 0;
}
// -------------------------------------------------------- //
// *** selection related operations
// -------------------------------------------------------- //
// selects an item, optionally replacing the complete former
// selection. If the type of the item to be selected differs
// from the type of items currently selected, this methods
// automatically replaces the former selection
bool DiagramItemGroup::selectItem(
DiagramItem *which,
bool deselectOthers)
// #pragma mark - selection related operations
/*! Selects an item, optionally replacing the complete former
selection. If the type of the item to be selected differs
from the type of items currently selected, this methods
automatically replaces the former selection
*/
bool
DiagramItemGroup::SelectItem(DiagramItem* which, bool deselectOthers)
{
D_METHOD(("DiagramItemGroup::selectItem()\n"));
D_METHOD(("DiagramItemGroup::SelectItem()\n"));
bool selectionChanged = false;
if (which && !which->isSelected() && which->isSelectable())
{
if (which && !which->isSelected() && which->isSelectable()) {
// check if the item's type is the same as of the other
// selected items
if (m_multiSelection)
{
if (which->type() != selectedType())
{
if (fMultiSelection) {
if (which->type() != SelectedType())
deselectOthers = true;
}
}
// check if the former selection has to be deselected
if (deselectOthers || !m_multiSelection)
{
while (countSelectedItems() > 0)
{
deselectItem(selectedItemAt(0));
}
if (deselectOthers || !fMultiSelection) {
while (CountSelectedItems() > 0)
DeselectItem(SelectedItemAt(0));
}
// select the item
if (deselectOthers || countSelectedItems() == 0)
{
if (deselectOthers || CountSelectedItems() == 0)
which->select();
}
else
{
which->selectAdding();
}
m_selection->AddItem(which);
fSelection->AddItem(which);
selectionChanged = true;
}
// resort the lists if necessary
if (selectionChanged)
{
sortItems(which->type(), compareSelectionTime);
sortSelectedItems(compareSelectionTime);
if (selectionChanged) {
SortItems(which->type(), compareSelectionTime);
SortSelectedItems(compareSelectionTime);
return true;
}
return false;
}
bool DiagramItemGroup::deselectItem(
DiagramItem *which)
//! Simply deselects one item
bool
DiagramItemGroup::DeselectItem(DiagramItem* which)
{
D_METHOD(("DiagramItemGroup::deselectItem()\n"));
if (which && which->isSelected())
{
m_selection->RemoveItem(which);
D_METHOD(("DiagramItemGroup::DeselectItem()\n"));
if (which && which->isSelected()) {
fSelection->RemoveItem(which);
which->deselect();
sortItems(which->type(), compareSelectionTime);
sortSelectedItems(compareSelectionTime);
SortItems(which->type(), compareSelectionTime);
SortSelectedItems(compareSelectionTime);
return true;
}
return false;
}
bool DiagramItemGroup::selectAll(
uint32 itemType)
//! Selects all items of the given \param itemType
bool
DiagramItemGroup::SelectAll(uint32 itemType)
{
D_METHOD(("DiagramItemGroup::selectAll()\n"));
D_METHOD(("DiagramItemGroup::SelectAll()\n"));
bool selectionChanged = false;
if (m_types & itemType)
{
for (int32 i = 0; i < countItems(itemType); i++)
{
if (selectItem(itemAt(i, itemType), false))
if (fTypes & itemType) {
for (uint32 i = 0; i < CountItems(itemType); i++) {
if (SelectItem(ItemAt(i, itemType), false))
selectionChanged = true;
}
}
return selectionChanged;
}
bool DiagramItemGroup::deselectAll(
uint32 itemType)
//! Deselects all items of the given \param itemType
bool
DiagramItemGroup::DeselectAll(uint32 itemType)
{
D_METHOD(("DiagramItemGroup::deselectAll()\n"));
D_METHOD(("DiagramItemGroup::DeselectAll()\n"));
bool selectionChanged = false;
if (m_types & itemType)
{
for (int32 i = 0; i < countItems(itemType); i++)
{
if (deselectItem(itemAt(i, itemType)))
if (fTypes & itemType) {
for (uint32 i = 0; i < CountItems(itemType); i++) {
if (DeselectItem(ItemAt(i, itemType)))
selectionChanged = true;
}
}
return selectionChanged;
}
void DiagramItemGroup::sortSelectedItems(
int (*compareFunc)(const void *, const void *))
/*! Performs a quicksort on the list of selected items with the
provided compare function (one is already defined in the DiagramItem
implementation)
*/
void
DiagramItemGroup::SortSelectedItems(int (*compareFunc)(const void *, const void *))
{
D_METHOD(("DiagramItemGroup::sortSelectedItems()\n"));
m_selection->SortItems(compareFunc);
D_METHOD(("DiagramItemGroup::SortSelectedItems()\n"));
fSelection->SortItems(compareFunc);
}
void DiagramItemGroup::dragSelectionBy(
float x,
float y,
BRegion *updateRegion)
/*! Moves all selected items by a given amount, taking
item alignment into account; in updateRegion the areas
that still require updating by the caller are returned
*/
void
DiagramItemGroup::DragSelectionBy(float x, float y, BRegion* updateRegion)
{
D_METHOD(("DiagramItemGroup::dragSelectionBy()\n"));
if (selectedType() == DiagramItem::M_BOX)
{
align(&x, &y);
if ((x != 0) || (y != 0))
{
for (int32 i = countSelectedItems() - 1; i >= 0; i--)
{
DiagramItem *item = dynamic_cast<DiagramItem *>(selectedItemAt(i));
D_METHOD(("DiagramItemGroup::DragSelectionBy()\n"));
if (SelectedType() == DiagramItem::M_BOX) {
Align(&x, &y);
if ((x != 0) || (y != 0)) {
for (int32 i = CountSelectedItems() - 1; i >= 0; i--) {
DiagramItem *item = dynamic_cast<DiagramItem *>(SelectedItemAt(i));
if (item->isDraggable())
{
item->moveBy(x, y, updateRegion);
}
}
}
}
}
void DiagramItemGroup::removeSelection()
//! Removes all selected items from the group
void
DiagramItemGroup::RemoveSelection()
{
D_METHOD(("DiagramItemGroup::removeSelection()\n"));
for (int32 i = 0; i < countSelectedItems(); i++)
{
removeItem(selectedItemAt(i));
}
D_METHOD(("DiagramItemGroup::RemoveSelection()\n"));
for (uint32 i = 0; i < CountSelectedItems(); i++)
RemoveItem(SelectedItemAt(i));
}
// -------------------------------------------------------- //
// *** alignment related accessors & operations
// -------------------------------------------------------- //
void DiagramItemGroup::getItemAlignment(
float *horizontal,
float *vertical)
// #pragma mark - alignment related accessors & operations
void
DiagramItemGroup::GetItemAlignment(float *horizontal, float *vertical)
{
D_METHOD(("DiagramItemGroup::getItemAlignment()\n"));
D_METHOD(("DiagramItemGroup::GetItemAlignment()\n"));
if (horizontal)
*horizontal = m_itemAlignment.x;
*horizontal = fItemAlignment.x;
if (vertical)
*vertical = m_itemAlignment.y;
*vertical = fItemAlignment.y;
}
void DiagramItemGroup::align(
float *x,
float *y) const
//! Align a given point(\param x, \param y) to the current grid
void
DiagramItemGroup::Align(float *x, float *y) const
{
D_METHOD(("DiagramItemGroup::align()\n"));
*x = ((int)*x / (int)m_itemAlignment.x) * m_itemAlignment.x;
*y = ((int)*y / (int)m_itemAlignment.y) * m_itemAlignment.y;
D_METHOD(("DiagramItemGroup::Align()\n"));
*x = ((int)*x / (int)fItemAlignment.x) * fItemAlignment.x;
*y = ((int)*y / (int)fItemAlignment.y) * fItemAlignment.y;
}
BPoint DiagramItemGroup::align(
BPoint point) const
//! Align a given \param point to the current grid
BPoint
DiagramItemGroup::Align(BPoint point) const
{
D_METHOD(("DiagramItemGroup::align()\n"));
D_METHOD(("DiagramItemGroup::Align()\n"));
float x = point.x, y = point.y;
align(&x, &y);
Align(&x, &y);
return BPoint(x, y);
}
// END -- DiagramItemGroup.cpp --
+85 -166
View File
@@ -1,203 +1,122 @@
// DiagramItemGroup.h (Cortex/DiagramView)
//
// * PURPOSE
// Basic class for managing and accessing DiagramItem objects.
// Objects of this class can manage one or more of the DiagramItem
// type M_BOX, M_WIRE and M_ENDPOINT. Many methods let you specify
// which type of item you want to deal with.
//
// * HISTORY
// c.lenz 28sep99 Begun
//
#ifndef DIAGRAM_ITEM_GROUP_H
#define DIAGRAM_ITEM_GROUP_H
#ifndef __DiagramItemGroup_H__
#define __DiagramItemGroup_H__
#include "cortex_defs.h"
#include "DiagramItem.h"
#include <List.h>
#include <Point.h>
#include "cortex_defs.h"
__BEGIN_CORTEX_NAMESPACE
class DiagramItemGroup
{
public: // *** ctor/dtor
class DiagramItemGroup {
public:
DiagramItemGroup(uint32 acceptedTypes, bool multiSelection = true);
virtual ~DiagramItemGroup();
DiagramItemGroup(
uint32 acceptedTypes,
bool multiSelection = true);
public: // hook functions
// is called whenever the current selection has changed
virtual void SelectionChanged()
{
}
virtual ~DiagramItemGroup();
public: // item accessors
uint32 CountItems(uint32 whichType = DiagramItem::M_ANY) const;
DiagramItem* ItemAt(uint32 index,
uint32 whichType = DiagramItem::M_ANY) const;
DiagramItem* ItemUnder(BPoint point);
public: // *** hook functions
public: // item operations
virtual bool AddItem(DiagramItem* item);
bool RemoveItem(DiagramItem* item);
void SortItems(uint32 itemType,
int (*compareFunc)(const void *, const void *));
void DrawItems(BRect updateRect, uint32 whichType = DiagramItem::M_ANY,
BRegion *updateRegion = 0);
bool GetClippingAbove(DiagramItem* which, BRegion* outRegion);
// is called whenever the current selection has changed
virtual void selectionChanged()
{ /*does nothing */ }
public: // selection accessors
uint32 SelectedType() const;
uint32 CountSelectedItems() const;
DiagramItem* SelectedItemAt(uint32 index) const;
public: // *** item accessors
// returns the ability of the group to handle multiple selections
// as set in the constructor
bool MultipleSelection() const
{
return fMultiSelection;
}
// returns the number of items in the group (optionally only those
// of the given type)
uint32 countItems(
uint32 whichType = DiagramItem::M_ANY) const;
// returns a pointer to the item in the lists which is
// at the given index; if none is found, this function
// returns 0
DiagramItem *itemAt(
uint32 index,
uint32 whichType = DiagramItem::M_ANY) const;
public: // selection related operations
bool SelectItem(DiagramItem* which, bool deselectOthers = true);
bool DeselectItem(DiagramItem *which);
void SortSelectedItems(int (*compareFunc)(const void *, const void *));
bool SelectAll(uint32 itemType = DiagramItem::M_ANY);
bool DeselectAll(uint32 itemType = DiagramItem::M_ANY);
void DragSelectionBy(float x, float y, BRegion *updateRegion);
void RemoveSelection();
// returns a pointer to the item that is currently under
// the given point, and 0 if there is none
DiagramItem *itemUnder(
BPoint point);
public: // alignment related
public: // *** item operations
// set/get the 'item alignment' grid size; this is used when
// items are being dragged and inserted
void SetItemAlignment(float horizontal, float vertical)
{
fItemAlignment.Set(horizontal, vertical);
}
// adds an item to the group; returns true on success
virtual bool addItem(
DiagramItem *item);
void GetItemAlignment(float *horizontal, float *vertical);
void Align(float *x, float *y) const;
BPoint Align(BPoint point) const;
// removes an item from the group; returns true on success
bool removeItem(
DiagramItem *item);
protected: // accessors
// performs a quicksort on a list of items with the provided
// compare function (one is already defined in the DiagramItem
// implementation); can't handle more than one item type at a
// time!
void sortItems(
uint32 itemType,
int (*compareFunc)(const void *, const void *));
/*! Returns a pointer to the last item returned by the ItemUnder()
function; this can be used by deriving classes to implement a
transit system
*/
DiagramItem* _LastItemUnder()
{
return fLastItemUnder;
}
// fires a draw() command at all items of a specific type that
// intersect with the updateRect
void drawItems(
BRect updateRect,
uint32 whichType = DiagramItem::M_ANY,
BRegion *updateRegion = 0);
void _ResetItemUnder()
{
fLastItemUnder = 0;
}
// returns in outRegion the region of items that lay "over" the given
// DiagramItem in which; returns false if no items are above or the item
// doesn't exist
bool getClippingAbove(
DiagramItem *which,
BRegion *outRegion);
private: // data members
public: // *** selection accessors
// pointers to the item-lists (one list for each item type)
BList* fBoxes;
BList* fWires;
BList* fEndPoints;
// returns the type of DiagramItems in the current selection
// (currently only one type at a time is supported!)
uint32 selectedType() const;
// returns the number of items in the current selection
uint32 countSelectedItems() const;
// returns a pointer to the item in the list which is
// at the given index; if none is found, this function
// returns 0
DiagramItem *selectedItemAt(
uint32 index) const;
// returns the ability of the group to handle multiple selections
// as set in the constructor
bool multipleSelection() const
{ return m_multiSelection; }
BList* fSelection;
// pointer to the list containing the current selection
public: // *** selection related operations
uint32 fTypes;
// the DiagramItem type(s) of items this group will accept
// selects the given item and optionally deselects all others
// (thereby replacing the former selection)
bool selectItem(
DiagramItem *which,
bool deselectOthers = true);
BPoint fItemAlignment;
// specifies the "grid"-size for the frames of items
// simply deselects one item
bool deselectItem(
DiagramItem *which);
bool fMultiSelection;
// can multiple items be selected at once ?
// performs a quicksort on the list of selected items with the
// provided compare function (one is already defined in the DiagramItem
// implementation)
void sortSelectedItems(
int (*compareFunc)(const void *, const void *));
// select all items of the given type
bool selectAll(
uint32 itemType = DiagramItem::M_ANY);
// deselect all items of the given type
bool deselectAll(
uint32 itemType = DiagramItem::M_ANY);
// moves all selected items by a given amount, taking
// item alignment into account; in updateRegion the areas
// that still require updating by the caller are returned
void dragSelectionBy(
float x,
float y,
BRegion *updateRegion);
// removes all selected items from the group
void removeSelection();
public: // *** alignment related
// set/get the 'item alignment' grid size; this is used when
// items are being dragged and inserted
void setItemAlignment(
float horizontal,
float vertical)
{ m_itemAlignment.Set(horizontal, vertical); }
void getItemAlignment(
float *horizontal,
float *vertical);
// align a given point to the current grid
void align(
float *x,
float *y) const;
BPoint align(
BPoint point) const;
protected: // *** accessors
// returns a pointer to the last item returned by the itemUnder()
// function; this can be used by deriving classes to implement a
// transit system
DiagramItem *lastItemUnder()
{ return m_lastItemUnder; }
void resetItemUnder()
{ m_lastItemUnder = 0; }
private: // *** data members
// pointers to the item-lists (one list for each item type)
BList *m_boxes;
BList *m_wires;
BList *m_endPoints;
// pointer to the list containing the current selection
BList *m_selection;
// the DiagramItem type(s) of items this group will accept
uint32 m_types;
// specifies the "grid"-size for the frames of items
BPoint m_itemAlignment;
// can multiple items be selected at once ?
bool m_multiSelection;
// cached pointer to the item that was found in itemUnder()
DiagramItem *m_lastItemUnder;
DiagramItem* fLastItemUnder;
// cached pointer to the item that was found in ItemUnder()
};
__END_CORTEX_NAMESPACE
#endif /* __DiagramItemGroup_H__ */
#endif // DIAGRAM_ITEM_GROUP_H
+46 -46
View File
@@ -114,8 +114,8 @@ void DiagramView::Draw(
{
D_METHOD(("DiagramView::Draw()\n"));
drawBackground(updateRect);
drawItems(updateRect, DiagramItem::M_WIRE);
drawItems(updateRect, DiagramItem::M_BOX);
DrawItems(updateRect, DiagramItem::M_WIRE);
DrawItems(updateRect, DiagramItem::M_BOX);
}
void DiagramView::FrameResized(
@@ -149,17 +149,17 @@ void DiagramView::MessageReceived(
{
bool deselectOthers = true;
message->FindBool("replace", &deselectOthers);
if (item->isSelected() && !deselectOthers && multipleSelection())
if (item->isSelected() && !deselectOthers && MultipleSelection())
{
if (deselectItem(item))
if (DeselectItem(item))
{
selectionChanged();
SelectionChanged();
}
}
else if (selectItem(item, deselectOthers))
else if (SelectItem(item, deselectOthers))
{
sortItems(item->type(), &compareSelectionTime);
selectionChanged();
SortItems(item->type(), &compareSelectionTime);
SelectionChanged();
}
}
break;
@@ -179,7 +179,7 @@ void DiagramView::MessageReceived(
{
_endWireTracking();
DiagramWire *wire = createWire(fromWhich, toWhich);
if (wire && addItem(wire))
if (wire && AddItem(wire))
{
connectionEstablished(fromWhich, toWhich);
break;
@@ -195,7 +195,7 @@ void DiagramView::MessageReceived(
if (message->WasDropped())
{
BPoint point = ConvertFromScreen(message->DropPoint());
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item)
{
item->messageDropped(point, message);
@@ -224,9 +224,9 @@ void DiagramView::KeyDown(
case B_LEFT_ARROW:
{
float x;
getItemAlignment(&x, 0);
GetItemAlignment(&x, 0);
BRegion updateRegion;
dragSelectionBy(-x, 0.0, &updateRegion);
DragSelectionBy(-x, 0.0, &updateRegion);
for (int32 i = 0; i < updateRegion.CountRects(); i++)
Invalidate(updateRegion.RectAt(i));
updateDataRect();
@@ -235,9 +235,9 @@ void DiagramView::KeyDown(
case B_RIGHT_ARROW:
{
float x;
getItemAlignment(&x, 0);
GetItemAlignment(&x, 0);
BRegion updateRegion;
dragSelectionBy(x, 0.0, &updateRegion);
DragSelectionBy(x, 0.0, &updateRegion);
for (int32 i = 0; i < updateRegion.CountRects(); i++)
Invalidate(updateRegion.RectAt(i));
updateDataRect();
@@ -246,9 +246,9 @@ void DiagramView::KeyDown(
case B_UP_ARROW:
{
float y;
getItemAlignment(0, &y);
GetItemAlignment(0, &y);
BRegion updateRegion;
dragSelectionBy(0.0, -y, &updateRegion);
DragSelectionBy(0.0, -y, &updateRegion);
for (int32 i = 0; i < updateRegion.CountRects(); i++)
Invalidate(updateRegion.RectAt(i));
updateDataRect();
@@ -257,9 +257,9 @@ void DiagramView::KeyDown(
case B_DOWN_ARROW:
{
float y;
getItemAlignment(0, &y);
GetItemAlignment(0, &y);
BRegion updateRegion;
dragSelectionBy(0.0, y, &updateRegion);
DragSelectionBy(0.0, y, &updateRegion);
for (int32 i = 0; i < updateRegion.CountRects(); i++)
Invalidate(updateRegion.RectAt(i));
updateDataRect();
@@ -305,16 +305,16 @@ void DiagramView::MouseDown(
}
// was an item clicked ?
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item)
{
item->mouseDown(point, m_lastButton, m_clickCount);
}
else // no, the background was clicked
{
if (!(modifiers() & B_SHIFT_KEY) && deselectAll(DiagramItem::M_ANY))
selectionChanged();
if (multipleSelection() && (m_lastButton == B_PRIMARY_MOUSE_BUTTON) && !(modifiers() & B_CONTROL_KEY))
if (!(modifiers() & B_SHIFT_KEY) && DeselectAll(DiagramItem::M_ANY))
SelectionChanged();
if (MultipleSelection() && (m_lastButton == B_PRIMARY_MOUSE_BUTTON) && !(modifiers() & B_CONTROL_KEY))
_beginRectTracking(point);
mouseDown(point, m_lastButton, m_clickCount);
}
@@ -395,7 +395,7 @@ void DiagramView::MouseMoved(
if (box)
{
BRegion updateRegion;
dragSelectionBy(point.x - box->frame().left - offset.x,
DragSelectionBy(point.x - box->frame().left - offset.x,
point.y - box->frame().top - offset.y,
&updateRegion);
updateDataRect();
@@ -409,7 +409,7 @@ void DiagramView::MouseMoved(
}
default: // unkwown message -> redirect to messageDragged()
{
DiagramItem *last = lastItemUnder();
DiagramItem *last = _LastItemUnder();
if (transit == B_EXITED_VIEW)
{
if (last)
@@ -420,7 +420,7 @@ void DiagramView::MouseMoved(
}
else
{
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item)
{
if (item != last)
@@ -450,19 +450,19 @@ void DiagramView::MouseMoved(
}
else // no message at all -> redirect to mouseOver()
{
DiagramItem *last = lastItemUnder();
DiagramItem *last = _LastItemUnder();
if ((transit == B_EXITED_VIEW) || (transit == B_OUTSIDE_VIEW))
{
if (last)
{
last->mouseOver(point, B_EXITED_VIEW);
resetItemUnder();
_ResetItemUnder();
mouseOver(point, B_EXITED_VIEW);
}
}
else
{
DiagramItem *item = itemUnder(point);
DiagramItem *item = ItemUnder(point);
if (item)
{
if (item != last)
@@ -489,7 +489,7 @@ void DiagramView::MouseUp(
BPoint point)
{
D_METHOD(("DiagramView::MouseUp()\n"));
if (multipleSelection())
if (MultipleSelection())
EndRectTracking();
_endWireTracking();
@@ -501,13 +501,13 @@ void DiagramView::MouseUp(
// *** derived from DiagramItemGroup (public)
// -------------------------------------------------------- //
bool DiagramView::addItem(
bool DiagramView::AddItem(
DiagramItem *item)
{
D_METHOD(("DiagramBox::addItem()\n"));
D_METHOD(("DiagramBox::AddItem()\n"));
if (item)
{
if (DiagramItemGroup::addItem(item))
if (DiagramItemGroup::AddItem(item))
{
item->_setOwner(this);
item->attachedToDiagram();
@@ -521,14 +521,14 @@ bool DiagramView::addItem(
return false;
}
bool DiagramView::removeItem(
bool DiagramView::RemoveItem(
DiagramItem *item)
{
D_METHOD(("DiagramBox::removeItem()\n"));
D_METHOD(("DiagramBox::RemoveItem()\n"));
if (item)
{
item->detachedFromDiagram();
if (DiagramItemGroup::removeItem(item))
if (DiagramItemGroup::RemoveItem(item))
{
item->_setOwner(0);
if (item->type() == DiagramItem::M_BOX)
@@ -632,8 +632,8 @@ DiagramView::updateDataRect()
D_METHOD(("DiagramView::updateDataRect()\n"));
// calculate the area in which boxes display
m_boxRegion.MakeEmpty();
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++) {
m_boxRegion.Include(itemAt(i, DiagramItem::M_BOX)->frame());
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) {
m_boxRegion.Include(ItemAt(i, DiagramItem::M_BOX)->frame());
}
// adapt the data rect to the new region of boxes
BRect boxRect = m_boxRegion.Frame();
@@ -652,8 +652,8 @@ DiagramView::_beginWireTracking(DiagramEndPoint *startPoint)
{
D_METHOD(("DiagramView::beginWireTracking()\n"));
m_draggedWire = createWire(startPoint);
addItem(m_draggedWire);
selectItem(m_draggedWire, true);
AddItem(m_draggedWire);
SelectItem(m_draggedWire, true);
Invalidate(startPoint->frame());
}
@@ -662,7 +662,7 @@ void DiagramView::_endWireTracking()
D_METHOD(("DiagramView::endWireTracking()\n"));
if (m_draggedWire)
{
removeItem(m_draggedWire);
RemoveItem(m_draggedWire);
Invalidate(m_draggedWire->frame());
DiagramEndPoint *endPoint = m_draggedWire->startPoint();
if (!endPoint)
@@ -699,19 +699,19 @@ DiagramView::_trackRect(BPoint origin, BPoint current)
rect.top = origin.y < current.y ? origin.y : current.y;
rect.right = origin.x < current.x ? current.x : origin.x;
rect.bottom = origin.y < current.y ? current.y : origin.y;
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++) {
DiagramBox *box = dynamic_cast<DiagramBox *>(itemAt(i, DiagramItem::M_BOX));
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) {
DiagramBox *box = dynamic_cast<DiagramBox *>(ItemAt(i, DiagramItem::M_BOX));
if (box) {
if (rect.Intersects(box->frame()))
changed |= selectItem(box, false);
changed |= SelectItem(box, false);
else
changed |= deselectItem(box);
changed |= DeselectItem(box);
}
}
if (changed) {
sortItems(DiagramItem::M_BOX, &compareSelectionTime);
selectionChanged();
SortItems(DiagramItem::M_BOX, &compareSelectionTime);
SelectionChanged();
}
}
+2 -2
View File
@@ -147,12 +147,12 @@ public: // *** derived from DiagramItemGroup
// extends the DiagramItemGroup implementation by setting
// the items owner and calling the attachedToDiagram() hook
// on it
virtual bool addItem(
virtual bool AddItem(
DiagramItem *item);
// extends the DiagramItemGroup implementation by calling
// the detachedToDiagram() hook on the item
virtual bool removeItem(
virtual bool RemoveItem(
DiagramItem *item);
public: // *** operations
+1 -1
View File
@@ -128,7 +128,7 @@ void DiagramWire::draw(
{
BRegion region, clipping;
region.Include(frame() & updateRect);
if (view()->getClippingAbove(this, &clipping))
if (view()->GetClippingAbove(this, &clipping))
region.Exclude(&clipping);
view()->ConstrainClippingRegion(&region);
drawWire();
@@ -136,7 +136,7 @@ void MediaNodePanel::mouseDown(
_inherited::mouseDown(point, buttons, clicks);
// +++ REALLY BAD WORKAROUND
MediaJack *jack = dynamic_cast<MediaJack *>(lastItemUnder());
MediaJack *jack = dynamic_cast<MediaJack *>(_LastItemUnder());
if (jack && jack->frame().Contains(point))
{
return;
@@ -210,7 +210,7 @@ void MediaNodePanel::messageDropped(
D_METHOD(("MediaNodePanel::messageDropped()\n"));
// +++ REALLY BAD WORKAROUND
MediaJack *jack = dynamic_cast<MediaJack *>(itemUnder(point));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemUnder(point));
if (jack)
{
jack->messageDropped(point, message);
@@ -253,9 +253,9 @@ void MediaNodePanel::layoutChanged(
m_alternatePosition = p;
resizeTo(M_DEFAULT_WIDTH, M_DEFAULT_HEIGHT);
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
jack->layoutChanged(layout);
}
_updateIcon(layout);
@@ -273,7 +273,7 @@ void MediaNodePanel::populateInit()
ref->getFreeInputs(freeInputs);
for (uint32 i = 0; i < freeInputs.size(); i++)
{
addItem(new MediaJack(freeInputs[i]));
AddItem(new MediaJack(freeInputs[i]));
}
}
if (ref->kind() & B_BUFFER_PRODUCER)
@@ -282,7 +282,7 @@ void MediaNodePanel::populateInit()
ref->getFreeOutputs(freeOutputs);
for (uint32 i = 0; i < freeOutputs.size(); i++)
{
addItem(new MediaJack(freeOutputs[i]));
AddItem(new MediaJack(freeOutputs[i]));
}
}
}
@@ -292,12 +292,12 @@ void MediaNodePanel::updateIOJacks()
D_METHOD(("MediaNodePanel::updateIOJacks()\n"));
// remove all free inputs/outputs, they may be outdated
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
if (jack && !jack->isConnected())
{
removeItem(jack);
RemoveItem(jack);
delete jack;
i--; // account for reindexing in the BList
}
@@ -311,7 +311,7 @@ void MediaNodePanel::updateIOJacks()
for (uint32 i = 0; i < freeInputs.size(); i++)
{
MediaJack *jack;
addItem(jack = new MediaJack(freeInputs[i]));
AddItem(jack = new MediaJack(freeInputs[i]));
}
}
@@ -323,7 +323,7 @@ void MediaNodePanel::updateIOJacks()
for (uint32 i = 0; i < freeOutputs.size(); i++)
{
MediaJack *jack;
addItem(jack = new MediaJack(freeOutputs[i]));
AddItem(jack = new MediaJack(freeOutputs[i]));
}
}
@@ -335,7 +335,7 @@ void MediaNodePanel::updateIOJacks()
void MediaNodePanel::arrangeIOJacks()
{
D_METHOD(("MediaNodePanel::arrangeIOJacks()\n"));
sortItems(DiagramItem::M_ENDPOINT, &compareTypeAndID);
SortItems(DiagramItem::M_ENDPOINT, &compareTypeAndID);
switch (dynamic_cast<MediaRoutingView *>(view())->getLayout())
{
@@ -343,13 +343,13 @@ void MediaNodePanel::arrangeIOJacks()
{
BRegion updateRegion;
float align = 1.0;
view()->getItemAlignment(0, &align);
view()->GetItemAlignment(0, &align);
// adjust this panel's size
int32 numInputs = 0, numOutputs = 0;
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
if (jack)
{
if (jack->isInput())
@@ -406,9 +406,9 @@ void MediaNodePanel::arrangeIOJacks()
outputOffset = center - ((numOutputs + 1) / 2) * (MediaJack::M_DEFAULT_HEIGHT + MediaJack::M_DEFAULT_GAP);
}
}
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
if (jack)
{
if (jack->isInput())
@@ -433,13 +433,13 @@ void MediaNodePanel::arrangeIOJacks()
{
BRegion updateRegion;
float align = 1.0;
view()->getItemAlignment(&align, 0);
view()->GetItemAlignment(&align, 0);
// adjust this panel's size
int32 numInputs = 0, numOutputs = 0;
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
if (jack)
{
if (jack->isInput())
@@ -493,9 +493,9 @@ void MediaNodePanel::arrangeIOJacks()
outputOffset = center - ((numOutputs + 1) / 2) * (MediaJack::M_DEFAULT_WIDTH + MediaJack::M_DEFAULT_GAP);
}
}
for (uint32 i = 0; i < countItems(); i++)
for (uint32 i = 0; i < CountItems(); i++)
{
MediaJack *jack = dynamic_cast<MediaJack *>(itemAt(i));
MediaJack *jack = dynamic_cast<MediaJack *>(ItemAt(i));
if (jack)
{
if (jack->isInput())
@@ -92,7 +92,7 @@ MediaRoutingView::MediaRoutingView(
ASSERT(manager);
setBackgroundColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT));
setItemAlignment(5.0, 5.0);
SetItemAlignment(5.0, 5.0);
_initLayout();
}
@@ -240,7 +240,7 @@ void MediaRoutingView::messageDropped(
m_lastDroppedNode = droppedNode->id();
BPoint dropPoint, dropOffset;
dropPoint = message->DropPoint(&dropOffset);
m_lastDropPoint = align(ConvertFromScreen(dropPoint - dropOffset));
m_lastDropPoint = Align(ConvertFromScreen(dropPoint - dropOffset));
}
else
{
@@ -510,7 +510,7 @@ void MediaRoutingView::MessageReceived(
case M_SELECT_ALL:
{
D_MESSAGE(("MediaRoutingView::MessageReceived(M_SELECT_ALL)\n"));
selectAll(DiagramItem::M_BOX);
SelectAll(DiagramItem::M_BOX);
break;
}
case M_DELETE_SELECTION:
@@ -721,9 +721,9 @@ BPoint MediaRoutingView::findFreePositionFor(
}
// find the bottom item in the column
float bottom = 0.0;
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
BRect r = itemAt(i, DiagramItem::M_BOX)->frame();
BRect r = ItemAt(i, DiagramItem::M_BOX)->frame();
if ((r.left >= p.x)
&& (r.left <= p.x + MediaNodePanel::M_DEFAULT_WIDTH))
{
@@ -750,9 +750,9 @@ BPoint MediaRoutingView::findFreePositionFor(
}
// find the right-most item in the row
float right = 0.0;
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
BRect r = itemAt(i, DiagramItem::M_BOX)->frame();
BRect r = ItemAt(i, DiagramItem::M_BOX)->frame();
if ((r.top >= p.y)
&& (r.top <= p.y + MediaNodePanel::M_DEFAULT_HEIGHT))
{
@@ -821,7 +821,7 @@ void MediaRoutingView::layoutChanged(
bodyHeight = 2 * MediaNodePanel::M_BODY_V_MARGIN + B_LARGE_ICON;
MediaNodePanel::M_DEFAULT_WIDTH = labelWidth > bodyWidth ? labelWidth : bodyWidth;
MediaNodePanel::M_DEFAULT_HEIGHT = labelHeight + bodyHeight;
align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
Align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
break;
}
case M_MINI_ICON_VIEW:
@@ -864,14 +864,14 @@ void MediaRoutingView::layoutChanged(
bodyHeight = 2 * MediaNodePanel::M_BODY_V_MARGIN + B_MINI_ICON;
MediaNodePanel::M_DEFAULT_WIDTH = labelWidth + bodyWidth;
MediaNodePanel::M_DEFAULT_HEIGHT = labelHeight > bodyHeight ? labelHeight : bodyHeight;
align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
Align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
break;
}
}
m_layout = layout;
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(itemAt(i, DiagramItem::M_BOX));
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(ItemAt(i, DiagramItem::M_BOX));
if (panel)
{
panel->layoutChanged(layout);
@@ -885,24 +885,24 @@ void MediaRoutingView::cleanUp()
{
D_METHOD(("MediaRoutingView::cleanUp()\n"));
sortItems(DiagramItem::M_BOX, compareID);
SortItems(DiagramItem::M_BOX, compareID);
// move all the panels offscreen
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
itemAt(i, DiagramItem::M_BOX)->moveTo(BPoint(-200.0, -200.0));
ItemAt(i, DiagramItem::M_BOX)->moveTo(BPoint(-200.0, -200.0));
}
// move all panels to their 'ideal' position
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
MediaNodePanel *panel;
panel = dynamic_cast<MediaNodePanel *>(itemAt(i, DiagramItem::M_BOX));
panel = dynamic_cast<MediaNodePanel *>(ItemAt(i, DiagramItem::M_BOX));
BPoint p = findFreePositionFor(panel);
panel->moveTo(p);
}
sortItems(DiagramItem::M_BOX, compareSelectionTime);
SortItems(DiagramItem::M_BOX, compareSelectionTime);
Invalidate();
updateDataRect();
}
@@ -1025,14 +1025,14 @@ status_t MediaRoutingView::importState(
// look up matching panel +++++ SLOW +++++
uint32 panelIndex;
uint32 items = countItems(DiagramItem::M_BOX);
uint32 items = CountItems(DiagramItem::M_BOX);
for(
panelIndex = 0;
panelIndex < items;
++panelIndex) {
MediaNodePanel* panel = dynamic_cast<MediaNodePanel*>(
itemAt(panelIndex, DiagramItem::M_BOX));
ItemAt(panelIndex, DiagramItem::M_BOX));
if(panel &&
!strcmp(panel->ref->name(), nodeName) &&
@@ -1080,9 +1080,9 @@ status_t MediaRoutingView::exportState(
}
// store panel positions w/ node names & signatures
for(uint32 n = 0; n < countItems(DiagramItem::M_BOX); ++n) {
for(uint32 n = 0; n < CountItems(DiagramItem::M_BOX); ++n) {
MediaNodePanel* panel = dynamic_cast<MediaNodePanel*>(
itemAt(n, DiagramItem::M_BOX));
ItemAt(n, DiagramItem::M_BOX));
if(!panel)
continue;
@@ -1173,7 +1173,7 @@ status_t MediaRoutingView::importStateFor(
panel->importState(&m);
// select the panel
selectItem(panel, false);
SelectItem(panel, false);
}
return B_OK;
@@ -1229,14 +1229,14 @@ status_t MediaRoutingView::_addPanelFor(
MediaNodePanel *panel = 0;
if (id == m_lastDroppedNode) // this was instantiated thru drag & drop
{
addItem(panel = new MediaNodePanel(m_lastDropPoint, ref));
selectItem(panel, true);
AddItem(panel = new MediaNodePanel(m_lastDropPoint, ref));
SelectItem(panel, true);
m_lastDroppedNode = 0;
}
else // this was an externally created node, must find a nice position first
{
panel = new MediaNodePanel(BPoint(0.0, 0.0), ref);
addItem(panel);
AddItem(panel);
BMessage state;
if(_fetchInactiveNodeState(panel, &state) == B_OK)
panel->importState(&state);
@@ -1257,9 +1257,9 @@ status_t MediaRoutingView::_findPanelFor(
{
D_METHOD(("MediaRoutingView::_findPanelFor()\n"));
for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++)
{
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(itemAt(i, DiagramItem::M_BOX));
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(ItemAt(i, DiagramItem::M_BOX));
if (panel)
{
if (panel->ref->id() == id)
@@ -1280,7 +1280,7 @@ status_t MediaRoutingView::_removePanelFor(
MediaNodePanel *panel;
if (_findPanelFor(id, &panel) == B_OK)
{
if (removeItem(panel))
if (RemoveItem(panel))
{
remove_observer(this, panel->ref);
Invalidate(panel->frame());
@@ -1309,7 +1309,7 @@ status_t MediaRoutingView::_addWireFor(
return error;
}
MediaJack *outputJack = new MediaJack(output);
source->addItem(outputJack);
source->AddItem(outputJack);
media_input input;
error = connection.getInput(&input);
@@ -1318,10 +1318,10 @@ status_t MediaRoutingView::_addWireFor(
return error;
}
MediaJack *inputJack = new MediaJack(input);
destination->addItem(inputJack);
destination->AddItem(inputJack);
MediaWire *wire = new MediaWire(connection, outputJack, inputJack);
addItem(wire);
AddItem(wire);
source->updateIOJacks();
source->arrangeIOJacks();
destination->updateIOJacks();
@@ -1348,9 +1348,9 @@ status_t MediaRoutingView::_findWireFor(
{
D_METHOD(("MediaRoutingView::_findWireFor()\n"));
for (uint32 i = 0; i < countItems(DiagramItem::M_WIRE); i++)
for (uint32 i = 0; i < CountItems(DiagramItem::M_WIRE); i++)
{
MediaWire *wire = dynamic_cast<MediaWire *>(itemAt(i, DiagramItem::M_WIRE));
MediaWire *wire = dynamic_cast<MediaWire *>(ItemAt(i, DiagramItem::M_WIRE));
if (wire && wire->connection.id() == connectionID)
{
*outWire = wire;
@@ -1371,7 +1371,7 @@ status_t MediaRoutingView::_removeWireFor(
MediaNodePanel *source, *destination;
_findPanelFor(wire->connection.sourceNode(), &source);
_findPanelFor(wire->connection.destinationNode(), &destination);
removeItem(wire);
RemoveItem(wire);
Invalidate(wire->frame());
delete wire;
if (source)
@@ -1449,7 +1449,7 @@ void MediaRoutingView::_initLayout()
bodyHeight = 2 * MediaNodePanel::M_BODY_V_MARGIN + B_LARGE_ICON;
MediaNodePanel::M_DEFAULT_WIDTH = labelWidth > bodyWidth ? labelWidth : bodyWidth;
MediaNodePanel::M_DEFAULT_HEIGHT = labelHeight + bodyHeight;
align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
Align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
// Adjust the cleanup settings
M_CLEANUP_H_GAP += MediaNodePanel::M_DEFAULT_WIDTH;
@@ -1472,7 +1472,7 @@ void MediaRoutingView::_initLayout()
bodyHeight = 2 * MediaNodePanel::M_BODY_V_MARGIN + B_MINI_ICON;
MediaNodePanel::M_DEFAULT_WIDTH = labelWidth + bodyWidth;
MediaNodePanel::M_DEFAULT_HEIGHT = labelHeight > bodyHeight ? labelHeight : bodyHeight;
align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
Align(&MediaNodePanel::M_DEFAULT_WIDTH, &MediaNodePanel::M_DEFAULT_HEIGHT);
// Adjust the cleanup settings
M_CLEANUP_V_GAP += MediaNodePanel::M_DEFAULT_HEIGHT;
@@ -1532,12 +1532,12 @@ void MediaRoutingView::_changeCyclingForSelection(
{
D_METHOD(("MediaRoutingView::_changeCyclingForSelection()\n"));
if (selectedType() == DiagramItem::M_BOX)
if (SelectedType() == DiagramItem::M_BOX)
{
manager->lock();
for (uint32 i = 0; i < countSelectedItems(); i++)
for (uint32 i = 0; i < CountSelectedItems(); i++)
{
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && (panel->ref->isCycling() != cycle))
{
panel->ref->setCycling(cycle);
@@ -1552,12 +1552,12 @@ void MediaRoutingView::_changeRunModeForSelection(
{
D_METHOD(("MediaRoutingView::_changeRunModeForSelection()\n"));
if (selectedType() == DiagramItem::M_BOX)
if (SelectedType() == DiagramItem::M_BOX)
{
manager->lock();
for (uint32 i = 0; i < countSelectedItems(); i++)
for (uint32 i = 0; i < CountSelectedItems(); i++)
{
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && (panel->ref->runMode() != mode))
{
panel->ref->setRunMode(mode);
@@ -1575,18 +1575,18 @@ void MediaRoutingView::_openInfoWindowsForSelection() {
return;
}
if (selectedType() == DiagramItem::M_BOX) {
for (uint32 i = 0; i < countSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
if (SelectedType() == DiagramItem::M_BOX) {
for (uint32 i = 0; i < CountSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && manager->Lock()) {
manager->openWindowFor(panel->ref);
manager->Unlock();
}
}
}
else if (selectedType() == DiagramItem::M_WIRE) {
for (uint32 i = 0; i < countSelectedItems(); i++) {
MediaWire *wire = dynamic_cast<MediaWire *>(selectedItemAt(i));
else if (SelectedType() == DiagramItem::M_WIRE) {
for (uint32 i = 0; i < CountSelectedItems(); i++) {
MediaWire *wire = dynamic_cast<MediaWire *>(SelectedItemAt(i));
if (wire && manager->Lock()) {
manager->openWindowFor(wire->connection);
manager->Unlock();
@@ -1598,13 +1598,13 @@ void MediaRoutingView::_openInfoWindowsForSelection() {
void MediaRoutingView::_openParameterWindowsForSelection() {
D_METHOD(("MediaRoutingView::_openParameterWindowsForSelection()\n"));
if (selectedType() != DiagramItem::M_BOX) {
if (SelectedType() != DiagramItem::M_BOX) {
// can only open parameter window for nodes
return;
}
for (uint32 i = 0; i < countSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
for (uint32 i = 0; i < CountSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && (panel->ref->kind() & B_CONTROLLABLE)) {
ParameterWindowManager *paramMgr= ParameterWindowManager::Instance();
if (paramMgr && paramMgr->Lock()) {
@@ -1618,13 +1618,13 @@ void MediaRoutingView::_openParameterWindowsForSelection() {
void MediaRoutingView::_startControlPanelsForSelection() {
D_METHOD(("MediaRoutingView::_startControlPanelsForSelection()\n"));
if (selectedType() != DiagramItem::M_BOX) {
if (SelectedType() != DiagramItem::M_BOX) {
// can only start control panel for nodes
return;
}
for (uint32 i = 0; i < countSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
for (uint32 i = 0; i < CountSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && (panel->ref->kind() & B_CONTROLLABLE)) {
ParameterWindowManager *paramMgr= ParameterWindowManager::Instance();
if (paramMgr && paramMgr->Lock()) {
@@ -1638,11 +1638,11 @@ void MediaRoutingView::_startControlPanelsForSelection() {
void MediaRoutingView::_deleteSelection()
{
D_METHOD(("MediaRoutingView::_deleteSelection()\n"));
if (selectedType() == DiagramItem::M_BOX)
if (SelectedType() == DiagramItem::M_BOX)
{
for (uint32 i = 0; i < countSelectedItems(); i++)
for (uint32 i = 0; i < CountSelectedItems(); i++)
{
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && panel->ref->isInternal())
{
status_t error = panel->ref->releaseNode();
@@ -1655,11 +1655,11 @@ void MediaRoutingView::_deleteSelection()
}
}
}
else if (selectedType() == DiagramItem::M_WIRE)
else if (SelectedType() == DiagramItem::M_WIRE)
{
for (uint32 i = 0; i < countSelectedItems(); i++)
for (uint32 i = 0; i < CountSelectedItems(); i++)
{
MediaWire *wire = dynamic_cast<MediaWire *>(selectedItemAt(i));
MediaWire *wire = dynamic_cast<MediaWire *>(SelectedItemAt(i));
if (wire && !(wire->connection.flags() & Connection::LOCKED))
{
status_t error = manager->disconnect(wire->connection);
@@ -1721,7 +1721,7 @@ void MediaRoutingView::_checkDroppedFile(
droppedNode->setFlags(droppedNode->flags() | NodeRef::NO_POSITION_REPORTING);
}
m_lastDroppedNode = droppedNode->id();
m_lastDropPoint = align(dropPoint);
m_lastDropPoint = Align(dropPoint);
}
else
{
@@ -1804,11 +1804,11 @@ MediaRoutingView::_broadcastSelection() const
{
int32 selectedGroup = 0;
if (selectedType() == DiagramItem::M_BOX) {
if (SelectedType() == DiagramItem::M_BOX) {
// iterate thru the list of selected node panels and make the
// first group we find the selected group
for (uint32 i = 0; i < countSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i));
for (uint32 i = 0; i < CountSelectedItems(); i++) {
MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(SelectedItemAt(i));
if (panel && panel->ref->group()) {
selectedGroup = panel->ref->group()->id();
BMessenger messenger(Window());
+5 -5
View File
@@ -505,7 +505,7 @@ public: // *** hooks
if(m_routingView) {
// m_routingView->LockLooper();
m_routingView->deselectAll();
m_routingView->DeselectAll();
status_t err = m_routingView->importStateFor(
this,
archive);
@@ -595,8 +595,8 @@ status_t RouteApp::_writeSelectedNodeSet(
ASSERT(v);
if(
v->countSelectedItems() < 0 ||
v->selectedType() != DiagramItem::M_BOX) {
v->CountSelectedItems() < 0 ||
v->SelectedType() != DiagramItem::M_BOX) {
PRINT((
"!!! RouteApp::_writeSelectedNodeSet():\n"
" Invalid selection!\n"));
@@ -607,8 +607,8 @@ status_t RouteApp::_writeSelectedNodeSet(
_RouteAppExportContext context(v);
for(uint32 i = 0; i < v->countSelectedItems(); ++i) {
MediaNodePanel* panel = dynamic_cast<MediaNodePanel*>(v->selectedItemAt(i));
for(uint32 i = 0; i < v->CountSelectedItems(); ++i) {
MediaNodePanel* panel = dynamic_cast<MediaNodePanel*>(v->SelectedItemAt(i));
if(!panel)
continue;
err = context.addNode(panel->ref->id());
@@ -79,13 +79,13 @@ NumericValControl::initSegments()
// *** SEGMENT DIVISION NEEDS TO BE CONFIGURABLE +++++
// GOOD 23aug99
// init segments:
add(new ValControlDigitSegment(fWholeDigits, 0, negativeVisible), RIGHT_MOST);
_Add(new ValControlDigitSegment(fWholeDigits, 0, negativeVisible), RIGHT_MOST);
if(fFractionalDigits)
add(ValCtrlLayoutEntry::decimalPoint, RIGHT_MOST);
if (fFractionalDigits)
_Add(ValCtrlLayoutEntry::decimalPoint, RIGHT_MOST);
for (int n = 0; n < fFractionalDigits; ++n)
add(new ValControlDigitSegment(1, (-1)-n, false, ValControlDigitSegment::ZERO_FILL),
_Add(new ValControlDigitSegment(1, (-1)-n, false, ValControlDigitSegment::ZERO_FILL),
RIGHT_MOST);
// add(new ValControlDigitSegment(fFractionalDigits, -fFractionalDigits,
// false, ValControlDigitSegment::ZERO_FILL),
@@ -193,7 +193,7 @@ NumericValControl::value() const
// double acc = 0.0;
//
// // walk segments, adding the value of each
// for(int n = countEntries(); n > 0; --n) {
// for(int n = CountEntries(); n > 0; --n) {
// const ValCtrlLayoutEntry& e = entryAt(n-1);
// if(e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
// const ValControlDigitSegment* digitSegment =
@@ -277,7 +277,7 @@ NumericValControl::setValue(double value, bool setParam)
// double dfCur = 0.0;
//
// // sum the values of all segments
// for(int nIndex = countEntries()-1; nIndex >= 0; nIndex--) {
// for(int nIndex = CountEntries()-1; nIndex >= 0; nIndex--) {
// if(entryAt(nIndex).type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
// const ValControlDigitSegment* pSeg =
// dynamic_cast<ValControlDigitSegment*>(entryAt(nIndex).pView);
@@ -313,7 +313,7 @@ NumericValControl::setValue(double value, bool setParam)
// Invoke();
//
// // hand value to each segment
// for(int nIndex = 0; nIndex < countEntries(); nIndex++) {
// for(int nIndex = 0; nIndex < CountEntries(); nIndex++) {
// if(entryAt(nIndex).type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
// const ValControlDigitSegment* pSeg =
// dynamic_cast<ValControlDigitSegment*>(entryAt(nIndex).pView);
@@ -527,11 +527,11 @@ NumericValControl::_ValueFixed() const {
int64 scaleBase = fFractionalDigits;
// walk segments, adding the value of each
for (int n = countEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = entryAt(n-1);
if (e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
for (int n = CountEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& entry = _EntryAt(n-1);
if (entry.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
const ValControlDigitSegment* digitSegment =
dynamic_cast<ValControlDigitSegment*>(e.pView);
dynamic_cast<ValControlDigitSegment*>(entry.pView);
ASSERT(digitSegment);
// PRINT((
@@ -571,13 +571,12 @@ NumericValControl::_SetValueFixed(int64 fixed)
int64 scaleBase = fFractionalDigits;
// set segments
for (int n = countEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = entryAt(n-1);
for (int n = CountEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& entry = _EntryAt(n-1);
if (e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
if (entry.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
ValControlDigitSegment* digitSegment =
dynamic_cast<ValControlDigitSegment*>(e.pView);
dynamic_cast<ValControlDigitSegment*>(entry.pView);
ASSERT(digitSegment);
// PRINT((
+340 -341
View File
@@ -17,232 +17,244 @@ using namespace std;
__USE_CORTEX_NAMESPACE
// -------------------------------------------------------- //
// constants
// -------------------------------------------------------- //
const float ValControl::s_segmentPadding = 2.0;
const float ValControl::fSegmentPadding = 2.0;
// the decimal point covers one more pixel x and y-ward:
const float ValControl::s_decimalPointWidth = 2.0;
const float ValControl::s_decimalPointHeight = 2.0;
const float ValControl::fDecimalPointWidth = 2.0;
const float ValControl::fDecimalPointHeight = 2.0;
// -------------------------------------------------------- //
// ctor/dtor/accessors
// -------------------------------------------------------- //
/*protected*/
ValControl::ValControl(
BRect frame,
const char* name,
const char* label,
BMessage* message,
align_mode alignMode,
align_flags alignFlags,
update_mode updateMode,
bool backBuffer) :
BControl(frame, name, label, message, B_FOLLOW_TOP|B_FOLLOW_LEFT,
ValControl::ValControl(BRect frame, const char* name, const char* label,
BMessage* message, align_mode alignMode, align_flags alignFlags,
update_mode updateMode, bool backBuffer)
: BControl(frame, name, label, message, B_FOLLOW_TOP|B_FOLLOW_LEFT,
B_WILL_DRAW|B_FRAME_EVENTS),
m_dirty(true),
m_updateMode(updateMode),
m_labelFont(be_bold_font),
m_valueFont(be_bold_font),
m_alignMode(alignMode),
m_alignFlags(alignFlags),
m_origBounds(Bounds()),
m_haveBackBuffer(backBuffer),
m_backBuffer(0),
m_backBufferView(0) {
if(m_haveBackBuffer)
_allocBackBuffer(frame.Width(), frame.Height());
fDirty(true),
fUpdateMode(updateMode),
fLabelFont(be_bold_font),
fValueFont(be_bold_font),
fAlignMode(alignMode),
fAlignFlags(alignFlags),
fOrigBounds(Bounds()),
fHaveBackBuffer(backBuffer),
fBackBuffer(NULL),
fBackBufferView(NULL)
{
if (fHaveBackBuffer)
_AllocBackBuffer(frame.Width(), frame.Height());
// m_font.SetSize(13.0);
// rgb_color red = {255,0,0,255};
// SetViewColor(red);
}
ValControl::~ValControl() {
if(m_backBuffer)
delete m_backBuffer;
ValControl::~ValControl()
{
delete fBackBuffer;
}
// +++++ sync
ValControl::update_mode ValControl::updateMode() const {
return m_updateMode;
ValControl::update_mode
ValControl::updateMode() const
{
return fUpdateMode;
}
// +++++ sync
void ValControl::setUpdateMode(
update_mode mode) {
m_updateMode = mode;
void
ValControl::setUpdateMode(update_mode mode)
{
fUpdateMode = mode;
}
//const BFont* ValControl::font() const {
// return &m_font;
//}
const BFont* ValControl::labelFont() const { return &m_labelFont; }
void ValControl::setLabelFont(
const BFont* labelFont) {
const BFont*
ValControl::labelFont() const
{
return &fLabelFont;
}
m_labelFont = labelFont;
// +++++ inform label segments
_invalidateAll();
void
ValControl::setLabelFont(const BFont* labelFont)
{
fLabelFont = labelFont;
// inform label segments
_InvalidateAll();
}
const BFont* ValControl::valueFont() const { return &m_valueFont; }
void ValControl::setValueFont(
const BFont* valueFont) {
m_valueFont = valueFont;
const BFont*
ValControl::valueFont() const
{
return &fValueFont;
}
void
ValControl::setValueFont(const BFont* valueFont)
{
fValueFont = valueFont;
// inform value segments
for(int n = countEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = entryAt(n-1);
if(e.type != ValCtrlLayoutEntry::SEGMENT_ENTRY)
for (int n = CountEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = _EntryAt(n-1);
if (e.type != ValCtrlLayoutEntry::SEGMENT_ENTRY)
continue;
ValControlSegment* s = dynamic_cast<ValControlSegment*>(e.pView);
ASSERT(s);
s->SetFont(&m_valueFont);
s->fontChanged(&m_valueFont);
s->SetFont(&fValueFont);
s->fontChanged(&fValueFont);
}
}
float ValControl::baselineOffset() const {
float
ValControl::baselineOffset() const
{
font_height h;
be_plain_font->GetHeight(&h);
return ceil(h.ascent);
}
float ValControl::segmentPadding() const {
return s_segmentPadding;
float
ValControl::segmentPadding() const
{
return fSegmentPadding;
}
BView* ValControl::backBufferView() const {
return m_backBufferView;
}
BBitmap* ValControl::backBuffer() const {
return m_backBuffer;
BView*
ValControl::backBufferView() const
{
return fBackBufferView;
}
// -------------------------------------------------------- //
// debugging [23aug99]
// -------------------------------------------------------- //
void ValControl::dump() {
BBitmap*
ValControl::backBuffer() const
{
return fBackBuffer;
}
void
ValControl::dump()
{
#if defined(DEBUG)
BRect f = Frame();
PRINT((
"*** ValControl::dump():\n"
" FRAME (%.1f,%.1f)-(%.1f,%.1f)\n"
" ENTRIES:\n",
f.left, f.top, f.right, f.bottom));
for(layout_set::const_iterator it = m_layoutSet.begin();
it != m_layoutSet.end(); ++it) {
for (layout_set::const_iterator it = fLayoutSet.begin();
it != fLayoutSet.end(); ++it) {
const ValCtrlLayoutEntry& e = *it;
switch(e.type) {
switch (e.type) {
case ValCtrlLayoutEntry::SEGMENT_ENTRY:
PRINT((" Segment "));
break;
case ValCtrlLayoutEntry::VIEW_ENTRY:
PRINT((" View "));
break;
case ValCtrlLayoutEntry::DECIMAL_POINT_ENTRY:
PRINT((" Decimal Point "));
break;
default:
PRINT((" ??? "));
break;
}
PRINT((
"\n cached frame (%.1f,%.1f)-(%.1f,%.1f) + pad(%.1f)\n",
PRINT(("\n cached frame (%.1f,%.1f)-(%.1f,%.1f) + pad(%.1f)\n",
e.frame.left, e.frame.top, e.frame.right, e.frame.bottom,
e.fPadding));
if(
e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY ||
e.type == ValCtrlLayoutEntry::VIEW_ENTRY) {
if(e.pView) {
PRINT((
" real frame (%.1f,%.1f)-(%.1f,%.1f)\n\n",
if (e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY
|| e.type == ValCtrlLayoutEntry::VIEW_ENTRY) {
if (e.pView) {
PRINT((" real frame (%.1f,%.1f)-(%.1f,%.1f)\n\n",
e.pView->Frame().left, e.pView->Frame().top,
e.pView->Frame().right, e.pView->Frame().bottom));
} else {
PRINT((
" (no view!)\n\n"));
}
} else
PRINT((" (no view!)\n\n"));
}
}
PRINT(("\n"));
#endif
}
// -------------------------------------------------------- //
// BControl impl.
// -------------------------------------------------------- //
void ValControl::SetEnabled(
bool enabled) {
// PRINT((
// "### SetEnabled(%s)\n"
// " (%.1f,%.1f)-(%.1f,%.1f)\n",
// bEnabled?"true":"false",
// Frame().left, Frame().top, Frame().right, Frame().bottom));
void
ValControl::SetEnabled(bool enabled)
{
// redraw if enabled-state changes
_inherited::SetEnabled(enabled);
_Inherited::SetEnabled(enabled);
_invalidateAll();
_InvalidateAll();
}
void ValControl::_invalidateAll() {
void
ValControl::_InvalidateAll()
{
Invalidate();
int c = CountChildren();
for(int n = 0; n < c; ++n) {
for (int n = 0; n < c; ++n)
ChildAt(n)->Invalidate();
}
}
// -------------------------------------------------------- //
// BView impl
// -------------------------------------------------------- //
// handle initial layout stuff:
void ValControl::AttachedToWindow() {
void
ValControl::AttachedToWindow()
{
// adopt parent view's color
if(Parent())
if (Parent())
SetViewColor(Parent()->ViewColor());
}
void ValControl::AllAttached() {
void
ValControl::AllAttached()
{
// move children to requested positions
BWindow* pWnd = Window();
pWnd->BeginViewTransaction();
for_each(m_layoutSet.begin(), m_layoutSet.end(),
for_each(fLayoutSet.begin(), fLayoutSet.end(),
ptr_fun(&ValCtrlLayoutEntry::InitChildFrame)); // +++++?
pWnd->EndViewTransaction();
}
// paint decorations (& decimal point)
void ValControl::Draw(
BRect updateRect) {
//! Paint decorations (& decimal point)
void
ValControl::Draw(BRect updateRect)
{
// draw lightweight entries:
for(unsigned int n = 0; n < m_layoutSet.size(); n++)
if(m_layoutSet[n].type == ValCtrlLayoutEntry::DECIMAL_POINT_ENTRY)
drawDecimalPoint(m_layoutSet[n]);
for (unsigned int n = 0; n < fLayoutSet.size(); n++) {
if (fLayoutSet[n].type == ValCtrlLayoutEntry::DECIMAL_POINT_ENTRY)
drawDecimalPoint(fLayoutSet[n]);
}
}
void ValControl::drawDecimalPoint(
ValCtrlLayoutEntry& e) {
rgb_color dark = {0,0,0,255};
rgb_color med = {200,200,200,255};
void
ValControl::drawDecimalPoint(ValCtrlLayoutEntry& e)
{
rgb_color dark = {0, 0, 0, 255};
rgb_color med = {200, 200, 200, 255};
// rgb_color light = {244,244,244,255};
BPoint center;
@@ -252,8 +264,8 @@ void ValControl::drawDecimalPoint(
SetHighColor(dark);
StrokeLine(center, center);
SetHighColor(med);
StrokeLine(center-BPoint(0,1), center+BPoint(1,0));
StrokeLine(center-BPoint(1,0), center+BPoint(0,1));
StrokeLine(center - BPoint(0, 1), center + BPoint(1, 0));
StrokeLine(center - BPoint(1, 0), center + BPoint(0, 1));
// SetHighColor(light);
// StrokeLine(center+BPoint(-1,1), center+BPoint(-1,1));
@@ -262,32 +274,32 @@ void ValControl::drawDecimalPoint(
// StrokeLine(center+BPoint(1,-1), center+BPoint(1,-1));
}
void ValControl::FrameResized(
float width,
float height) {
_inherited::FrameResized(width,height);
if(m_haveBackBuffer)
_allocBackBuffer(width, height);
void
ValControl::FrameResized(float width, float height)
{
_Inherited::FrameResized(width,height);
if (fHaveBackBuffer)
_AllocBackBuffer(width, height);
//
// PRINT((
// "# ValControl::FrameResized(): %.1f, %.1f\n",
// width, height));
}
// calculate minimum size
void ValControl::GetPreferredSize(
float* outWidth,
float* outHeight) {
ASSERT(m_layoutSet.size() > 0);
void
ValControl::GetPreferredSize(float* outWidth, float* outHeight)
{
ASSERT(fLayoutSet.size() > 0);
*outWidth =
m_layoutSet.back().frame.right -
m_layoutSet.front().frame.left;
fLayoutSet.back().frame.right -
fLayoutSet.front().frame.left;
*outHeight = 0;
for(layout_set::const_iterator it = m_layoutSet.begin();
it != m_layoutSet.end(); ++it) {
for(layout_set::const_iterator it = fLayoutSet.begin();
it != fLayoutSet.end(); ++it) {
if((*it).frame.Height() > *outHeight)
*outHeight = (*it).frame.Height();
}
@@ -297,36 +309,35 @@ void ValControl::GetPreferredSize(
// *outWidth, *outHeight));
}
void ValControl::MakeFocus(
bool focused) {
_inherited::MakeFocus(focused);
void
ValControl::MakeFocus(bool focused)
{
_Inherited::MakeFocus(focused);
// +++++ only the underline needs to be redrawn
_invalidateAll();
_InvalidateAll();
}
void ValControl::MouseDown(
BPoint where) {
void
ValControl::MouseDown(BPoint where)
{
MakeFocus(true);
}
// -------------------------------------------------------- //
// BHandler impl.
// -------------------------------------------------------- //
void ValControl::MessageReceived(
BMessage* message) {
void
ValControl::MessageReceived(BMessage* message)
{
status_t err;
const char* stringValue;
// PRINT((
// "ValControl::MessageReceived():\n"));
// message->PrintToStream();
switch(message->what) {
switch (message->what) {
case M_SET_VALUE:
err = message->FindString("_value", &stringValue);
if(err < B_OK) {
@@ -337,7 +348,7 @@ void ValControl::MessageReceived(
// set from string
err = setValueFrom(stringValue);
if(err < B_OK) {
if (err < B_OK) {
PRINT((
"! ValControl::MessageReceived(): setValueFrom('%s'):\n"
" %s\n",
@@ -352,57 +363,53 @@ void ValControl::MessageReceived(
break;
default:
_inherited::MessageReceived(message);
_Inherited::MessageReceived(message);
}
}
// -------------------------------------------------------- //
// archiving/instantiation
// -------------------------------------------------------- //
ValControl::ValControl(
BMessage* archive) :
BControl(archive),
m_dirty(true) {
status_t err;
ValControl::ValControl(BMessage* archive)
: BControl(archive),
fDirty(true)
{
// fetch parameters
err = archive->FindInt32("updateMode", (int32*)&m_updateMode);
ASSERT(err == B_OK);
archive->FindInt32("updateMode", (int32*)&fUpdateMode);
archive->FindInt32("alignMode", (int32*)&fAlignMode);
archive->FindInt32("alignFlags", (int32*)&fAlignFlags);
err = archive->FindInt32("alignMode", (int32*)&m_alignMode);
ASSERT(err == B_OK);
err = archive->FindInt32("alignFlags", (int32*)&m_alignFlags);
ASSERT(err == B_OK);
// original bounds
err = archive->FindRect("origBounds", &m_origBounds);
ASSERT(err == B_OK);
archive->FindRect("origBounds", &fOrigBounds);
}
status_t ValControl::Archive(
BMessage* archive,
bool deep) const {
_inherited::Archive(archive, deep);
status_t err;
status_t
ValControl::Archive(BMessage* archive, bool deep) const
{
status_t err = _Inherited::Archive(archive, deep);
// write parameters
archive->AddInt32("updateMode", (int32)m_updateMode);
archive->AddInt32("alignMode", (int32)m_alignMode);
archive->AddInt32("alignFlags", (int32)m_alignFlags);
archive->AddRect("origBounds", m_origBounds);
if (err == B_OK)
err = archive->AddInt32("updateMode", (int32)fUpdateMode);
if (err == B_OK)
err = archive->AddInt32("alignMode", (int32)fAlignMode);
if (err == B_OK)
err = archive->AddInt32("alignFlags", (int32)fAlignFlags);
if (err == B_OK)
err = archive->AddRect("origBounds", fOrigBounds);
if (err < B_OK)
return err;
// write layout set?
if(!deep)
if (!deep)
return B_OK;
// yes; spew it:
for(layout_set::const_iterator it = m_layoutSet.begin();
it != m_layoutSet.end(); it++) {
for (layout_set::const_iterator it = fLayoutSet.begin();
it != fLayoutSet.end(); it++) {
// archive entry
BMessage layoutSet;
@@ -413,221 +420,217 @@ status_t ValControl::Archive(
// write it
archive->AddMessage("layoutSet", &layoutSet);
}
return B_OK;
}
// -------------------------------------------------------- //
// internal operations
// -------------------------------------------------------- //
// add segment view (which is responsible for generating its
// own ValCtrlLayoutEntry)
void ValControl::add(
ValControlSegment* segment,
entry_location from,
uint16 distance) {
void
ValControl::_Add(ValControlSegment* segment, entry_location from,
uint16 distance)
{
BWindow* pWnd = Window();
if(pWnd)
pWnd->BeginViewTransaction();
AddChild(segment);
segment->SetFont(&m_valueFont);
segment->fontChanged(&m_valueFont);
segment->SetFont(&fValueFont);
segment->fontChanged(&fValueFont);
uint16 nIndex = _locationToIndex(from, distance);
uint16 nIndex = _LocationToIndex(from, distance);
ValCtrlLayoutEntry entry = segment->makeLayoutEntry();
_insertEntry(entry, nIndex);
_InsertEntry(entry, nIndex);
// linkSegment(segment, nIndex);
if(pWnd)
if (pWnd)
pWnd->EndViewTransaction();
}
// add general view (manipulator, label, etc.)
// the entry's frame rectangle will be filled in
void ValControl::add(
ValCtrlLayoutEntry& entry,
entry_location from) {
void
ValControl::_Add(ValCtrlLayoutEntry& entry, entry_location from)
{
BWindow* window = Window();
if (window)
window->BeginViewTransaction();
BWindow* pWnd = Window();
if(pWnd)
pWnd->BeginViewTransaction();
if(entry.pView)
if (entry.pView)
AddChild(entry.pView);
uint16 nIndex = _locationToIndex(from, 0);
_insertEntry(entry, nIndex);
if(pWnd)
pWnd->EndViewTransaction();
uint16 index = _LocationToIndex(from, 0);
_InsertEntry(entry, index);
if (window)
window->EndViewTransaction();
}
// access child-view ValCtrlLayoutEntry
// (indexOf returns index from left)
const ValCtrlLayoutEntry& ValControl::entryAt(
entry_location from,
uint16 distance) const {
uint16 nIndex = _locationToIndex(from, distance);
ASSERT(nIndex < m_layoutSet.size());
return m_layoutSet[nIndex];
// (_IndexOf returns index from left)
const ValCtrlLayoutEntry&
ValControl::_EntryAt(entry_location from, uint16 distance) const
{
uint16 nIndex = _LocationToIndex(from, distance);
ASSERT(nIndex < fLayoutSet.size());
return fLayoutSet[nIndex];
}
const ValCtrlLayoutEntry& ValControl::entryAt(
uint16 offset) const {
uint16 nIndex = _locationToIndex(FROM_LEFT, offset);
ASSERT(nIndex < m_layoutSet.size());
return m_layoutSet[nIndex];
}
uint16 ValControl::indexOf(
BView* child) const {
for(uint16 n = 0; n < m_layoutSet.size(); n++)
if(m_layoutSet[n].pView == child)
const ValCtrlLayoutEntry&
ValControl::_EntryAt(uint16 offset) const
{
uint16 nIndex = _LocationToIndex(FROM_LEFT, offset);
ASSERT(nIndex < fLayoutSet.size());
return fLayoutSet[nIndex];
}
uint16
ValControl::_IndexOf(BView* child) const
{
for (uint16 n = 0; n < fLayoutSet.size(); n++) {
if (fLayoutSet[n].pView == child)
return n;
}
ASSERT(!"shouldn't be here");
return 0;
}
uint16 ValControl::countEntries() const {
return m_layoutSet.size();
uint16
ValControl::CountEntries() const
{
return fLayoutSet.size();
}
// pop up keyboard input field +++++
void ValControl::showEditField() {
void
ValControl::showEditField()
{
BString valueString;
#if defined(DEBUG)
status_t err = getString(valueString);
ASSERT(err == B_OK);
#endif // DEBUG
BRect f = Bounds().OffsetByCopy(4.0, -4.0);
ConvertToScreen(&f);
// PRINT((
// "# ValControl::showEditField(): base bounds (%.1f, %.1f)-(%.1f,%.1f)\n",
// f.left, f.top, f.right, f.bottom));
new TextControlFloater(
f,
B_ALIGN_RIGHT,
&m_valueFont,
valueString.String(),
BMessenger(this),
new BMessage(M_SET_VALUE)); // TextControlFloater embeds new value
// in message: _value (string) +++++ DO NOT HARDCODE
//PRINT((
//"# ValControl::showEditField(): base bounds (%.1f, %.1f)-(%.1f,%.1f)\n",
//f.left, f.top, f.right, f.bottom));
new TextControlFloater(f, B_ALIGN_RIGHT, &fValueFont, valueString.String(),
BMessenger(this), new BMessage(M_SET_VALUE));
// TextControlFloater embeds new value
// in message: _value (string) +++++ DO NOT HARDCODE
}
// -------------------------------------------------------- //
// internal operation guts
// -------------------------------------------------------- //
// (re-)initialize backbuffer
void ValControl::_allocBackBuffer(
float width,
float height) {
ASSERT(m_haveBackBuffer);
if(m_backBuffer && m_backBuffer->Bounds().Width() >= width &&
m_backBuffer->Bounds().Height() >= height)
//! (Re-)initialize backbuffer
void
ValControl::_AllocBackBuffer(float width, float height)
{
ASSERT(fHaveBackBuffer);
if (fBackBuffer && fBackBuffer->Bounds().Width() >= width
&& fBackBuffer->Bounds().Height() >= height)
return;
if(m_backBuffer) {
delete m_backBuffer;
m_backBuffer = 0;
m_backBufferView = 0;
if (fBackBuffer) {
delete fBackBuffer;
fBackBuffer = NULL;
fBackBufferView = NULL;
}
BRect bounds(0,0,width,height);
m_backBuffer = new BBitmap(bounds, B_RGB32, true);
ASSERT(m_backBuffer);
m_backBufferView = new BView(bounds, "back", B_FOLLOW_NONE, B_WILL_DRAW);
ASSERT(m_backBufferView);
m_backBuffer->AddChild(m_backBufferView);
BRect bounds(0, 0, width, height);
fBackBuffer = new BBitmap(bounds, B_RGB32, true);
fBackBufferView = new BView(bounds, "back", B_FOLLOW_NONE, B_WILL_DRAW);
fBackBuffer->AddChild(fBackBufferView);
}
// ref'd view must already be a child +++++
// (due to GetPreferredSize implementation in segment views)
void ValControl::_insertEntry(
ValCtrlLayoutEntry& entry,
uint16 index) {
void
ValControl::_InsertEntry(ValCtrlLayoutEntry& entry, uint16 index)
{
// view ptr must be 0, or a ValControlSegment that's already a child
ValControlSegment* pSeg = dynamic_cast<ValControlSegment*>(entry.pView);
if(entry.pView)
if (entry.pView)
ASSERT(pSeg);
if(pSeg)
if (pSeg)
ASSERT(this == pSeg->Parent());
// entry must be at one side or the other:
ASSERT(!index || index == m_layoutSet.size());
// figure padding
ASSERT(!index || index == fLayoutSet.size());
// figure padding
bool bNeedsPadding =
!(entry.flags & ValCtrlLayoutEntry::LAYOUT_NO_PADDING ||
((index-1 >= 0 &&
m_layoutSet[index-1].flags & ValCtrlLayoutEntry::LAYOUT_NO_PADDING)) ||
((index+1 < m_layoutSet.size() &&
m_layoutSet[index+1].flags & ValCtrlLayoutEntry::LAYOUT_NO_PADDING)));
((index - 1 >= 0 &&
fLayoutSet[index - 1].flags & ValCtrlLayoutEntry::LAYOUT_NO_PADDING)) ||
((index + 1 < static_cast<uint16>(fLayoutSet.size()) &&
fLayoutSet[index + 1].flags & ValCtrlLayoutEntry::LAYOUT_NO_PADDING)));
entry.fPadding = (bNeedsPadding) ? s_segmentPadding : 0.0;
entry.fPadding = (bNeedsPadding) ? fSegmentPadding : 0.0;
// fetch (and grant) requested frame size
BRect frame(0,0,0,0);
if(pSeg)
BRect frame(0, 0, 0, 0);
if (pSeg)
pSeg->GetPreferredSize(&frame.right, &frame.bottom);
else
_getDefaultEntrySize(entry.type, &frame.right, &frame.bottom);
_GetDefaultEntrySize(entry.type, &frame.right, &frame.bottom);
// figure amount this entry will displace:
float fDisplacement = frame.Width() + entry.fPadding + 1;
// set entry's top-left position:
if(!m_layoutSet.size()) {
if (!fLayoutSet.size()) {
// sole entry:
if(m_alignMode == ALIGN_FLUSH_RIGHT)
if (fAlignMode == ALIGN_FLUSH_RIGHT)
frame.OffsetBy(Bounds().right - frame.Width(), 0.0);
}
else if(index) {
} else if (index) {
// insert at right side
if(m_alignMode == ALIGN_FLUSH_LEFT)
frame.OffsetBy(m_layoutSet.back().frame.right + 1 + entry.fPadding, 0.0);
if (fAlignMode == ALIGN_FLUSH_LEFT)
frame.OffsetBy(fLayoutSet.back().frame.right + 1 + entry.fPadding, 0.0);
else
frame.OffsetBy(m_layoutSet.back().frame.right - frame.Width(), 0.0); //+++++
}
else {
frame.OffsetBy(fLayoutSet.back().frame.right - frame.Width(), 0.0); //+++++
} else {
// insert at left side
if(m_alignMode == ALIGN_FLUSH_RIGHT)
frame.OffsetBy(m_layoutSet.front().frame.left - fDisplacement, 0.0);
if (fAlignMode == ALIGN_FLUSH_RIGHT)
frame.OffsetBy(fLayoutSet.front().frame.left - fDisplacement, 0.0);
}
// add to layout set
entry.frame = frame;
m_layoutSet.insert(
index ? m_layoutSet.end() : m_layoutSet.begin(),
fLayoutSet.insert(
index ? fLayoutSet.end() : fLayoutSet.begin(),
entry);
// slide following or preceding entries (depending on align mode)
// to make room:
switch(m_alignMode) {
switch (fAlignMode) {
case ALIGN_FLUSH_LEFT:
// following entries are shifted to the right
for(int n = index+1; n < m_layoutSet.size(); n++)
_slideEntry(n, fDisplacement);
for(uint32 n = index+1; n < fLayoutSet.size(); n++)
_SlideEntry(n, fDisplacement);
break;
case ALIGN_FLUSH_RIGHT: {
// preceding entries are shifted to the left
for(int n = index-1; n >= 0; n--)
_slideEntry(n, -fDisplacement);
_SlideEntry(n, -fDisplacement);
break;
}
@@ -638,54 +641,52 @@ void ValControl::_insertEntry(
// frame.left, frame.top, frame.right, frame.bottom));
}
void ValControl::_slideEntry(
int index,
float delta) {
ValCtrlLayoutEntry& e = m_layoutSet[index];
void
ValControl::_SlideEntry(int index, float delta)
{
ValCtrlLayoutEntry& e = fLayoutSet[index];
e.frame.OffsetBy(delta, 0.0);
// move & possibly resize view:
if(e.pView) {
if (e.pView) {
e.pView->MoveTo(e.frame.LeftTop());
BRect curFrame = e.pView->Frame();
float fWidth = e.frame.Width();
float fHeight = e.frame.Height();
if(curFrame.Width() != fWidth ||
curFrame.Height() != fHeight)
if (curFrame.Width() != fWidth
|| curFrame.Height() != fHeight)
e.pView->ResizeTo(fWidth + 5.0, fHeight);
}
}
uint16 ValControl::_locationToIndex(
entry_location from,
uint16 distance) const {
uint16
ValControl::_LocationToIndex(entry_location from, uint16 distance) const
{
uint16 nResult = 0;
switch(from) {
switch (from) {
case FROM_LEFT:
nResult = distance;
break;
case FROM_RIGHT:
nResult = m_layoutSet.size() - distance;
nResult = fLayoutSet.size() - distance;
break;
}
ASSERT(nResult <= m_layoutSet.size());
ASSERT(nResult <= fLayoutSet.size());
return nResult;
}
void ValControl::_getDefaultEntrySize(
ValCtrlLayoutEntry::entry_type type,
float* outWidth,
float* outHeight) {
switch(type) {
void
ValControl::_GetDefaultEntrySize(ValCtrlLayoutEntry::entry_type type,
float* outWidth, float* outHeight)
{
switch (type) {
case ValCtrlLayoutEntry::SEGMENT_ENTRY:
case ValCtrlLayoutEntry::VIEW_ENTRY:
*outWidth = 1.0;
@@ -693,10 +694,8 @@ void ValControl::_getDefaultEntrySize(
break;
case ValCtrlLayoutEntry::DECIMAL_POINT_ENTRY:
*outWidth = s_decimalPointWidth;
*outHeight = s_decimalPointHeight;
*outWidth = fDecimalPointWidth;
*outHeight = fDecimalPointHeight;
break;
}
}
// END -- ValControl.cpp --
+218 -269
View File
@@ -32,7 +32,7 @@
// The control view consists of:
//
// - One or more segments. Each segment is individually
// draggable. Subclasses may mix segment types, or add
// draggable. Subclasses may mix segment types, or Add
// and remove segments dynamically.
//
// - A manipulator region, to which subcontrols (such as 'spin
@@ -58,330 +58,279 @@
// e.moon 19sep99 Cleanup
// e.moon 23aug99 begun Cortex integration
// e.moon 17jan99 started
#ifndef VAL_CONTROL_H
#define VAL_CONTROL_H
#ifndef __ValControl_H__
#define __ValControl_H__
#include <vector>
#include <Bitmap.h>
#include <View.h>
#include <Font.h>
#include <Control.h>
#include <Message.h>
#include "cortex_defs.h"
#include "ValCtrlLayoutEntry.h"
#include "cortex_defs.h"
#include <Bitmap.h>
#include <Control.h>
#include <Font.h>
#include <Message.h>
#include <View.h>
#include <vector>
__BEGIN_CORTEX_NAMESPACE
class ValControlSegment;
// ---------------------------------------------------------------- //
/* abstract */
class ValControl : public BControl {
typedef BControl _inherited;
public:
typedef BControl _Inherited;
public: // types & constants
// child-view alignment options:
enum align_mode {
ALIGN_FLUSH_LEFT,
ALIGN_FLUSH_RIGHT
};
public: // types & constants
// child-view alignment options:
enum align_mode {
ALIGN_FLUSH_LEFT,
ALIGN_FLUSH_RIGHT
};
// alignment flags +++++ 23aug99: not implemented -- should they be?
enum align_flags {
ALIGN_NONE = 0,
ALIGN_GROW = 1
};
// alignment flags +++++ 23aug99: not implemented -- should they be?
enum align_flags {
ALIGN_NONE = 0,
ALIGN_GROW = 1
};
// should value update messages be sent asynchronously (during
// a mouse operation) or synchronously (after the mouse is
// released)?
enum update_mode {
UPDATE_ASYNC,
UPDATE_SYNC
};
// should value update messages be sent asynchronously (during
// a mouse operation) or synchronously (after the mouse is
// released)?
enum update_mode {
UPDATE_ASYNC,
UPDATE_SYNC
};
enum entry_location {
LEFT_MOST = 0,
FROM_LEFT = 0,
RIGHT_MOST = 1,
FROM_RIGHT = 1
};
enum entry_location {
LEFT_MOST = 0,
FROM_LEFT = 0,
RIGHT_MOST = 1,
FROM_RIGHT = 1
};
// layout system state +++++
// layout system state +++++
public: // types
public: // types
public: // messages (all ValControl-related messages go here!)
enum message_t {
public: // messages (all ValControl-related messages go here!)
enum message_t {
// Set value of a control or segment:
// [your value field(s)] or "_value" (string)
M_SET_VALUE = ValControl_message_base,
// Set value of a control or segment:
// [your value field(s)] or "_value" (string)
M_SET_VALUE = ValControl_message_base,
// Request for value of control/segment:
// [your value field(s)]
M_GET_VALUE,
// Request for value of control/segment:
// [your value field(s)]
M_GET_VALUE,
// ... reply to M_GET_VALUE with this:
// [your value field(s)]
M_VALUE
};
// ... reply to M_GET_VALUE with this:
// [your value field(s)]
M_VALUE
};
public: // hooks
public: // hooks
// * parameter-mode value access
// * parameter-mode value access
// called to set the control's value from raw BParameter data
virtual void setValue(const void* data, size_t size) = 0;
// called to set the control's value from raw BParameter data
virtual void setValue(
const void* data,
size_t size)=0;
// called to request the control's value in raw form
virtual void getValue(void* data, size_t* ioSize) = 0;
// called to request the control's value in raw form
virtual void getValue(
void* data,
size_t* ioSize)=0;
// * string value access
// * string value access
virtual status_t setValueFrom(const char* text) = 0;
virtual status_t setValueFrom(
const char* text)=0;
virtual status_t getString(BString& buffer) = 0;
virtual status_t getString(
BString& buffer)=0;
// called when a child view's preferred size has changed;
// it's up to the ValControl to grant the resize request.
// Return true to notify the child that the request has
// been granted, or false if denied (the default.)
// called when a child view's preferred size has changed;
// it's up to the ValControl to grant the resize request.
// Return true to notify the child that the request has
// been granted, or false if denied (the default.)
virtual bool childResizeRequest(
BView* child) { return false; }
public: // ctor/dtor/accessors
virtual ~ValControl();
// value-access methods are left up to the subclasses,
// since they'll take varying types of arguments.
// (M_SET_VALUE and M_GET_VALUE should always behave
// as you'd expect, with a 'value' field of the appropriate
// type replacing or returning the current value.) +++++ decrepit
//
// Note that all implementations offering pop-up keyboard entry
// must accept an M_SET_VALUE with a value of B_STRING_TYPE.
// get/set update mode (determines whether value updates are
// sent to the target during mouse operations, or only on
// mouse-up)
update_mode updateMode() const;
void setUpdateMode(
update_mode mode);
// +++++ get/set font used by segments
// (would separate 'value' and 'label' fonts be a good move?)
// const BFont* font() const;
virtual bool childResizeRequest(BView* child) { return false; }
const BFont* labelFont() const; //nyi
void setLabelFont(
const BFont* labelFont); //nyi
public: // ctor/dtor/accessors
virtual ~ValControl();
// value-access methods are left up to the subclasses,
// since they'll take varying types of arguments.
// (M_SET_VALUE and M_GET_VALUE should always behave
// as you'd expect, with a 'value' field of the appropriate
// type replacing or returning the current value.) +++++ decrepit
//
// Note that all implementations offering pop-up keyboard entry
// must accept an M_SET_VALUE with a value of B_STRING_TYPE.
const BFont* valueFont() const; //nyi
void setValueFont(
const BFont* valueFont); //nyi
// get/set update mode (determines whether value updates are
// sent to the target during mouse operations, or only on
// mouse-up)
update_mode updateMode() const;
void setUpdateMode(update_mode mode);
// get baseline y offset: this is measured relative to the top of the
// view
float baselineOffset() const;
// segment padding: this amount of padding is added to the
// right of each segment bounds-rectangle
float segmentPadding() const;
// fast drag rate: returns ratio of pixels:units for fast
// (left-button) dragging
float fastDragRate() const; //nyi
// slow drag rate: returns ratio for precise (both/middle-button)
// dragging
float slowDragRate() const; //nyi
// fetch back-buffer
BView* backBufferView() const; //nyi
BBitmap* backBuffer() const; //nyi
// pop up keyboard input field
// +++++ should this turn into a message?
virtual void showEditField();
public: // debugging [23aug99]
virtual void dump();
// +++++ get/set font used by segments
// (would separate 'value' and 'label' fonts be a good move?)
// const BFont* font() const;
public: // BControl impl.
// SetValue(), Value() aren't defined, since they only support
// 32-bit integer values. TextControl provides a precedent for
// this kind of naughtiness.
// empty implementation (hands off to BControl)
virtual void SetEnabled(
bool enabled);
const BFont* labelFont() const; //nyi
void setLabelFont(const BFont* labelFont); //nyi
public: // BView impl.
const BFont* valueFont() const; //nyi
void setValueFont(const BFont* valueFont); //nyi
// handle initial layout stuff:
virtual void AttachedToWindow();
virtual void AllAttached();
// paint decorations (& decimal point)
virtual void Draw(
BRect updateRect);
// get baseline y offset: this is measured relative to the top of the
// view
float baselineOffset() const;
virtual void drawDecimalPoint(
ValCtrlLayoutEntry& entry);
// handle frame resize (grow backbuffer if need be)
virtual void FrameResized(
float width,
float height);
// calculate minimum size
virtual void GetPreferredSize(
float* outWidth,
float* outHeight);
// segment padding: this amount of padding is added to the
// right of each segment bounds-rectangle
float segmentPadding() const;
// fast drag rate: returns ratio of pixels:units for fast
// (left-button) dragging
float fastDragRate() const; //nyi
// slow drag rate: returns ratio for precise (both/middle-button)
// dragging
float slowDragRate() const; //nyi
// fetch back-buffer
BView* backBufferView() const; //nyi
BBitmap* backBuffer() const; //nyi
// pop up keyboard input field
// +++++ should this turn into a message?
virtual void showEditField();
public: // debugging [23aug99]
virtual void dump();
public: // BControl impl.
// SetValue(), Value() aren't defined, since they only support
// 32-bit integer values. TextControl provides a precedent for
// this kind of naughtiness.
// empty implementation (hands off to BControl)
virtual void SetEnabled(bool enabled);
public: // BView impl.
// handle initial layout stuff:
virtual void AttachedToWindow();
virtual void AllAttached();
// paint decorations (& decimal point)
virtual void Draw(BRect updateRect);
virtual void drawDecimalPoint(ValCtrlLayoutEntry& entry);
// handle frame resize (grow backbuffer if need be)
virtual void FrameResized(float width, float height);
// calculate minimum size
virtual void GetPreferredSize(float* outWidth, float* outHeight);
virtual void MakeFocus(
bool focused=true);
virtual void MakeFocus(bool focused = true);
virtual void MouseDown(
BPoint where);
virtual void MouseDown(BPoint where);
public: // BHandler impl.
virtual void MessageReceived(
BMessage* message);
public:
virtual void MessageReceived(BMessage* message);
public: // archiving/instantiation
ValControl(
BMessage* archive);
public: // archiving/instantiation
ValControl(BMessage* archive);
status_t Archive(
BMessage* archive,
bool deep=true) const;
status_t Archive(BMessage* archive, bool deep = true) const;
protected: // internal ctor/operations
ValControl(
BRect frame,
const char* name,
const char* label,
BMessage* message,
align_mode alignMode,
align_flags alignFlags,
update_mode updateMode=UPDATE_ASYNC,
bool backBuffer=true);
protected: // internal ctor/operations
ValControl(BRect frame, const char* name, const char* label,
BMessage* message, align_mode alignMode, align_flags alignFlags,
update_mode updateMode = UPDATE_ASYNC, bool backBuffer = true);
// add segment view (which is responsible for generating its
// own ValCtrlLayoutEntry)
void add(
ValControlSegment* segment,
entry_location from,
uint16 distance=0);
// Add segment view (which is responsible for generating its
// own ValCtrlLayoutEntry)
void _Add(ValControlSegment* segment, entry_location from,
uint16 distance = 0);
// add general view (manipulator, label, etc.)
// (the entry's frame rectangle will be filled in)
// covers ValCtrlLayoutEntry ctor:
void add(
ValCtrlLayoutEntry& entry,
entry_location from);
// Add general view (manipulator, label, etc.)
// (the entry's frame rectangle will be filled in)
// covers ValCtrlLayoutEntry ctor:
void _Add(ValCtrlLayoutEntry& entry, entry_location from);
// access child-view ValCtrlLayoutEntry
// (_IndexOf returns index from left)
const ValCtrlLayoutEntry& _EntryAt(uint16 offset) const;
const ValCtrlLayoutEntry& _EntryAt(entry_location from,
uint16 distance = 0) const;
uint16 _IndexOf(BView* child) const;
uint16 CountEntries() const;
private: // steaming entrails
// (re-)initialize the backbuffer
void _AllocBackBuffer(float width, float height);
// insert a layout entry in ordered position (doesn't call
// AddChild())
void _InsertEntry(ValCtrlLayoutEntry& entry, uint16 index);
// move given entry horizontally (update child view's position
// and size as well, if any)
void _SlideEntry(int index, float delta);
// access child-view ValCtrlLayoutEntry
// (indexOf returns index from left)
const ValCtrlLayoutEntry& entryAt(
uint16 offset) const;
// turn entry_location/offset into an index:
uint16 _LocationToIndex(entry_location from, uint16 distance = 0) const;
const ValCtrlLayoutEntry& entryAt(
entry_location from,
uint16 distance=0) const;
void _GetDefaultEntrySize(ValCtrlLayoutEntry::entry_type type,
float* outWidth, float* outHeight);
uint16 indexOf(
BView* child) const;
uint16 countEntries() const;
private: // steaming entrails
// (re-)initialize the backbuffer
void _allocBackBuffer(
float width,
float height);
// insert a layout entry in ordered position (doesn't call
// AddChild())
void _insertEntry(
ValCtrlLayoutEntry& entry,
uint16 index);
// move given entry horizontally (update child view's position
// and size as well, if any)
void _slideEntry(
int index,
float delta);
void _InvalidateAll();
// turn entry_location/offset into an index:
uint16 _locationToIndex(
entry_location from,
uint16 distance=0) const;
private:
// the set of visible segments and other child views,
// in left-to-right. top-to-bottom order
typedef std::vector<ValCtrlLayoutEntry> layout_set;
layout_set fLayoutSet;
void _getDefaultEntrySize(
ValCtrlLayoutEntry::entry_type type,
float* outWidth,
float* outHeight);
void _invalidateAll();
protected: // impl. members
// true if value has been changed since last request
// (allows caching of value)
bool fDirty;
// the set of visible segments and other child views,
// in left-to-right. top-to-bottom order
typedef std::vector<ValCtrlLayoutEntry> layout_set;
layout_set m_layoutSet;
// when should messages be sent to the target?
update_mode fUpdateMode;
// true if value has been changed since last request
// (allows caching of value)
bool m_dirty;
BFont fLabelFont;
BFont fValueFont;
// when should messages be sent to the target?
update_mode m_updateMode;
align_mode fAlignMode;
align_flags fAlignFlags;
// layout stuff
// BFont m_font;
// the bounds rectangle requested upon construction.
// if the ALIGN_GROW flag is set, the real bounds
// rectangle may be wider
BRect fOrigBounds;
BFont m_labelFont;
BFont m_valueFont;
// backbuffer (made available to segments for flicker-free
// drawing)
bool fHaveBackBuffer;
BBitmap* fBackBuffer;
BView* fBackBufferView;
align_mode m_alignMode;
align_flags m_alignFlags;
// the bounds rectangle requested upon construction.
// if the ALIGN_GROW flag is set, the real bounds
// rectangle may be wider
BRect m_origBounds;
// backbuffer (made available to segments for flicker-free
// drawing)
bool m_haveBackBuffer;
BBitmap* m_backBuffer;
BView* m_backBufferView;
static const float s_segmentPadding;
static const float s_decimalPointWidth;
static const float s_decimalPointHeight;
private: // guts
class fnInitChild;
static const float fSegmentPadding;
static const float fDecimalPointWidth;
static const float fDecimalPointHeight;
private:
class fnInitChild;
};
__END_CORTEX_NAMESPACE
#endif /* __ValControl_H__ */
#endif // VAL_CONTROL_H
+121 -122
View File
@@ -11,47 +11,43 @@
__USE_CORTEX_NAMESPACE
// -------------------------------------------------------- //
// static stuff
// -------------------------------------------------------- //
const double ValControlSegment::s_defDragScaleFactor = 4;
// -------------------------------------------------------- //
// dtor/accessors
// -------------------------------------------------------- //
ValControlSegment::~ValControlSegment() {}
// -------------------------------------------------------- //
// ctor/internal operations
// -------------------------------------------------------- //
ValControlSegment::ValControlSegment(
underline_style underlineStyle) :
BView(
BRect(),
"ValControlSegment",
B_FOLLOW_LEFT|B_FOLLOW_TOP,
ValControlSegment::ValControlSegment(underline_style underlineStyle)
:BView(BRect(), "ValControlSegment", B_FOLLOW_LEFT|B_FOLLOW_TOP,
B_WILL_DRAW|B_FRAME_EVENTS),
m_underlineStyle(underlineStyle),
m_dragScaleFactor(s_defDragScaleFactor),
m_lastClickTime(0LL),
m_xUnderlineLeft(0.0),
m_xUnderlineRight(0.0) {
init();
fDragScaleFactor(fDefDragScaleFactor),
fLastClickTime(0LL),
fUnderlineStyle(underlineStyle),
fXUnderlineLeft(0.0),
fXUnderlineRight(0.0)
{
_Init();
}
void ValControlSegment::init() {
// m_pLeft = 0;
ValControlSegment::~ValControlSegment()
{
}
void
ValControlSegment::_Init()
{
//m_pLeft = 0;
}
const double ValControlSegment::fDefDragScaleFactor = 4;
// get parent
ValControl* ValControlSegment::parent() const {
ValControl*
ValControlSegment::parent() const
{
return dynamic_cast<ValControl*>(Parent());
}
//
//// send message -> segment to my left
//void ValControlSegment::sendMessageLeft(BMessage* pMsg) {
@@ -63,51 +59,56 @@ ValControl* ValControlSegment::parent() const {
// m.SendMessage(pMsg);
// delete pMsg;
//}
// init mouse tracking
void ValControlSegment::trackMouse(
BPoint point,
track_flags flags) {
m_trackFlags = flags;
m_prevPoint = point;
void
ValControlSegment::trackMouse(BPoint point, track_flags flags)
{
fTrackFlags = flags;
fPrevPoint = point;
setTracking(true);
SetMouseEventMask(
B_POINTER_EVENTS,
SetMouseEventMask(B_POINTER_EVENTS,
B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY);
}
void ValControlSegment::setTracking(
bool tracking) {
m_tracking = tracking;
void
ValControlSegment::setTracking(bool tracking)
{
fTracking = tracking;
}
bool ValControlSegment::isTracking() const {
return m_tracking;
bool
ValControlSegment::isTracking() const
{
return fTracking;
}
double ValControlSegment::dragScaleFactor() const {
return m_dragScaleFactor;
double
ValControlSegment::dragScaleFactor() const
{
return fDragScaleFactor;
}
// -------------------------------------------------------- //
// default hook implementations
// -------------------------------------------------------- //
void ValControlSegment::sizeUnderline(
float* outLeft,
float* outRight) {
void
ValControlSegment::sizeUnderline(float* outLeft, float* outRight)
{
*outLeft = 0.0;
*outRight = Bounds().right;
}
// -------------------------------------------------------- //
// BView impl.
// -------------------------------------------------------- //
void ValControlSegment::AttachedToWindow() {
void
ValControlSegment::AttachedToWindow()
{
// if(parent()->backBuffer())
// SetViewColor(B_TRANSPARENT_COLOR);
@@ -115,10 +116,11 @@ void ValControlSegment::AttachedToWindow() {
SetViewColor(parent()->ViewColor());
}
void ValControlSegment::Draw(
BRect updateRect) {
if(m_underlineStyle == NO_UNDERLINE)
void
ValControlSegment::Draw(BRect updateRect)
{
if (fUnderlineStyle == NO_UNDERLINE)
return;
// +++++ move to layout function
@@ -135,57 +137,57 @@ void ValControlSegment::Draw(
else
SetHighColor(gray);
if(m_xUnderlineRight <= m_xUnderlineLeft)
sizeUnderline(&m_xUnderlineLeft, &m_xUnderlineRight);
if (fXUnderlineRight <= fXUnderlineLeft)
sizeUnderline(&fXUnderlineLeft, &fXUnderlineRight);
// PRINT((
// "### ValControlSegment::Draw(): underline spans %.1f, %.1f\n",
// m_xUnderlineLeft, m_xUnderlineRight));
// fXUnderlineLeft, fXUnderlineRight));
//
StrokeLine(
BPoint(m_xUnderlineLeft, fY),
BPoint(m_xUnderlineRight, fY),
(m_underlineStyle == DOTTED_UNDERLINE) ? B_MIXED_COLORS :
StrokeLine(BPoint(fXUnderlineLeft, fY),
BPoint(fXUnderlineRight, fY),
(fUnderlineStyle == DOTTED_UNDERLINE) ? B_MIXED_COLORS :
B_SOLID_HIGH);
SetHighColor(old);
}
void ValControlSegment::FrameResized(
float width,
float height) {
_inherited::FrameResized(width, height);
void
ValControlSegment::FrameResized(float width, float height)
{
_Inherited::FrameResized(width, height);
// PRINT((
// "### ValControlSegment::FrameResized(%.1f,%.1f)\n",
// fWidth, fHeight));
sizeUnderline(&m_xUnderlineLeft, &m_xUnderlineRight);
sizeUnderline(&fXUnderlineLeft, &fXUnderlineRight);
}
void ValControlSegment::MouseDown(
BPoint point) {
if(!parent()->IsEnabled())
void
ValControlSegment::MouseDown(BPoint point)
{
if (!parent()->IsEnabled())
return;
parent()->MakeFocus();
// not left button?
uint32 nButton;
GetMouse(&point, &nButton);
if(!(nButton & B_PRIMARY_MOUSE_BUTTON))
if (!(nButton & B_PRIMARY_MOUSE_BUTTON))
return;
// double click?
bigtime_t doubleClickInterval;
if(get_click_speed(&doubleClickInterval) < B_OK) {
PRINT((
"* ValControlSegment::MouseDown():\n"
if (get_click_speed(&doubleClickInterval) < B_OK) {
PRINT(("* ValControlSegment::MouseDown():\n"
" get_click_speed() failed."));
return;
}
bigtime_t now = system_time();
if(now - m_lastClickTime < doubleClickInterval) {
if (now - fLastClickTime < doubleClickInterval) {
if(isTracking()) {
setTracking(false);
mouseReleased();
@@ -193,86 +195,83 @@ void ValControlSegment::MouseDown(
// hand off to parent control
parent()->showEditField();
m_lastClickTime = 0LL;
fLastClickTime = 0LL;
return;
}
else
m_lastClickTime = now;
fLastClickTime = now;
// engage tracking
trackMouse(point, TRACK_VERTICAL);
}
void ValControlSegment::MouseMoved(
BPoint point,
uint32 transit,
const BMessage* dragMessage) {
if(!parent()->IsEnabled())
void
ValControlSegment::MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage)
{
if (!parent()->IsEnabled())
return;
if(!isTracking() || m_prevPoint == point)
if (!isTracking() || fPrevPoint == point)
return;
// float fXDelta = m_trackFlags & TRACK_HORIZONTAL ?
// point.x - m_prevPoint.x : 0.0;
float fYDelta = m_trackFlags & TRACK_VERTICAL ?
point.y - m_prevPoint.y : 0.0;
// float fXDelta = fTrackFlags & TRACK_HORIZONTAL ?
// point.x - fPrevPoint.x : 0.0;
float fYDelta = fTrackFlags & TRACK_VERTICAL ?
point.y - fPrevPoint.y : 0.0;
// printf("MouseMoved(): %2f,%2f\n",
// fXDelta, fYDelta);
// printf("MouseMoved(): %2f,%2f\n",
// fXDelta, fYDelta);
// hand off
// +++++ config'able x/y response would be nice...
float fRemaining = handleDragUpdate(fYDelta);
m_prevPoint = point;
m_prevPoint.y -= fRemaining;
fPrevPoint = point;
fPrevPoint.y -= fRemaining;
}
void ValControlSegment::MouseUp(
BPoint point) {
if(isTracking()) {
void
ValControlSegment::MouseUp(BPoint point)
{
if (isTracking()) {
setTracking(false);
mouseReleased();
}
}
// -------------------------------------------------------- //
// BHandler impl.
// -------------------------------------------------------- //
void ValControlSegment::MessageReceived(
BMessage* message) {
void
ValControlSegment::MessageReceived(BMessage* message)
{
switch(message->what) {
default:
_inherited::MessageReceived(message);
_Inherited::MessageReceived(message);
}
}
// -------------------------------------------------------- //
// archiving/instantiation
// -------------------------------------------------------- //
ValControlSegment::ValControlSegment(
BMessage* archive) :
BView(archive) {
init();
archive->FindInt32("ulStyle", (int32*)&m_underlineStyle);
ValControlSegment::ValControlSegment(BMessage* archive)
: BView(archive)
{
_Init();
archive->FindInt32("ulStyle", (int32*)&fUnderlineStyle);
}
status_t
ValControlSegment::Archive(BMessage* archive, bool deep) const
{
_Inherited::Archive(archive, deep);
status_t ValControlSegment::Archive(
BMessage* archive,
bool deep) const {
_inherited::Archive(archive, deep);
archive->AddInt32("ulStyle", m_underlineStyle);
archive->AddInt32("ulStyle", fUnderlineStyle);
return B_OK;
}
// END -- ValControlSegment.cpp --
+94 -112
View File
@@ -15,9 +15,9 @@
// CLASS: ValControlStringSegment
// Extends ValControlSegment to provide a string-selection
// segment. [+++++ driven by BMenu?]
#ifndef VAL_CONTROL_SEGMENT_H
#define VAL_CONTROL_SEGMENT_H
#ifndef __ValControlSegment_H__
#define __ValControlSegment_H__
#include <View.h>
@@ -41,130 +41,112 @@ class ValCtrlLayoutEntry;
// M_DECREMENT messages.
class ValControlSegment : public BView {
typedef BView _inherited;
public:
typedef BView _Inherited;
friend class ValControl;
friend class ValControl;
public: // constants
enum underline_style {
NO_UNDERLINE,
DOTTED_UNDERLINE,
SOLID_UNDERLINE
};
// mouse-tracking
enum track_flags {
TRACK_HORIZONTAL =1,
TRACK_VERTICAL =2
};
public:
protected: // pure virtuals
// fetch layout entry (called by ValControl)
virtual ValCtrlLayoutEntry makeLayoutEntry()=0;
public: // hooks
enum underline_style {
NO_UNDERLINE,
DOTTED_UNDERLINE,
SOLID_UNDERLINE
};
// * mouse-tracking callbacks
// do any font-related layout work
virtual void fontChanged(
const BFont* font) {}
// mouse-tracking
enum track_flags {
TRACK_HORIZONTAL = 1,
TRACK_VERTICAL = 2
};
// return 'unused pixels' (if value updates are triggered
// at less than one per pixel)
virtual float handleDragUpdate(
float distance) { return 0; }
protected: // pure virtuals
// fetch layout entry (called by ValControl)
virtual ValCtrlLayoutEntry makeLayoutEntry() = 0;
virtual void mouseReleased() {}
// underline size (tweak if you must)
// +++++ 18sep99: 'ewww.'
virtual void sizeUnderline(
float* outLeft,
float* outRight);
public: // ctor/dtor/accessors
virtual ~ValControlSegment();
protected: // ctor/internal operations
ValControlSegment(
underline_style underlineStyle);
public: // hooks
// get parent
ValControl* parent() const;
// * mouse-tracking callbacks
// init mouse tracking: must be called from MouseDown()
void trackMouse(
BPoint point,
track_flags flags);
void setTracking(
bool tracking);
bool isTracking() const;
// fetch pixel:unit ratio for dragging
double dragScaleFactor() const;
public: // BView impl.
// calls sizeUnderline()
virtual void AttachedToWindow();
// do any font-related layout work
virtual void fontChanged(const BFont* font) {}
virtual void Draw(
BRect updateRect);
// calls sizeUnderline() after bounds changed
virtual void FrameResized(
float width,
float height);
// return 'unused pixels' (if value updates are triggered
// at less than one per pixel)
virtual float handleDragUpdate(float distance) { return 0; }
// calls trackMouse(TRACK_VERTICAL) if left button down
virtual void MouseDown(
BPoint point);
// feeds trackUpdate()
virtual void MouseMoved(
BPoint point,
uint32 transit,
const BMessage* dragMessage);
// triggers mouseReleased()
virtual void MouseUp(
BPoint point);
public: // BHandler impl.
virtual void MessageReceived(
BMessage* message); //nyi
virtual void mouseReleased() {}
public: // archiving/instantiation
ValControlSegment(
BMessage* archive);
virtual status_t Archive(
BMessage* archive,
bool deep=true) const;
// underline size (tweak if you must)
// +++++ 18sep99: 'ewww.'
virtual void sizeUnderline(float* outLeft, float* outRight);
private: // guts
// ctor helper
void init();
public:
virtual ~ValControlSegment();
// // left segment (ValControl)
// ValControlSegment* m_pLeft;
//
// mouse-tracking machinery
track_flags m_trackFlags;
bool m_tracking;
BPoint m_prevPoint;
double m_dragScaleFactor;
bigtime_t m_lastClickTime;
protected: // ctor/internal operations
ValControlSegment(underline_style underlineStyle);
// look'n'feel parameters
underline_style m_underlineStyle;
float m_xUnderlineLeft, m_xUnderlineRight;
// constants
static const double s_defDragScaleFactor;
// get parent
ValControl* parent() const;
// init mouse tracking: must be called from MouseDown()
void trackMouse(BPoint point, track_flags flags);
void setTracking(bool tracking);
bool isTracking() const;
// fetch pixel:unit ratio for dragging
double dragScaleFactor() const;
public:// BView impl.
// calls sizeUnderline()
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
// calls sizeUnderline() after bounds changed
virtual void FrameResized(float width, float height);
// calls trackMouse(TRACK_VERTICAL) if left button down
virtual void MouseDown(BPoint point);
// feeds trackUpdate()
virtual void MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage);
// triggers mouseReleased()
virtual void MouseUp(BPoint point);
public:
virtual void MessageReceived(BMessage* message); //nyi
public:
ValControlSegment(BMessage* archive);
virtual status_t Archive(BMessage* archive, bool deep = true) const;
private:
void _Init();
// left segment (ValControl)
// ValControlSegment* m_pLeft;
// mouse-tracking machinery
track_flags fTrackFlags;
bool fTracking;
BPoint fPrevPoint;
double fDragScaleFactor;
bigtime_t fLastClickTime;
// look'n'feel parameters
underline_style fUnderlineStyle;
float fXUnderlineLeft;
float fXUnderlineRight;
// constants
static const double fDefDragScaleFactor;
};
__END_CORTEX_NAMESPACE
#endif /* __ValControlSegment_H__ */
#endif // VAL_CONTROL_SEGMENT_H
+12 -13
View File
@@ -35,31 +35,30 @@
// message 'what' code base values
const uint32 NodeManager_message_base = 'NMaA';
const uint32 NodeManager_message_base = 'NMaA';
const uint32 NodeManager_int_message_base = 'Nm_A';
const uint32 NodeGroup_message_base = 'NGrA';
const uint32 NodeRef_message_base = 'NReA';
const uint32 NodeGroup_message_base = 'NGrA';
const uint32 NodeRef_message_base = 'NReA';
const uint32 NodeSyncThread_message_base = 'NStA';
const uint32 RouteApp_message_base = 'RoAA';
const uint32 RouteWindow_message_base = 'RoWA';
const uint32 DiagramView_message_base = 'DiVA';
const uint32 MediaRoutingView_message_base = 'RoVA';
const uint32 RouteApp_message_base = 'RoAA';
const uint32 RouteWindow_message_base = 'RoWA';
const uint32 DiagramView_message_base = 'DiVA';
const uint32 MediaRoutingView_message_base = 'RoVA';
const uint32 TransportWindow_message_base = 'TrWA';
const uint32 TransportView_message_base = 'TrVA';
const uint32 ValControl_message_base = 'VcnA';
const uint32 ValControl_message_base = 'VcnA';
const uint32 Observable_message_base = 'ObTA';
const uint32 Observer_message_base = 'Ob_A';
const uint32 Observable_message_base = 'ObTA';
const uint32 Observer_message_base = 'Ob_A';
const uint32 AddOnHostApp_message_base = 'NahA';
const uint32 RouteAppNodeManager_message_base
= 'RMaA';
const uint32 RouteAppNodeManager_message_base = 'RMaA';
const uint32 InfoView_message_base = 'InVA';
const uint32 InfoView_message_base = 'InVA';
const uint32 ParameterWindow_message_base = 'PaWA';