#include <sgbrush.h>
Inheritance diagram for BrushAttrItem:
Public Member Functions | |
BrushAttrItem (BrushAttrValue *pBrush, const String &strDescription) | |
Constructs a user-interface item representing a stroke type. | |
~BrushAttrItem () | |
Destructor. | |
virtual BrushAttrValue * | GetBrushAttrValue () |
virtual BrushDefinition * | GetBrushDefinition () |
Get the BrushDefinition for this item. | |
virtual BrushHandle | GetBrushHandle () |
Get the BrushHandle for this item. | |
virtual void | RenderItem (RenderRegion *pRender, DocRect *pDocRect, INT32 Width=c_nDefaultLineWidth) |
Renders a representation of the stroke into the given renderregion. This is used by the line properties dialog since all the stuff needed seems to be private... | |
virtual void | UpdateGalleryItem () |
Updates the gallery item's cached data to represent any changes this Stoke might have had done to it. Also redraw the gallery if necessary. | |
virtual BOOL | ItemSelected (NodeAttribute *pNewAttr) |
Sets the default line width to be that of the brush, or the previous line width if the brush doesn't have one. Also broadcasts a message saying that it has been selected, for the benefit of the freehand tool. | |
BOOL | IsEqualValueToAny (NodeAttribute **ppOtherAttribs) const |
Used when searching for display items representing the selection's current attributes. | |
BOOL | UpdateProcessor () |
Protected Member Functions | |
virtual void | SetAttributes (RenderRegion *pRegion) const |
Sets the brush attributes in the given render-region to render this item correctly. | |
void | DrawItem (RenderRegion *pRegion, const DocRect &drBounds) const |
Draws this item within the bounding box. The aim is to work out what scaling we need in order to fit the brush into the FormatRect. Therefore we draw a line through the bounding box, get its bounding box with the brush applied and work out the scaling that will fit this into the formatrect. | |
virtual NodeAttribute * | CreateNewAttribute (BOOL fIsAdjust) const |
Create a NodeAttribute representing the attribute this item applies. | |
virtual CCRuntimeClass ** | GetAttribRuntimeClasses () const |
Used when searching for display items representing the selection's current attributes. | |
BrushHandle | GetCurrentDefaultBrushHandle () |
as above | |
Private Member Functions | |
CC_DECLARE_DYNAMIC (BrushAttrItem) | |
Private Attributes | |
BrushAttrValue * | m_pBrushAttrVal |
Definition at line 118 of file sgbrush.h.
|
Constructs a user-interface item representing a stroke type.
Definition at line 137 of file sgbrush.cpp. 00138 : LineAttrItem(strDescription, BELOW) 00139 { 00140 ERROR3IF(pBrush == NULL, "Illegal NULL param"); 00141 m_pBrushAttrVal = pBrush; 00142 }
|
|
Destructor.
Definition at line 157 of file sgbrush.cpp. 00158 { 00159 if (m_pBrushAttrVal != NULL) 00160 { 00161 m_pBrushAttrVal->FlushCache(); 00162 m_pBrushAttrVal->SetPathProcessor(NULL); 00163 delete m_pBrushAttrVal; 00164 } 00165 }
|
|
|
|
Create a NodeAttribute representing the attribute this item applies.
Implements LineAttrItem. Definition at line 212 of file sgbrush.cpp. 00213 { 00214 // because we may have changed some of the attribute data to render the brush objects 00215 // in the line gallery we really want to make sure the new path processor takes all 00216 // its data from the original brush definition. 00217 // This is a bit long winded but safer than just taking the local data 00218 AttrBrushType* pAttrBrushType = (AttrBrushType*)m_pBrushAttrVal->MakeNode(); 00219 if (pAttrBrushType == NULL) 00220 { 00221 ERROR3("Failed to make node"); 00222 return NULL; 00223 } 00224 BrushAttrValue* pNewBrushAttrVal = (BrushAttrValue*)pAttrBrushType->GetAttributeValue(); 00225 if (pNewBrushAttrVal == NULL) 00226 { 00227 ERROR3("No BrushAttrVal"); 00228 return NULL; 00229 } 00230 00231 // now get the brush definition 00232 BrushDefinition* pBrush = m_pBrushAttrVal->GetBrushDefinition(); 00233 if (pBrush == NULL) 00234 { 00235 // not an error 00236 return pAttrBrushType; 00237 } 00238 00239 PathProcessorBrush* pPathProc = pNewBrushAttrVal->GetPathProcessor(); 00240 if (pPathProc == NULL) 00241 { 00242 // not actually an error, as this could be a default 'normal line' brush 00243 return pAttrBrushType; 00244 } 00245 00246 00247 // copy the data to the new processor 00248 pBrush->CopyDataToProcessor(pPathProc); 00249 00250 // tell the processor which attribute value it belongs to 00251 pPathProc->SetParentAttribute(pAttrBrushType); 00252 00253 00254 return pAttrBrushType; 00255 }
|
|
Draws this item within the bounding box. The aim is to work out what scaling we need in order to fit the brush into the FormatRect. Therefore we draw a line through the bounding box, get its bounding box with the brush applied and work out the scaling that will fit this into the formatrect.
Reimplemented from LineAttrItem. Definition at line 500 of file sgbrush.cpp. 00501 { 00502 if (m_pBrushAttrVal == NULL) 00503 { 00504 ERROR3("Wheres the AttrVal gone?"); 00505 return; 00506 } 00507 00508 // Calculate the mid-point of the vertical sides of the bounding box. 00509 INT32 yMid = ((drBounds.lo.y + drBounds.hi.y) / 2) - (drBounds.Height() / 3); 00510 00511 // Draw a line at this height from the left to the right edge. 00512 Path pthLinePath; 00513 if (pthLinePath.Initialise()) 00514 { 00515 pthLinePath.InsertMoveTo(DocCoord(drBounds.lo.x, yMid)); 00516 pthLinePath.InsertLineTo(DocCoord(drBounds.hi.x, yMid)); 00517 pthLinePath.IsFilled = FALSE; 00518 pthLinePath.IsStroked = TRUE; 00519 00520 // Get the brush definition and the local path processor 00521 BrushDefinition* pBrushDef = m_pBrushAttrVal->GetBrushDefinition(); 00522 if (pBrushDef != NULL) 00523 { 00524 PathProcessorBrush* pPathProc = m_pBrushAttrVal->GetPathProcessor(); 00525 if (pPathProc == NULL) 00526 { 00527 ERROR3("No brush definition"); 00528 return; 00529 } 00530 MILLIPOINT LineWidth = 18000; 00531 00532 pPathProc->ScaleToValue(LineWidth); 00533 pRegion->SetLineWidth(LineWidth); 00534 00535 // render the attribute, i.e. push the path processor 00536 m_pBrushAttrVal->Render(pRegion, FALSE); 00537 // draw the line 00538 pRegion->DrawPath(&pthLinePath); 00539 } 00540 else // no actual brush - just draw the line 00541 pRegion->DrawPath(&pthLinePath); 00542 } 00543 else 00544 ERROR3("Failed to initialise path"); 00545 00546 }
|
|
Used when searching for display items representing the selection's current attributes.
Implements LineAttrItem. Definition at line 470 of file sgbrush.cpp. 00471 { 00472 static CCRuntimeClass* aprtc[] = 00473 { 00474 CC_RUNTIME_CLASS(AttrBrushType), 00475 NULL 00476 }; 00477 00478 return aprtc; 00479 }
|
|
Definition at line 129 of file sgbrush.h. 00129 { return m_pBrushAttrVal;}
|
|
Get the BrushDefinition for this item.
Definition at line 309 of file sgbrush.cpp. 00310 { 00311 BrushHandle Handle = GetBrushHandle(); 00312 if(Handle != BrushHandle(-1)) 00313 { 00314 // get the brush component 00315 Document* pDoc = Document::GetCurrent(); 00316 ERROR2IF(pDoc == NULL, NULL, "Wheres the document?"); 00317 BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent)); 00318 ERROR2IF(pBrushComp == NULL, NULL, "No brush component"); 00319 return pBrushComp->FindBrushDefinition(Handle); 00320 } 00321 00322 return NULL; 00323 }
|
|
Get the BrushHandle for this item.
Definition at line 337 of file sgbrush.cpp. 00338 { 00339 BrushAttrValue *pAttrValue = GetBrushAttrValue(); 00340 if(pAttrValue != NULL) 00341 { 00342 PathProcessorBrush *pProcessor = pAttrValue->GetPathProcessor(); 00343 if (pProcessor != NULL && pProcessor->IsKindOf(CC_RUNTIME_CLASS(PathProcessorBrush))) 00344 { 00345 BrushHandle Handle = ((PathProcessorBrush *)pProcessor)->GetBrushDefinitionHandle(); 00346 return Handle; 00347 } 00348 } 00349 00350 return BrushHandle_NoBrush; 00351 }
|
|
as above
Definition at line 706 of file sgbrush.cpp. 00707 { 00708 Document* pDoc = Document::GetCurrent(); 00709 if (pDoc == NULL) 00710 { 00711 ERROR3("No document"); 00712 return BrushHandle_NoBrush; 00713 } 00714 00715 AttributeManager* pAttrMgr = &(pDoc->GetAttributeMgr()); 00716 if (pAttrMgr == NULL) 00717 { 00718 ERROR3("No attribute manager"); 00719 return BrushHandle_NoBrush; 00720 } 00721 00722 AttrBrushType* pAttr = (AttrBrushType*)(pAttrMgr->GetCurrentAttribute(CC_RUNTIME_CLASS(NodeRenderableInk), CC_RUNTIME_CLASS(AttrBrushType))); 00723 00724 if (pAttr == NULL) 00725 { 00726 ERROR3("No current brush attribute"); 00727 return BrushHandle_NoBrush; 00728 } 00729 return pAttr->GetBrushHandle(); 00730 00731 }
|
|
Used when searching for display items representing the selection's current attributes.
Implements LineAttrItem. Definition at line 273 of file sgbrush.cpp. 00274 { 00275 if (*ppOtherAttribs == NULL) // When multiple attribs are selected, this will be NULL 00276 return(FALSE); 00277 00278 AttrBrushType* pAttr = (AttrBrushType *) *ppOtherAttribs; 00279 ERROR3IF(!pAttr->IsKindOf(CC_RUNTIME_CLASS(AttrBrushType)), 00280 "BrushAttrItem::IsEqualValueToAny - unexpected object type"); 00281 00282 if (pAttr != NULL) 00283 { 00284 BrushAttrValue *pOther = (BrushAttrValue *) pAttr->GetAttributeValue(); 00285 //return((*m_pBrushAttrVal) == (*pOther)); 00286 00287 // to simplify - just check to see if they have the same brush handle 00288 BrushHandle Other = pOther->GetBrushHandle(); 00289 BrushHandle This = m_pBrushAttrVal->GetBrushHandle(); 00290 return (Other == This); 00291 } 00292 00293 return(FALSE); 00294 }
|
|
Sets the default line width to be that of the brush, or the previous line width if the brush doesn't have one. Also broadcasts a message saying that it has been selected, for the benefit of the freehand tool.
Reimplemented from LineAttrItem. Definition at line 563 of file sgbrush.cpp. 00564 { 00565 if (m_pBrushAttrVal == NULL) 00566 { 00567 ERROR3("BrushAttrValue is NULL"); 00568 return TRUE; 00569 } 00570 00571 // if we are setting a 'no brush' brush we must restore its line width to the last 00572 // line width set that had 'no brush' 00573 BOOL bSettingNoBrush = (m_pBrushAttrVal->GetBrushHandle() == BrushHandle_NoBrush); 00574 00575 // if there is something in the selection then we do not want to change 00576 // the line width, as they may be different. the only exception to this is 00577 // if we are setting the default 'no brush' 00578 SelRange* pSel = GetApplication()->FindSelection(); 00579 if (pSel == NULL) 00580 return TRUE; 00581 if (pSel->FindFirst() != NULL) 00582 { 00583 if (!bSettingNoBrush) 00584 return TRUE; 00585 } 00586 00587 MILLIPOINT OldLineWidth = 500; // initialise to default 00588 00589 // first make sure the line gallery has its previous line width member set 00590 LineGallery* pLineGal = LineGallery::GetInstance(); 00591 if (pLineGal == NULL) 00592 return TRUE; 00593 else 00594 { 00595 // get the last line width in case we need it 00596 OldLineWidth = pLineGal->GetPreviousLineWidth(); 00597 00598 // if we are going from a 'no brush' to a brush then we need to store the line 00599 // width of the 'no brush' 00600 if ((GetCurrentDefaultBrushHandle() == BrushHandle_NoBrush) && (!bSettingNoBrush)) 00601 pLineGal->SetPreviousLineWidth(); 00602 } 00603 00604 // get the line width from the attribute 00605 MILLIPOINT LineWidth = m_pBrushAttrVal->GetDefaultLineWidth(TRUE); 00606 00607 // if we receive < 0 from GetDefaultLineWidth it means that we have no 00608 // ink objects associated with this brush. In this instance it means we 00609 // are probably selecting the 'simple line' brush and should set the old line 00610 // width 00611 if (LineWidth <= 0) 00612 { 00613 if (OldLineWidth < 0) 00614 { 00615 ERROR3("negative line width"); 00616 return TRUE; 00617 } 00618 else 00619 LineWidth = OldLineWidth; 00620 } 00621 00622 // quick hack until the problems in attrmgr.cpp with applying non-text attributes in the 00623 // text tool are sorted out 00624 if (Tool::GetCurrentID() == TOOLID_TEXT) 00625 return FALSE; 00626 00627 // make a new line width node 00628 NodeAttribute* pNewAttr = new AttrLineWidth; 00629 if (pNewAttr == NULL) 00630 { 00631 ERROR3("Failed to allocate new line width"); 00632 return TRUE; 00633 } 00634 ((AttrLineWidth*)pNewAttr)->Value.LineWidth = LineWidth; 00635 00636 // in order to apply the attributes together we need to make a list 00637 List AttribsList; 00638 NodeAttributePtrItem* pBrushAttrPtr = new NodeAttributePtrItem; 00639 if (pBrushAttrPtr == NULL) 00640 { 00641 delete pNewAttr; 00642 return TRUE; 00643 } 00644 pBrushAttrPtr->NodeAttribPtr = pAttrBrush; 00645 00646 AttribsList.AddHead(pBrushAttrPtr); 00647 00648 NodeAttributePtrItem* pLineWidthPtr = new NodeAttributePtrItem; 00649 if (pLineWidthPtr == NULL) 00650 { 00651 pBrushAttrPtr->NodeAttribPtr = NULL; 00652 return TRUE; 00653 } 00654 pLineWidthPtr->NodeAttribPtr = pNewAttr; 00655 00656 AttribsList.AddHead(pLineWidthPtr); 00657 00658 AttributeManager::AttributesSelected(AttribsList, _R(IDS_APPLYBRUSH_UNDO)); 00659 00660 00661 // We don't need the list of attrs anymore 00662 NodeAttributePtrItem* pAttrItem = (NodeAttributePtrItem*)AttribsList.GetHead(); 00663 while (pAttrItem) 00664 { 00665 delete (pAttrItem->NodeAttribPtr); 00666 pAttrItem->NodeAttribPtr = NULL; 00667 pAttrItem = (NodeAttributePtrItem*)AttribsList.GetNext(pAttrItem); 00668 } 00669 AttribsList.DeleteAll(); // tidyup 00670 00671 BrushHandle NewHandle = GetBrushHandle(); 00672 BROADCAST_TO_ALL(BrushMsg(NewHandle)); 00673 return FALSE; 00674 }
|
|
Renders a representation of the stroke into the given renderregion. This is used by the line properties dialog since all the stuff needed seems to be private...
Definition at line 370 of file sgbrush.cpp. 00371 { 00372 if(pRender == NULL || pDocRect == NULL) 00373 { 00374 ERROR3("BrushAttrItem::RenderItem given null params"); 00375 return; 00376 } 00377 00378 pRender->SaveContext(); 00379 00380 // Make sure we're anti-aliasing 00381 Quality AntiAliasQuality(Quality::QualityMax); 00382 QualityAttribute AntiAliasQualityAttr(AntiAliasQuality); 00383 pRender->SetQuality(&AntiAliasQualityAttr,FALSE); 00384 00385 // Render the background rectangle 00386 DialogColourInfo RedrawColours; 00387 pRender->SetLineColour(RedrawColours.DialogBack()); 00388 pRender->SetFillColour(RedrawColours.DialogBack()); 00389 pRender->DrawRect(pDocRect); 00390 00391 // Draw the Saturation vs. Value square 00392 Path SquarePath; 00393 LinearFillAttribute ValueGradFill; 00394 LinearTranspFillAttribute TransFill; 00395 00396 ValueGradFill.Colour = DocColour(255L, 0L, 0L); 00397 ValueGradFill.EndColour = DocColour(255L, 255L, 255L); 00398 00399 DocCoord ThePoint(pDocRect->lo.x, pDocRect->hi.y); 00400 ValueGradFill.SetStartPoint(&ThePoint); 00401 ThePoint = DocCoord(pDocRect->hi.x, pDocRect->hi.y); 00402 ValueGradFill.SetEndPoint(&ThePoint); 00403 ValueGradFill.SetEndPoint2(NULL); 00404 00405 pRender->SetFillGeometry(&ValueGradFill, FALSE); // Set Grad-filled 00406 00407 00408 pRender->SetLineColour(RedrawColours.TextFore()); 00409 00410 SetAttributes(pRender); 00411 pRender->SetLineWidth((INT32)((double)Width * 0.8)); 00412 DrawItem(pRender, *pDocRect); 00413 00414 pRender->RestoreContext(); 00415 }
|
|
Sets the brush attributes in the given render-region to render this item correctly.
Implements LineAttrItem. Definition at line 182 of file sgbrush.cpp. 00183 { 00184 // code has been moved into DrawItem, as we need to know the bounding box 00185 // before we can make the scaling adjustment 00186 00187 00188 // Set a line width 00189 //pRegion->SetLineWidth(1000); 00190 00191 // Set the line width (this overrides the "default" line width set by the caller). 00192 //m_pBrushAttrVal->Render(pRegion, FALSE); 00193 }
|
|
Updates the gallery item's cached data to represent any changes this Stoke might have had done to it. Also redraw the gallery if necessary.
Definition at line 431 of file sgbrush.cpp. 00432 { 00433 BrushDefinition *pBrush = GetBrushDefinition(); 00434 if(pBrush != NULL) 00435 { 00436 // first try and allocate a new PPB 00437 PathProcessorBrush* pNewPPB = new PathProcessorBrush; 00438 if (pNewPPB == NULL) 00439 return; 00440 // give it the latest data 00441 pBrush->CopyDataToProcessor(pNewPPB); 00442 00443 // tell it what handle to use 00444 pNewPPB->SetBrushDefinition(m_pBrushAttrVal->GetBrushHandle()); 00445 //ask our attr to delete its path processor 00446 m_pBrushAttrVal->SetPathProcessor(pNewPPB); 00447 00448 // set the new name 00449 SetDescription(pBrush->GetLineName()); 00450 } 00451 00452 ForceRedrawOfMyself(); 00453 }
|
|
|
|
|