// **************************************************************************** // // Function Name: RWHPTriple::operator=( ) // // Description: Assignment operator // // Returns: Reference to this color // // Exceptions: None // // **************************************************************************** const RWHPTriple& RWHPTriple::operator=( const RSolidColor& color ) { double flRed = color.GetRed() / 255.0 ; double flGreen = color.GetGreen() / 255.0 ; double flBlue = color.GetBlue() / 255.0 ; // Get the white fraction, the least component ; m_flWhite = min( flRed, min( flGreen, flBlue ) ) ; // Remove the white fraction from the components flRed -= m_flWhite ; flGreen -= m_flWhite ; flBlue -= m_flWhite ; // Get purity fraction, the largest of the components m_flPurity = max( flRed, max( flGreen, flBlue ) ) ; // Get Hue ////////// short nCmps = 0 ; if (flRed > 0) nCmps++ ; if (flGreen > 0) nCmps++ ; if (flBlue) nCmps++ ; if (nCmps == 1) // Simple case, one-component hue { if (flRed > 0) m_flHue = kRedPrimary ; if (flGreen > 0) m_flHue = kGreenPrimary ; if (flBlue) m_flHue = kBluePrimary ; } else { if (AreFloatsEqual( flBlue, 0.0 )) m_flHue = kRedPrimary + HueBetween( flRed, flGreen ) ; if (AreFloatsEqual( flGreen, 0.0 )) m_flHue = kBluePrimary + HueBetween( flBlue, flRed ) ; if (AreFloatsEqual( flRed, 0.0 )) m_flHue = kGreenPrimary + HueBetween( flGreen, flBlue ) ; } return *this ; }
double RWHPTriple::HueBetween( double flBelowWt, double flAboveWt ) { if (AreFloatsEqual( flAboveWt, 0.0 ) && AreFloatsEqual( flBelowWt, 0.0 )) { return (0.0) ; } if (flAboveWt > flBelowWt) { return (1.0 - 0.5 * flBelowWt / flAboveWt) ; } return (0.5 * flAboveWt / flBelowWt ) ; }
// **************************************************************************** // // Function Name: RResizeSelectionTracker::CalcScaleFactor( ) // // Description: Calculates the scale factor we have resized to given a // mouse point // // Returns: Scale factor // // Exceptions: None // // **************************************************************************** // RRealSize RResizeSelectionTracker::CalcScaleFactor( const RRealPoint& point ) const { // Adjust the mouse point to take into account the difference in the size of selection rect and object rect RRealPoint adjustedMousePoint = point + m_RectDelta; // Untransform the points. We really dont want to work in a tranformed reference frame RRealPoint transformedMousePoint = adjustedMousePoint * m_InverseTransform; RRealPoint transformedMouseDownPoint = m_MouseDownPoint * m_InverseTransform; RRealPoint transformedScalingCenter = m_ScalingCenter * m_InverseTransform; // Calculate a new scale factor RRealSize scaleFactor; if ( AreFloatsEqual((transformedMouseDownPoint.m_x-transformedScalingCenter.m_x), 0.0) ) scaleFactor.m_dx = 1.0; else scaleFactor.m_dx = ( transformedMousePoint.m_x - transformedScalingCenter.m_x ) / ( transformedMouseDownPoint.m_x - transformedScalingCenter.m_x ); if ( AreFloatsEqual( (transformedMouseDownPoint.m_y-transformedScalingCenter.m_y), 0.0) ) scaleFactor.m_dy = 1.0; else scaleFactor.m_dy = ( transformedMousePoint.m_y - transformedScalingCenter.m_y ) / ( transformedMouseDownPoint.m_y - transformedScalingCenter.m_y ); // If we are preserving aspect ratio, do so here if( m_fMaintainAspectRatio ) { if( scaleFactor.m_dx > scaleFactor.m_dy ) scaleFactor.m_dy = scaleFactor.m_dx; else scaleFactor.m_dx = scaleFactor.m_dy; // Constrain the scale factor ConstrainScaleFactor( scaleFactor ); } else { // Constrain the scale factor ConstrainScaleFactor( scaleFactor ); if ( m_fFixVertical ) scaleFactor.m_dy = 1.0; else if ( m_fFixHorizontal ) scaleFactor.m_dx = 1.0; } return scaleFactor; }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- inline bool AreVectorsEqual( const Vector2& a, const Vector2& b, float tolerance ) { if (AreFloatsEqual( a.x, b.x, tolerance ) && AreFloatsEqual( a.y, b.y, tolerance ) ) return true; return false; }
// **************************************************************************** // // Function Name: RWHPTriple::operator( ) // // Description: Conversion operator // // Returns: A Renaissance RSolidColor object // // Exceptions: None // // **************************************************************************** RWHPTriple::operator RSolidColor() const { double flBelowHuePrimary, flHueFrac ; double flBelowHueWt, flAboveHueWt ; double flMaxWt, flScale ; // Get component ration from hue flBelowHuePrimary = (short) m_flHue ; flHueFrac = m_flHue - flBelowHuePrimary ; if (AreFloatsEqual( flHueFrac, 0.0 )) { flBelowHueWt = 1.0 ; flAboveHueWt = 0.0 ; } else if (flHueFrac > 0.5) { flAboveHueWt = 1.0 ; // Simplifying assumption flBelowHueWt = (1.0 - flHueFrac) / 0.5 ; } else { flBelowHueWt = 1.0 ; // Simplifying assumption flAboveHueWt = flHueFrac * flBelowHueWt / 0.5 ; } // Scale to purity flMaxWt = flBelowHueWt ; if (flAboveHueWt > flMaxWt) { flMaxWt = flAboveHueWt ; } flScale = m_flPurity / flMaxWt ; flBelowHueWt *= flScale ; flAboveHueWt *= flScale ; // Assign to components double flRed(0.0), flGreen(0.0), flBlue(0.0) ; if (AreFloatsEqual( flBelowHuePrimary, kRedPrimary )) { flRed = flBelowHueWt ; flGreen = flAboveHueWt ; } if (AreFloatsEqual( flBelowHuePrimary, kGreenPrimary )) { flGreen = flBelowHueWt ; flBlue = flAboveHueWt ; } if (AreFloatsEqual( flBelowHuePrimary, kBluePrimary )) { flBlue = flBelowHueWt ; flRed = flAboveHueWt ; } // Add back white fraction flRed += m_flWhite; TpsAssert( 0.0 <= flRed && flRed <= 1.001, "Invalid Component!" ) ; flGreen += m_flWhite; TpsAssert( 0.0 <= flGreen && flGreen <= 1.001, "Invalid Component!" ) ; flBlue += m_flWhite; TpsAssert( 0.0 <= flBlue && flBlue <= 1.001, "Invalid Component!" ) ; RSolidColor crResult( YColorComponent( flRed * 255.0 + 0.5 ), YColorComponent( flGreen * 255.0 + 0.5 ), YColorComponent( flBlue * 255.0 + 0.5 ) ) ; return crResult ; }
// **************************************************************************** // // Function Name: RSingleSelection::HitTest( ) // // Description: Hits test this selection // // Returns: The location of this selection that was hit // // Exceptions: Memory // // **************************************************************************** // RSelection::EHitLocation RSingleSelection::HitTest( const RRealPoint& point ) const { RRealRect rect; RRealSize scaleFactor(kDummyScale,kDummyScale); // This is just to be able to see if the object is constrainted scaleFactor = m_pSelectedObject->ApplyResizeConstraint( scaleFactor ); // Get the component attributes const RComponentAttributes& componentAttributes = m_pSelectedObject->GetComponentAttributes( ); if( componentAttributes.IsResizable( ) ) { R2dTransform transform; // Test the resize handles GetResizeSelectionHandle( rect, transform, kTopLeftResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kTopLeftResizeHandle; GetResizeSelectionHandle( rect, transform, kTopRightResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kTopRightResizeHandle; GetResizeSelectionHandle( rect, transform, kBottomRightResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kBottomRightResizeHandle; GetResizeSelectionHandle( rect, transform, kBottomLeftResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kBottomLeftResizeHandle; if ( !AreFloatsEqual( scaleFactor.m_dy, kConstrainedScale ) ) { GetResizeSelectionHandle( rect, transform, kTopResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kTopResizeHandle; GetResizeSelectionHandle( rect, transform, kBottomResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kBottomResizeHandle; } if ( !AreFloatsEqual( scaleFactor.m_dx, kConstrainedScale ) ) { GetResizeSelectionHandle( rect, transform, kRightResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kRightResizeHandle; GetResizeSelectionHandle( rect, transform, kLeftResizeHandle, FALSE ); if( rect.PointInRect( point ) ) return kLeftResizeHandle; } } // Test the selection rect if( componentAttributes.IsMovable( ) ) { if( m_pSelectedObject->HitTestSelectionFrame( point ) ) return kInside; } // Test the rotate handle if( componentAttributes.IsRotatable( ) ) { RRealVectorRect vRect; GetRotateHandle( vRect ); if( vRect.PointInRect( point ) ) return kRotateHandle; } return kNothing; }
// **************************************************************************** // // Function Name: RSingleSelection::Render( ) // // Description: Draws the selection rect and handles // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RIntRect& rcRender, BOOLEAN fRenderIfLocked ) const { // Get the component attributes const RComponentAttributes& componentAttributes = m_pSelectedObject->GetComponentAttributes( ); BOOLEAN fIsLocked = componentAttributes.IsLocked( ); if( fRenderIfLocked || !fIsLocked ) { // Set surface attributes drawingSurface.SetPenWidth( kSelectionOutlineWidth ); drawingSurface.SetPenStyle( kSolidPen ); RRealRect resizeHandleRect; // Draw the resize handles if( componentAttributes.IsResizable( FALSE ) ) { RArray<RRealRect> rectList; RRealSize scaleFactor( kDummyScale, kDummyScale ); scaleFactor = m_pSelectedObject->ApplyResizeConstraint( scaleFactor ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kBottomRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kBottomLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); if ( !AreFloatsEqual( scaleFactor.m_dy, kConstrainedScale ) ) { GetResizeSelectionHandle( resizeHandleRect, transform, kBottomResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); } if ( !AreFloatsEqual( scaleFactor.m_dx, kConstrainedScale ) ) { GetResizeSelectionHandle( resizeHandleRect, transform, kRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); } RArray<RRealRect>::YIterator iterator = rectList.Start( ); RArray<RRealRect>::YIterator iteratorEnd = rectList.End( ); if( fIsLocked ) { while ( iterator != iteratorEnd ) drawingSurface.FrameRectangle( *iterator++ ); } else { while ( iterator != iteratorEnd ) drawingSurface.FillRectangle( *iterator++ ); } } // Draw the rotate line and handle if( componentAttributes.IsRotatable( ) ) DrawRotateHandle( drawingSurface, transform, rcRender ); // Draw the selection frame m_pSelectedObject->DrawSelectionFrame( drawingSurface, transform ); } }