00001 // $Id: sgstroke.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // SGStroke.cpp - definitions for line gallery classes for handling new-style Stroke attributes 00099 00100 #include "camtypes.h" 00101 00102 #include "sgstroke.h" 00103 00104 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 #include "lineattr.h" 00106 //#include "paths.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "ppstroke.h" 00108 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 #include "strkattr.h" 00110 00111 #include "dlgcol.h" 00112 00113 #include "qualattr.h" 00114 #include "ppvecstr.h" 00115 00116 #include "ndoptmz.h" 00117 //#include "rik.h" 00118 #include "brushmsg.h" 00119 00120 CC_IMPLEMENT_DYNAMIC(StrokeTypeItem, LineAttrItem); 00121 CC_IMPLEMENT_DYNAMIC(VarWidthItem, LineAttrItem); 00122 00123 00124 #define new CAM_DEBUG_NEW 00125 00126 00127 /******************************************************************************************** 00128 00129 > StrokeTypeItem::StrokeTypeItem(StrokeTypeAttrValue *pStroke, const String &strDescription) 00130 00131 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00132 Created: 3/3/97 00133 Inputs: pStroke - a pointer to an attribute to be used for this 00134 stroke type. This now belongs to the StrokeTypeItem, 00135 so you must not delete it 00136 strDescription - a text description of this user-interface item 00137 Outputs: - 00138 Returns: - 00139 Purpose: Constructs a user-interface item representing a stroke type 00140 00141 ********************************************************************************************/ 00142 00143 StrokeTypeItem::StrokeTypeItem(StrokeTypeAttrValue *pStroke, const String &strDescription) 00144 : LineAttrItem(strDescription, BELOW) 00145 { 00146 ERROR3IF(pStroke == NULL, "Illegal NULL param"); 00147 pStrokeDef = pStroke; 00148 } 00149 00150 00151 00152 /******************************************************************************************** 00153 00154 > StrokeTypeItem::~StrokeTypeItem() 00155 00156 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00157 Created: 3/3/97 00158 00159 Purpose: Destructor 00160 00161 ********************************************************************************************/ 00162 00163 StrokeTypeItem::~StrokeTypeItem() 00164 { 00165 if (pStrokeDef != NULL) 00166 delete pStrokeDef; 00167 } 00168 00169 00170 00171 /******************************************************************************************** 00172 00173 > virtual void StrokeTypeItem::SetAttributes(RenderRegion* pRegion) const 00174 00175 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00176 Created: 3/3/97 00177 00178 Inputs: pRegion - the render-region to draw into 00179 00180 Purpose: Sets the stroke typeattributes in the given render-region to render this 00181 item correctly. 00182 00183 ********************************************************************************************/ 00184 00185 void StrokeTypeItem::SetAttributes(RenderRegion* pRegion) const 00186 { 00187 // Set a 16pt line width - nice & thick 00188 pRegion->SetLineWidth(16000); 00189 00190 // Set the line width (this overrides the "default" line width set by the caller). 00191 pStrokeDef->Render(pRegion, FALSE); 00192 } 00193 00194 00195 00196 /******************************************************************************************** 00197 00198 > virtual NodeAttribute *StrokeTypeItem::CreateNewAttribute(BOOL) const 00199 00200 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00201 Created: 3/3/97 00202 00203 Returns: A pointer to a NodeAttribute-derivative that this user-interface item 00204 represents, ie. a line-width attribute that can be passed to the 00205 attribute manager. 00206 00207 Purpose: Create a NodeAttribute representing the attribute this item applies 00208 00209 ********************************************************************************************/ 00210 00211 NodeAttribute *StrokeTypeItem::CreateNewAttribute(BOOL) const 00212 { 00213 return(pStrokeDef->MakeNode()); 00214 } 00215 00216 00217 00218 /******************************************************************************************** 00219 00220 > virtual MILLIPOINT StrokeTypeItem::GetWidth() const 00221 00222 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00223 Created: 3/3/97 00224 Inputs: - 00225 Outputs: - 00226 Returns: The width of a line-width item, in millipoints. 00227 Purpose: Called by the line gallery formatting code. 00228 00229 ********************************************************************************************/ 00230 00231 MILLIPOINT StrokeTypeItem::GetWidth() const 00232 { 00233 return 2 * LineAttrItem::GetWidth() / 3; 00234 } 00235 00236 00237 00238 /******************************************************************************************** 00239 00240 > virtual CCRuntimeClass** StrokeTypeItem::GetAttribRuntimeClasses() const 00241 00242 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00243 Created: 3/3/97 00244 Inputs: - 00245 Outputs: - 00246 Returns: The run-time class of the line attribute this type of display item 00247 represents. 00248 Purpose: Used when searching for display items representing the selection's current 00249 attributes. 00250 00251 ********************************************************************************************/ 00252 00253 CCRuntimeClass** StrokeTypeItem::GetAttribRuntimeClasses() const 00254 { 00255 static CCRuntimeClass* aprtc[] = 00256 { 00257 CC_RUNTIME_CLASS(AttrStrokeType), 00258 NULL 00259 }; 00260 00261 return aprtc; 00262 } 00263 00264 00265 00266 /******************************************************************************************** 00267 00268 > virtual BOOL StrokeTypeItem::IsEqualValueToAny(NodeAttribute** ppOtherAttribs) const 00269 00270 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00271 Created: 3/3/97 00272 Inputs: pOtherAttrib the attribute value to compare this item to 00273 Outputs: - 00274 Returns: TRUE if this item represents the same attribute value as the given 00275 attribute. 00276 Purpose: Used when searching for display items representing the selection's current 00277 attributes. 00278 00279 ********************************************************************************************/ 00280 00281 BOOL StrokeTypeItem::IsEqualValueToAny(NodeAttribute** ppOtherAttribs) const 00282 { 00283 if (*ppOtherAttribs == NULL) // When multiple attribs are selected, this will be NULL 00284 return(FALSE); 00285 00286 AttrStrokeType* pAttr = (AttrStrokeType *) *ppOtherAttribs; 00287 ERROR3IF(!pAttr->IsKindOf(CC_RUNTIME_CLASS(AttrStrokeType)), 00288 "StrokeTypeItem::IsEqualValueToAny - unexpected object type"); 00289 00290 if (pAttr != NULL) 00291 { 00292 StrokeTypeAttrValue *pOther = (StrokeTypeAttrValue *) pAttr->GetAttributeValue(); 00293 return((*pStrokeDef) == (*pOther)); 00294 } 00295 00296 return(FALSE); 00297 } 00298 00299 00300 00301 /******************************************************************************************** 00302 00303 > virtual MILLIPOINT StrokeTypeItem::GetHorzGap() const 00304 00305 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00306 Created: 3/3/97 00307 00308 Returns: The horizontal gap between this item and another item of the same type, in 00309 millipoints. 00310 Purpose: Called by the formatting code to determine the gap between items of this type 00311 00312 ********************************************************************************************/ 00313 00314 MILLIPOINT StrokeTypeItem::GetHorzGap() const 00315 { 00316 // I would like the gap to be the same all the way around 00317 return(GetVertGap()); 00318 } 00319 00320 00321 /******************************************************************************************** 00322 00323 > virtual BOOL StrokeTypeItem::IsRepeating() 00324 00325 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00326 Created: 6/3/97 00327 00328 Returns: TRUE if the stroke is a repeating stroke. 00329 Purpose: Determins if the stroke repeats 00330 00331 ********************************************************************************************/ 00332 00333 BOOL StrokeTypeItem::IsRepeating() 00334 { 00335 BOOL Repeating = FALSE; 00336 StrokeDefinition *pStroke = GetStrokeDefinition(); 00337 if (pStroke != NULL) 00338 { 00339 Repeating = pStroke->IsRepeating(); 00340 } 00341 00342 return Repeating; 00343 } 00344 00345 /******************************************************************************************** 00346 00347 > virtual INT32 StrokeTypeItem::NumRepeats() 00348 00349 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00350 Created: 6/3/97 00351 00352 Returns: Number of times the brush should be repeated along the line. If 0, then we 00353 work out the best based on the aspect ratio and line thickness. 00354 Purpose: See Returns. 00355 00356 ********************************************************************************************/ 00357 00358 INT32 StrokeTypeItem::NumRepeats() 00359 { 00360 INT32 Repeats = 0; 00361 StrokeDefinition *pStroke = GetStrokeDefinition(); 00362 if (pStroke != NULL) 00363 { 00364 Repeats = pStroke->NumRepeats(); 00365 } 00366 00367 return Repeats; 00368 } 00369 00370 /******************************************************************************************** 00371 00372 > virtual BOOL StrokeTypeItem::OverridesFill() 00373 00374 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00375 Created: 6/3/97 00376 00377 Returns: TRUE if the stroke's overrides fill flag is set 00378 Purpose: Determins if the stroke overrides the fill or not 00379 00380 ********************************************************************************************/ 00381 00382 BOOL StrokeTypeItem::OverridesFill() 00383 { 00384 BOOL OverridesFill = FALSE; 00385 StrokeDefinition *pStroke = GetStrokeDefinition(); 00386 if (pStroke != NULL) 00387 { 00388 OverridesFill = pStroke->OverrideFill(); 00389 } 00390 00391 return OverridesFill; 00392 } 00393 00394 /******************************************************************************************** 00395 00396 > virtual BOOL StrokeTypeItem::OverridesTrans() 00397 00398 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00399 Created: 6/3/97 00400 00401 Returns: TRUE if the stroke's overrides transparency flag is set 00402 Purpose: Determins if the stroke overrides transparency or not 00403 00404 ********************************************************************************************/ 00405 00406 BOOL StrokeTypeItem::OverridesTrans() 00407 { 00408 BOOL OverridesTrans = FALSE; 00409 StrokeDefinition *pStroke = GetStrokeDefinition(); 00410 if (pStroke != NULL) 00411 { 00412 OverridesTrans = pStroke->OverrideTrans(); 00413 } 00414 00415 return OverridesTrans; 00416 } 00417 00418 /******************************************************************************************** 00419 00420 > virtual StrokeDefinition *StrokeTypeItem::GetStrokeDefinition() 00421 00422 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00423 Created: 6/3/97 00424 00425 Returns: The StrokeDefinition for this item 00426 Purpose: Get the StrokeDefinition for this item 00427 00428 ********************************************************************************************/ 00429 00430 StrokeDefinition *StrokeTypeItem::GetStrokeDefinition() 00431 { 00432 StrokeHandle Handle = GetStrokeHandle(); 00433 if(Handle != StrokeHandle(-1)) 00434 return StrokeComponent::FindStroke(Handle); 00435 00436 return NULL; 00437 } 00438 00439 /******************************************************************************************** 00440 00441 > virtual StrokeHandle StrokeTypeItem::GetStrokeHandle() 00442 00443 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00444 Created: 6/3/97 00445 00446 Returns: The StrokeHandle for this item, or StrokeHandle_NoStroke if strife 00447 Purpose: Get the StrokeHandle for this item 00448 00449 ********************************************************************************************/ 00450 00451 StrokeHandle StrokeTypeItem::GetStrokeHandle() 00452 { 00453 StrokeTypeAttrValue *pAttrValue = GetStrokeTypeAttrValue(); 00454 if(pAttrValue != NULL) 00455 { 00456 PathProcessorStroke *pProcessor = pAttrValue->GetPathProcessor(); 00457 if (pProcessor != NULL && pProcessor->IsKindOf(CC_RUNTIME_CLASS(PathProcessorStrokeVector))) 00458 { 00459 StrokeHandle Handle = ((PathProcessorStrokeVector *)pProcessor)->GetStrokeDefinition(); 00460 return Handle; 00461 } 00462 } 00463 00464 return StrokeHandle_NoStroke; 00465 } 00466 00467 00468 /******************************************************************************************** 00469 00470 > virtual void StrokeTypeItem::RenderItem(RenderRegion *pRender, DocRect *pDocRect) 00471 00472 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00473 Created: 6/3/97 00474 00475 Inputs: pRender - RenderRegion to render into 00476 pDocRect - Rectangle to render 00477 00478 Purpose: Renders a representation of the stroke into the given renderregion. This 00479 is used by the line properties dialog since all the stuff needed seems to 00480 be private... 00481 00482 ********************************************************************************************/ 00483 00484 void StrokeTypeItem::RenderItem(RenderRegion *pRender, DocRect *pDocRect, INT32 Width) 00485 { 00486 if(pRender == NULL || pDocRect == NULL) 00487 { 00488 ERROR3("StrokeTypeItem::RenderItem given null params"); 00489 return; 00490 } 00491 00492 pRender->SaveContext(); 00493 00494 // Make sure we're anti-aliasing 00495 Quality AntiAliasQuality(Quality::QualityMax); 00496 QualityAttribute AntiAliasQualityAttr(AntiAliasQuality); 00497 pRender->SetQuality(&AntiAliasQualityAttr,FALSE); 00498 00499 // Render the background rectangle 00500 DialogColourInfo RedrawColours; 00501 pRender->SetLineColour(RedrawColours.DialogBack()); 00502 pRender->SetFillColour(RedrawColours.DialogBack()); 00503 pRender->DrawRect(pDocRect); 00504 00505 // Draw the Saturation vs. Value square 00506 Path SquarePath; 00507 LinearFillAttribute ValueGradFill; 00508 LinearTranspFillAttribute TransFill; 00509 00510 ValueGradFill.Colour = DocColour(255L, 0L, 0L); 00511 ValueGradFill.EndColour = DocColour(255L, 255L, 255L); 00512 00513 DocCoord ThePoint(pDocRect->lo.x, pDocRect->hi.y); 00514 ValueGradFill.SetStartPoint(&ThePoint); 00515 ThePoint = DocCoord(pDocRect->hi.x, pDocRect->hi.y); 00516 ValueGradFill.SetEndPoint(&ThePoint); 00517 ValueGradFill.SetEndPoint2(NULL); 00518 00519 pRender->SetFillGeometry(&ValueGradFill, FALSE); // Set Grad-filled 00520 00521 //pRender->DrawRect(pDocRect); 00522 00523 /* SquarePath.Initialise(12, 12); 00524 SquarePath.FindStartOfPath(); 00525 00526 SquarePath.InsertMoveTo(ValSatSquare.lo); 00527 SquarePath.InsertLineTo(DocCoord(ValSatSquare.hi.x, ValSatSquare.lo.y)); 00528 SquarePath.InsertLineTo(ValSatSquare.hi); 00529 SquarePath.InsertLineTo(DocCoord(ValSatSquare.lo.x, ValSatSquare.hi.y)); 00530 SquarePath.IsFilled = TRUE; 00531 00532 pRender->DrawPath(&SquarePath); // Render the value square 00533 00534 // Render a white linear-grad-transparency square over the top to get the 00535 // effect of the Saturation gradient 00536 pRender->SetFillColour(DocColour(0L, 0L, 0L)); 00537 00538 // Set transparency to circular 0% at center, 100% at radius, && plot it 00539 TransFill.SetStartPoint(&ValSatSquare.hi); 00540 ThePoint = DocCoord(ValSatSquare.hi.x, ValSatSquare.lo.y); 00541 TransFill.SetEndPoint(&ThePoint); 00542 TransFill.SetEndPoint2(NULL); 00543 TransFill.Transp = 255; 00544 TransFill.EndTransp = 0; 00545 TransFill.TranspType = 2; // 'Stained glass' transparency 00546 00547 pRender->SetTranspFillGeometry(&TransFill, FALSE); 00548 */ 00549 00550 00551 pRender->SetLineColour(RedrawColours.TextFore()); 00552 00553 SetAttributes(pRender); 00554 pRender->SetLineWidth((INT32)((double)Width * 0.8)); 00555 DrawItem(pRender, *pDocRect); 00556 00557 pRender->RestoreContext(); 00558 } 00559 00560 00561 00562 /******************************************************************************************** 00563 00564 > virtual void StrokeTypeItem::UpdateGalleryItem() 00565 00566 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00567 Created: 6/3/97 00568 00569 Purpose: Updates the gallery item's cached data to represent any changes this 00570 Stoke might have had done to it. Also redraw the gallery if necessary. 00571 00572 ********************************************************************************************/ 00573 00574 void StrokeTypeItem::UpdateGalleryItem() 00575 { 00576 StrokeDefinition *pStroke = GetStrokeDefinition(); 00577 if(pStroke != NULL) 00578 { 00579 SetDescription(pStroke->GetStrokeName()); 00580 } 00581 00582 ForceRedrawOfMyself(); 00583 } 00584 00585 00586 00587 00588 00589 00590 /******************************************************************************************** 00591 00592 > VarWidthItem::VarWidthItem(VariableWidthAttrValue *pAttr, const String &strDescription) 00593 00594 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00595 Created: 3/3/97 00596 Inputs: pAttr - a pointer to an attribute to be used for this 00597 stroke type. This now belongs to the VarWidthItem, 00598 so you must not delete it 00599 strDescription - a text description of this user-interface item 00600 Outputs: - 00601 Returns: - 00602 Purpose: Constructs a user-interface item representing a stroke type 00603 00604 ********************************************************************************************/ 00605 00606 VarWidthItem::VarWidthItem(VariableWidthAttrValue *pAttr, const String &strDescription) 00607 : LineAttrItem(strDescription, BELOW) 00608 { 00609 ERROR3IF(pAttr == NULL, "Illegal NULL param"); 00610 pAttrDef = pAttr; 00611 } 00612 00613 00614 00615 /******************************************************************************************** 00616 00617 > StrokeTypeItem::~StrokeTypeItem() 00618 00619 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00620 Created: 3/3/97 00621 00622 Purpose: Destructor 00623 00624 ********************************************************************************************/ 00625 00626 VarWidthItem::~VarWidthItem() 00627 { 00628 if (pAttrDef != NULL) 00629 delete pAttrDef; 00630 } 00631 00632 00633 00634 /******************************************************************************************** 00635 00636 > virtual void VarWidthItem::SetAttributes(RenderRegion* pRegion) const 00637 00638 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00639 Created: 3/3/97 00640 00641 Inputs: pRegion - the render-region to draw into 00642 00643 Purpose: Sets the stroke typeattributes in the given render-region to render this 00644 item correctly. 00645 00646 ********************************************************************************************/ 00647 00648 void VarWidthItem::SetAttributes(RenderRegion* pRegion) const 00649 { 00650 // Set a 16pt line width - nice & thick 00651 pRegion->SetLineWidth(16000); 00652 00653 // Set the line width (this overrides the "default" line width set by the caller). 00654 pAttrDef->Render(pRegion, FALSE); 00655 00656 // Set a path processor up so that the variable line width is used when stroking 00657 StrokeTypeAttrValue *pStroke = new StrokeTypeAttrValue(new PathProcessorStroke); 00658 if (pStroke != NULL) 00659 pStroke->Render(pRegion, TRUE); 00660 } 00661 00662 00663 00664 /******************************************************************************************** 00665 00666 > virtual NodeAttribute *VarWidthItem::CreateNewAttribute(BOOL) const 00667 00668 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00669 Created: 3/3/97 00670 00671 Returns: A pointer to a NodeAttribute-derivative that this user-interface item 00672 represents, ie. a line-width attribute that can be passed to the 00673 attribute manager. 00674 00675 Purpose: Create a NodeAttribute representing the attribute this item applies 00676 00677 ********************************************************************************************/ 00678 00679 NodeAttribute *VarWidthItem::CreateNewAttribute(BOOL) const 00680 { 00681 return(pAttrDef->MakeNode()); 00682 } 00683 00684 00685 00686 /******************************************************************************************** 00687 00688 > virtual MILLIPOINT VarWidthItem::GetWidth() const 00689 00690 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00691 Created: 3/3/97 00692 Inputs: - 00693 Outputs: - 00694 Returns: The width of a line-width item, in millipoints. 00695 Purpose: Called by the line gallery formatting code. 00696 00697 ********************************************************************************************/ 00698 00699 MILLIPOINT VarWidthItem::GetWidth() const 00700 { 00701 return 2 * LineAttrItem::GetWidth() / 3; 00702 } 00703 00704 00705 00706 /******************************************************************************************** 00707 00708 > virtual CCRuntimeClass** VarWidthItem::GetAttribRuntimeClasses() const 00709 00710 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00711 Created: 3/3/97 00712 Inputs: - 00713 Outputs: - 00714 Returns: The run-time class of the line attribute this type of display item 00715 represents. 00716 Purpose: Used when searching for display items representing the selection's current 00717 attributes. 00718 00719 ********************************************************************************************/ 00720 00721 CCRuntimeClass** VarWidthItem::GetAttribRuntimeClasses() const 00722 { 00723 static CCRuntimeClass* aprtc[] = 00724 { 00725 CC_RUNTIME_CLASS(AttrVariableWidth), 00726 NULL 00727 }; 00728 00729 return aprtc; 00730 } 00731 00732 00733 00734 /******************************************************************************************** 00735 00736 > virtual BOOL VarWidthItem::IsEqualValueToAny(NodeAttribute** ppOtherAttribs) const 00737 00738 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00739 Created: 3/3/97 00740 Inputs: pOtherAttrib the attribute value to compare this item to 00741 Outputs: - 00742 Returns: TRUE if this item represents the same attribute value as the given 00743 attribute. 00744 Purpose: Used when searching for display items representing the selection's current 00745 attributes. 00746 00747 ********************************************************************************************/ 00748 00749 BOOL VarWidthItem::IsEqualValueToAny(NodeAttribute** ppOtherAttribs) const 00750 { 00751 if (*ppOtherAttribs == NULL) 00752 return(FALSE); 00753 00754 AttrVariableWidth* pAttr = (AttrVariableWidth *) *ppOtherAttribs; 00755 ERROR3IF(!pAttr->IsKindOf(CC_RUNTIME_CLASS(AttrVariableWidth)), 00756 "VarWidthItem::IsEqualValueToAny - unexpected object type"); 00757 00758 if (pAttr != NULL) 00759 { 00760 VariableWidthAttrValue *pOther = (VariableWidthAttrValue *) pAttr->GetAttributeValue(); 00761 return((*pAttrDef) == (*pOther)); 00762 } 00763 00764 return(FALSE); 00765 } 00766 00767 00768 00769 /******************************************************************************************** 00770 00771 > virtual MILLIPOINT VarWidthItem::GetHorzGap() const 00772 00773 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00774 Created: 3/3/97 00775 00776 Returns: The horizontal gap between this item and another item of the same type, in 00777 millipoints. 00778 Purpose: Called by the formatting code to determine the gap between items of this type 00779 00780 ********************************************************************************************/ 00781 00782 MILLIPOINT VarWidthItem::GetHorzGap() const 00783 { 00784 // I would like the gap to be the same all the way around 00785 return(GetVertGap()); 00786 } 00787 00788 00789 /******************************************************************************************** 00790 > virtual BOOL LineAttrItem::ItemSelected() 00791 00792 Author: Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com> 00793 Created: 20/1/2000 00794 Inputs: pNewAttr - the attribute that we are about to apply 00795 Outputs: - 00796 Returns: TRUE if we want the line gallery to go ahead and apply the attribute, 00797 FALSE if we applied it ourselves. 00798 Purpose: utility fn called when the item is selected. As we now wish to apply both the 00799 stroke type item and the variable width item through one UI action we must 00800 do so here. 00801 Notes: This was implemented so that the user could apply a variable width stroke with 00802 just one click. As we have abaondoned the idea of keeping the different stroke 00803 types for this release it has been decided that we will only have the basic 00804 stroke type which will automatically be applied when you select a variable width 00805 ********************************************************************************************/ 00806 00807 BOOL VarWidthItem::ItemSelected(NodeAttribute* pAttribute) 00808 { 00809 if (pAttribute == NULL || !pAttribute->IsKindOf(CC_RUNTIME_CLASS(AttrVariableWidth))) 00810 { 00811 ERROR3("Invalid attribute in VarWidthItem::ItemSelected"); 00812 return FALSE; 00813 } 00814 00815 // if we're applying a default then we should also apply an old-style stroke so... 00816 PathProcessorStroke* PPS = NULL; 00817 VariableWidthAttrValue* pVal = (VariableWidthAttrValue*)pAttribute->GetAttributeValue(); 00818 if (pVal->GetWidthFunction() != NULL) 00819 { 00820 // If not a default then create the PathProcessor for the stroke attribute 00821 // The default case will fall through with NULL and create an old-style stroke 00822 PPS = new PathProcessorStroke; 00823 if (PPS == NULL) 00824 return FALSE; 00825 } 00826 00827 StrokeTypeAttrValue NewStroke(PPS); 00828 AttrStrokeType* pAttrStroke = (AttrStrokeType*)NewStroke.MakeNode(); 00829 00830 if (pAttrStroke == NULL) 00831 return FALSE; 00832 00833 List AttribsList; 00834 NodeAttributePtrItem* pStrokeAttrPtr = new NodeAttributePtrItem; 00835 if (pStrokeAttrPtr == NULL) 00836 { 00837 delete pAttrStroke; 00838 return TRUE; 00839 } 00840 pStrokeAttrPtr->NodeAttribPtr = pAttrStroke; 00841 00842 // in order to apply the attributes simultaneously we need a list 00843 AttribsList.AddHead(pStrokeAttrPtr); 00844 00845 NodeAttributePtrItem* pVarWidthPtr = new NodeAttributePtrItem; 00846 if (pVarWidthPtr == NULL) 00847 { 00848 pStrokeAttrPtr->NodeAttribPtr = NULL; 00849 delete pAttrStroke; 00850 delete pStrokeAttrPtr; 00851 return TRUE; 00852 } 00853 pVarWidthPtr->NodeAttribPtr = pAttribute; 00854 00855 AttribsList.AddHead(pVarWidthPtr); 00856 00857 AttributeManager::AttributesSelected(AttribsList, _R(IDS_STROKEAPPLY_UNDO)); 00858 00859 // We don't need the list of attrs anymore 00860 NodeAttributePtrItem* pAttrItem = (NodeAttributePtrItem*)AttribsList.GetHead(); 00861 while (pAttrItem) 00862 { 00863 delete (pAttrItem->NodeAttribPtr); 00864 pAttrItem->NodeAttribPtr = NULL; 00865 pAttrItem = (NodeAttributePtrItem*)AttribsList.GetNext(pAttrItem); 00866 } 00867 AttribsList.DeleteAll(); // tidyup 00868 00869 BROADCAST_TO_ALL(StrokeMsg()); 00870 return FALSE; // means do not go ahead and apply pAttribute again 00871 }