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