[Chlor-commits] SF.net SVN: chlor: [488] trunk/src/core
Status: Pre-Alpha
Brought to you by:
lenny222
From: Chlor c. to s. <chl...@li...> - 2007-03-22 18:11:35
|
Revision: 488 http://svn.sourceforge.net/chlor/?rev=488&view=rev Author: lenny222 Date: 2007-03-22 11:11:25 -0700 (Thu, 22 Mar 2007) Log Message: ----------- readd selection observation but fix CGroups fill and stroke methods Modified Paths: -------------- trunk/src/core/CGroup.m trunk/src/core/ChlorApplication.m Modified: trunk/src/core/CGroup.m =================================================================== --- trunk/src/core/CGroup.m 2007-03-22 17:49:03 UTC (rev 487) +++ trunk/src/core/CGroup.m 2007-03-22 18:11:25 UTC (rev 488) @@ -101,6 +101,12 @@ // Invalidate the shape boundary. [self shapeBoundaryChanged: nil]; + + // Invalidate fill and stroke. + [m_fill release]; + m_fill = nil; + [m_stroke release]; + m_stroke = nil; } - (void) addGroup: (CGroup*) aGroup withZOrder: (NSIndexSet*) zOrder @@ -110,9 +116,15 @@ @"Group and zOrder array aren't symmetric (differently sized)." ); [m_objects insertObjects:[aGroup objects] atIndexes: zOrder]; - + // Invalidate the shape boundary. [self shapeBoundaryChanged: nil]; + + // Invalidate fill and stroke. + [m_fill release]; + m_fill = nil; + [m_stroke release]; + m_stroke = nil; } - (void) clear @@ -184,6 +196,28 @@ return m_drawingBoundary; } +- (CFill*) fill +{ + // Return fill if there is one. + if( m_fill != nil ) + return m_fill; + + // If there is exactly one child, copy and use its fill. + if( [self count] == 1 ) + { + m_fill = [[(CObject*) [m_objects objectAtIndex: 0] fill] copy]; + } + // Group containts more than one or no children. + else + { + // TODO: use the "unknown" fill. + [m_fill release]; + m_fill = nil; + } + + return m_fill; +} + - (CObject*) first { return [m_objects objectAtIndex: 0]; @@ -228,6 +262,12 @@ // Invalidate the shape boundary. [self shapeBoundaryChanged: nil]; + + // Invalidate fill and stroke. + [m_fill release]; + m_fill = nil; + [m_stroke release]; + m_stroke = nil; } - (void) setFill: (CFill*) theFill @@ -316,6 +356,28 @@ [anObject show]; } +- (CStroke*) stroke +{ + // Return stroke if there is one. + if( m_stroke != nil ) + return m_stroke; + + // If there is exactly one child, copy and use its stroke. + if( [self count] == 1 ) + { + m_stroke = [[(CObject*) [m_objects objectAtIndex: 0] stroke] copy]; + } + // Group containts more than one or no children. + else + { + // TODO: use the "unknown" stroke. + [m_stroke release]; + m_stroke = nil; + } + + return m_stroke; +} + - (NSIndexSet *) zOrderOfGroup: (CGroup*) otherGroup { NSAssert( Modified: trunk/src/core/ChlorApplication.m =================================================================== --- trunk/src/core/ChlorApplication.m 2007-03-22 17:49:03 UTC (rev 487) +++ trunk/src/core/ChlorApplication.m 2007-03-22 18:11:25 UTC (rev 488) @@ -35,6 +35,13 @@ { m_fill = nil; m_stroke = nil; + + // Get fill and stroke from the selection when it got modified. + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector( selectionFillStrokeChanged: ) + name: CSelectionChangedNotification + object: nil]; } return self; @@ -57,6 +64,21 @@ return (ChlorApplication*) [NSApplication sharedApplication]; } +- (void) selectionFillStrokeChanged: (NSNotification*) theNotification +{ + NSAssert( [[theNotification object] isKindOfClass: [CSelection class]], @"Object must be a CSelection!" ); + + CSelection* selection = (CSelection*) [theNotification object]; + + // Don't get fill/stroke if selection is empty. + if( [selection isEmpty] ) + return; + + // Set copy of selection's fill and stroke. + [self setFill: [[[selection fill] copy] autorelease]]; + [self setStroke: [[[selection stroke] copy] autorelease]]; +} + - (void) setFill: (CFill*) theFill { [theFill retain]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |