/*--------------------------------------------------------------------------------*/ AudioObjectParameters& AudioObjectParameters::Modify(const Modifier& modifier, const ADMAudioObject *object) { if (modifier.rotation.IsSet()) { SetPosition(GetPosition() * modifier.rotation.Get()); if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.rotation.Get()); if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.rotation.Get()); Position size(GetWidth(), GetDepth(), GetHeight()); size *= modifier.rotation.Get(); SetWidth(static_cast<float>(size.pos.x)); SetDepth(static_cast<float>(size.pos.y)); SetHeight(static_cast<float>(size.pos.z)); } if (modifier.position.IsSet()) SetPosition(GetPosition() + modifier.position.Get()); if (modifier.scale.IsSet()) { SetPosition(GetPosition() * modifier.scale.Get()); if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.scale.Get()); if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.scale.Get()); Position size(GetWidth(), GetDepth(), GetHeight()); size *= modifier.scale.Get(); SetWidth(static_cast<float>(size.pos.x)); SetDepth(static_cast<float>(size.pos.y)); SetHeight(static_cast<float>(size.pos.z)); } if (modifier.gain.IsSet()) SetGain(GetGain() * modifier.gain.Get()); // apply specific modifications (from derived classes) modifier.Modify(*this, object); return *this; }
void AudioObjectParameters::MultiplyByScene(float width, float height, float depth) { Position pos = GetPosition().Cart(); pos.pos.x *= width; pos.pos.y *= depth; pos.pos.z *= height; SetPosition(GetPosition().polar ? pos.Polar() : pos); if (IsMinPositionSet()) { Position pos = GetMinPosition().Cart(); pos.pos.x *= width; pos.pos.y *= depth; pos.pos.z *= height; SetMinPosition(GetMinPosition().polar ? pos.Polar() : pos); } if (IsMaxPositionSet()) { Position pos = GetMaxPosition().Cart(); pos.pos.x *= width; pos.pos.y *= depth; pos.pos.z *= height; SetMaxPosition(GetMaxPosition().polar ? pos.Polar() : pos); } SetWidth(GetWidth() * width); SetHeight(GetHeight() * height); SetDepth(GetDepth() * depth); if (excludedZones) excludedZones->MultiplyByScene(width, height, depth); }
/*--------------------------------------------------------------------------------*/ void AudioObjectParameters::DivideByScene(float width, float height, float depth) { Position pos = GetPosition().Cart(); pos.pos.x /= width; pos.pos.y /= depth; pos.pos.z /= height; SetPosition(GetPosition().polar ? pos.Polar() : pos); if (IsMinPositionSet()) { Position pos = GetMinPosition().Cart(); pos.pos.x /= width; pos.pos.y /= depth; pos.pos.z /= height; SetMinPosition(GetMinPosition().polar ? pos.Polar() : pos); } if (IsMaxPositionSet()) { Position pos = GetMaxPosition().Cart(); pos.pos.x /= width; pos.pos.y /= depth; pos.pos.z /= height; SetMaxPosition(GetMaxPosition().polar ? pos.Polar() : pos); } SetWidth(GetWidth() / width); SetHeight(GetHeight() / height); SetDepth(GetDepth() / depth); if (excludedZones) excludedZones->DivideByScene(width, height, depth); }
void nsSliderFrame::PageUpDown(nscoord change) { // on a page up or down get our page increment. We get this by getting the scrollbar we are in and // asking it for the current position and the page increment. If we are not in a scrollbar we will // get the values from our own node. nsIBox* scrollbarBox = GetScrollbar(); nsCOMPtr<nsIContent> scrollbar; scrollbar = GetContentOfBox(scrollbarBox); if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir, nsGkAtoms::reverse, eCaseMatters)) change = -change; nscoord pageIncrement = GetPageIncrement(scrollbar); PRInt32 curpos = GetCurrentPosition(scrollbar); PRInt32 minpos = GetMinPosition(scrollbar); PRInt32 maxpos = GetMaxPosition(scrollbar); // get the new position and make sure it is in bounds PRInt32 newpos = curpos + change * pageIncrement; if (newpos < minpos || maxpos < minpos) newpos = minpos; else if (newpos > maxpos) newpos = maxpos; SetCurrentPositionInternal(scrollbar, newpos, PR_TRUE, PR_FALSE); }
/*--------------------------------------------------------------------------------*/ bool AudioObjectParameters::operator == (const AudioObjectParameters& obj) const { bool same = ((position == obj.position) && (memcmp(&values, &obj.values, sizeof(obj.values)) == 0) && Compare(excludedZones, obj.excludedZones) && (GetMinPosition() == obj.GetMinPosition()) && (GetMaxPosition() == obj.GetMaxPosition()) && (othervalues == obj.othervalues)); #if BBCDEBUG_LEVEL>=4 if (!same) { BBCDEBUG("Compare: %u/%u/%u/%u/%08x/%08x", (uint_t)(position == obj.position), (uint_t)(memcmp(&values, &obj.values, sizeof(obj.values)) == 0), (uint_t)Compare(excludedZones, obj.excludedZones), (uint_t)(othervalues == obj.othervalues), setbitmap, obj.setbitmap); std::string line; const uint8_t *p1 = (const uint8_t *)&values, *p2 = (const uint8_t *)&obj.values; uint_t i; for (i = 0; i < sizeof(values); i++) { if (line.empty()) { Printf(line, "%04x:", i); } Printf(line, " %02x/%02x", (uint_t)p1[i], (uint_t)p2[i]); if ((i & 7) == 7) { BBCDEBUG("%s", line.c_str()); line = ""; } } if (!line.empty()) BBCDEBUG("%s", line.c_str()); } #endif return same; }
bool ModPlugin::open( const QString &_file ) { MemFile f( _file ); if ( !f.open( IO_ReadOnly ) ) return false; CSoundFile::SetWaveConfig( s_frequency, s_bytesPerSample * 8, s_channels ); CSoundFile::SetWaveConfigEx( false, /* surround */ true, /* no oversampling */ false, /* reverb */ true, /* high quality resampler */ true, /* megabass ;) */ true, /* noise reduction */ false /* some eq stuff I didn't really understand..*/ ); CSoundFile::SetResamplingMode( SRCMODE_POLYPHASE ); QByteArray &rawData = f.data(); if ( !Create( reinterpret_cast<BYTE *>( rawData.data() ), rawData.size() ) ) return false; m_songTime = GetSongTime(); m_maxPosition = GetMaxPosition(); return true; }
void main(void) { TRISB = 0; TRISC = 1; TRISD = 0; PORTD = 0; SetClockBase(CLOCK_20MHz); SetPulseWidth(1000, 2000); SetServoScale(0, 180); posMin = GetMinPosition(); posMax = GetMaxPosition(); InitServos(4, (char) &PORTB); MoveAllServos(180); Delay10KTCYx(150); MoveServoAsync(6, 5); Delay10KTCYx(150); MoveServoAsync(6, 5); }
// Use this function when you know the target scroll position of the scrolled content. // aNewPos should be passed to this function as a position as if the minpos is 0. // That is, the minpos will be added to the position by this function. In a reverse // direction slider, the newpos should be the distance from the end. void nsSliderFrame::SetCurrentPosition(nsIContent* aScrollbar, PRInt32 aNewPos, PRBool aIsSmooth, PRBool aImmediateRedraw) { // get min and max position from our content node PRInt32 minpos = GetMinPosition(aScrollbar); PRInt32 maxpos = GetMaxPosition(aScrollbar); // in reverse direction sliders, flip the value so that it goes from // right to left, or bottom to top. if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir, nsGkAtoms::reverse, eCaseMatters)) aNewPos = maxpos - aNewPos; else aNewPos += minpos; // get the new position and make sure it is in bounds if (aNewPos < minpos || maxpos < minpos) aNewPos = minpos; else if (aNewPos > maxpos) aNewPos = maxpos; SetCurrentPositionInternal(aScrollbar, aNewPos, aIsSmooth, aImmediateRedraw); }
// called when the current position changed and we need to update the thumb's location nsresult nsSliderFrame::CurrentPositionChanged(nsPresContext* aPresContext, PRBool aImmediateRedraw) { nsIBox* scrollbarBox = GetScrollbar(); nsCOMPtr<nsIContent> scrollbar; scrollbar = GetContentOfBox(scrollbarBox); // get the current position PRInt32 curPos = GetCurrentPosition(scrollbar); // do nothing if the position did not change if (mCurPos == curPos) return NS_OK; // get our current min and max position from our content node PRInt32 minPos = GetMinPosition(scrollbar); PRInt32 maxPos = GetMaxPosition(scrollbar); maxPos = NS_MAX(minPos, maxPos); curPos = NS_MAX(minPos, NS_MIN(curPos, maxPos)); // get the thumb's rect nsIFrame* thumbFrame = mFrames.FirstChild(); if (!thumbFrame) return NS_OK; // The thumb may stream in asynchronously via XBL. nsRect thumbRect = thumbFrame->GetRect(); nsRect clientRect; GetClientRect(clientRect); // figure out the new rect nsRect newThumbRect(thumbRect); PRBool reverse = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir, nsGkAtoms::reverse, eCaseMatters); nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos); if (IsHorizontal()) newThumbRect.x = clientRect.x + NSToCoordRound(pos * mRatio); else newThumbRect.y = clientRect.y + NSToCoordRound(pos * mRatio); // set the rect thumbFrame->SetRect(newThumbRect); // Redraw the scrollbar InvalidateWithFlags(clientRect, aImmediateRedraw ? INVALIDATE_IMMEDIATE : 0); mCurPos = curPos; // inform the parent <scale> if it exists that the value changed nsIFrame* parent = GetParent(); if (parent) { nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent()); if (sliderListener) { nsContentUtils::AddScriptRunner( new nsValueChangedRunnable(sliderListener, nsGkAtoms::curpos, mCurPos, mUserChanged)); } } return NS_OK; }
NS_IMETHODIMP nsSliderFrame::DoLayout(nsBoxLayoutState& aState) { // get the thumb should be our only child nsIBox* thumbBox = GetChildBox(); if (!thumbBox) { SyncLayout(aState); return NS_OK; } EnsureOrient(); #ifdef DEBUG_LAYOUT if (mState & NS_STATE_DEBUG_WAS_SET) { if (mState & NS_STATE_SET_TO_DEBUG) SetDebug(aState, PR_TRUE); else SetDebug(aState, PR_FALSE); } #endif // get the content area inside our borders nsRect clientRect; GetClientRect(clientRect); // get the scrollbar nsIBox* scrollbarBox = GetScrollbar(); nsCOMPtr<nsIContent> scrollbar; scrollbar = GetContentOfBox(scrollbarBox); // get the thumb's pref size nsSize thumbSize = thumbBox->GetPrefSize(aState); if (IsHorizontal()) thumbSize.height = clientRect.height; else thumbSize.width = clientRect.width; PRInt32 curPos = GetCurrentPosition(scrollbar); PRInt32 minPos = GetMinPosition(scrollbar); PRInt32 maxPos = GetMaxPosition(scrollbar); PRInt32 pageIncrement = GetPageIncrement(scrollbar); maxPos = NS_MAX(minPos, maxPos); curPos = NS_MAX(minPos, NS_MIN(curPos, maxPos)); nscoord& availableLength = IsHorizontal() ? clientRect.width : clientRect.height; nscoord& thumbLength = IsHorizontal() ? thumbSize.width : thumbSize.height; if ((pageIncrement + maxPos - minPos) > 0 && thumbBox->GetFlex(aState) > 0) { float ratio = float(pageIncrement) / float(maxPos - minPos + pageIncrement); thumbLength = NS_MAX(thumbLength, NSToCoordRound(availableLength * ratio)); } // Round the thumb's length to device pixels. nsPresContext* presContext = PresContext(); thumbLength = presContext->DevPixelsToAppUnits( presContext->AppUnitsToDevPixels(thumbLength)); // mRatio translates the thumb position in app units to the value. mRatio = (minPos != maxPos) ? float(availableLength - thumbLength) / float(maxPos - minPos) : 1; // in reverse mode, curpos is reversed such that lower values are to the // right or bottom and increase leftwards or upwards. In this case, use the // offset from the end instead of the beginning. PRBool reverse = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir, nsGkAtoms::reverse, eCaseMatters); nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos); // set the thumb's coord to be the current pos * the ratio. nsRect thumbRect(clientRect.x, clientRect.y, thumbSize.width, thumbSize.height); PRInt32& thumbPos = (IsHorizontal() ? thumbRect.x : thumbRect.y); thumbPos += NSToCoordRound(pos * mRatio); nsRect oldThumbRect(thumbBox->GetRect()); LayoutChildAt(aState, thumbBox, thumbRect); SyncLayout(aState); // Redraw only if thumb changed size. if (oldThumbRect != thumbRect) Redraw(aState); return NS_OK; }
NS_IMETHODIMP nsSliderFrame::AttributeChanged(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aModType) { nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType); // if the current position changes if (aAttribute == nsGkAtoms::curpos) { rv = CurrentPositionChanged(PresContext(), PR_FALSE); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to change position"); if (NS_FAILED(rv)) return rv; } else if (aAttribute == nsGkAtoms::minpos || aAttribute == nsGkAtoms::maxpos) { // bounds check it. nsIBox* scrollbarBox = GetScrollbar(); nsCOMPtr<nsIContent> scrollbar; scrollbar = GetContentOfBox(scrollbarBox); PRInt32 current = GetCurrentPosition(scrollbar); PRInt32 min = GetMinPosition(scrollbar); PRInt32 max = GetMaxPosition(scrollbar); // inform the parent <scale> that the minimum or maximum changed nsIFrame* parent = GetParent(); if (parent) { nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent()); if (sliderListener) { nsContentUtils::AddScriptRunner( new nsValueChangedRunnable(sliderListener, aAttribute, aAttribute == nsGkAtoms::minpos ? min : max, PR_FALSE)); } } if (current < min || current > max) { if (current < min || max < min) current = min; else if (current > max) current = max; // set the new position and notify observers nsIScrollbarFrame* scrollbarFrame = do_QueryFrame(scrollbarBox); if (scrollbarFrame) { nsIScrollbarMediator* mediator = scrollbarFrame->GetScrollbarMediator(); if (mediator) { mediator->PositionChanged(scrollbarFrame, GetCurrentPosition(scrollbar), current); } } nsAutoString currentStr; currentStr.AppendInt(current); nsContentUtils::AddScriptRunner( new nsSetAttrRunnable(scrollbar, nsGkAtoms::curpos, currentStr)); } } if (aAttribute == nsGkAtoms::minpos || aAttribute == nsGkAtoms::maxpos || aAttribute == nsGkAtoms::pageincrement || aAttribute == nsGkAtoms::increment) { PresContext()->PresShell()-> FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY); } return rv; }