Another round of style updates by Vasilis Kaoutsis.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20880 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-04-28 12:05:46 +00:00
parent c94089f5db
commit 08a996b87a
9 changed files with 491 additions and 643 deletions

View File

@ -22,7 +22,7 @@
__BEGIN_CORTEX_NAMESPACE
namespace addon_host {
class App:public BApplication {
class App : public BApplication {
typedef BApplication _inherited;
public:

View File

@ -16,41 +16,35 @@ __USE_CORTEX_NAMESPACE
#define D_MOUSE(x) //PRINT (x)
#define D_DRAW(x) //PRINT (x)
// -------------------------------------------------------- //
// *** ctor/dtor (public)
// -------------------------------------------------------- //
DiagramBox::DiagramBox(
BRect frame,
uint32 flags)
// #pragma mark -
DiagramBox::DiagramBox(BRect frame, uint32 flags)
: DiagramItem(DiagramItem::M_BOX),
DiagramItemGroup(DiagramItem::M_ENDPOINT),
m_frame(frame),
m_flags(flags)
DiagramItemGroup(DiagramItem::M_ENDPOINT),
m_frame(frame),
m_flags(flags)
{
D_METHOD(("DiagramBox::DiagramBox()\n"));
makeDraggable(true);
}
DiagramBox::~DiagramBox()
{
D_METHOD(("DiagramBox::~DiagramBox()\n"));
}
// -------------------------------------------------------- //
// *** derived from DiagramItemGroup (public)
// -------------------------------------------------------- //
bool DiagramBox::addItem(
DiagramItem *item)
// derived from DiagramItemGroup (public)
bool
DiagramBox::addItem(DiagramItem *item)
{
D_METHOD(("DiagramBox::addItem()\n"));
if (item)
{
if (DiagramItemGroup::addItem(item))
{
if (m_view)
{
if (item) {
if (DiagramItemGroup::addItem(item)) {
if (m_view) {
item->_setOwner(m_view);
item->attachedToDiagram();
}
@ -60,15 +54,14 @@ bool DiagramBox::addItem(
return false;
}
bool DiagramBox::removeItem(
DiagramItem *item)
bool
DiagramBox::removeItem(DiagramItem *item)
{
D_METHOD(("DiagramBox::removeItem()\n"));
if (item)
{
if (item) {
item->detachedFromDiagram();
if (DiagramItemGroup::removeItem(item))
{
if (DiagramItemGroup::removeItem(item)) {
item->_setOwner(0);
return true;
}
@ -76,47 +69,36 @@ bool DiagramBox::removeItem(
return false;
}
// -------------------------------------------------------- //
// *** derived from DiagramItem (public)
// -------------------------------------------------------- //
void DiagramBox::draw(
BRect updateRect)
// derived from DiagramItem (public)
void
DiagramBox::draw(BRect updateRect)
{
D_DRAW(("DiagramBox::draw()\n"));
if (view())
{
if (view()) {
view()->PushState();
{
if (m_flags & M_DRAW_UNDER_ENDPOINTS)
{
if (m_flags & M_DRAW_UNDER_ENDPOINTS) {
BRegion region, clipping;
region.Include(frame());
if (group()->getClippingAbove(this, &clipping))
region.Exclude(&clipping);
view()->ConstrainClippingRegion(&region);
drawBox();
for (int32 i = 0; i < countItems(); i++)
{
for (int32 i = 0; i < countItems(); i++) {
DiagramItem *item = itemAt(i);
if (region.Intersects(item->frame()))
{
item->draw(item->frame());
}
}
}
else
{
} else {
BRegion region, clipping;
region.Include(frame());
if (view()->getClippingAbove(this, &clipping))
region.Exclude(&clipping);
for (int32 i = 0; i < countItems(); i++)
{
for (int32 i = 0; i < countItems(); i++) {
DiagramItem *item = itemAt(i);
BRect r;
if (region.Intersects(r = item->frame()))
{
if (region.Intersects(r = item->frame())) {
item->draw(r);
region.Exclude(r);
}
@ -129,36 +111,26 @@ void DiagramBox::draw(
}
}
void DiagramBox::mouseDown(
BPoint point,
uint32 buttons,
uint32 clicks)
void
DiagramBox::mouseDown(BPoint point, uint32 buttons, uint32 clicks)
{
D_MOUSE(("DiagramBox::mouseDown()\n"));
DiagramItem *item = itemUnder(point);
if (item)
{
item->mouseDown(point, buttons, clicks);
}
else if (clicks == 1)
{
if (isSelectable())
{
else if (clicks == 1) {
if (isSelectable()) {
BMessage selectMsg(M_SELECTION_CHANGED);
if (modifiers() & B_SHIFT_KEY)
{
selectMsg.AddBool("replace", false);
}
else
{
selectMsg.AddBool("replace", true);
}
selectMsg.AddPointer("item", reinterpret_cast<void *>(this));
DiagramView* v = view();
BMessenger(v).SendMessage(&selectMsg);
}
if (isDraggable() && (buttons == B_PRIMARY_MOUSE_BUTTON))
{
if (isDraggable() && (buttons == B_PRIMARY_MOUSE_BUTTON)) {
BMessage dragMsg(M_BOX_DRAGGED);
dragMsg.AddPointer("item", static_cast<void *>(this));
dragMsg.AddPoint("offset", point - frame().LeftTop());
@ -167,159 +139,114 @@ void DiagramBox::mouseDown(
}
}
void DiagramBox::mouseOver(
BPoint point,
uint32 transit)
void
DiagramBox::mouseOver(BPoint point, uint32 transit)
{
D_MOUSE(("DiagramBox::mouseOver()\n"));
DiagramItem *last = lastItemUnder();
if (last && (transit == B_EXITED_VIEW))
{
if (last && (transit == B_EXITED_VIEW)) {
last->mouseOver(point, B_EXITED_VIEW);
resetItemUnder();
}
else
{
} else {
DiagramItem *item = itemUnder(point);
if (item)
{
if (item != last)
{
if (item) {
if (item != last) {
if (last)
last->mouseOver(point, B_EXITED_VIEW);
item->mouseOver(point, B_ENTERED_VIEW);
}
else
{
} else
item->mouseOver(point, B_INSIDE_VIEW);
}
}
else if (last)
{
last->mouseOver(point, B_EXITED_VIEW);
}
}
}
void DiagramBox::messageDragged(
BPoint point,
uint32 transit,
const BMessage *message)
void
DiagramBox::messageDragged(BPoint point, uint32 transit, const BMessage *message)
{
D_MOUSE(("DiagramBox::messageDragged()\n"));
DiagramItem *last = lastItemUnder();
if (last && (transit == B_EXITED_VIEW))
{
if (last && (transit == B_EXITED_VIEW)) {
last->messageDragged(point, B_EXITED_VIEW, message);
resetItemUnder();
}
else
{
} else {
DiagramItem *item = itemUnder(point);
if (item)
{
if (item != last)
{
if (item) {
if (item != last) {
if (last)
{
last->messageDragged(point, B_EXITED_VIEW, message);
}
item->messageDragged(point, B_ENTERED_VIEW, message);
}
else
{
} else
item->messageDragged(point, B_INSIDE_VIEW, message);
}
return;
}
else if (last)
{
} else if (last)
last->messageDragged(point, B_EXITED_VIEW, message);
}
if (message->what == M_WIRE_DRAGGED)
{
view()->trackWire(point);
}
}
}
void DiagramBox::messageDropped(
BPoint point,
BMessage *message)
void
DiagramBox::messageDropped(BPoint point, BMessage *message)
{
D_METHOD(("DiagramBox::messageDropped()\n"));
DiagramItem *item = itemUnder(point);
if (item)
{
if (item) {
item->messageDropped(point, message);
return;
}
}
// -------------------------------------------------------- //
// *** operations (public)
// -------------------------------------------------------- //
void DiagramBox::moveBy(
float x,
float y,
BRegion *wireRegion)
// operations (public)
void
DiagramBox::moveBy(float x, float y, BRegion *wireRegion)
{
D_METHOD(("DiagramBox::moveBy()\n"));
if (view())
{
if (view()) {
view()->PushState();
{
for (int32 i = 0; i < countItems(); i++)
{
for (int32 i = 0; i < countItems(); i++) {
DiagramEndPoint *endPoint = dynamic_cast<DiagramEndPoint *>(itemAt(i));
if (endPoint)
{
endPoint->moveBy(x, y, wireRegion);
}
}
if (wireRegion)
{
if (wireRegion) {
wireRegion->Include(m_frame);
m_frame.OffsetBy(x, y);
wireRegion->Include(m_frame);
}
else
{
m_frame.OffsetBy(x, y);
}
}
view()->PopState();
}
}
void DiagramBox::resizeBy(
float horizontal,
float vertical)
void
DiagramBox::resizeBy(float horizontal, float vertical)
{
D_METHOD(("DiagramBox::resizeBy()\n"));
m_frame.right += horizontal;
m_frame.bottom += vertical;
}
// -------------------------------------------------------- //
// *** internal operations (private)
// -------------------------------------------------------- //
void DiagramBox::_setOwner(
DiagramView *owner)
// internal operations (private)
void
DiagramBox::_setOwner(DiagramView *owner)
{
D_METHOD(("DiagramBox::_setOwner()\n"));
m_view = owner;
for (int32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++)
{
for (int32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++) {
DiagramItem *item = itemAt(i);
item->_setOwner(m_view);
if (m_view)
{
item->attachedToDiagram();
}
}
}
// END -- DiagramBox.cpp --

View File

@ -8,123 +8,95 @@
// * HISTORY
// c.lenz 25sep99 Begun
//
#ifndef DIAGRAM_BOX_H
#define DIAGRAM_BOX_H
#ifndef __DiagramBox_H__
#define __DiagramBox_H__
#include "cortex_defs.h"
#include "DiagramItem.h"
#include "DiagramItemGroup.h"
#include <Region.h>
#include <Window.h>
#include "DiagramItem.h"
#include "DiagramItemGroup.h"
#include "cortex_defs.h"
__BEGIN_CORTEX_NAMESPACE
class DiagramBox : public DiagramItem,
public DiagramItemGroup
{
public: // *** flags
class DiagramBox : public DiagramItem, public DiagramItemGroup {
public: // flags
enum flag_t
{
M_DRAW_UNDER_ENDPOINTS = 0x1
};
enum flag_t {
M_DRAW_UNDER_ENDPOINTS = 0x1
};
public: // *** ctor/dtor
public:
DiagramBox(BRect frame, uint32 flags = 0);
virtual ~DiagramBox();
DiagramBox(
BRect frame,
uint32 flags = 0);
public: // hook functions
// is called from draw() to do the actual drawing
virtual void drawBox() = 0;
virtual ~DiagramBox();
public: // derived from DiagramItemGroup
public: // *** hook functions
// extends the DiagramItemGroup implementation by setting
// the items owner and calling the attachedToDiagram() hook
// on it
virtual bool addItem(DiagramItem *item);
// is called from draw() to do the actual drawing
virtual void drawBox() = 0;
// extends the DiagramItemGroup implementation by calling
// the detachedToDiagram() hook on the item
virtual bool removeItem(DiagramItem *item);
public: // ** derived from DiagramItemGroup
public: // derived from DiagramItem
// extends the DiagramItemGroup implementation by setting
// the items owner and calling the attachedToDiagram() hook
// on it
virtual bool addItem(
DiagramItem *item);
// returns the Boxes frame rectangle
BRect frame() const { return m_frame; }
// extends the DiagramItemGroup implementation by calling
// the detachedToDiagram() hook on the item
virtual bool removeItem(
DiagramItem *item);
// prepares the drawing stack and clipping region, then
// calls drawBox
void draw(BRect updateRect);
public: // *** derived from DiagramItem
// is called from the parent DiagramViews MouseDown() implementation
// if the Box was hit; this version initiates selection and dragging
virtual void mouseDown(BPoint point, uint32 buttons, uint32 clicks);
// returns the Boxes frame rectangle
BRect frame() const
{ return m_frame; }
// prepares the drawing stack and clipping region, then
// calls drawBox
void draw(
BRect updateRect);
// is called from the parent DiagramViews MouseDown() implementation
// if the Box was hit; this version initiates selection and dragging
virtual void mouseDown(
BPoint point,
uint32 buttons,
uint32 clicks);
// is called from the DiagramViews MouseMoved() when no message is being
// dragged, but the mouse has moved above the box
virtual void mouseOver(
BPoint point,
uint32 transit);
// is called from the DiagramViews MouseMoved() when no message is being
// dragged, but the mouse has moved above the box
virtual void mouseOver(BPoint point, uint32 transit);
// is called from the DiagramViews MouseMoved() when a message is being
// dragged over the DiagramBox
virtual void messageDragged(
BPoint point,
uint32 transit,
const BMessage *message);
// is called from the DiagramViews MouseMoved() when a message is being
// dragged over the DiagramBox
virtual void messageDragged(BPoint point, uint32 transit, const BMessage *message);
// is called from the DiagramViews MessageReceived() function when a
// message has been dropped on the DiagramBox
virtual void messageDropped(
BPoint point,
BMessage *message);
// is called from the DiagramViews MessageReceived() function when a
// message has been dropped on the DiagramBox
virtual void messageDropped(BPoint point, BMessage *message);
public: // *** operations
public: // operations
// moves the box by a given amount, and returns in updateRegion the
// frames of wires impacted by the move
void moveBy(
float x,
float y,
BRegion *updateRegion);
// moves the box by a given amount, and returns in updateRegion the
// frames of wires impacted by the move
void moveBy(float x, float y, BRegion *updateRegion);
// resizes the boxes frame without doing any updating
virtual void resizeBy(
float horizontal,
float vertical);
// resizes the boxes frame without doing any updating
virtual void resizeBy(float horizontal, float vertical);
private: // *** internal methods
private:// internal methods
// is called by the DiagramView when added
void _setOwner(
DiagramView *owner);
private: // *** data
// is called by the DiagramView when added
void _setOwner(DiagramView *owner);
private:
// the boxes' frame rectangle
BRect m_frame;
BRect m_frame;
// flags:
// M_DRAW_UNDER_ENDPOINTS - don't remove EndPoint frames from
// the clipping region
uint32 m_flags;
uint32 m_flags;
};
__END_CORTEX_NAMESPACE
#endif /* __DiagramBox_H__ */
#endif // DIAGRAM_BOX_H

View File

@ -7,9 +7,8 @@
// * HISTORY
// c.lenz 25sep99 Begun
//
#ifndef __DiagramDefs_H__
#define __DiagramDefs_H__
#ifndef DIAGRAM_DEFS_H
#define DIAGRAM_DEFS_H
#include "cortex_defs.h"
__BEGIN_CORTEX_NAMESPACE
@ -43,4 +42,4 @@ enum message_t
};
__END_CORTEX_NAMESPACE
#endif /* __DiagramDefs_H__ */
#endif // DIAGRAM_DEFS_H

View File

@ -1,6 +1,7 @@
// NumericValControl.cpp
// e.moon 30jan99
#include "NumericValControl.h"
#include "ValControlDigitSegment.h"
#include "ValCtrlLayoutEntry.h"
@ -15,30 +16,18 @@
__USE_CORTEX_NAMESPACE
// ---------------------------------------------------------------- //
// ctor/dtor/accessors
// ---------------------------------------------------------------- //
// parameter-linked ctor
NumericValControl::NumericValControl(
BRect frame,
const char* name,
BContinuousParameter* param,
uint16 wholeDigits,
uint16 fractionalDigits,
align_mode alignMode,
align_flags alignFlags) :
ValControl(frame, name, 0, 0, alignMode, alignFlags, UPDATE_ASYNC, false),
m_param(param),
m_wholeDigits(wholeDigits),
m_fractionalDigits(fractionalDigits) {
NumericValControl::NumericValControl(BRect frame, const char* name, BContinuousParameter* param,
uint16 wholeDigits, uint16 fractionalDigits, align_mode alignMode, align_flags alignFlags)
: ValControl(frame, name, 0, 0, alignMode, alignFlags, UPDATE_ASYNC, false),
fParam(param),
fWholeDigits(wholeDigits),
fFractionalDigits(fractionalDigits)
{
// ensure that the parameter represents a continuous value
ASSERT(
m_param->ValueType() == B_FLOAT_TYPE ||
m_param->ValueType() == B_DOUBLE_TYPE
ASSERT(fParam->ValueType() == B_FLOAT_TYPE ||
fParam->ValueType() == B_DOUBLE_TYPE
/*|| unimplemented so far
m_pParam->ValueType() == B_INT8_TYPE ||
m_pParam->ValueType() == B_UINT8_TYPE ||
@ -54,82 +43,83 @@ NumericValControl::NumericValControl(
mediaParameterChanged();
}
NumericValControl::NumericValControl(
BRect frame,
const char* name,
BMessage* message,
uint16 wholeDigits,
uint16 fractionalDigits,
bool negativeVisible,
align_mode alignMode,
align_flags alignFlags) :
ValControl(frame, name, 0, message, alignMode, alignFlags, UPDATE_ASYNC, false),
m_wholeDigits(wholeDigits),
m_fractionalDigits(fractionalDigits),
m_param(0) {
setDefaultConstraints(negativeVisible);
NumericValControl::NumericValControl(BRect frame, const char* name, BMessage* message,
uint16 wholeDigits, uint16 fractionalDigits, bool negativeVisible,
align_mode alignMode, align_flags alignFlags)
: ValControl(frame, name, 0, message, alignMode, alignFlags, UPDATE_ASYNC, false),
fParam(0),
fWholeDigits(wholeDigits),
fFractionalDigits(fractionalDigits)
{
_SetDefaultConstraints(negativeVisible);
initSegments();
}
NumericValControl::~NumericValControl() {}
BContinuousParameter* NumericValControl::param() const {
return m_param;
NumericValControl::~NumericValControl()
{
}
void NumericValControl::initSegments() {
// sanity check
ASSERT(m_wholeDigits);
BContinuousParameter*
NumericValControl::param() const
{
return fParam;
}
void
NumericValControl::initSegments()
{
ASSERT(fWholeDigits);
bool negativeVisible = m_minFixed < 0.0;
bool negativeVisible = fMinFixed < 0.0;
// *** SEGMENT DIVISION NEEDS TO BE CONFIGURABLE +++++
// GOOD 23aug99
// GOOD 23aug99
// init segments:
add(
new ValControlDigitSegment(m_wholeDigits, 0, negativeVisible),
RIGHT_MOST);
add(new ValControlDigitSegment(fWholeDigits, 0, negativeVisible), RIGHT_MOST);
if(m_fractionalDigits)
if(fFractionalDigits)
add(ValCtrlLayoutEntry::decimalPoint, RIGHT_MOST);
for(int n = 0; n < m_fractionalDigits; ++n)
add(
new ValControlDigitSegment(1, (-1)-n, false, ValControlDigitSegment::ZERO_FILL),
for (int n = 0; n < fFractionalDigits; ++n)
add(new ValControlDigitSegment(1, (-1)-n, false, ValControlDigitSegment::ZERO_FILL),
RIGHT_MOST);
// add(new ValControlDigitSegment(m_fractionalDigits, -m_fractionalDigits,
// add(new ValControlDigitSegment(fFractionalDigits, -fFractionalDigits,
// false, ValControlDigitSegment::ZERO_FILL),
// RIGHT_MOST);
// }
// // +++++ individual-segment test
//
// for(int n = 0; n < m_wholeDigits; ++n)
// for(int n = 0; n < fWholeDigits; ++n)
// add(
// new ValControlDigitSegment(1, m_wholeDigits-n, bNegativeCapable),
// new ValControlDigitSegment(1, fWholeDigits-n, bNegativeCapable),
// RIGHT_MOST);
//
// if(m_fractionalDigits)
// if(fFractionalDigits)
// add(ValCtrlLayoutEntry::decimalPoint, RIGHT_MOST);
//
// for(int n = 0; n < m_fractionalDigits; ++n)
// for(int n = 0; n < fFractionalDigits; ++n)
// add(
// new ValControlDigitSegment(1, (-1)-n, false, ValControlDigitSegment::ZERO_FILL),
// RIGHT_MOST);
}
void NumericValControl::initConstraintsFromParam() {
// +++++
ASSERT(m_param);
void
NumericValControl::initConstraintsFromParam()
{
ASSERT(fParam);
printf("NumericValControl::initConstraintsFromParam():\n ");
int r;
float fFactor;
float fOffset;
m_param->GetResponse(&r, &fFactor, &fOffset);
switch(r) {
fParam->GetResponse(&r, &fFactor, &fOffset);
switch (r) {
case BContinuousParameter::B_LINEAR:
printf("Linear");
break;
@ -149,57 +139,57 @@ void NumericValControl::initConstraintsFromParam() {
default:
printf("unknown (?)");
}
printf(" response; factor %.2f, offset %.2f\n",
fFactor, fOffset);
setConstraints(
m_param->MinValue(),
m_param->MaxValue());
printf(" response; factor %.2f, offset %.2f\n", fFactor, fOffset);
setConstraints(fParam->MinValue(), fParam->MaxValue());
// step not yet supported +++++ 19sep99
//
float fStep = m_param->ValueStep();
float fStep = fParam->ValueStep();
printf(" min value: %f\n", m_param->MinValue());
printf(" max value: %f\n", m_param->MaxValue());
printf(" min value: %f\n", fParam->MinValue());
printf(" max value: %f\n", fParam->MaxValue());
printf(" value step: %f\n\n", fStep);
}
// value constraints (by default, the min/max allowed by the
//! Value constraints (by default, the min/max allowed by the
// setting of nWholeDigits, nFractionalDigits, and bNegativeCapable)
void NumericValControl::getConstraints(
double* outMinValue,
double* outMaxValue) {
void
NumericValControl::getConstraints(double* outMinValue, double* outMaxValue)
{
double factor = pow(10, -fFractionalDigits);
double factor = pow(10, -m_fractionalDigits);
*outMinValue = (double)m_minFixed * factor;
*outMaxValue = (double)m_maxFixed * factor;
*outMinValue = (double)fMinFixed * factor;
*outMaxValue = (double)fMaxFixed * factor;
}
status_t NumericValControl::setConstraints(
double minValue,
double maxValue) {
if(maxValue < minValue)
return B_BAD_VALUE;
double factor = pow(10, m_fractionalDigits);
m_minFixed = (minValue < 0.0) ?
status_t
NumericValControl::setConstraints(double minValue, double maxValue)
{
if (maxValue < minValue)
return B_BAD_VALUE;
double factor = pow(10, fFractionalDigits);
fMinFixed = (minValue < 0.0) ?
(int64)floor(minValue * factor) :
(int64)ceil(minValue * factor);
m_maxFixed = (maxValue < 0.0) ?
fMaxFixed = (maxValue < 0.0) ?
(int64)floor(maxValue * factor) :
(int64)ceil(maxValue * factor);
return B_OK;
}
// fetches the current value (calculated on the spot from each
//! Fetches the current value (calculated on the spot from each
// segment.)
double NumericValControl::value() const {
double
NumericValControl::value() const
{
// double acc = 0.0;
//
// // walk segments, adding the value of each
@ -229,25 +219,26 @@ double NumericValControl::value() const {
//
// return acc;
double ret = (double)_value_fixed() / pow(10, m_fractionalDigits);
double ret = (double)_ValueFixed() / pow(10, fFractionalDigits);
// PRINT((
// "### NumericValControl::value(): %.12f\n", ret));
return ret;
}
// set the displayed value (and, if setParam is true, the
//! Set the displayed value (and, if setParam is true, the
// linked parameter.) The value will be constrained if necessary.
void NumericValControl::setValue(
double value,
bool setParam) {
void
NumericValControl::setValue(double value, bool setParam)
{
// PRINT((
// "### NumericValControl::setValue(%.12f)\n", value));
// round to displayed precision
double scaleFactor = pow(10, m_fractionalDigits);
double scaleFactor = pow(10, fFractionalDigits);
int64 fixed = (int64)(value * scaleFactor);
double junk = (value * scaleFactor) - (double)fixed;
@ -255,11 +246,11 @@ void NumericValControl::setValue(
// PRINT((
// " : junk == %.12f\n", junk));
if(value < 0.0) {
if(junk * scaleFactor < 0.5)
if (value < 0.0) {
if (junk * scaleFactor < 0.5)
fixed--;
} else {
if(junk * scaleFactor >= 0.5)
if (junk * scaleFactor >= 0.5)
fixed++;
}
@ -268,13 +259,13 @@ void NumericValControl::setValue(
// PRINT((
// " -> %.12f, %Ld\n", value, fixed));
_set_value_fixed(fixed);
_SetValueFixed(fixed);
// notify target
Invoke();
// set parameter
if(setParam && m_param)
if (setParam && fParam)
updateParameter(value);
// +++++ redraw?
@ -315,7 +306,7 @@ void NumericValControl::setValue(
// m_dfValue = dfValue;
//
// // set parameter
// if(bSetParam && m_param)
// if(bSetParam && fParam)
// updateParameter();
//
// // notify target (ugh. what if the target called this? +++++)
@ -345,19 +336,18 @@ void NumericValControl::setValue(
// 18sep99: new segment interface. 'offset' is given
// in the segment's units.
void NumericValControl::offsetSegmentValue(
ValControlDigitSegment* segment,
int64 offset) {
void
NumericValControl::offsetSegmentValue(ValControlDigitSegment* segment,
int64 offset)
{
// PRINT((
// "### offsetSegmentValue(): %Ld\n",
// offset));
int64 segmentFactor = (int64)pow(
10,
m_fractionalDigits + segment->scaleFactor());
int64 segmentFactor = (int64)pow(10, fFractionalDigits + segment->scaleFactor());
int64 value = _value_fixed();
int64 value = _ValueFixed();
// cut values below domain of the changed segment
value /= segmentFactor;
@ -368,44 +358,43 @@ void NumericValControl::offsetSegmentValue(
// restore
value *= segmentFactor;
_set_value_fixed(value);
_SetValueFixed(value);
// notify target
Invoke();
if(m_param)
updateParameter(
(double)value * (double)segmentFactor);
if (fParam)
updateParameter((double)value * (double)segmentFactor);
}
// ---------------------------------------------------------------- //
// hook implementations
// ---------------------------------------------------------------- //
void NumericValControl::mediaParameterChanged() {
void
NumericValControl::mediaParameterChanged()
{
// fetch value
size_t nSize;
bigtime_t tLastChanged;
status_t err;
switch(m_param->ValueType()) {
case B_FLOAT_TYPE: { // +++++ left-channel hack
switch (fParam->ValueType()) {
case B_FLOAT_TYPE:
{ // +++++ left-channel hack
float fParamValue[4];
nSize = sizeof(float)*4;
nSize = sizeof(float) * 4;
// +++++ broken
err = m_param->GetValue((void*)&fParamValue, &nSize, &tLastChanged);
// if(err != B_OK)
// break;
err = fParam->GetValue((void*)&fParamValue, &nSize, &tLastChanged);
// if (err != B_OK)
// break;
setValue(fParamValue[0]);
break;
}
case B_DOUBLE_TYPE: {
case B_DOUBLE_TYPE:
{
double fParamValue;
nSize = sizeof(double);
err = m_param->GetValue((void*)&fParamValue, &nSize, &tLastChanged);
if(err != B_OK)
err = fParam->GetValue((void*)&fParamValue, &nSize, &tLastChanged);
if (err != B_OK)
break;
setValue(fParamValue);
@ -414,10 +403,11 @@ void NumericValControl::mediaParameterChanged() {
}
}
void NumericValControl::updateParameter(
double value) {
ASSERT(m_param);
void
NumericValControl::updateParameter(double value)
{
ASSERT(fParam);
// // is this kosher? +++++
// // ++++++ 18sep99: no.
@ -425,52 +415,53 @@ void NumericValControl::updateParameter(
// store value
status_t err;
switch(m_param->ValueType()) {
case B_FLOAT_TYPE: { // +++++ left-channel hack
switch (fParam->ValueType()) {
case B_FLOAT_TYPE:
{ // +++++ left-channel hack
float fValue[2];
fValue[0] = value;
fValue[1] = value;
err = m_param->SetValue((void*)&fValue, sizeof(float)*2, 0LL);
err = fParam->SetValue((void*)&fValue, sizeof(float)*2, 0LL);
break;
}
case B_DOUBLE_TYPE: {
double fValue = value;
err = m_param->SetValue((void*)&fValue, sizeof(double), 0LL);
err = fParam->SetValue((void*)&fValue, sizeof(double), 0LL);
break;
}
}
}
// ---------------------------------------------------------------- //
// ValControl impl.
// ---------------------------------------------------------------- //
void
NumericValControl::setValue(const void* data, size_t size)
{
}
void NumericValControl::setValue(
const void* data,
size_t size) {} //nyi +++++
void NumericValControl::getValue(
void* data,
size_t* ioSize) {} //nyi +++++
void
NumericValControl::getValue(void* data, size_t* ioSize)
{
}
// * string value access
status_t NumericValControl::setValueFrom(
const char* text) {
status_t
NumericValControl::setValueFrom(const char* text)
{
double d = atof(text);
setValue(d, true);
return B_OK;
}
status_t NumericValControl::getString(
BString& buffer) {
status_t
NumericValControl::getString(BString& buffer)
{
// should provide the same # of digits as the control! +++++
BString format = "%.";
format << (int32)m_fractionalDigits << 'f';
format << (int32)fFractionalDigits << 'f';
char cbuf[120];
sprintf(cbuf, format.String(), value());
buffer = cbuf;
@ -479,19 +470,16 @@ status_t NumericValControl::getString(
}
// ---------------------------------------------------------------- //
// BHandler impl.
// ---------------------------------------------------------------- //
void NumericValControl::MessageReceived(BMessage* pMsg) {
void
NumericValControl::MessageReceived(BMessage* pMsg)
{
status_t err;
double dfValue;
switch(pMsg->what) {
switch (pMsg->what) {
case M_SET_VALUE:
err = pMsg->FindDouble("value", &dfValue);
if(err < B_OK) {
if (err < B_OK) {
_inherited::MessageReceived(pMsg);
break;
}
@ -499,12 +487,13 @@ void NumericValControl::MessageReceived(BMessage* pMsg) {
setValue(dfValue);
break;
case B_MEDIA_PARAMETER_CHANGED: {
case B_MEDIA_PARAMETER_CHANGED:
{
int32 id;
if(pMsg->FindInt32("be:parameter", &id) != B_OK)
if (pMsg->FindInt32("be:parameter", &id) != B_OK)
break;
ASSERT(id == m_param->ID());
ASSERT(id == fParam->ID());
mediaParameterChanged();
break;
}
@ -515,38 +504,32 @@ void NumericValControl::MessageReceived(BMessage* pMsg) {
}
}
// ---------------------------------------------------------------- //
// internal operations
// ---------------------------------------------------------------- //
void NumericValControl::setDefaultConstraints(
bool negativeVisible) {
double max = pow(10, m_wholeDigits) - pow(10, -m_fractionalDigits);
void
NumericValControl::_SetDefaultConstraints(bool negativeVisible)
{
double max = pow(10, fWholeDigits) - pow(10, -fFractionalDigits);
double min = (negativeVisible) ? -max : 0.0;
setConstraints(min, max);
}
// ---------------------------------------------------------------- //
// guts
// ---------------------------------------------------------------- //
// calculates the current value as an int64
int64 NumericValControl::_value_fixed() const {
//! calculates the current value as an int64
int64
NumericValControl::_ValueFixed() const {
// PRINT((
// "### NumericValControl::_value_fixed()\n", value));
// "### NumericValControl::_ValueFixed()\n", value));
int64 acc = 0LL;
int64 scaleBase = m_fractionalDigits;
int64 scaleBase = fFractionalDigits;
// walk segments, adding the value of each
for(int n = countEntries(); n > 0; --n) {
for (int n = countEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = entryAt(n-1);
if(e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
if (e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
const ValControlDigitSegment* digitSegment =
dynamic_cast<ValControlDigitSegment*>(e.pView);
ASSERT(digitSegment);
@ -558,10 +541,8 @@ int64 NumericValControl::_value_fixed() const {
// digitSegment->scaleFactor(),
// digitSegment->value()));
//
acc += digitSegment->value() *
(int64)pow(
10,
scaleBase + digitSegment->scaleFactor());
acc += digitSegment->value() * (int64)pow(10,
scaleBase + digitSegment->scaleFactor());
//
// PRINT((
// "\t-> %Ld\n\n", acc));
@ -571,26 +552,30 @@ int64 NumericValControl::_value_fixed() const {
return acc;
}
// sets the value of each segment based on an int64 value;
// does not constrain the value
void NumericValControl::_set_value_fixed(
int64 fixed) {
//! sets the value of each segment based on an int64 value;
// does not constrain the value
void
NumericValControl::_SetValueFixed(int64 fixed)
{
// PRINT((
// "### NumericValControl::_set_value_fixed(%Ld)\n", fixed));
// "### NumericValControl::_SetValueFixed(%Ld)\n", fixed));
// constrain
if(fixed > m_maxFixed) fixed = m_maxFixed;
if(fixed < m_minFixed) fixed = m_minFixed;
if (fixed > fMaxFixed)
fixed = fMaxFixed;
int64 scaleBase = m_fractionalDigits;
if (fixed < fMinFixed)
fixed = fMinFixed;
int64 scaleBase = fFractionalDigits;
// set segments
for(int n = countEntries(); n > 0; --n) {
for (int n = countEntries(); n > 0; --n) {
const ValCtrlLayoutEntry& e = entryAt(n-1);
if(e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
if (e.type == ValCtrlLayoutEntry::SEGMENT_ENTRY) {
ValControlDigitSegment* digitSegment =
dynamic_cast<ValControlDigitSegment*>(e.pView);
ASSERT(digitSegment);
@ -602,27 +587,20 @@ void NumericValControl::_set_value_fixed(
// digitSegment->scaleFactor()));
// subtract higher-magnitude segments' value
int64 hiCut = fixed %
(int64)pow(
10,
scaleBase + digitSegment->scaleFactor() + digitSegment->digitCount());
int64 hiCut = fixed % (int64)pow(10,
scaleBase + digitSegment->scaleFactor() + digitSegment->digitCount());
// PRINT((
// "\t [] %Ld\n", hiCut));
// shift value
int64 segmentValue = hiCut /
(int64)pow(
10,
scaleBase + digitSegment->scaleFactor());
int64 segmentValue = hiCut / (int64)pow(10,
scaleBase + digitSegment->scaleFactor());
// PRINT((
// "\t -> %Ld\n\n", segmentValue));
// set
digitSegment->setValue(segmentValue, fixed < 0);
}
}
}
// END -- NumericValControl.cpp --

View File

@ -9,146 +9,117 @@
// +++++ 31jan99: negatives are still handled wrong...
//
// CLASS: NumericValControl
#ifndef __NumericValControl_H__
#define __NumericValControl_H__
#include "ValControl.h"
class BContinuousParameter;
#include <MediaDefs.h>
#ifndef NUMERIC_VAL_CONTROL_H
#define NUMERIC_VAL_CONTROL_H
#include "cortex_defs.h"
#include "ValControl.h"
#include <MediaDefs.h>
class BContinuousParameter;
__BEGIN_CORTEX_NAMESPACE
class ValControlDigitSegment;
class NumericValControl : /*extends*/ public ValControl {
typedef ValControl _inherited;
public: // ctor/dtor/accessors
class NumericValControl : public ValControl {
public:
typedef ValControl _inherited;
// +++++ need control over number of segments +++++
public:
// parameter-linked ctor
NumericValControl(
BRect frame,
const char* name,
BContinuousParameter* param,
uint16 wholeDigits,
uint16 fractionalDigits=0,
align_mode alignMode=ALIGN_FLUSH_RIGHT,
align_flags alignFlags=ALIGN_NONE);
// +++++ need control over number of segments +++++
// parameter-linked ctor
NumericValControl(BRect frame, const char* name, BContinuousParameter* param,
uint16 wholeDigits, uint16 fractionalDigits = 0, align_mode alignMode = ALIGN_FLUSH_RIGHT,
align_flags alignFlags = ALIGN_NONE);
// 'plain' ctor
NumericValControl(
BRect frame,
const char* name,
BMessage* message,
uint16 wholeDigits,
uint16 fractionalDigits=0,
bool negativeVisible=true,
align_mode alignMode=ALIGN_FLUSH_RIGHT,
align_flags alignFlags=ALIGN_NONE);
~NumericValControl();
// 'plain' ctor
NumericValControl(BRect frame, const char* name, BMessage* message, uint16 wholeDigits,
uint16 fractionalDigits = 0, bool negativeVisible = true,
align_mode alignMode = ALIGN_FLUSH_RIGHT, align_flags alignFlags = ALIGN_NONE);
~NumericValControl();
BContinuousParameter* param() const;
// bound parameter, or 0 if none
void getConstraints(double* outMinValue, double* outMaxValue);
// value constraints (by default, the min/max allowed by the ctor
// settings: wholeDigits, fractionalDigits, and negativeVisible)
status_t setConstraints(double minValue, double maxValue);
// the current value is not yet re-constrained by this call
double value() const;
// fetches the current value (calculated on the spot from each
// segment.)
void setValue(double value, bool setParam = false);
// set the displayed value (and, if setParam is true, the
// linked parameter.) The value will be constrained if necessary.
public: // segment interface
// 18sep99: old segment interface
// virtual void offsetValue(double dfDelta);
// 18sep99: new segment interface. 'offset' is given
// in the segment's units.
// bound parameter, or 0 if none
BContinuousParameter* param() const;
virtual void offsetSegmentValue(ValControlDigitSegment* segment, int64 offset);
// value constraints (by default, the min/max allowed by the ctor
// settings: wholeDigits, fractionalDigits, and negativeVisible)
public:
virtual void mediaParameterChanged();
virtual void updateParameter(double value);
// writes the stored value to the bound parameter
virtual void initSegments();
virtual void initConstraintsFromParam();
public: // ValControl impl.
void setValue(const void* data, size_t size); //nyi
void getValue(void* data, size_t* ioSize); //nyi
// string value access
virtual status_t setValueFrom(const char* text);
virtual status_t getString(BString& buffer);
public:
virtual void MessageReceived(BMessage* message);
protected: // internal operations
virtual void _SetDefaultConstraints(bool negativeVisible);
private:
int64 _ValueFixed() const; //nyi
// calculates the current value as an int64
void _SetValueFixed(int64 fixed); //nyi
// sets the value of each segment based on an int64 value;
// does not constrain the value
void getConstraints(
double* outMinValue,
double* outMaxValue);
protected:
// double m_dfValue; removed 18sep99
// +++++ the current value is not yet re-constrained by this call
BContinuousParameter* fParam;
// bound parameter
uint16 fWholeDigits;
uint16 fFractionalDigits;
// constraints
int64 fMinFixed;
int64 fMaxFixed;
status_t setConstraints(
double minValue,
double maxValue);
// fetches the current value (calculated on the spot from each
// segment.)
double value() const;
// set the displayed value (and, if setParam is true, the
// linked parameter.) The value will be constrained if necessary.
void setValue(
double value,
bool setParam=false);
public: // segment interface
// 18sep99: old segment interface
// virtual void offsetValue(double dfDelta);
// 18sep99: new segment interface. 'offset' is given
// in the segment's units.
virtual void offsetSegmentValue(
ValControlDigitSegment* segment,
int64 offset);
public: // hooks
virtual void mediaParameterChanged();
// writes the stored value to the bound parameter
virtual void updateParameter(
double value);
virtual void initSegments();
virtual void initConstraintsFromParam();
public: // ValControl impl.
void setValue(
const void* data,
size_t size); //nyi
void getValue(
void* data,
size_t* ioSize); //nyi
// * string value access
virtual status_t setValueFrom(
const char* text);
virtual status_t getString(
BString& buffer);
public: // BHandler impl.
virtual void MessageReceived(
BMessage* message);
protected: // internal operations
virtual void setDefaultConstraints(
bool negativeVisible);
private: // guts
// calculates the current value as an int64
int64 _value_fixed() const; //nyi
// sets the value of each segment based on an int64 value;
// does not constrain the value
void _set_value_fixed(
int64 fixed); //nyi
protected: // members
// double m_dfValue; removed 18sep99
uint16 m_wholeDigits;
uint16 m_fractionalDigits;
// constraints
int64 m_minFixed;
int64 m_maxFixed;
// bound parameter
BContinuousParameter* m_param;
};
__END_CORTEX_NAMESPACE
#endif /* __NumericValControl_H__ */
#endif /* NUMERIC_VAL_CONTROL_H */

View File

@ -10,12 +10,14 @@
__USE_CORTEX_NAMESPACE
/*static*/
ValCtrlLayoutEntry ValCtrlLayoutEntry::decimalPoint(
DECIMAL_POINT_ENTRY, LAYOUT_NO_PADDING);
ValCtrlLayoutEntry ValCtrlLayoutEntry::decimalPoint(DECIMAL_POINT_ENTRY,
LAYOUT_NO_PADDING);
/*static*/
void ValCtrlLayoutEntry::InitChildFrame(ValCtrlLayoutEntry& e) {
if(e.pView) {
void
ValCtrlLayoutEntry::InitChildFrame(ValCtrlLayoutEntry& e)
{
if (e.pView) {
// PRINT((
// "### ValCtrlLayoutEntry::InitChildFrame(): (%.1f,%.1f)-(%.1f,%.1f)\n",
// e.frame.left, e.frame.top, e.frame.right, e.frame.bottom));
@ -23,7 +25,3 @@ void ValCtrlLayoutEntry::InitChildFrame(ValCtrlLayoutEntry& e) {
e.pView->ResizeTo(e.frame.Width(), e.frame.Height());
}
}
// END -- ValCtrlLayoutEntry.cpp --

View File

@ -3,93 +3,96 @@
// hide this class!
//
// e.moon 28jan99
#ifndef VAL_CTRL_LAYOUT_ENTRY_H
#define VAL_CTRL_LAYOUT_ENTRY_H
#ifndef __VALCTRLLAYOUTENTRY_H__
#define __VALCTRLLAYOUTENTRY_H__
#include "cortex_defs.h"
#include <View.h>
#include "cortex_defs.h"
__BEGIN_CORTEX_NAMESPACE
// a ValCtrlLayoutEntry manages the layout state information for
// a single child view
class ValCtrlLayoutEntry {
friend class ValControl;
public:
friend class ValControl;
public: // static instances
static ValCtrlLayoutEntry decimalPoint;
public: // static instances
static ValCtrlLayoutEntry decimalPoint;
public:
enum entry_type {
SEGMENT_ENTRY,
VIEW_ENTRY,
DECIMAL_POINT_ENTRY
};
public:
enum entry_type {
SEGMENT_ENTRY,
VIEW_ENTRY,
DECIMAL_POINT_ENTRY
};
enum layout_flags {
LAYOUT_NONE =0,
LAYOUT_NO_PADDING =1, // disables left/right padding
};
enum layout_flags {
LAYOUT_NONE = 0,
LAYOUT_NO_PADDING = 1, // disables left/right padding
};
public:
// stl compatibility ctor
ValCtrlLayoutEntry() {}
// standard: yes, the frame is left invalid; that's for
// ValControl::insertEntry() to fix
ValCtrlLayoutEntry(BView* _pView, entry_type t,
layout_flags f=LAYOUT_NONE) :
pView(_pView),
type(t),
flags(f),
fPadding(0.0) {}
ValCtrlLayoutEntry(entry_type t,
layout_flags f=LAYOUT_NONE) :
pView(0),
type(t),
flags(f),
fPadding(0.0) {}
ValCtrlLayoutEntry(const ValCtrlLayoutEntry& clone) {
operator=(clone);
}
ValCtrlLayoutEntry& operator=(const ValCtrlLayoutEntry& clone) {
type = clone.type;
flags = clone.flags;
pView = clone.pView;
frame = clone.frame;
fPadding = clone.fPadding;
return *this;
}
// order first by x position, then by y:
bool operator<(const ValCtrlLayoutEntry& b) const {
return frame.left < b.frame.left ||
frame.top < b.frame.top;
}
public:
ValCtrlLayoutEntry() {}
// stl compatibility ctor
protected:
// move & size ref'd child view to match 'frame'
static void InitChildFrame(ValCtrlLayoutEntry& e);
// standard: yes, the frame is left invalid; that's for
// ValControl::insertEntry() to fix
ValCtrlLayoutEntry(BView* _pView, entry_type t,
layout_flags f = LAYOUT_NONE)
:
pView(_pView),
type(t),
flags(f),
fPadding(0.0)
{}
public:
BView* pView;
entry_type type;
layout_flags flags;
ValCtrlLayoutEntry(entry_type t, layout_flags f = LAYOUT_NONE)
:
pView(0),
type(t),
flags(f),
fPadding(0.0)
{}
ValCtrlLayoutEntry(const ValCtrlLayoutEntry& clone) {
operator=(clone);
}
// layout state info (filled in by ValControl):
BRect frame;
float fPadding;
ValCtrlLayoutEntry& operator=(const ValCtrlLayoutEntry& clone) {
type = clone.type;
flags = clone.flags;
pView = clone.pView;
frame = clone.frame;
fPadding = clone.fPadding;
return *this;
}
// order first by x position, then by y:
bool operator<(const ValCtrlLayoutEntry& b) const {
return frame.left < b.frame.left ||
frame.top < b.frame.top;
}
protected:
// move & size ref'd child view to match 'frame'
static void InitChildFrame(ValCtrlLayoutEntry& e);
public:
BView* pView;
entry_type type;
layout_flags flags;
// layout state info (filled in by ValControl):
BRect frame;
float fPadding;
};
__END_CORTEX_NAMESPACE
#endif /* __VALCTRLLAYOUTENTRY_H__ */
#endif // VAL_CTRL_LAYOUT_ENTRY_H

View File

@ -11,13 +11,13 @@
//
// * HISTORY
// e.moon 25jun99 Begun
#ifndef CORTEX_DEFS_H
#define CORTEX_DEFS_H
#ifndef __cortex_defs_h__
#define __cortex_defs_h__
#include <SupportDefs.h>
// *** namespace support
// namespace support
#ifdef CORTEX_NAMESPACE
#define __BEGIN_CORTEX_NAMESPACE namespace CORTEX_NAMESPACE {
#define __END_CORTEX_NAMESPACE }
@ -33,7 +33,7 @@
#define TOUCH(x) ((void)(x))
// *** message 'what' code base values
// message 'what' code base values
const uint32 NodeManager_message_base = 'NMaA';
const uint32 NodeManager_int_message_base = 'Nm_A';
@ -63,4 +63,4 @@ const uint32 InfoView_message_base = 'InVA';
const uint32 ParameterWindow_message_base = 'PaWA';
#endif /*__cortex_defs_h__*/
#endif // CORTEX_DEFS_H