00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 #include "infobar.h"
00116 #include "csrstack.h"
00117
00118 #include "osrndrgn.h"
00119 #include "oilfiles.h"
00120 #include "blobs.h"
00121 #include "freeinfo.h"
00122 #include "opfree.h"
00123 #include "freehand.h"
00124
00125 #include "fitcurve.h"
00126 #include "opretro.h"
00127 #include "module.h"
00128 #include "ezmodule.h"
00129
00130 #include "progress.h"
00131
00132 #include "nodepath.h"
00133
00134 #include "opdrbrsh.h"
00135 #include "opbevel.h"
00136
00137
00138
00139
00140 #include "nodeblnd.h"
00141 #include "ndbldpth.h"
00142 #include "nodetxts.h"
00143 #include "ndtxtpth.h"
00144 #include "attrmap.h"
00145 #include "nodershp.h"
00146 #include "brushref.h"
00147 #include "brshcomp.h"
00148 #include "ppbrush.h"
00149
00150 #include "brshattr.h"
00151 #include "sgline.h"
00152 #include "progress.h"
00153 #include "brshdata.h"
00154 #include "brshgdgt.h"
00155 #include "lineattr.h"
00156 #include "brushmsg.h"
00157 #include "coldlog.h"
00158 #include "comattrmsg.h"
00159 #include "pen.h"
00160 #include "brshname.h"
00161 #include "brshbeca.h"
00162
00163
00164 #include "layer.h"
00165
00166
00167 DECLARE_SOURCE("$Revision: 1750 $");
00168
00169
00170
00171 TCHAR* FreeHandTool::FamilyName = _T("Drawing Tools");
00172 TCHAR* FreeHandTool::ToolName = _T("Free Hand Tool");
00173 TCHAR* FreeHandTool::Purpose = _T("To Draw arbitrary lines");
00174 TCHAR* FreeHandTool::Author = _T("Rik");
00175
00176 CC_IMPLEMENT_MEMDUMP( FreeHandTool, Tool_v1 )
00177
00178
00179 #define new CAM_DEBUG_NEW
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 BOOL FreeHandTool::FreehandPtrCrosshair = FALSE;
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 FreeHandTool::FreeHandTool()
00206 {
00207
00208 Smoothness = 50;
00209
00210
00211 pInfoBarOp = NULL;
00212 PreviousPath = NULL;
00213
00214
00215 IsPreviousPathValid = FALSE;
00216 IsRetroPathValid = FALSE;
00217 AreWeRetroFitting = FALSE;
00218
00219
00220 TrackData = NULL;
00221 RetroPath = NULL;
00222
00223
00224 StartSlot = 0;
00225 NumSlots = 0;
00226
00227
00228 pNormalCursor = NULL;
00229 pActiveCursor = NULL;
00230 pJoinCursor = NULL;
00231
00232
00233 JoinInfo.pJoinPath = NULL;
00234 JoinInfo.IsNearEndPoint = FALSE;
00235 JoinInfo.CloseSlot = 0;
00236 JoinInfo.Into = 0.0;
00237 JoinInfo.pAttrBrush = NULL;
00238 JoinInfo.FirstBrushSpacing = 25;
00239
00240
00241 StatusMsg = String_256("");
00242
00243 m_pBlendRef = NULL;
00244 m_BrushSpacing = 10000;
00245 m_NumInkNodes = 0;
00246 m_pGRenderBrush = NULL;
00247 m_BrushHandle = BrushHandle_NoBrush;
00248
00249 m_LastBrushDocument = TEXT("No document");
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 FreeHandTool::~FreeHandTool()
00265 {
00266
00267 DeletePaths();
00268 PORTNOTE("other", "Removed m_pGRenderBrush support");
00269 #ifndef EXCLUDE_FROM_XARALX
00270 if (m_pGRenderBrush != NULL)
00271 delete m_pGRenderBrush;
00272 #endif
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 BOOL FreeHandTool::Init()
00290 {
00291
00292
00293 pInfoBarOp = NULL;
00294
00295 if (!OpRetroFit::Init())
00296 return FALSE;
00297
00298
00299
00300 if (OpFreeHand::Declare())
00301 {
00302 pInfoBarOp = new FreeHandInfoBarOp();
00303 if (pInfoBarOp)
00304 pInfoBarOp->pTool = this;
00305 PORTNOTE("dialog", "Removed Bar reading")
00306 #if 0
00307
00308 CCResTextFile ResFile;
00309 FreeHandInfoBarOpCreate BarCreate;
00310
00311 if (ResFile.open(_R(IDM_FREEHAND_BAR), _R(IDT_INFO_BAR_RES)))
00312 {
00313
00314 if (DialogBarOp::ReadBarsFromFile(ResFile,BarCreate))
00315 {
00316
00317 ResFile.close();
00318
00319
00320 String_32 str = String_32(_R(IDS_FREEHAND_INFOBARNAME));
00321 DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(str);
00322
00323
00324 if (pDialogBarOp != NULL)
00325 {
00326
00327 if (pDialogBarOp->IsKindOf(CC_RUNTIME_CLASS(FreeHandInfoBarOp)))
00328 {
00329 pInfoBarOp = (FreeHandInfoBarOp*) pDialogBarOp;
00330 pInfoBarOp->pTool = this;
00331 }
00332 }
00333 }
00334 }
00335 #endif
00336 }
00337
00338 GetApplication()->DeclareSection(_T("Mouse"), 10);
00339 GetApplication()->DeclarePref(_T("Mouse"), _T("FreehandPtrCrosshair"), &FreehandPtrCrosshair, FALSE, TRUE);
00340
00341
00342 ENSURE(pInfoBarOp!=NULL, "Failed to create FreeHand Info Bar" );
00343 if (pInfoBarOp==NULL)
00344 return FALSE;
00345 else
00346 return TRUE;
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 void FreeHandTool::Describe(void *InfoPtr)
00369 {
00370
00371 ToolInfo_v1 *Info = (ToolInfo_v1 *) InfoPtr;
00372
00373 Info->InfoVersion = 1;
00374 Info->InterfaceVersion = GetToolInterfaceVersion();
00375
00376
00377 Info->Version = 1;
00378 Info->ID = GetID();
00379 Info->TextID = _R(IDS_FREE_HAND_TOOL);
00380 Info->BubbleID = _R(IDBBL_FHND_TOOLBOX);
00381
00382 Info->Family = FamilyName;
00383 Info->Name = ToolName;
00384 Info->Purpose = Purpose;
00385 Info->Author = Author;
00386
00387 Info->InfoBarDialog = _R(IDD_FREEHANDTOOL);
00388 }
00389
00390
00391 UINT32 FreeHandTool::GetID()
00392 {
00393 return TOOLID_FREEHAND;
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 void FreeHandTool::SelectChange(BOOL isSelected)
00415 {
00416
00417 if (isSelected)
00418 {
00419 CCPen *pPen = Camelot.GetPressurePen();
00420 if (pPen != NULL)
00421 {
00422 PressureMode NewState = (pPen->IsRealPen()) ? PressureMode_Pen : PressureMode_None;
00423 pPen->SetPressureMode(NewState);
00424 }
00425
00426 m_UpdateBrushState = UPDATE_ONIDLE;
00427
00428 BOOL ok = BrushSelected(m_BrushHandle, FALSE);
00429
00430 if (!ok)
00431 m_BrushHandle = BrushHandle_NoBrush;
00432
00433
00434
00435
00436
00437
00438
00439 m_LastBrushDocument = TEXT("No document");
00440
00441
00442 if (!LoadCursors())
00443 InformError();
00444
00445
00446 JoinInfo.pJoinPath = NULL;
00447 JoinInfo.FirstBrushSpacing = 25;
00448
00449 BlobManager* BlobMgr = GetApplication()->GetBlobManager();
00450
00451
00452 BOOL IsPathWithSubSelection = FALSE;
00453 if (Document::GetSelected() != NULL)
00454 {
00455
00456 SelRange* Selected = GetApplication()->FindSelection();
00457 Node* pNode = Selected->FindFirst();
00458 while ((pNode!=NULL) && (!IsPathWithSubSelection))
00459 {
00460
00461 if (pNode->IsNodePath())
00462 {
00463
00464 if (((NodePath*)pNode)->InkPath.IsSubSelection())
00465 IsPathWithSubSelection = TRUE;
00466 }
00467
00468
00469 pNode = Selected->FindNext(pNode);
00470 }
00471
00472
00473 if ((IsPathWithSubSelection) && (BlobMgr!=NULL))
00474 {
00475
00476 BlobStyle ClearBlobs;
00477 ClearBlobs.Object = FALSE;
00478 BlobMgr->ToolInterest(ClearBlobs);
00479
00480
00481 pNode = Selected->FindFirst();
00482 while (pNode!=NULL)
00483 {
00484
00485 if (pNode->IsNodePath())
00486 ((NodePath*)pNode)->InkPath.ClearSubSelection();
00487
00488
00489 pNode = Selected->FindNext(pNode);
00490 }
00491 }
00492 }
00493
00494
00495
00496
00497
00498
00499 Range SelRng(*(GetApplication()->FindSelection()));
00500 Node* pNode = SelRng.FindFirst();
00501
00502 while (pNode != NULL)
00503 {
00504 if (IS_A(pNode, TextStory))
00505 {
00506 TextStory* pStory = (TextStory*)pNode;
00507 if (pStory->GetTextPath() != NULL)
00508 pStory->GetTextPath()->Select(TRUE);
00509 }
00510
00511 if (IS_A(pNode, NodeBlend))
00512 {
00513 NodeBlend* pNodeBlend = (NodeBlend*)pNode;
00514 UINT32 NBPCounter = 0;
00515 while (pNodeBlend->GetNodeBlendPath(NBPCounter) != NULL)
00516 pNodeBlend->GetNodeBlendPath(NBPCounter++)->Select(TRUE);
00517 }
00518
00519 pNode = SelRng.FindNext(pNode);
00520 }
00521
00522
00523 if (pInfoBarOp != NULL)
00524 {
00525 pInfoBarOp->Create();
00526 pInfoBarOp->SetToolActiveState(TRUE);
00527 }
00528
00529
00530 if (BlobMgr != NULL)
00531 {
00532
00533 BlobStyle MyBlobs;
00534 MyBlobs.Object = TRUE;
00535
00536
00537 BlobMgr->ToolInterest(MyBlobs);
00538 }
00539
00540
00541 if (pInfoBarOp != NULL)
00542 {
00543
00544 BOOL IsStillValid = IsRetroPathStillValid();
00545 pInfoBarOp->SetRetroState(IsStillValid);
00546 }
00547
00548 }
00549 else
00550 {
00551
00552
00553 RemoveCursors();
00554
00555 PORTNOTE("other", "Removed m_pGRenderBrush support");
00556 #ifndef EXCLUDE_FROM_XARALX
00557 if (m_pGRenderBrush != NULL)
00558 {
00559 delete m_pGRenderBrush;
00560 m_pGRenderBrush = NULL;
00561 }
00562 #endif
00563
00564
00565 if (pInfoBarOp != NULL)
00566 {
00567 pInfoBarOp->SetToolActiveState(FALSE);
00568
00569 PORTNOTE("other", "Removed brush gadget support");
00570 #ifndef EXCLUDE_FROM_XARALX
00571 if (FreeHandInfoBarOp::GetBrushGadget()->IsDialogOpen ())
00572 {
00573 FreeHandInfoBarOp::GetBrushGadget()->CloseDialog ();
00574 }
00575 #endif
00576 pInfoBarOp->Delete();
00577 }
00578
00579 SetColourEditorProcessing(TRUE);
00580
00581
00582 BlobManager* BlobMgr = GetApplication()->GetBlobManager();
00583 if (BlobMgr != NULL)
00584 {
00585 BlobStyle bsRemoves;
00586 bsRemoves.ToolObject = TRUE;
00587 BlobMgr->RemoveInterest(bsRemoves);
00588 }
00589 }
00590 }
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607 BOOL FreeHandTool::LoadCursors()
00608 {
00609
00610 pActiveCursor = NULL;
00611
00612
00613 if (FreehandPtrCrosshair)
00614 {
00615 pNormalCursor = new Cursor(this, _R(IDC_FREEHANDTOOLCURSOR_X));
00616 pJoinCursor = new Cursor(this, _R(IDC_FREEHANDJOINCURSOR_X));
00617 pModifyCursor = new Cursor(this, _R(IDC_FREEHANDMODIFY_X));
00618 }
00619 else
00620 {
00621 pNormalCursor = new Cursor(this, _R(IDC_FREEHANDTOOLCURSOR));
00622 pJoinCursor = new Cursor(this, _R(IDC_FREEHANDJOINCURSOR));
00623 pModifyCursor = new Cursor(this, _R(IDC_FREEHANDMODIFY));
00624 }
00625
00626
00627 if ((pNormalCursor==NULL) || (!pNormalCursor->IsValid()) ||
00628 (pJoinCursor==NULL) || (!pJoinCursor->IsValid()) ||
00629 (pModifyCursor==NULL) || (!pModifyCursor->IsValid()))
00630 {
00631
00632
00633 delete pNormalCursor;
00634 delete pJoinCursor;
00635 delete pModifyCursor;
00636
00637
00638 pNormalCursor = NULL;
00639 pJoinCursor = NULL;
00640 pModifyCursor = NULL;
00641
00642
00643 ERROR1(FALSE, _R(IDE_FHAND_BADCURSORS));
00644 }
00645
00646
00647
00648 CurrentCursorID = CursorStack::GPush(pNormalCursor, FALSE);
00649 pActiveCursor = pNormalCursor;
00650
00651
00652 return TRUE;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 void FreeHandTool::RemoveCursors()
00671 {
00672
00673 if (pActiveCursor!=NULL)
00674 {
00675
00676 CursorStack::GPop(CurrentCursorID);
00677
00678
00679 delete pNormalCursor;
00680 delete pJoinCursor;
00681 delete pModifyCursor;
00682
00683
00684 pNormalCursor = NULL;
00685 pJoinCursor = NULL;
00686 pActiveCursor = NULL;
00687 pModifyCursor = NULL;
00688 CurrentCursorID = 0;
00689 }
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 void FreeHandTool::ChangeCursor(Cursor* pCursor)
00709 {
00710
00711 if ((pCursor!=pActiveCursor) && (pCursor!=NULL))
00712 {
00713
00714 CursorStack::GSetTop(pCursor, CurrentCursorID);
00715
00716
00717 pActiveCursor = pCursor;
00718 }
00719 }
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746 void FreeHandTool::OnClick( DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods,
00747 Spread* pSpread )
00748 {
00749 if (ClickMods.Menu) return;
00750
00751
00752 if (Operation::GetCurrentDragOp()!=NULL)
00753 return;
00754
00755
00756
00757
00758 if (Click==CLICKTYPE_SINGLE)
00759 {
00760 OnMouseMove(PointerPos, pSpread, ClickMods);
00761 DragTool::OnClick (PointerPos, Click, ClickMods, pSpread);
00762 }
00763 if (Click == CLICKTYPE_UP)
00764 {
00765
00766
00767
00768 {
00769 DragTool::OnClick (PointerPos, Click, ClickMods, pSpread);
00770
00771 BROADCAST_TO_ALL(CommonAttrsChangedMsg);
00772 }
00773 }
00774
00775 if (Click==CLICKTYPE_DRAG)
00776 {
00777
00778
00779
00780
00781
00782 MILLIPOINT LineWidth = OpDrawBrush::GetCurrentLineWidthIfNotDefault();
00783
00784
00785
00786 if (m_BrushHandle == BrushHandle_NoBrush || (LineWidth != -1 && LineWidth < 501)
00787 || JoinInfo.m_BrushHandle == BrushHandle_NoBrush)
00788 {
00789 OpFreeHand* pOpFreeHand = new OpFreeHand;
00790 if ((pOpFreeHand!=NULL) && (GetNewPaths()))
00791 {
00792
00793 pOpFreeHand->DoDrag(StartPos, StartSpread, Smoothness, &JoinInfo, TrackData);
00794 }
00795 else
00796 {
00797
00798 ToolInformError(_R(IDS_OUT_OF_MEMORY), _R(IDS_OK));
00799 }
00800 }
00801 else
00802 {
00803
00804 Document* pDoc = Document::GetCurrent();
00805 if (pDoc == NULL)
00806 {
00807 ERROR3("No document in FreeHandTool::OnClick");
00808 return;
00809 }
00810
00811 String_256 CurrentDoc = pDoc->GetDocName();
00812 if (CurrentDoc != m_LastBrushDocument)
00813 {
00814 m_LastBrushDocument = CurrentDoc;
00815 m_UpdateBrushState = UPDATE_NOW;
00816 BrushSelected(m_BrushHandle, FALSE);
00817 }
00818
00819 PORTNOTE("other", "Removed m_pGRenderBrush support");
00820 #ifndef EXCLUDE_FROM_XARALX
00821
00822 if (m_pGRenderBrush && m_pGRenderBrush->GetRenderDC()->GetSafeHdc() == NULL)
00823 {
00824 delete m_pGRenderBrush;
00825 m_pGRenderBrush = NULL;
00826 }
00827 #endif
00828
00829 if (m_pGRenderBrush == NULL || CurrentDoc != m_LastBrushDocument)
00830 {
00831
00832 String_32 ProgString = _T("Preparing brush, please wait..");
00833 Progress Hourglass(&ProgString, -1, FALSE);
00834 m_pGRenderBrush = GetBigGRenderBrush(pSpread);
00835
00836 PORTNOTE("other", "Removed m_pGRenderBrush support");
00837 #ifndef EXCLUDE_FROM_XARALX
00838 if (m_pGRenderBrush == NULL)
00839 {
00840 ToolInformError(_R(IDS_OUT_OF_MEMORY), _R(IDS_OK));
00841 return;
00842 }
00843 #endif
00844 m_LastBrushDocument = CurrentDoc;
00845 return;
00846
00847 }
00848
00849 OnMouseMove(PointerPos, pSpread, ClickMods);
00850
00851 OpDrawBrush* pOpDrawBrush = new OpDrawBrush(this);
00852
00853 if ((pOpDrawBrush != NULL)&& (GetNewPaths()))
00854 {
00855
00856
00857
00858 DocView* pDocView = DocView::GetCurrent();
00859 if (pDocView != NULL)
00860 pDocView->SetPreventRenderView(TRUE);
00861
00862
00863 SetColourEditorProcessing(FALSE);
00864 PORTNOTE("other", "Removed m_pGRenderBrush support");
00865 #ifndef EXCLUDE_FROM_XARALX
00866 m_pGRenderBrush->SetupMainBitmap();
00867 #endif
00868
00869 BrushDefinition* pBrushDef = GetSelectedBrush();
00870 if (pBrushDef != NULL)
00871 pOpDrawBrush->SetTimeStamp(pBrushDef->GetTimeStampingPeriod());
00872
00873 pOpDrawBrush->DoDrag(StartPos, StartSpread, Smoothness, m_BrushHandle, &JoinInfo, TrackData,
00874 m_pGRenderBrush, ClickMods);
00875
00876 m_UpdateBrushState = UPDATE_NEVER;
00877 }
00878 else
00879 {
00880
00881 ToolInformError(_R(IDS_OUT_OF_MEMORY), _R(IDS_OK));
00882 PORTNOTE("other", "Removed m_pGRenderBrush support");
00883 #ifndef EXCLUDE_FROM_XARALX
00884 delete m_pGRenderBrush;
00885 m_pGRenderBrush = NULL;
00886 #endif
00887 }
00888
00889 }
00890 }
00891
00892
00893 }
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914 void FreeHandTool::OnMouseMove(DocCoord Coord, Spread* pSpread, ClickModifiers mods)
00915 {
00916
00917 JoinInfo.pJoinPath = NULL;
00918 StartPos = Coord;
00919 StartSpread = pSpread;
00920 JoinInfo.FirstBrushSpacing = 25;
00921
00922 JoinInfo.m_BrushHandle = m_BrushHandle;
00923 JoinInfo.pAttrBrush = NULL;
00924 JoinInfo.BrushDistance = 0;
00925
00926
00927
00928 SelRange* Selected = GetApplication()->FindSelection();
00929 Node* pNode = Selected->FindFirst();
00930
00931
00932 if (pNode!=NULL)
00933 {
00934
00935 Spread* pNodeSpread = pNode->FindParentSpread();
00936 if (pNodeSpread!=pSpread)
00937 return;
00938 }
00939
00940
00941 BlobManager* pBlobMgr = GetApplication()->GetBlobManager();
00942 if (pBlobMgr==NULL)
00943 return;
00944
00945
00946 DocRect BlobRect;
00947 pBlobMgr->GetBlobRect(Coord, &BlobRect);
00948
00949
00950 INT32 Range = BlobRect.Width() / 2;
00951 Range *= Range;
00952
00953
00954
00955 while (pNode!=NULL)
00956 {
00957
00958
00959
00960 if (pNode->IsNodePath())
00961 {
00962
00963 NodePath* pPath = (NodePath*) pNode;
00964
00965
00966
00967 if (IsCursorNearEndPoint(pPath, BlobRect))
00968 return;
00969
00970
00971
00972 if (IsCursorNearPath(pPath, Range, Coord))
00973 return;
00974 }
00975
00976 else if (pNode->IS_KIND_OF(NodeBlend))
00977 {
00978 UINT32 NBPCounter = 0;
00979 NodeBlendPath* pNodeBlendPath = ((NodeBlend*)pNode)->GetNodeBlendPath(NBPCounter++);
00980
00981 while (pNodeBlendPath != NULL)
00982 {
00983 NodePath* pPath = (NodePath*)pNodeBlendPath;
00984
00985
00986 if (IsCursorNearEndPoint(pPath, BlobRect))
00987 return;
00988
00989
00990
00991 if (IsCursorNearPath(pPath, Range, Coord))
00992 return;
00993
00994 pNodeBlendPath = ((NodeBlend*)pNode)->GetNodeBlendPath(NBPCounter++);
00995 }
00996 }
00997
00998
00999 pNode = Selected->FindNext(pNode);
01000 }
01001
01002
01003
01004 if (m_BrushHandle != BrushHandle_NoBrush)
01005 {
01006 Document* pDoc = Document::GetCurrent();
01007 if (pDoc != NULL)
01008 {
01009 String_256 CurrentDoc = pDoc->GetDocName();
01010 if (CurrentDoc != m_LastBrushDocument)
01011 {
01012 m_LastBrushDocument = CurrentDoc;
01013 m_UpdateBrushState = UPDATE_NOW;
01014 BrushSelected(m_BrushHandle, FALSE);
01015 }
01016 }
01017 }
01018
01019
01020
01021 ChangeCursor(pNormalCursor);
01022
01023
01024 StatusMsg.Load(_R(IDS_FREEHANDSTART), Tool::GetModuleID(GetID()));
01025 GetApplication()->UpdateStatusBarText(&StatusMsg);
01026 }
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043 BOOL FreeHandTool::GetStatusLineText(String_256* ptext, Spread*, DocCoord, ClickModifiers)
01044 {
01045 *ptext = StatusMsg;
01046 return TRUE;
01047 }
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 BOOL FreeHandTool::IsCursorNearEndPoint(NodePath* pNodePath, const DocRect& BlobRect)
01070 {
01071
01072 Path* pPath = &(pNodePath->InkPath);
01073
01074
01075 INT32 CloseSlot;
01076 if (pPath->IsNearOpenEnd(BlobRect, &CloseSlot))
01077 {
01078
01079
01080 pPath->SetPathPosition(CloseSlot);
01081 StartPos = pPath->GetCoord();
01082
01083
01084 JoinInfo.pJoinPath = pNodePath;
01085 JoinInfo.IsNearEndPoint = TRUE;
01086
01087
01088 ChangeCursor(pJoinCursor);
01089
01090
01091 StatusMsg.Load(_R(IDS_FREEHANDSTARTJOIN), Tool::GetModuleID(GetID()));
01092 GetApplication()->UpdateStatusBarText(&StatusMsg);
01093
01094
01095 NodeAttribute* pAttr = NULL;
01096 pNodePath->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrBrushType), &pAttr);
01097 if (pAttr != NULL)
01098 {
01099 InitialiseJoinInfoForBrush((AttrBrushType*)pAttr, pNodePath, BlobRect.Centre());
01100 }
01101
01102
01103 return TRUE;
01104 }
01105
01106
01107 return FALSE;
01108 }
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 BOOL FreeHandTool::IsCursorNearPath(NodePath* pNodePath, INT32 Range, const DocCoord& PointerPos)
01132 {
01133
01134 Path* pPath = &(pNodePath->InkPath);
01135
01136
01137 INT32 CloseSlot = 0;
01138 double mu;
01139 if (pPath->IsPointCloseTo(PointerPos, Range, &CloseSlot, &mu))
01140 {
01141
01142
01143 StartPos = pPath->ClosestPointTo(mu, CloseSlot);
01144
01145
01146 JoinInfo.pJoinPath = pNodePath;
01147 JoinInfo.IsNearEndPoint = FALSE;
01148 JoinInfo.CloseSlot = CloseSlot;
01149 JoinInfo.Into = mu;
01150
01151
01152 ChangeCursor(pModifyCursor);
01153
01154
01155 StatusMsg.Load(_R(IDS_FREEHANDMODSTART), Tool::GetModuleID(GetID()));
01156 GetApplication()->UpdateStatusBarText(&StatusMsg);
01157
01158
01159 NodeAttribute* pAttr = NULL;
01160 pNodePath->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrBrushType), &pAttr);
01161 if (pAttr != NULL)
01162 {
01163 AttrBrushType* pAttrBrush = (AttrBrushType*)pAttr;
01164 InitialiseJoinInfoForBrush(pAttrBrush, pNodePath, PointerPos);
01165 }
01166
01167
01168 return TRUE;
01169 }
01170
01171
01172 return FALSE;
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190 void FreeHandTool::RenderToolBlobs(Spread* pSpread, DocRect* pClipRect)
01191 {
01192
01193 if (IsPreviousPathValid && IsRetroPathValid && RetroPath!=NULL)
01194 {
01195 RenderRegion* pRegion = DocView::RenderOnTop(pClipRect, pSpread, ClippedEOR);
01196 while (pRegion)
01197 {
01198
01199 pRegion->SetLineColour(COLOUR_XOREDIT);
01200 pRegion->SetLineWidth(0);
01201 pRegion->DrawPath(RetroPath);
01202
01203
01204 pRegion = DocView::GetNextOnTop(pClipRect);
01205 }
01206 }
01207 }
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 void FreeHandTool::SetSmoothness(INT32 Smooth)
01224 {
01225 Smoothness = Smooth;
01226 }
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242 INT32 FreeHandTool::GetSmoothness()
01243 {
01244 return Smoothness;
01245 }
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262 void FreeHandTool::PreviousPathInvalid()
01263 {
01264
01265
01266 IsPreviousPathValid = FALSE;
01267 IsRetroPathValid = FALSE;
01268 IsSelectBlobsOnScreen = FALSE;
01269 PreviousPath = NULL;
01270 StartSlot = 0;
01271 NumSlots = 0;
01272 PathCRC = 0;
01273
01274
01275 if (pInfoBarOp != NULL)
01276 pInfoBarOp->SetRetroState(FALSE);
01277 }
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298 void FreeHandTool::SetPreviousPath(NodePath* PrevPath, INT32 Start, INT32 Len)
01299 {
01300
01301 PreviousPath = PrevPath;
01302 StartSlot = Start;
01303 NumSlots = Len;
01304
01305
01306 PathCRC = BuildPathCRC(PreviousPath);
01307
01308
01309 IsPreviousPathValid = TRUE;
01310 IsRetroPathValid = FALSE;
01311 IsSelectBlobsOnScreen = TRUE;
01312
01313
01314 if (pInfoBarOp != NULL)
01315 pInfoBarOp->SetRetroState(TRUE);
01316
01317
01318 RetroPath->ClearPath();
01319 }
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336 BOOL FreeHandTool::IsRetroPathStillValid()
01337 {
01338
01339 BOOL IsStillValid = FALSE;
01340 SelRange* Selected = GetApplication()->FindSelection();
01341 DocView* pDocView = DocView::GetSelected();
01342
01343
01344 if ((pDocView!=NULL) && (Selected->Count()==1))
01345 {
01346
01347 Node* pNode = Selected->FindFirst();
01348
01349
01350 if ((pNode==PreviousPath) && (pNode->IS_KIND_OF(NodePath)))
01351 {
01352
01353 INT32 CurrentCRC = BuildPathCRC(PreviousPath);
01354 if (CurrentCRC==PathCRC)
01355 IsStillValid = TRUE;
01356 }
01357 }
01358
01359
01360 return IsStillValid;
01361 }
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378 INT32 FreeHandTool::BuildPathCRC(NodePath* PrevPath)
01379 {
01380 INT32 TotalCRC = 0;
01381
01382
01383 Path* CRCPath = &(PrevPath->InkPath);
01384
01385
01386 DocCoord* Coords = CRCPath->GetCoordArray();
01387 INT32 NumCoords = StartSlot+NumSlots;
01388
01389
01390 for (INT32 i=StartSlot; i<NumCoords; i++)
01391 {
01392
01393
01394
01395 TotalCRC += (Coords[i].x-Coords[StartSlot].x) + (Coords[i].y-Coords[StartSlot].y);
01396 }
01397
01398
01399 return TotalCRC;
01400 }
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416 void FreeHandTool::TranslateTrackData()
01417 {
01418
01419 if (TrackData==NULL)
01420 return;
01421
01422
01423 DocCoord* TrackCoords = TrackData->GetCoordArray();
01424 DocCoord* TreeCoords = PreviousPath->InkPath.GetCoordArray();
01425
01426
01427 if ((TrackCoords[0].x!=TreeCoords[StartSlot].x) || (TrackCoords[0].y!=TreeCoords[StartSlot].y))
01428 {
01429
01430 INT32 Dx = TreeCoords[StartSlot].x - TrackCoords[0].x;
01431 INT32 Dy = TreeCoords[StartSlot].y - TrackCoords[0].y;
01432
01433
01434 INT32 NumCoords = TrackData->GetNumCoords();
01435 for (INT32 i=0; i<NumCoords; i++)
01436 {
01437
01438 TrackCoords[i].x += Dx;
01439 TrackCoords[i].y += Dy;
01440 }
01441 }
01442 }
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455 void FreeHandTool::RetroFitChanging()
01456 {
01457 BOOL IsStillValid = IsRetroPathStillValid();
01458 if (IsStillValid)
01459 {
01460
01461 Spread* pSpread = PreviousPath->FindParentSpread();
01462
01463
01464 DocView* pDocView = DocView::GetSelected();
01465
01466
01467 if (pSpread!=NULL && pDocView!=NULL)
01468 {
01469 BlobManager* BlobMgr = GetApplication()->GetBlobManager();
01470 ENSURE(BlobMgr!=NULL, "Blob Manager was not there");
01471
01472
01473 TranslateTrackData();
01474
01475
01476 if (IsSelectBlobsOnScreen)
01477 {
01478 BlobMgr->RenderMyBlobs(NULL, pSpread, PreviousPath);
01479 IsSelectBlobsOnScreen = FALSE;
01480 }
01481
01482
01483 BlobMgr->RenderToolBlobsOff(this, pSpread, NULL);
01484
01485
01486 double ScaleFactor = (pDocView->GetViewScale()).MakeDouble();
01487 double ErrorLevel = (64 + (160*Smoothness)) / ScaleFactor;
01488 ErrorLevel = ErrorLevel * ErrorLevel;
01489
01490
01491 if ((RetroPath!=NULL) && (TrackData!=NULL))
01492 {
01493 CurveFitObject CurveFitter(RetroPath, ErrorLevel);
01494 if (CurveFitter.Initialise(TrackData, TrackData->GetNumCoords()))
01495 CurveFitter.FitCurve();
01496 }
01497
01498
01499 IsRetroPathValid = TRUE;
01500 BlobMgr->RenderToolBlobsOn(this, pSpread, NULL);
01501 AreWeRetroFitting = TRUE;
01502 }
01503 else
01504 {
01505 IsStillValid = FALSE;
01506 }
01507 }
01508
01509
01510 if (!IsStillValid)
01511 {
01512
01513 PreviousPathInvalid();
01514 }
01515 }
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529 void FreeHandTool::RetroFitFinished()
01530 {
01531
01532
01533 if ((IsPreviousPathValid && AreWeRetroFitting) && (RetroPath!=NULL))
01534 {
01535
01536 Spread* pSpread = PreviousPath->FindParentSpread();
01537 if (pSpread!=NULL)
01538 {
01539 BlobManager* BlobMgr = GetApplication()->GetBlobManager();
01540 ENSURE(BlobMgr!=NULL, "Blob Manager was not there");
01541
01542
01543 if (!IsSelectBlobsOnScreen)
01544 {
01545 BlobMgr->RenderMyBlobs(NULL, pSpread, PreviousPath);
01546 IsSelectBlobsOnScreen = TRUE;
01547 }
01548
01549
01550 BlobMgr->RenderToolBlobsOff(this, pSpread, NULL);
01551
01552
01553 if (IsRetroPathValid)
01554 {
01555
01556 Node* pNode;
01557 if (PreviousPath->NodeCopy(&pNode))
01558 {
01559
01560 BeginSlowJob();
01561
01562
01563 NodePath* pNewPath = (NodePath*) pNode;
01564
01565
01566 BOOL IsOk;
01567 if (StartSlot==0)
01568 IsOk = pNewPath->InkPath.RetroReplaceSection(StartSlot, NumSlots, RetroPath, TRUE);
01569 else
01570 IsOk = pNewPath->InkPath.RetroReplaceSection(StartSlot, NumSlots, RetroPath, FALSE);
01571
01572
01573 if (IsOk)
01574 {
01575
01576 OpRetroFit* pRetroOp = new OpRetroFit;
01577 if (pRetroOp!=NULL)
01578 {
01579
01580
01581 INT32 OldStartSlot = StartSlot;
01582 INT32 OldNumSlots = RetroPath->GetNumCoords();
01583 if (pRetroOp->BuildUndo(PreviousPath, (NodePath*)pNode))
01584 SetPreviousPath(pNewPath, OldStartSlot, OldNumSlots);
01585 }
01586 else
01587 {
01588
01589 IsOk = FALSE;
01590 }
01591 }
01592
01593
01594 EndSlowJob();
01595
01596
01597 if (!IsOk)
01598 ToolInformError(_R(IDS_RETROOUTOFMEM));
01599 }
01600 }
01601
01602
01603
01604 RetroPath->ClearPath();
01605 IsRetroPathValid = FALSE;
01606 }
01607 }
01608
01609
01610 AreWeRetroFitting = FALSE;
01611 }
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628 BOOL FreeHandTool::GetNewPaths()
01629 {
01630
01631 DeletePaths();
01632
01633
01634 if ((RetroPath==NULL) && (TrackData==NULL))
01635 {
01636
01637 TrackData = new Path();
01638 if (TrackData==NULL)
01639 return FALSE;
01640
01641
01642 RetroPath = new Path();
01643 if (RetroPath==NULL)
01644 {
01645 delete TrackData;
01646 TrackData = NULL;
01647 return FALSE;
01648 }
01649
01650
01651 if (!TrackData->Initialise(48,48))
01652 {
01653 DeletePaths();
01654 return FALSE;
01655 }
01656
01657
01658 if (!RetroPath->Initialise(12, 12))
01659 {
01660 DeletePaths();
01661 return FALSE;
01662 }
01663
01664 }
01665
01666
01667 return TRUE;
01668 }
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684 BOOL FreeHandTool::DeletePaths()
01685 {
01686
01687 PreviousPathInvalid();
01688
01689
01690 if (TrackData!=NULL)
01691 {
01692 delete TrackData;
01693 TrackData = NULL;
01694 }
01695
01696 if (RetroPath!=NULL)
01697 {
01698 delete RetroPath;
01699 RetroPath = NULL;
01700 }
01701
01702 return TRUE;
01703 }
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717 void FreeHandTool::SetCurrentBrushHandle()
01718 {
01719 Document* pDoc = Document::GetCurrent();
01720 if (pDoc == NULL)
01721 {
01722 ERROR3("No document");
01723 return;
01724 }
01725
01726 AttributeManager* pAttrMgr = &(pDoc->GetAttributeMgr());
01727 if (pAttrMgr == NULL)
01728 {
01729 ERROR3("No attribute manager");
01730 return;
01731 }
01732
01733 AttrBrushType* pAttr = (AttrBrushType*)(pAttrMgr->GetCurrentAttribute(CC_RUNTIME_CLASS(NodeRenderableInk), CC_RUNTIME_CLASS(AttrBrushType)));
01734
01735 if (pAttr == NULL)
01736 {
01737 ERROR3("No current brush attribute");
01738 return;
01739 }
01740 m_BrushHandle = pAttr->GetBrushHandle();
01741
01742 }
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758 void FreeHandTool::CreateBrush()
01759 {
01760
01761
01762
01763 SelRange* pSel = GetApplication()->FindSelection();
01764
01765 if (pSel == NULL)
01766 {
01767 return ;
01768 }
01769
01770 m_NumInkNodes = 0;
01771
01772 Node* pNode = pSel->FindFirst();
01773
01774 if (pNode == NULL)
01775 {
01776 InformWarning(_R(IDS_BRUSHCREATENOSEL));
01777 return;
01778 }
01779
01780
01781 while (pNode != NULL)
01782 {
01783 if (pNode->IsAnObject())
01784 {
01785 if (BrushDefinition::ObjectCanCreateBrush((NodeRenderableInk*)pNode))
01786 m_NumInkNodes++;
01787
01788 if (m_NumInkNodes >= MAX_BRUSH_OBJECTS)
01789 {
01790 InformWarning(_R(IDS_BRUSHCREATE_TOOMANY));
01791 break;
01792 }
01793 }
01794 pNode = pSel->FindNext(pNode);
01795 }
01796
01797 if (m_NumInkNodes == 0)
01798 {
01799 InformWarning(_R(IDS_BRUSHCREATE_INVALID));
01800 return;
01801 }
01802
01803 InitialiseBrushInkNodeArray((UINT32)m_NumInkNodes);
01804
01805 DocRect BBox;
01806
01807
01808 UINT32 Counter = 0;
01809 pNode = pSel->FindFirst();
01810
01811 while (pNode != NULL && Counter < m_NumInkNodes)
01812 {
01813 if (pNode->IsAnObject())
01814 {
01815
01816 BBox = ((NodeRenderableInk*)pNode)->GetBoundingRect();
01817 if (BBox.Height() > MAX_BRUSH_SPACING || BBox.Width() > MAX_BRUSH_SPACING)
01818 {
01819 InformWarning(_R(IDS_BRUSH_TOOBIG));
01820 return;
01821 }
01822 if (BrushDefinition::ObjectCanCreateBrush((NodeRenderableInk*)pNode))
01823 {
01824 m_BrushInkNodeArray[Counter++] = (NodeRenderableInk*)pNode;
01825 }
01826 }
01827 pNode = pSel->FindNext(pNode);
01828 }
01829
01830 Spread *pBrushSpread = new Spread;
01831 if (pBrushSpread == NULL)
01832 {
01833 ERROR3("Couldn't create new brush spread");
01834 return;
01835 }
01836
01837 Layer *pBrushLayer = new Layer(pBrushSpread, FIRSTCHILD, String_256(TEXT("Diccon did this")));
01838 if (pBrushLayer == NULL)
01839 {
01840 ERROR3("Couldn't create new brush (5)");
01841 delete pBrushSpread;
01842 return;
01843 }
01844
01845 BOOL LineWidth = FALSE;
01846 BOOL Compound = FALSE;
01847
01848 Node* pLastNode = NULL;
01849
01850
01851 for (UINT32 i = 0; i < m_NumInkNodes; i++)
01852 {
01853 NodeRenderableInk* pInk = m_BrushInkNodeArray[i];
01854
01855
01856 if (NodeHasLineWidth(pInk))
01857 LineWidth = TRUE;
01858 if (pInk->IsCompound())
01859 Compound = TRUE;
01860 pInk->MakeAttributeComplete();
01861
01862 Node* pInsertNode = NULL;
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887 {
01888
01889 pInsertNode = pInk->PublicCopy();
01890
01891 if (pInsertNode == NULL)
01892 {
01893 ERROR3("Error copying node");
01894 return;
01895 }
01896
01897 pInk->CopyChildrenTo(pInsertNode);
01898
01899 }
01900 pInk->NormaliseAttributes();
01901 if (i==0)
01902 pInsertNode->AttachNode(pBrushLayer, FIRSTCHILD, FALSE, TRUE);
01903 else
01904 pInsertNode->AttachNode(pLastNode, NEXT, FALSE, TRUE);
01905
01906 pLastNode = pInsertNode;
01907 }
01908
01909
01910 LineDefinition::ConvertIndexedColours(pBrushSpread);
01911
01912
01913 BrushDefinition* pBrushDef = new BrushDefinition(pBrushSpread);
01914
01915 if (pBrushDef == NULL)
01916 {
01917 ERROR3("Couldn't allocate brush def");
01918 delete pBrushSpread;
01919 delete pBrushLayer;
01920 return;
01921 }
01922
01923
01924 if (!pBrushDef->IsActivated())
01925 {
01926 ERROR3("Brush failed to initialise correctly, aborting Create Brush");
01927 delete pBrushDef;
01928 delete pBrushSpread;
01929 delete pBrushLayer;
01930 return;
01931 }
01932
01933
01934 DocRect BRect = pBrushDef->GetLargestBoundingBox();
01935 MILLIPOINT Width = BRect.Width();
01936 if (pBrushDef->GetNumBrushObjects() > 1 || LineWidth || Compound)
01937 {
01938 MILLIPOINT Spacing = (MILLIPOINT)(Width * 1.1);
01939 if (Spacing > MAX_BRUSH_SPACING)
01940 Spacing = MAX_BRUSH_SPACING;
01941
01942 pBrushDef->SetSpacing(Spacing);
01943 }
01944 else
01945 pBrushDef->SetSpacing(Width / 5);
01946
01947
01948 Document* pDoc = Document::GetCurrent();
01949 if (pDoc == NULL)
01950 {
01951 ERROR3("No document");
01952 delete pBrushSpread;
01953 delete pBrushLayer;
01954 return;
01955 }
01956 BrushComponent *pBrushComp = (BrushComponent*)(pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent)));
01957 if (pBrushComp == NULL)
01958 {
01959 ERROR3("Couldn't get brush component");
01960 delete pBrushSpread;
01961 delete pBrushLayer;
01962 return;
01963 }
01964 BrushHandle NewHandle = pBrushComp->AddNewItem(pBrushDef, TRUE);
01965
01966 if (NewHandle != BrushHandle_NoBrush)
01967 {
01968 if (pInfoBarOp != NULL)
01969 pInfoBarOp->AddBrush();
01970
01971
01972 BrushSelected(NewHandle, FALSE);
01973
01974
01975 NodeRenderableInk::DeselectAll();
01976 }
01977 else
01978 delete pBrushDef;
01979
01980 }
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997 void FreeHandTool::LaunchBrushDefinitionDialog(BrushHandle Handle)
01998 {
01999
02000
02001 Document* pDoc = Document::GetCurrent();
02002 if (!pDoc) return;
02003 BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent));
02004 if (!pBrushComp) return;
02005
02006 BrushDefinition* pBrushDef = pBrushComp->FindBrushDefinition(Handle);
02007 if (!pBrushDef) return;
02008
02009
02010 BrushData* pData = pBrushDef->GetBrushData();
02011
02012 if (pData != NULL)
02013 {
02014 PORTNOTE("other", "Removed CBrushGadget support");
02015 #ifndef EXCLUDE_FROM_XARALX
02016
02017 LineGallery* pLineGallery = LineGallery::GetInstance();
02018 if (pLineGallery != NULL)
02019 {
02020
02021 CBrushGadget* pGadget = pLineGallery->GetBrushGadget();
02022 if (pGadget != NULL)
02023 {
02024
02025 pData->m_BrushHandle = Handle;
02026
02027 pGadget->EnableEditingBrushDefinition ();
02028 pGadget->HandleBrushButtonClick(pData->m_BrushHandle);
02029 }
02030
02031 delete pData;
02032 }
02033 #endif
02034 }
02035 }
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049 void FreeHandTool::InitialiseBrushInkNodeArray(UINT32 NumObjects)
02050 {
02051 UINT32 i = 0;
02052
02053
02054 m_BrushInkNodeArray.clear();
02055
02056 m_BrushInkNodeArray.resize(NumObjects);
02057
02058
02059
02060 i = 0;
02061 while (i < m_BrushInkNodeArray.size())
02062 {
02063 m_BrushInkNodeArray[i++] = NULL;
02064 }
02065
02066 }
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081 GRenderBrush* FreeHandTool::GetBigGRenderBrush(Spread* pSpread)
02082 {
02083 PORTNOTE("other", "Removed m_pGRenderBrush support");
02084 #ifndef EXCLUDE_FROM_XARALX
02085 m_bBrushReady = FALSE;
02086 Document* pDoc = Document::GetSelected();
02087 if (!pDoc)
02088 return NULL;
02089
02090 DocView * pDocView = DocView::GetSelected();
02091
02092
02093 DocRect ViewRect = pDocView->GetDocViewRect(pSpread);
02094 pSpread->DocCoordToSpreadCoord(&ViewRect);
02095
02096
02097
02098 CCamView* pCCamView = pDocView->GetConnectionToOilView();
02099 CDC* pDevContext = ((ScreenCamView*)pCCamView)->GetRenderDC();
02100 HDC DeviceHdc = pDevContext->GetSafeHdc();
02101 INT32 DeviceBPP = GetDeviceCaps(DeviceHdc, BITSPIXEL);
02102
02103
02104 Matrix RenderMat = pDocView->ConstructRenderingMatrix(pSpread);
02105 FIXED16 Scale = 1;
02106
02107 GRenderBrush* pGRender = NULL;
02108
02109 INT32 DeviceRes = GetDeviceCaps( DeviceHdc, LOGPIXELSX );
02110
02111 pGRender = new GRenderBrush(ViewRect, RenderMat, Scale, 32, DeviceRes);
02112
02113
02114 if (pGRender == NULL)
02115 {
02116 ERROR3("Failed to allocate DIB");
02117 return NULL;
02118 }
02119
02120 BOOL ok = pGRender->AttachDevice(pDocView, pDevContext, pSpread);
02121 if (!ok)
02122 {
02123 delete pGRender;
02124 pGRender = NULL;
02125 return NULL;
02126 }
02127
02128 if (DeviceBPP < 24)
02129 pGRender->SetDeepDIB(FALSE);
02130 else
02131 pGRender->SetDeepDIB(TRUE);
02132
02133
02134 pGRender->InitDevice();
02135 pGRender->m_DoCompression = TRUE;
02136
02137 pGRender->InitAttributes();
02138 pGRender->RRQuality.SetQuality(QUALITY_MAX);
02139 pGRender->SetQualityLevel();
02140 pGRender->SetLineAttributes();
02141 pGRender->SetFillAttributes();
02142
02143
02144
02145 if (!pGRender->StartRender())
02146 {
02147 ERROR3("Unable to setup bitmap");
02148 delete pGRender;
02149 return NULL;
02150 }
02151
02152
02153 if (DeviceBPP < 24)
02154 {
02155 if (!InitialiseBrushBitmaps(pGRender))
02156 {
02157 InformWarning(_R(IDS_BRUSHBITMAP_INVALID));
02158 delete pGRender;
02159 return NULL;
02160 }
02161 }
02162
02163
02164 if (!pGRender->CaptureView(pSpread))
02165 {
02166 ERROR3("Unable to capture view");
02167 delete pGRender;
02168 return NULL;
02169 }
02170
02171
02172 m_bBrushReady = TRUE;
02173 return pGRender;
02174 #else
02175 return NULL;
02176 #endif
02177 }
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191 MILLIPOINT FreeHandTool::GetBrushSpacing()
02192 {
02193 return m_BrushSpacing;
02194 }
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209 void FreeHandTool::SetBrushSpacing(MILLIPOINT Spacing)
02210 {
02211 m_BrushSpacing = Spacing;
02212 }
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229 BOOL FreeHandTool::InitialiseBlendRef(NodeRenderableInk* pInk)
02230 {
02231 ERROR2IF(pInk == NULL,FALSE,"InkNode is NULL");
02232
02233 if (m_pBlendRef != NULL)
02234 {
02235 delete m_pBlendRef;
02236 m_pBlendRef = NULL;
02237 }
02238 m_pBlendRef = new BlendRef;
02239
02240 BOOL ok = (m_pBlendRef != NULL);
02241
02242 Progress* pProgress = NULL;
02243 if (ok) ok = m_pBlendRef->Initialise(pInk, -1, NULL, pProgress, FALSE, NULL);
02244
02245 return ok;
02246 }
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263 DocRect FreeHandTool::GetLargestInkBoundingRect()
02264 {
02265 DocRect LargestBRect;
02266
02267
02268
02269 INT32 BiggestArea = 0;
02270 for (UINT32 i = 0; i < m_NumInkNodes; i++)
02271 {
02272 DocRect TempRect = m_BrushInkNodeArray[i]->GetBoundingRect();
02273 INT32 TempArea = TempRect.Height() * TempRect.Width();
02274 if (TempArea > BiggestArea)
02275 {
02276 LargestBRect = TempRect;
02277 BiggestArea = TempArea;
02278 }
02279 }
02280 return LargestBRect;
02281 }
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297 BOOL FreeHandTool::NodeHasLineWidth(NodeRenderableInk* pNode)
02298 {
02299 ERROR2IF(pNode == NULL, FALSE, "pNode is NULL in FreeHandTool::NodeHasLineWidth");
02300 NodeAttribute* pAttr = NULL;
02301 pNode->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrStrokeColour), &pAttr);
02302
02303 if (pAttr == NULL)
02304 return FALSE;
02305
02306
02307 StrokeColourAttribute* pVal = (StrokeColourAttribute*)pAttr->GetAttributeValue();
02308 if (pVal != NULL)
02309 {
02310 DocColour Col = pVal->Colour;
02311 if (Col.IsTransparent())
02312 return FALSE;
02313 }
02314
02315 return TRUE;
02316 }
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334 BrushDefinition* FreeHandTool::GetSelectedBrush()
02335 {
02336 Document* pDoc = Document::GetCurrent();
02337 ERROR2IF(pDoc == NULL, NULL, "No document");
02338
02339 BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent));
02340 if (pBrushComp == NULL)
02341 {
02342 ERROR3("No brush component");
02343 return NULL;
02344 }
02345
02346 return pBrushComp->FindBrushDefinition(m_BrushHandle);
02347
02348 }
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371 BOOL FreeHandTool::SetBrushUpdateState(UPDATE_STATE Update)
02372 {
02373 if (Update < UPDATE_NOW || Update > UPDATE_NEVER)
02374 {
02375 ERROR3("Invalid update flag");
02376 return FALSE;
02377 }
02378 m_UpdateBrushState = Update;
02379 return TRUE;
02380 }
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398 BOOL FreeHandTool::BrushSelected(BrushHandle Handle, BOOL ApplyToSelection)
02399 {
02400 if (m_UpdateBrushState == UPDATE_NEVER)
02401 return TRUE;
02402
02403
02404 if (ApplyToSelection)
02405 {
02406
02407 if (!ApplyBrushToSelection(Handle))
02408 return FALSE;
02409
02410 m_UpdateBrushState = UPDATE_ONIDLE;
02411 }
02412
02413
02414 m_BrushHandle = Handle;
02415
02416
02417
02418
02419
02420 if (m_UpdateBrushState == UPDATE_NOW)
02421 m_UpdateBrushState = UPDATE_NEVER;
02422 else
02423 {
02424 m_UpdateBrushState = UPDATE_ONIDLE;
02425 return TRUE;
02426 }
02427
02428
02429 if (m_BrushHandle == BrushHandle_NoBrush)
02430 {
02431 PORTNOTE("other", "Removed m_pGRenderBrush support");
02432 #ifndef EXCLUDE_FROM_XARALX
02433 if (m_pGRenderBrush != NULL)
02434 {
02435 delete m_pGRenderBrush;
02436 m_pGRenderBrush = NULL;
02437 }
02438 #endif
02439 return TRUE;
02440 }
02441
02442 PORTNOTE("other", "Removed m_pGRenderBrush support");
02443 #ifndef EXCLUDE_FROM_XARALX
02444
02445
02446 if (m_pGRenderBrush != NULL && m_pGRenderBrush->GetScreenDepth() < 24)
02447 {
02448 delete m_pGRenderBrush;
02449 m_pGRenderBrush = NULL;
02450 }
02451
02452 String_32 ProgString = _T("Preparing brush, please wait..");
02453 Progress Hourglass(&ProgString, -1, FALSE);
02454
02455
02456
02457
02458 Spread* pCurrentSpread = Document::GetSelectedSpread();
02459
02460 if (pCurrentSpread == NULL)
02461 {
02462 ERROR3("No Spread in FreeHandTool::BrushSelected");
02463 return FALSE;
02464 }
02465
02466
02467 JoinInfo.m_BrushHandle = m_BrushHandle;
02468
02469 if (m_pGRenderBrush == NULL)
02470 {
02471 m_pGRenderBrush = GetBigGRenderBrush(pCurrentSpread);
02472
02473 if (m_pGRenderBrush != NULL)
02474 {
02475 if (!InitialiseBrushBitmaps(m_pGRenderBrush))
02476 {
02477 InformWarning(_R(IDS_BRUSHBITMAP_INVALID));
02478 delete m_pGRenderBrush;
02479 m_pGRenderBrush = NULL;
02480
02481 return FALSE;
02482 }
02483
02484 m_bBrushReady = TRUE;
02485
02486 }
02487 else
02488 {
02489 ToolInformError(_R(IDS_OUT_OF_MEMORY));
02490
02491 return FALSE;
02492 }
02493 }
02494 else
02495 {
02496
02497 BOOL ok = m_pGRenderBrush->CaptureView(pCurrentSpread);
02498
02499
02500 if (ok) m_pGRenderBrush->SetupMainBitmap();
02501 return ok;
02502 }
02503 #endif
02504
02505 return TRUE;
02506 }
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523 BOOL FreeHandTool::InitialiseBrushBitmaps(GRenderBrush* pGRender)
02524 {
02525 ERROR2IF(pGRender == NULL, FALSE, "GRenderBrush is NULL in FreeHandTool::InitialiseBrushBitmaps");
02526
02527
02528 BrushDefinition* pBrushDef = GetSelectedBrush();
02529 if (pBrushDef == NULL)
02530 {
02531 ERROR3("No brush definition");
02532 return FALSE;
02533 }
02534
02535 DocRect LargestRect = pBrushDef->GetLargestPossibleRect(TRUE);
02536 if (LargestRect.IsEmpty())
02537 {
02538 ERROR3("Empty bounding rect");
02539 return FALSE;
02540 }
02541
02542
02543
02544
02545
02546
02547
02548
02549 PORTNOTE("other", "Removed m_pGRenderBrush support");
02550 #ifndef EXCLUDE_FROM_XARALX
02551 if (!pGRender->InitialiseBrushBitmaps(LargestRect))
02552 {
02553 return FALSE;
02554 }
02555 #endif
02556 return TRUE;
02557 }
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579 void FreeHandTool::BrushDeleted(BrushHandle Handle)
02580 {
02581 if (Handle == m_BrushHandle)
02582 BrushSelected(BrushHandle_NoBrush, FALSE);
02583
02584 if (pInfoBarOp != NULL)
02585 pInfoBarOp->RemoveBrush(Handle);
02586 }
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601 void FreeHandTool::BrushFinished()
02602 {
02603
02604 SetColourEditorProcessing(TRUE);
02605
02606
02607 Document* pDoc = Document::GetSelected();
02608 DocView* pDocView = pDoc->GetFirstDocView();
02609
02610 while (pDocView)
02611 {
02612 pDocView->SetPreventRenderView(FALSE);
02613 pDocView = pDoc->GetNextDocView(pDocView);
02614 }
02615
02616
02617
02618
02619
02620
02621 m_bBrushReady = FALSE;
02622 m_UpdateBrushState = UPDATE_ONIDLE;
02624 BrushSelected(m_BrushHandle, FALSE);
02625
02626
02627 }
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643 void FreeHandTool::ScreenChanged(BOOL WipeRegion)
02644 {
02645
02646
02647 if (WipeRegion == TRUE)
02648 {
02649 PORTNOTE("other", "Removed m_pGRenderBrush support");
02650 #ifndef EXCLUDE_FROM_XARALX
02651 if (m_pGRenderBrush != NULL)
02652 {
02653 delete m_pGRenderBrush;
02654 m_pGRenderBrush = NULL;
02655 }
02656 #endif
02657 }
02658
02659 m_bBrushReady = FALSE;
02660
02661 m_UpdateBrushState = UPDATE_ONIDLE;
02662 }
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680 BOOL FreeHandTool::ApplyBrushToSelection(BrushHandle Handle)
02681 {
02682
02683 SelRange* pSel = GetApplication()->FindSelection();
02684 if (pSel == NULL)
02685 {
02686 ERROR3("No selection in FreeHandTool::ApplyBrushToSelection");
02687 return FALSE;
02688 }
02689
02690
02691
02692
02693 if (pSel->IsEmpty())
02694 return TRUE;
02695
02696
02697 NodeAttribute* pNewAttr = BrushComponent::CreateNode(Handle);
02698 if (pNewAttr != NULL)
02699 AttributeManager::AttributeSelected(pNewAttr);
02700
02701
02702 if (Handle == BrushHandle_NoBrush)
02703 {
02704
02705 NodeAttribute* pAttr = new AttrBrushType;
02706 if (pAttr != NULL)
02707 AttributeManager::AttributeSelected(pAttr);
02708 }
02709 return TRUE;
02710
02711 }
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726 BOOL FreeHandTool::OnIdle()
02727 {
02728
02729 if (Document::GetCurrent() == NULL)
02730 {
02731 m_UpdateBrushState = UPDATE_NEVER;
02732 return FALSE;
02733 }
02734
02735 if (m_UpdateBrushState == UPDATE_ONIDLE)
02736 {
02737 #ifdef NEWFASTBRUSHES
02738 static Application* pApp = GetApplication ();
02739
02740 BOOL doCaptureNow = TRUE;
02741
02742 if (pApp)
02743 {
02744 if (!pApp->IsRenderingComplete ())
02745 {
02746
02747
02748
02749 doCaptureNow = FALSE;
02750 TRACEUSER( "ChrisS", _T("Brush System: Not finished rendering - just ignored screen capture request ...."));
02751 }
02752 }
02753
02754 if (doCaptureNow)
02755 {
02756 #endif
02757
02758 PORTNOTE("other", "Removed cursor bodge");
02759 #ifndef EXCLUDE_FROM_XARALX
02760 HCURSOR Cursor = GetCursor();
02761 #endif
02762 m_UpdateBrushState = UPDATE_NOW;
02763 BrushSelected(m_BrushHandle, FALSE);
02764 PORTNOTE("other", "Removed cursor bodge");
02765 #ifndef EXCLUDE_FROM_XARALX
02766 SetCursor(Cursor);
02767 #endif
02768 #ifdef NEWFASTBRUSHES
02769 }
02770 #endif
02771
02772 }
02773 return FALSE;
02774 }
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790 void FreeHandTool::SetColourEditorProcessing(BOOL Value)
02791 {
02792 ColourEditDlg* pColourEditor = ColourEditDlg::GetColourEditDlg();
02793 if (pColourEditor != NULL)
02794 pColourEditor->SetDoTimerProcessing(Value);
02795 }
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813 void FreeHandTool::InitialiseJoinInfoForBrush(AttrBrushType* pAttrBrush, NodePath* pPath, DocCoord JoinPoint)
02814 {
02815 if (pAttrBrush == NULL || pPath == NULL)
02816 {
02817 ERROR3("NULL entry pointers in FreeHandTool::InitialiseJoinInfoForBrush");
02818 return;
02819 }
02820
02821
02822 JoinInfo.m_BrushHandle = pAttrBrush->GetBrushHandle();
02823
02824
02825
02826
02827 MILLIPOINT Distance = 0;
02828 if (!pPath->InkPath.GetDistanceToPoint(JoinPoint, &Distance))
02829 {
02830 ERROR3("Unable to find distance to point in FreeHandTool::InitialiseJoinInfoForBrush");
02831 return;
02832 }
02833
02834
02835
02836 BrushAttrValue* pVal = (BrushAttrValue*)pAttrBrush->GetAttributeValue();
02837 if (pVal != NULL)
02838 {
02839 PathProcessorBrush* pPPB = pVal->GetPathProcessor();
02840 if (pPPB != NULL)
02841 {
02842
02843 double Scaling = 1.0;
02844 MILLIPOINT Spacing = pPPB->GetSpacing();
02845 pPPB->GetSpacingAndScalingAtDistance(Distance, &Spacing, &Scaling);
02846 JoinInfo.FirstBrushSpacing = (MILLIPOINT)((double)Spacing * Scaling);
02847 JoinInfo.BrushDistance = Distance;
02848
02849 pPPB->CopyBrushData(&JoinInfo.m_BrushData);
02850
02851
02852 JoinInfo.UseLocalColour = pPPB->GetUseLocalFillColour();
02853 JoinInfo.UseNamedColour = pPPB->GetUseNamedColours();
02854 if ( JoinInfo.UseLocalColour == TRUE || JoinInfo.UseNamedColour == FALSE)
02855 {
02856 AttrStrokeColour *pStrokeCol = NULL;
02857 pPath->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrStrokeColour), (NodeAttribute**)&pStrokeCol);
02858 if (pStrokeCol)
02859 {
02860 JoinInfo.StrokeColour = pStrokeCol->Value.Colour;
02861 }
02862 }
02863
02864 }
02865
02866 JoinInfo.pAttrBrush = pAttrBrush;
02867
02868 }
02869
02870
02871
02872 }
02873
02874
02875 IMPLEMENT_SIMPLE_MODULE( FreeHandModule, MODULEID_FREEHAND, FreeHandTool,
02876 "Freehand Tool", "To draw things", "Rik" );
02877
02878
02879
02880
02881
02882
02883
02884