ToolConfigStrip.cs 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113
  1. using PaintDotNet.Measurement.Enum;
  2. using PaintDotNet.Measurement.Interface;
  3. using PaintDotNet.Measurement.ObjInfo;
  4. using PaintDotNet.SystemLayer;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. namespace PaintDotNet.Measurement
  13. {
  14. public class ToolConfigStrip : ToolStripEx,
  15. IBrushConfig,
  16. IShapeTypeConfig,
  17. IPenConfig,
  18. IAntiAliasingConfig,
  19. IAlphaBlendingConfig,
  20. ITextConfig,
  21. IToleranceConfig,
  22. IColorPickerConfig,
  23. IGradientConfig,
  24. IResamplingConfig,
  25. ISelectionCombineModeConfig,
  26. IFloodModeConfig,
  27. ISelectionDrawModeConfig
  28. {
  29. private ToolBarConfigItems toolBarConfigItems = ToolBarConfigItems.None;
  30. private EnumLocalizer hatchStyleNames = EnumLocalizer.Create(typeof(HatchStyle));
  31. private string solidBrushText;
  32. private ImageResource shapeOutlineImage = PdnResources.GetImageResource("Icons.ShapeOutlineIcon.png");
  33. private ImageResource shapeInteriorImage = PdnResources.GetImageResource("Icons.ShapeInteriorIcon.png");
  34. private ImageResource shapeBothImage = PdnResources.GetImageResource("Icons.ShapeBothIcon.png");
  35. private ToolStripSeparator brushSeparator;
  36. private ToolStripLabel brushStyleLabel;
  37. private ToolStripComboBox brushStyleComboBox;
  38. private ToolStripSeparator shapeSeparator;
  39. private ToolStripSplitButton shapeButton;
  40. private ToolStripSeparator penSeparator;
  41. private ToolStripLabel penSizeLabel;
  42. private ToolStripButton penSizeDecButton;
  43. private ToolStripComboBox penSizeComboBox;
  44. private ToolStripButton penSizeIncButton;
  45. private ToolStripLabel penStyleLabel;
  46. private ToolStripSplitButton penStartCapSplitButton; // Tag property is used to store chosen LineCap value
  47. private ToolStripSplitButton penDashStyleSplitButton; // Tag property is used to store chosen DashStyle value
  48. private ToolStripSplitButton penEndCapSplitButton; // Tag property is used to store chosen LineCap value
  49. private EnumLocalizer lineCapLocalizer = EnumLocalizer.Create(typeof(LineCap2));
  50. private EnumLocalizer dashStyleLocalizer = EnumLocalizer.Create(typeof(DashStyle));
  51. private ToolStripSeparator blendingSeparator;
  52. private ToolStripSplitButton alphaBlendingSplitButton;
  53. private bool alphaBlendingEnabled = true;
  54. private ImageResource alphaBlendingEnabledImage;
  55. private ImageResource alphaBlendingOverwriteImage;
  56. private ToolStripSplitButton antiAliasingSplitButton;
  57. private bool antiAliasingEnabled = true;
  58. private ImageResource antiAliasingEnabledImage;
  59. private ImageResource antiAliasingDisabledImage;
  60. private EnumLocalizer resamplingAlgorithmNames = EnumLocalizer.Create(typeof(ResamplingAlgorithm));
  61. private ToolStripSeparator resamplingSeparator;
  62. private ToolStripLabel resamplingLabel;
  63. private ToolStripComboBox resamplingComboBox;
  64. private EnumLocalizer colorPickerBehaviorNames = EnumLocalizer.Create(typeof(ColorPickerClickBehavior));
  65. private ToolStripSeparator colorPickerSeparator;
  66. private ToolStripLabel colorPickerLabel;
  67. private ToolStripComboBox colorPickerComboBox;
  68. private ToolStripSeparator toleranceSeparator;
  69. private ToolStripLabel toleranceLabel;
  70. private ToolStripControlHost toleranceSliderStrip;
  71. private ToleranceSliderControl toleranceSlider;
  72. private LineCap2[] lineCaps =
  73. new LineCap2[]
  74. {
  75. LineCap2.Flat,
  76. LineCap2.Arrow,
  77. LineCap2.ArrowFilled,
  78. LineCap2.Rounded
  79. };
  80. private DashStyle[] dashStyles =
  81. new DashStyle[]
  82. {
  83. DashStyle.Solid,
  84. DashStyle.Dash,
  85. DashStyle.DashDot,
  86. DashStyle.DashDotDot,
  87. DashStyle.Dot
  88. };
  89. private const float minPenSize = 1.0f;
  90. private const float maxPenSize = 500.0f;
  91. private int[] brushSizes =
  92. new int[]
  93. {
  94. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  95. 11, 12, 13, 14, 15, 20, 25, 30,
  96. 35, 40, 45, 50, 55, 60, 65, 70,
  97. 75, 80, 85, 90, 95, 100, 125,
  98. 150, 175, 200, 225, 250, 275, 300,
  99. 325, 350, 375, 400, 425, 450, 475,
  100. 500
  101. };
  102. private ShapeDrawType shapeDrawType;
  103. private EnumLocalizer gradientTypeNames = EnumLocalizer.Create(typeof(GradientType));
  104. private GradientInfo gradientInfo = new GradientInfo(GradientType.LinearClamped, false);
  105. private ToolStripSeparator gradientSeparator1;
  106. private ToolStripButton gradientLinearClampedButton;
  107. private ToolStripButton gradientLinearReflectedButton;
  108. private ToolStripButton gradientLinearDiamondButton;
  109. private ToolStripButton gradientRadialButton;
  110. private ToolStripButton gradientConicalButton;
  111. private ToolStripSeparator gradientSeparator2;
  112. private ToolStripSplitButton gradientChannelsSplitButton;
  113. private ImageResource gradientAllColorChannelsImage;
  114. private ImageResource gradientAlphaChannelOnlyImage;
  115. private EnumLocalizer fontSmoothingLocalizer = EnumLocalizer.Create(typeof(FontSmoothing));
  116. private const int maxFontSize = 2000;
  117. private const int minFontSize = 1;
  118. private const int initialFontSize = 12;
  119. private FontFamily arialFontFamily;
  120. private FontStyle fontStyle;
  121. private TextAlignment alignment;
  122. private float oldSizeValue;
  123. private Brush highlightBrush;
  124. private Brush highlightTextBrush;
  125. private Brush windowBrush;
  126. private Brush windowTextBrush;
  127. private Font arialFontBase;
  128. private const string arialName = "Arial";
  129. private static ManualResetEvent staticFontNamesPopulatedEvent = new ManualResetEvent(false);
  130. private static List<string> staticFontNames = null;
  131. private bool fontsComboBoxPopulated = false;
  132. private ToolStripSeparator fontSeparator;
  133. private ToolStripLabel fontLabel;
  134. private ToolStripComboBox fontFamilyComboBox;
  135. private ToolStripComboBox fontSizeComboBox;
  136. private ToolStripComboBox fontSmoothingComboBox;
  137. private ToolStripSeparator fontStyleSeparator;
  138. private ToolStripButton fontBoldButton;
  139. private ToolStripButton fontItalicsButton;
  140. private ToolStripButton fontUnderlineButton;
  141. private ToolStripSeparator fontAlignSeparator;
  142. private ToolStripButton fontAlignLeftButton;
  143. private ToolStripButton fontAlignCenterButton;
  144. private ToolStripButton fontAlignRightButton;
  145. private int[] defaultFontSizes =
  146. new int[]
  147. {
  148. 8, 9, 10, 11, 12, 14, 16, 18, 20,
  149. 22, 24, 26, 28, 36, 48, 72, 84, 96,
  150. 108, 144, 192, 216, 288
  151. };
  152. private ToolStripSeparator selectionCombineModeSeparator;
  153. private ToolStripLabel selectionCombineModeLabel;
  154. private ToolStripSplitButton selectionCombineModeSplitButton;
  155. private ToolStripSeparator floodModeSeparator;
  156. private ToolStripLabel floodModeLabel;
  157. private ToolStripSplitButton floodModeSplitButton;
  158. private SelectionDrawModeInfo selectionDrawModeInfo;
  159. private ToolStripSeparator selectionDrawModeSeparator;
  160. private ToolStripLabel selectionDrawModeModeLabel;
  161. private ToolStripSplitButton selectionDrawModeSplitButton;
  162. private ToolStripLabel selectionDrawModeWidthLabel;
  163. private ToolStripTextBox selectionDrawModeWidthTextBox;
  164. private ToolStripButton selectionDrawModeSwapButton;
  165. private ToolStripLabel selectionDrawModeHeightLabel;
  166. private ToolStripTextBox selectionDrawModeHeightTextBox;
  167. private UnitsComboBoxStrip selectionDrawModeUnits;
  168. public event EventHandler SelectionDrawModeUnitsChanging;
  169. protected void OnSelectionDrawModeUnitsChanging()
  170. {
  171. if (SelectionDrawModeUnitsChanging != null)
  172. {
  173. SelectionDrawModeUnitsChanging(this, EventArgs.Empty);
  174. }
  175. }
  176. public event EventHandler SelectionDrawModeUnitsChanged;
  177. protected void OnSelectionDrawModeUnitsChanged()
  178. {
  179. if (SelectionDrawModeUnitsChanged != null)
  180. {
  181. SelectionDrawModeUnitsChanged(this, EventArgs.Empty);
  182. }
  183. }
  184. public void LoadFromAppEnvironment(IAppEnvironment appEnvironment)
  185. {
  186. AlphaBlending = appEnvironment.AlphaBlending();
  187. AntiAliasing = appEnvironment.AntiAliasing();
  188. BrushInfo = appEnvironment.BrushInfo();
  189. ColorPickerClickBehavior = appEnvironment.ColorPickerClickBehavior();
  190. GradientInfo = appEnvironment.GradientInfo();
  191. PenInfo = appEnvironment.PenInfo();
  192. ResamplingAlgorithm = appEnvironment.ResamplingAlgorithm();
  193. ShapeDrawType = appEnvironment.ShapeDrawType();
  194. FontInfo = appEnvironment.FontInfo();
  195. FontSmoothing = appEnvironment.FontSmoothing();
  196. FontAlignment = appEnvironment.TextAlignment();
  197. Tolerance = appEnvironment.Tolerance();
  198. SelectionCombineMode = appEnvironment.SelectionCombineMode();
  199. FloodMode = appEnvironment.FloodMode();
  200. SelectionDrawModeInfo = appEnvironment.SelectionDrawModeInfo();
  201. }
  202. public event EventHandler BrushInfoChanged;
  203. protected virtual void OnBrushChanged()
  204. {
  205. if (BrushInfoChanged != null)
  206. {
  207. BrushInfoChanged(this, EventArgs.Empty);
  208. }
  209. }
  210. public BrushInfo BrushInfo
  211. {
  212. get
  213. {
  214. if (this.brushStyleComboBox.SelectedItem.ToString() == this.solidBrushText)
  215. {
  216. return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
  217. }
  218. if (this.brushStyleComboBox.SelectedIndex == -1)
  219. {
  220. return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
  221. }
  222. else
  223. {
  224. return new BrushInfo(
  225. BrushType.Hatch,
  226. (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(this.brushStyleComboBox.SelectedItem.ToString()));
  227. }
  228. }
  229. set
  230. {
  231. if (value.BrushType == BrushType.Solid)
  232. {
  233. this.brushStyleComboBox.SelectedItem = this.solidBrushText;
  234. }
  235. else
  236. {
  237. this.brushStyleComboBox.SelectedItem = this.hatchStyleNames.EnumValueToLocalizedName(value.HatchStyle);
  238. }
  239. }
  240. }
  241. public event EventHandler GradientInfoChanged;
  242. protected virtual void OnGradientInfoChanged()
  243. {
  244. if (GradientInfoChanged != null)
  245. {
  246. GradientInfoChanged(this, EventArgs.Empty);
  247. }
  248. }
  249. public void PerformGradientInfoChanged()
  250. {
  251. OnGradientInfoChanged();
  252. }
  253. public GradientInfo GradientInfo
  254. {
  255. get
  256. {
  257. return this.gradientInfo;
  258. }
  259. set
  260. {
  261. if (value == null)
  262. {
  263. throw new ArgumentNullException();
  264. }
  265. this.gradientInfo = value;
  266. OnGradientInfoChanged();
  267. SyncGradientInfo();
  268. }
  269. }
  270. private void SyncGradientInfo()
  271. {
  272. this.gradientConicalButton.Checked = false;
  273. this.gradientRadialButton.Checked = false;
  274. this.gradientLinearClampedButton.Checked = false;
  275. this.gradientLinearReflectedButton.Checked = false;
  276. this.gradientLinearDiamondButton.Checked = false;
  277. switch (this.gradientInfo.GradientType)
  278. {
  279. case GradientType.Conical:
  280. this.gradientConicalButton.Checked = true;
  281. break;
  282. case GradientType.LinearClamped:
  283. this.gradientLinearClampedButton.Checked = true;
  284. break;
  285. case GradientType.LinearReflected:
  286. this.gradientLinearReflectedButton.Checked = true;
  287. break;
  288. case GradientType.LinearDiamond:
  289. this.gradientLinearDiamondButton.Checked = true;
  290. break;
  291. case GradientType.Radial:
  292. this.gradientRadialButton.Checked = true;
  293. break;
  294. default:
  295. throw new InvalidEnumArgumentException();
  296. }
  297. if (this.gradientInfo.AlphaOnly)
  298. {
  299. this.gradientChannelsSplitButton.Image = this.gradientAlphaChannelOnlyImage.Reference;
  300. }
  301. else
  302. {
  303. this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
  304. }
  305. }
  306. private void ShapeButton_DropDownOpening(object sender, EventArgs e)
  307. {
  308. ToolStripMenuItem outlineMI = new ToolStripMenuItem();
  309. outlineMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.OutlineButton.ToolTipText");
  310. outlineMI.Image = this.shapeOutlineImage.Reference;
  311. outlineMI.Tag = (object)ShapeDrawType.Outline;
  312. outlineMI.Click += new EventHandler(ShapeMI_Click);
  313. ToolStripMenuItem interiorMI = new ToolStripMenuItem();
  314. interiorMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.InteriorButton.ToolTipText");
  315. interiorMI.Image = this.shapeInteriorImage.Reference;
  316. interiorMI.Tag = (object)ShapeDrawType.Interior;
  317. interiorMI.Click += new EventHandler(ShapeMI_Click);
  318. ToolStripMenuItem bothMI = new ToolStripMenuItem();
  319. bothMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.BothButton.ToolTipText");
  320. bothMI.Image = this.shapeBothImage.Reference;
  321. bothMI.Tag = (object)ShapeDrawType.Both;
  322. bothMI.Click += new EventHandler(ShapeMI_Click);
  323. switch (this.shapeDrawType)
  324. {
  325. case ShapeDrawType.Outline:
  326. outlineMI.Checked = true;
  327. break;
  328. case ShapeDrawType.Interior:
  329. interiorMI.Checked = true;
  330. break;
  331. case ShapeDrawType.Both:
  332. bothMI.Checked = true;
  333. break;
  334. default:
  335. throw new InvalidEnumArgumentException();
  336. }
  337. this.shapeButton.DropDownItems.AddRange(
  338. new ToolStripItem[]
  339. {
  340. outlineMI,
  341. interiorMI,
  342. bothMI
  343. });
  344. }
  345. private void ShapeMI_Click(object sender, EventArgs e)
  346. {
  347. ShapeDrawType sdt = (ShapeDrawType)((ToolStripMenuItem)sender).Tag;
  348. Tracing.LogFeature("ToolConfigStrip(" + sdt.ToString() + ")");
  349. this.ShapeDrawType = sdt;
  350. }
  351. public ToolConfigStrip()
  352. {
  353. SuspendLayout();
  354. InitializeComponent();
  355. this.solidBrushText = PdnResources.GetString("BrushConfigWidget.SolidBrush.Text"); // "Solid Brush"
  356. this.brushStyleComboBox.Items.Add(this.solidBrushText);
  357. string[] styleNames = this.hatchStyleNames.GetLocalizedNames();
  358. Array.Sort(styleNames);
  359. foreach (string styleName in styleNames)
  360. {
  361. brushStyleComboBox.Items.Add(styleName);
  362. }
  363. brushStyleComboBox.SelectedIndex = 0;
  364. this.brushStyleLabel.Text = PdnResources.GetString("BrushConfigWidget.FillStyleLabel.Text");
  365. this.shapeDrawType = ShapeDrawType.Outline;
  366. this.shapeButton.Image = this.shapeOutlineImage.Reference;
  367. this.penSizeLabel.Text = PdnResources.GetString("PenConfigWidget.BrushWidthLabel");
  368. this.penSizeComboBox.ComboBox.SuspendLayout();
  369. for (int i = 0; i < this.brushSizes.Length; ++i)
  370. {
  371. this.penSizeComboBox.Items.Add(this.brushSizes[i].ToString());
  372. }
  373. this.penSizeComboBox.ComboBox.ResumeLayout(false);
  374. this.penSizeComboBox.SelectedIndex = 1; // default to brush size of 2
  375. this.penSizeDecButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeDecButton.ToolTipText");
  376. this.penSizeDecButton.Image = PdnResources.GetImageResource("Icons.MinusButtonIcon.png").Reference;
  377. this.penSizeIncButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeIncButton.ToolTipText");
  378. this.penSizeIncButton.Image = PdnResources.GetImageResource("Icons.PlusButtonIcon.png").Reference;
  379. this.penStyleLabel.Text = PdnResources.GetString("ToolConfigStrip.PenStyleLabel.Text");
  380. this.penStartCapSplitButton.Tag = PenInfo.DefaultLineCap;
  381. this.penStartCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, true).Reference;
  382. this.penStartCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenStartCapSplitButton.ToolTipText");
  383. this.penDashStyleSplitButton.Tag = PenInfo.DefaultDashStyle;
  384. this.penDashStyleSplitButton.Image = GetDashStyleImage(PenInfo.DefaultDashStyle);
  385. this.penDashStyleSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenDashStyleSplitButton.ToolTipText");
  386. this.penEndCapSplitButton.Tag = PenInfo.DefaultLineCap;
  387. this.penEndCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, false).Reference;
  388. this.penEndCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenEndCapSplitButton.ToolTipText");
  389. this.gradientLinearClampedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearClamped);
  390. this.gradientLinearClampedButton.Image = PdnResources.GetImageResource("Icons.LinearClampedGradientIcon.png").Reference;
  391. this.gradientLinearReflectedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearReflected);
  392. this.gradientLinearReflectedButton.Image = PdnResources.GetImageResource("Icons.LinearReflectedGradientIcon.png").Reference;
  393. this.gradientLinearDiamondButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearDiamond);
  394. this.gradientLinearDiamondButton.Image = PdnResources.GetImageResource("Icons.LinearDiamondGradientIcon.png").Reference;
  395. this.gradientRadialButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Radial);
  396. this.gradientRadialButton.Image = PdnResources.GetImageResource("Icons.RadialGradientIcon.png").Reference;
  397. this.gradientConicalButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Conical);
  398. this.gradientConicalButton.Image = PdnResources.GetImageResource("Icons.ConicalGradientIcon.png").Reference;
  399. this.gradientAllColorChannelsImage = PdnResources.GetImageResource("Icons.AllColorChannelsIcon.png");
  400. this.gradientAlphaChannelOnlyImage = PdnResources.GetImageResource("Icons.AlphaChannelOnlyIcon.png");
  401. this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
  402. this.antiAliasingEnabledImage = PdnResources.GetImageResource("Icons.AntiAliasingEnabledIcon.png");
  403. this.antiAliasingDisabledImage = PdnResources.GetImageResource("Icons.AntiAliasingDisabledIcon.png");
  404. this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
  405. this.alphaBlendingEnabledImage = PdnResources.GetImageResource("Icons.BlendingEnabledIcon.png");
  406. this.alphaBlendingOverwriteImage = PdnResources.GetImageResource("Icons.BlendingOverwriteIcon.png");
  407. this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
  408. this.penSizeComboBox.Size = new Size(UI.ScaleWidth(this.penSizeComboBox.Width), penSizeComboBox.Height);
  409. this.brushStyleComboBox.Size = new Size(UI.ScaleWidth(this.brushStyleComboBox.Width), brushStyleComboBox.Height);
  410. this.brushStyleComboBox.DropDownWidth = UI.ScaleWidth(this.brushStyleComboBox.DropDownWidth);
  411. this.brushStyleComboBox.DropDownHeight = UI.ScaleHeight(this.brushStyleComboBox.DropDownHeight);
  412. this.toleranceLabel.Text = PdnResources.GetString("ToleranceConfig.ToleranceLabel.Text");
  413. this.toleranceSlider.Tolerance = 0.5f;
  414. this.fontSizeComboBox.ComboBox.SuspendLayout();
  415. for (int i = 0; i < this.defaultFontSizes.Length; ++i)
  416. {
  417. this.fontSizeComboBox.Items.Add(this.defaultFontSizes[i].ToString());
  418. }
  419. this.fontSizeComboBox.ComboBox.ResumeLayout(false);
  420. this.fontSmoothingComboBox.Items.AddRange(
  421. new object[]
  422. {
  423. this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Smooth),
  424. this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Sharp)
  425. });
  426. this.fontSmoothingComboBox.SelectedIndex = 0;
  427. this.fontLabel.Text = PdnResources.GetString("TextConfigWidget.FontLabel.Text");
  428. try
  429. {
  430. this.arialFontFamily = new FontFamily(arialName);
  431. }
  432. catch (Exception)
  433. {
  434. this.arialFontFamily = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
  435. }
  436. try
  437. {
  438. this.arialFontBase = new Font(arialFontFamily, initialFontSize, FontStyle.Regular);
  439. }
  440. catch (Exception)
  441. {
  442. this.arialFontBase = new Font(FontFamily.GenericSansSerif, initialFontSize, FontStyle.Regular);
  443. }
  444. this.fontFamilyComboBox.ComboBox.DropDownHeight = 600;
  445. this.alignment = TextAlignment.Left;
  446. this.fontAlignLeftButton.Checked = true;
  447. this.oldSizeValue = initialFontSize;
  448. this.highlightBrush = new SolidBrush(SystemColors.Highlight);
  449. this.highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
  450. this.windowBrush = new SolidBrush(SystemColors.Window);
  451. this.windowTextBrush = new SolidBrush(SystemColors.WindowText);
  452. // These buttons need a color key to maintain consistency with v2.5 language packs
  453. this.fontBoldButton.ImageTransparentColor = Utility.TransparentKey;
  454. this.fontItalicsButton.ImageTransparentColor = Utility.TransparentKey;
  455. this.fontUnderlineButton.ImageTransparentColor = Utility.TransparentKey;
  456. this.fontBoldButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontBoldIcon");
  457. this.fontItalicsButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontItalicIcon");
  458. this.fontUnderlineButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontUnderlineIcon");
  459. this.fontAlignLeftButton.Image = PdnResources.GetImageResource("Icons.TextAlignLeftIcon.png").Reference;
  460. this.fontAlignCenterButton.Image = PdnResources.GetImageResource("Icons.TextAlignCenterIcon.png").Reference;
  461. this.fontAlignRightButton.Image = PdnResources.GetImageResource("Icons.TextAlignRightIcon.png").Reference;
  462. this.fontBoldButton.ToolTipText = PdnResources.GetString("TextConfigWidget.BoldButton.ToolTipText");
  463. this.fontItalicsButton.ToolTipText = PdnResources.GetString("TextConfigWidget.ItalicButton.ToolTipText");
  464. this.fontUnderlineButton.ToolTipText = PdnResources.GetString("TextConfigWidget.UnderlineButton.ToolTipText");
  465. this.fontAlignLeftButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignLeftButton.ToolTipText");
  466. this.fontAlignCenterButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignCenterButton.ToolTipText");
  467. this.fontAlignRightButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignRightButton.ToolTipText");
  468. this.fontFamilyComboBox.Size = new Size(UI.ScaleWidth(this.fontFamilyComboBox.Width), fontFamilyComboBox.Height);
  469. this.fontFamilyComboBox.DropDownWidth = UI.ScaleWidth(this.fontFamilyComboBox.DropDownWidth);
  470. this.fontSizeComboBox.Size = new Size(UI.ScaleWidth(this.fontSizeComboBox.Width), fontSizeComboBox.Height);
  471. this.fontSmoothingComboBox.Size = new Size(UI.ScaleWidth(this.fontSmoothingComboBox.Width), fontSmoothingComboBox.Height);
  472. this.fontSmoothingComboBox.DropDownWidth = UI.ScaleWidth(this.fontSmoothingComboBox.DropDownWidth);
  473. this.resamplingLabel.Text = PdnResources.GetString("ToolConfigStrip.ResamplingLabel.Text");
  474. this.resamplingComboBox.BeginUpdate();
  475. this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.Bilinear));
  476. this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.NearestNeighbor));
  477. this.resamplingComboBox.EndUpdate();
  478. this.resamplingComboBox.SelectedIndex = 0; // bilinear
  479. this.resamplingComboBox.Size = new Size(UI.ScaleWidth(this.resamplingComboBox.Width), resamplingComboBox.Height);
  480. this.resamplingComboBox.DropDownWidth = UI.ScaleWidth(this.resamplingComboBox.DropDownWidth);
  481. this.colorPickerLabel.Text = PdnResources.GetString("ToolConfigStrip.ColorPickerLabel.Text");
  482. string[] colorPickerBehaviorNames = this.colorPickerBehaviorNames.GetLocalizedNames();
  483. // Make sure these items are sorted to be in the order specified by the enumeration
  484. Array.Sort<string>(
  485. colorPickerBehaviorNames,
  486. delegate (string lhs, string rhs)
  487. {
  488. ColorPickerClickBehavior lhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(lhs);
  489. ColorPickerClickBehavior rhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(rhs);
  490. if ((int)lhsE < (int)rhsE)
  491. {
  492. return -1;
  493. }
  494. else if ((int)lhsE > (int)rhsE)
  495. {
  496. return +1;
  497. }
  498. else
  499. {
  500. return 0;
  501. }
  502. });
  503. this.colorPickerComboBox.Items.AddRange(colorPickerBehaviorNames);
  504. this.colorPickerComboBox.SelectedIndex = 0;
  505. this.colorPickerComboBox.Size = new Size(UI.ScaleWidth(this.colorPickerComboBox.Width), colorPickerComboBox.Height);
  506. this.colorPickerComboBox.DropDownWidth = UI.ScaleWidth(this.colorPickerComboBox.DropDownWidth);
  507. this.toleranceSlider.Size = UI.ScaleSize(this.toleranceSlider.Size);
  508. this.selectionCombineModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionCombineModeLabel.Text");
  509. this.floodModeLabel.Text = PdnResources.GetString("ToolConfigStrip.FloodModeLabel.Text");
  510. this.selectionDrawModeModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeLabel.Text");
  511. this.selectionDrawModeWidthLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeWidthLabel.Text");
  512. this.selectionDrawModeHeightLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeHeightLabel.Text");
  513. this.selectionDrawModeSwapButton.Image = PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSwapButton.png").Reference;
  514. this.selectionDrawModeWidthTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeWidthTextBox.Width), this.selectionDrawModeWidthTextBox.Height);
  515. this.selectionDrawModeHeightTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeHeightTextBox.Width), this.selectionDrawModeHeightTextBox.Height);
  516. this.selectionDrawModeUnits.Size = new Size(UI.ScaleWidth(this.selectionDrawModeUnits.Width), this.selectionDrawModeUnits.Height);
  517. ToolBarConfigItems = ToolBarConfigItems.None;
  518. ResumeLayout(false);
  519. }
  520. private void AsyncInitFontNames()
  521. {
  522. if (!IsHandleCreated)
  523. {
  524. CreateControl();
  525. }
  526. if (!this.fontFamilyComboBox.ComboBox.IsHandleCreated)
  527. {
  528. this.fontFamilyComboBox.ComboBox.CreateControl();
  529. }
  530. if (staticFontNames == null)
  531. {
  532. ThreadPool.QueueUserWorkItem(new WaitCallback(this.PopulateFontsBackgroundThread), null);
  533. }
  534. }
  535. protected override void OnHandleCreated(EventArgs e)
  536. {
  537. if ((this.toolBarConfigItems & ToolBarConfigItems.Text) == ToolBarConfigItems.Text)
  538. {
  539. AsyncInitFontNames();
  540. }
  541. base.OnHandleCreated(e);
  542. }
  543. private void InitializeComponent()
  544. {
  545. this.brushSeparator = new ToolStripSeparator();
  546. this.brushStyleLabel = new ToolStripLabel();
  547. this.brushStyleComboBox = new ToolStripComboBox();
  548. this.shapeSeparator = new ToolStripSeparator();
  549. this.shapeButton = new ToolStripSplitButton();
  550. this.gradientSeparator1 = new ToolStripSeparator();
  551. this.gradientLinearClampedButton = new ToolStripButton();
  552. this.gradientLinearReflectedButton = new ToolStripButton();
  553. this.gradientLinearDiamondButton = new ToolStripButton();
  554. this.gradientRadialButton = new ToolStripButton();
  555. this.gradientConicalButton = new ToolStripButton();
  556. this.gradientSeparator2 = new ToolStripSeparator();
  557. this.gradientChannelsSplitButton = new ToolStripSplitButton();
  558. this.penSeparator = new ToolStripSeparator();
  559. this.penSizeLabel = new ToolStripLabel();
  560. this.penSizeDecButton = new ToolStripButton();
  561. this.penSizeComboBox = new ToolStripComboBox();
  562. this.penSizeIncButton = new ToolStripButton();
  563. this.penStyleLabel = new ToolStripLabel();
  564. this.penStartCapSplitButton = new ToolStripSplitButton();
  565. this.penDashStyleSplitButton = new ToolStripSplitButton();
  566. this.penEndCapSplitButton = new ToolStripSplitButton();
  567. this.blendingSeparator = new ToolStripSeparator();
  568. this.antiAliasingSplitButton = new ToolStripSplitButton();
  569. this.alphaBlendingSplitButton = new ToolStripSplitButton();
  570. this.toleranceSeparator = new ToolStripSeparator();
  571. this.toleranceLabel = new ToolStripLabel();
  572. this.toleranceSlider = new ToleranceSliderControl();
  573. this.toleranceSliderStrip = new ToolStripControlHost(this.toleranceSlider);
  574. this.fontSeparator = new ToolStripSeparator();
  575. this.fontLabel = new ToolStripLabel();
  576. this.fontFamilyComboBox = new ToolStripComboBox();
  577. this.fontSizeComboBox = new ToolStripComboBox();
  578. this.fontSmoothingComboBox = new ToolStripComboBox();
  579. this.fontStyleSeparator = new ToolStripSeparator();
  580. this.fontBoldButton = new ToolStripButton();
  581. this.fontItalicsButton = new ToolStripButton();
  582. this.fontUnderlineButton = new ToolStripButton();
  583. this.fontAlignSeparator = new ToolStripSeparator();
  584. this.fontAlignLeftButton = new ToolStripButton();
  585. this.fontAlignCenterButton = new ToolStripButton();
  586. this.fontAlignRightButton = new ToolStripButton();
  587. this.resamplingSeparator = new ToolStripSeparator();
  588. this.resamplingLabel = new ToolStripLabel();
  589. this.resamplingComboBox = new ToolStripComboBox();
  590. this.colorPickerSeparator = new ToolStripSeparator();
  591. this.colorPickerLabel = new ToolStripLabel();
  592. this.colorPickerComboBox = new ToolStripComboBox();
  593. this.selectionCombineModeSeparator = new ToolStripSeparator();
  594. this.selectionCombineModeLabel = new ToolStripLabel();
  595. this.selectionCombineModeSplitButton = new ToolStripSplitButton();
  596. this.floodModeSeparator = new ToolStripSeparator();
  597. this.floodModeLabel = new ToolStripLabel();
  598. this.floodModeSplitButton = new ToolStripSplitButton();
  599. this.selectionDrawModeSeparator = new ToolStripSeparator();
  600. this.selectionDrawModeModeLabel = new ToolStripLabel();
  601. this.selectionDrawModeSplitButton = new ToolStripSplitButton();
  602. this.selectionDrawModeWidthLabel = new ToolStripLabel();
  603. this.selectionDrawModeWidthTextBox = new ToolStripTextBox();
  604. this.selectionDrawModeSwapButton = new ToolStripButton();
  605. this.selectionDrawModeHeightLabel = new ToolStripLabel();
  606. this.selectionDrawModeHeightTextBox = new ToolStripTextBox();
  607. this.selectionDrawModeUnits = new UnitsComboBoxStrip();
  608. this.SuspendLayout();
  609. //
  610. // brushStyleLabel
  611. //
  612. this.brushStyleLabel.Name = "fillStyleLabel";
  613. //
  614. // brushStyleComboBox
  615. //
  616. this.brushStyleComboBox.Name = "styleComboBox";
  617. this.brushStyleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  618. this.brushStyleComboBox.DropDownWidth = 234;
  619. this.brushStyleComboBox.AutoSize = true;
  620. //
  621. // brushStyleComboBox.ComboBox
  622. //
  623. this.brushStyleComboBox.ComboBox.DrawMode = DrawMode.OwnerDrawVariable;
  624. this.brushStyleComboBox.ComboBox.MeasureItem += ComboBoxStyle_MeasureItem;
  625. this.brushStyleComboBox.ComboBox.SelectedValueChanged += ComboBoxStyle_SelectedValueChanged;
  626. this.brushStyleComboBox.ComboBox.DrawItem += ComboBoxStyle_DrawItem;
  627. //
  628. // shapeButton
  629. //
  630. this.shapeButton.Name = "shapeButton";
  631. this.shapeButton.DropDownOpening += new EventHandler(ShapeButton_DropDownOpening);
  632. this.shapeButton.DropDownClosed +=
  633. delegate (object sender, EventArgs e)
  634. {
  635. this.shapeButton.DropDownItems.Clear();
  636. };
  637. this.shapeButton.ButtonClick +=
  638. delegate (object sender, EventArgs e)
  639. {
  640. Tracing.LogFeature("ToolConfigStrip(shapeButton)");
  641. switch (ShapeDrawType)
  642. {
  643. case ShapeDrawType.Outline:
  644. ShapeDrawType = ShapeDrawType.Interior;
  645. break;
  646. case ShapeDrawType.Interior:
  647. ShapeDrawType = ShapeDrawType.Both;
  648. break;
  649. case ShapeDrawType.Both:
  650. ShapeDrawType = ShapeDrawType.Outline;
  651. break;
  652. default:
  653. throw new InvalidEnumArgumentException();
  654. }
  655. };
  656. //
  657. // gradientSeparator
  658. //
  659. this.gradientSeparator1.Name = "gradientSeparator";
  660. //
  661. // gradientLinearClampedButton
  662. //
  663. this.gradientLinearClampedButton.Name = "gradientLinearClampedButton";
  664. this.gradientLinearClampedButton.Click += GradientTypeButtonClicked;
  665. this.gradientLinearClampedButton.Tag = GradientType.LinearClamped;
  666. //
  667. // gradientLinearReflectedButton
  668. //
  669. this.gradientLinearReflectedButton.Name = "gradientLinearReflectedButton";
  670. this.gradientLinearReflectedButton.Click += GradientTypeButtonClicked;
  671. this.gradientLinearReflectedButton.Tag = GradientType.LinearReflected;
  672. //
  673. // gradientLinearDiamondButton
  674. //
  675. this.gradientLinearDiamondButton.Name = "gradientLinearDiamondButton";
  676. this.gradientLinearDiamondButton.Click += GradientTypeButtonClicked;
  677. this.gradientLinearDiamondButton.Tag = GradientType.LinearDiamond;
  678. //
  679. // gradientRadialButton
  680. //
  681. this.gradientRadialButton.Name = "gradientRadialButton";
  682. this.gradientRadialButton.Click += GradientTypeButtonClicked;
  683. this.gradientRadialButton.Tag = GradientType.Radial;
  684. //
  685. // gradientConicalButton
  686. //
  687. this.gradientConicalButton.Name = "gradientConicalButton";
  688. this.gradientConicalButton.Click += GradientTypeButtonClicked;
  689. this.gradientConicalButton.Tag = GradientType.Conical;
  690. //
  691. // gradientSeparator2
  692. //
  693. this.gradientSeparator2.Name = "gradientSeparator2";
  694. //
  695. // gradientChannelsSplitButton
  696. //
  697. this.gradientChannelsSplitButton.Name = "gradientChannelsSplitButton";
  698. this.gradientChannelsSplitButton.DropDownOpening += new EventHandler(GradientChannelsSplitButton_DropDownOpening);
  699. this.gradientChannelsSplitButton.DropDownClosed +=
  700. delegate (object sender, EventArgs e)
  701. {
  702. this.gradientChannelsSplitButton.DropDownItems.Clear();
  703. };
  704. this.gradientChannelsSplitButton.ButtonClick +=
  705. delegate (object sender, EventArgs e)
  706. {
  707. Tracing.LogFeature("ToolConfigStrip(gradientChannelsSplitButton)");
  708. GradientInfo = new GradientInfo(GradientInfo.GradientType, !GradientInfo.AlphaOnly);
  709. };
  710. //
  711. // penSeparator
  712. //
  713. this.penSeparator.Name = "penSeparator";
  714. //
  715. // penSizeLabel
  716. //
  717. this.penSizeLabel.Name = "brushSizeLabel";
  718. //
  719. // penSizeDecButton
  720. //
  721. this.penSizeDecButton.Name = "penSizeDecButton";
  722. this.penSizeDecButton.Click +=
  723. delegate (object sender, EventArgs e)
  724. {
  725. Tracing.LogFeature("ToolConfigStrip(penSizeDecButton)");
  726. float amount = -1.0f;
  727. if ((Control.ModifierKeys & Keys.Control) != 0)
  728. {
  729. amount *= 5.0f;
  730. }
  731. AddToPenSize(amount);
  732. };
  733. //
  734. // penSizeComboBox
  735. //
  736. this.penSizeComboBox.Name = "penSizeComboBox";
  737. this.penSizeComboBox.Validating += new CancelEventHandler(this.BrushSizeComboBox_Validating);
  738. this.penSizeComboBox.TextChanged += new EventHandler(this.SizeComboBox_TextChanged);
  739. this.penSizeComboBox.AutoSize = false;
  740. this.penSizeComboBox.Width = 44;
  741. //
  742. // penSizeIncButton
  743. //
  744. this.penSizeIncButton.Name = "penSizeIncButton";
  745. this.penSizeIncButton.Click +=
  746. delegate (object sender, EventArgs e)
  747. {
  748. Tracing.LogFeature("ToolConfigStrip(penSizeIncButton)");
  749. float amount = 1.0f;
  750. if ((Control.ModifierKeys & Keys.Control) != 0)
  751. {
  752. amount *= 5.0f;
  753. }
  754. AddToPenSize(amount);
  755. };
  756. //
  757. // penStartCapLabel
  758. //
  759. this.penStyleLabel.Name = "penStartCapLabel";
  760. //
  761. // penStartCapSplitButton
  762. //
  763. this.penStartCapSplitButton.Name = "penStartCapSplitButton";
  764. this.penStartCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
  765. this.penStartCapSplitButton.DropDownClosed +=
  766. delegate (object sender, EventArgs e)
  767. {
  768. this.penStartCapSplitButton.DropDownItems.Clear();
  769. };
  770. this.penStartCapSplitButton.ButtonClick +=
  771. delegate (object sender, EventArgs e)
  772. {
  773. Tracing.LogFeature("ToolConfigStrip(penStartCapSplitButton)");
  774. CyclePenStartCap();
  775. };
  776. //
  777. // penDashStyleSplitButton
  778. //
  779. this.penDashStyleSplitButton.Name = "penDashStyleSplitButton";
  780. this.penDashStyleSplitButton.ImageScaling = ToolStripItemImageScaling.None;
  781. this.penDashStyleSplitButton.DropDownOpening += PenDashStyleButton_DropDownOpening;
  782. this.penDashStyleSplitButton.DropDownClosed +=
  783. delegate (object sender, EventArgs e)
  784. {
  785. this.penDashStyleSplitButton.DropDownItems.Clear();
  786. };
  787. this.penDashStyleSplitButton.ButtonClick +=
  788. delegate (object sender, EventArgs e)
  789. {
  790. Tracing.LogFeature("ToolConfigStrip(penDashStyleSplitButton)");
  791. CyclePenDashStyle();
  792. };
  793. //
  794. // penEndCapSplitButton
  795. //
  796. this.penEndCapSplitButton.Name = "penEndCapSplitButton";
  797. this.penEndCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
  798. this.penEndCapSplitButton.DropDownClosed +=
  799. delegate (object sender, EventArgs e)
  800. {
  801. this.penEndCapSplitButton.DropDownItems.Clear();
  802. };
  803. this.penEndCapSplitButton.ButtonClick +=
  804. delegate (object sender, EventArgs e)
  805. {
  806. Tracing.LogFeature("ToolConfigStrip(penEndCapSplitButton)");
  807. CyclePenEndCap();
  808. };
  809. //
  810. // antiAliasingSplitButton
  811. //
  812. this.antiAliasingSplitButton.Name = "antiAliasingSplitButton";
  813. this.antiAliasingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  814. this.antiAliasingSplitButton.DropDownOpening += AntiAliasingSplitButton_DropDownOpening;
  815. this.antiAliasingSplitButton.DropDownClosed +=
  816. delegate (object sender, EventArgs e)
  817. {
  818. this.antiAliasingSplitButton.DropDownItems.Clear();
  819. };
  820. this.antiAliasingSplitButton.ButtonClick +=
  821. delegate (object sender, EventArgs e)
  822. {
  823. Tracing.LogFeature("ToolConfigStrip(antiAliasingSplitButton)");
  824. AntiAliasing = !AntiAliasing;
  825. };
  826. //
  827. // alphaBlendingSplitButton
  828. //
  829. this.alphaBlendingSplitButton.Name = "alphaBlendingSplitButton";
  830. this.alphaBlendingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  831. this.alphaBlendingSplitButton.DropDownOpening += new EventHandler(AlphaBlendingSplitButton_DropDownOpening);
  832. this.alphaBlendingSplitButton.DropDownClosed +=
  833. delegate (object sender, EventArgs e)
  834. {
  835. this.alphaBlendingSplitButton.DropDownItems.Clear();
  836. };
  837. this.alphaBlendingSplitButton.ButtonClick +=
  838. delegate (object sender, EventArgs e)
  839. {
  840. Tracing.LogFeature("ToolConfigStrip(alphaBlendingSplitButton)");
  841. AlphaBlending = !AlphaBlending;
  842. };
  843. //
  844. // toleranceLabel
  845. //
  846. this.toleranceLabel.Name = "toleranceLabel";
  847. //
  848. // toleranceSlider
  849. //
  850. this.toleranceSlider.Name = "toleranceSlider";
  851. this.toleranceSlider.ToleranceChanged += new EventHandler(ToleranceSlider_ToleranceChanged);
  852. this.toleranceSlider.Size = new Size(150, 16);
  853. //
  854. // toleranceSliderStrip
  855. //
  856. this.toleranceSliderStrip.Name = "toleranceSliderStrip";
  857. this.toleranceSliderStrip.AutoSize = false;
  858. //
  859. // fontLabel
  860. //
  861. this.fontLabel.Name = "fontLabel";
  862. //
  863. // fontFamilyComboBox
  864. //
  865. this.fontFamilyComboBox.Name = "fontComboBox";
  866. this.fontFamilyComboBox.DropDownWidth = 240;
  867. this.fontFamilyComboBox.MaxDropDownItems = 12;
  868. this.fontFamilyComboBox.Sorted = true;
  869. this.fontFamilyComboBox.GotFocus += new EventHandler(FontFamilyComboBox_GotFocus);
  870. this.fontFamilyComboBox.Items.Add(arialName);
  871. this.fontFamilyComboBox.SelectedItem = arialName;
  872. this.fontFamilyComboBox.SelectedIndexChanged += FontFamilyComboBox_SelectedIndexChanged;
  873. this.fontFamilyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  874. //
  875. // fontFamilyComboBox.ComboBox
  876. //
  877. this.fontFamilyComboBox.ComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  878. this.fontFamilyComboBox.ComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.FontFamilyComboBox_MeasureItem);
  879. this.fontFamilyComboBox.ComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.FontFamilyComboBox_DrawItem);
  880. //
  881. // fontSizeComboBox
  882. //
  883. this.fontSizeComboBox.Name = "fontSizeComboBox";
  884. this.fontSizeComboBox.AutoSize = false;
  885. this.fontSizeComboBox.TextChanged += new EventHandler(FontSizeComboBox_TextChanged);
  886. this.fontSizeComboBox.Validating += new CancelEventHandler(FontSizeComboBox_Validating);
  887. this.fontSizeComboBox.Text = initialFontSize.ToString();
  888. this.fontSizeComboBox.Width = 44;
  889. //
  890. // fontSmoothingComboBox
  891. //
  892. this.fontSmoothingComboBox.Name = "smoothingComboBOx";
  893. this.fontSmoothingComboBox.AutoSize = false;
  894. this.fontSmoothingComboBox.Sorted = false;
  895. this.fontSmoothingComboBox.Width = 70;
  896. this.fontSmoothingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  897. this.fontSmoothingComboBox.SelectedIndexChanged += new EventHandler(SmoothingComboBox_SelectedIndexChanged);
  898. //
  899. // fontBoldButton
  900. //
  901. this.fontBoldButton.Name = "boldButton";
  902. //
  903. // fontItalicsButton
  904. //
  905. this.fontItalicsButton.Name = "italicsButton";
  906. //
  907. // fontUnderlineButton
  908. //
  909. this.fontUnderlineButton.Name = "underlineButton";
  910. //
  911. // fontAlignLeftButton
  912. //
  913. this.fontAlignLeftButton.Name = "alignLeftButton";
  914. //
  915. // fontAlignCenterButton
  916. //
  917. this.fontAlignCenterButton.Name = "alignCenterButton";
  918. //
  919. // fontAlignRightButton
  920. //
  921. this.fontAlignRightButton.Name = "alignRightButton";
  922. //
  923. // resamplingSeparator
  924. //
  925. this.resamplingSeparator.Name = "resamplingSeparator";
  926. //
  927. // resamplingLabel
  928. //
  929. this.resamplingLabel.Name = "resamplingLabel";
  930. //
  931. // resamplingComboBox
  932. //
  933. this.resamplingComboBox.Name = "resamplingComboBox";
  934. this.resamplingComboBox.AutoSize = true;
  935. this.resamplingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  936. this.resamplingComboBox.Sorted = false;
  937. this.resamplingComboBox.Width = 100;
  938. this.resamplingComboBox.DropDownWidth = 100;
  939. this.resamplingComboBox.SelectedIndexChanged += new EventHandler(ResamplingComboBox_SelectedIndexChanged);
  940. //
  941. // colorPickerSeparator
  942. //
  943. this.colorPickerSeparator.Name = "colorPickerSeparator";
  944. //
  945. // colorPickerLabel
  946. //
  947. this.colorPickerLabel.Name = "colorPickerLabel";
  948. //
  949. // colorPickerComboBox
  950. //
  951. this.colorPickerComboBox.Name = "colorPickerComboBox";
  952. this.colorPickerComboBox.AutoSize = true;
  953. this.colorPickerComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  954. this.colorPickerComboBox.Width = 200;
  955. this.colorPickerComboBox.DropDownWidth = 200;
  956. this.colorPickerComboBox.Sorted = false;
  957. this.colorPickerComboBox.SelectedIndexChanged += new EventHandler(ColorPickerComboBox_SelectedIndexChanged);
  958. //
  959. // selectionCombineModeSeparator
  960. //
  961. this.selectionCombineModeSeparator.Name = "selectionCombineModeSeparator";
  962. //
  963. // selectionCombineModeLabel
  964. //
  965. this.selectionCombineModeLabel.Name = "selectionCombineModeLabel";
  966. //
  967. // selectionCombineModeSplitButton
  968. //
  969. this.selectionCombineModeSplitButton.Name = "selectionCombineModeSplitButton";
  970. this.selectionCombineModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  971. this.selectionCombineModeSplitButton.DropDownOpening += new EventHandler(SelectionCombineModeSplitButton_DropDownOpening);
  972. this.selectionCombineModeSplitButton.DropDownClosed +=
  973. delegate (object sender, EventArgs e)
  974. {
  975. this.selectionCombineModeSplitButton.DropDownItems.Clear();
  976. };
  977. this.selectionCombineModeSplitButton.ButtonClick +=
  978. delegate (object sender, EventArgs e)
  979. {
  980. Tracing.LogFeature("ToolConfigStrip(selectionCombineModeSplitButton)");
  981. this.SelectionCombineMode = CycleSelectionCombineMode(this.SelectionCombineMode);
  982. };
  983. //
  984. // floodModeSeparator
  985. //
  986. this.floodModeSeparator.Name = "floodModeSeparator";
  987. //
  988. // floodModeLabel
  989. //
  990. this.floodModeLabel.Name = "floodModeLabel";
  991. //
  992. // floodModeSplitButton
  993. //
  994. this.floodModeSplitButton.Name = "floodModeSplitButton";
  995. this.floodModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  996. this.floodModeSplitButton.DropDownOpening += new EventHandler(FloodModeSplitButton_DropDownOpening);
  997. this.floodModeSplitButton.DropDownClosed +=
  998. delegate (object sender, EventArgs e)
  999. {
  1000. this.floodModeSplitButton.DropDownItems.Clear();
  1001. };
  1002. this.floodModeSplitButton.ButtonClick +=
  1003. delegate (object sender, EventArgs e)
  1004. {
  1005. Tracing.LogFeature("ToolConfigStrip(floodModeSplitButton)");
  1006. this.FloodMode = CycleFloodMode(this.FloodMode);
  1007. };
  1008. //
  1009. // selectionDrawModeSeparator
  1010. //
  1011. this.selectionDrawModeSeparator.Name = "selectionDrawModeSeparator";
  1012. //
  1013. // selectionDrawModeModeLabel
  1014. //
  1015. this.selectionDrawModeModeLabel.Name = "selectionDrawModeModeLabel";
  1016. //
  1017. // selectionDrawModeSplitButton
  1018. //
  1019. this.selectionDrawModeSplitButton.Name = "selectionDrawModeSplitButton";
  1020. this.selectionDrawModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
  1021. this.selectionDrawModeSplitButton.DropDownOpening += new EventHandler(SelectionDrawModeSplitButton_DropDownOpening);
  1022. this.selectionDrawModeSplitButton.DropDownClosed +=
  1023. delegate (object sender, EventArgs e)
  1024. {
  1025. this.selectionDrawModeSplitButton.DropDownItems.Clear();
  1026. };
  1027. this.selectionDrawModeSplitButton.ButtonClick +=
  1028. delegate (object sender, EventArgs e)
  1029. {
  1030. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSplitButton)");
  1031. SelectionDrawMode newSDM = CycleSelectionDrawMode(this.SelectionDrawModeInfo.DrawMode);
  1032. this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
  1033. };
  1034. //
  1035. // selectionDrawModeWidthLabel
  1036. //
  1037. this.selectionDrawModeWidthLabel.Name = "selectionDrawModeWidthLabel";
  1038. //
  1039. // selectionDrawModeWidthTextBox
  1040. //
  1041. this.selectionDrawModeWidthTextBox.Name = "selectionDrawModeWidthTextBox";
  1042. this.selectionDrawModeWidthTextBox.TextBox.Width = 50;
  1043. this.selectionDrawModeWidthTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
  1044. this.selectionDrawModeWidthTextBox.Enter +=
  1045. delegate (object sender, EventArgs e)
  1046. {
  1047. this.selectionDrawModeWidthTextBox.TextBox.Select(0, this.selectionDrawModeWidthTextBox.TextBox.Text.Length);
  1048. };
  1049. this.selectionDrawModeWidthTextBox.Leave +=
  1050. delegate (object sender, EventArgs e)
  1051. {
  1052. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeWidthTextBox.Leave)");
  1053. double newWidth;
  1054. if (double.TryParse(this.selectionDrawModeWidthTextBox.Text, out newWidth))
  1055. {
  1056. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewWidth(newWidth);
  1057. }
  1058. else
  1059. {
  1060. this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
  1061. }
  1062. };
  1063. //
  1064. // selectionDrawModeSwapButton
  1065. //
  1066. this.selectionDrawModeSwapButton.Name = "selectionDrawModeSwapButton";
  1067. this.selectionDrawModeSwapButton.Click +=
  1068. delegate (object sender, EventArgs e)
  1069. {
  1070. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSwapButton)");
  1071. SelectionDrawModeInfo oldSDMI = this.SelectionDrawModeInfo;
  1072. SelectionDrawModeInfo newSDMI = new SelectionDrawModeInfo(oldSDMI.DrawMode, oldSDMI.Height, oldSDMI.Width, oldSDMI.Units);
  1073. this.SelectionDrawModeInfo = newSDMI;
  1074. };
  1075. //
  1076. // selectionDrawModeHeightLabel
  1077. //
  1078. this.selectionDrawModeHeightLabel.Name = "selectionDrawModeHeightLabel";
  1079. //
  1080. // selectionDrawModeHeightTextBox
  1081. //
  1082. this.selectionDrawModeHeightTextBox.Name = "selectionDrawModeHeightTextBox";
  1083. this.selectionDrawModeHeightTextBox.TextBox.Width = 50;
  1084. this.selectionDrawModeHeightTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
  1085. this.selectionDrawModeHeightTextBox.Enter +=
  1086. delegate (object sender, EventArgs e)
  1087. {
  1088. this.selectionDrawModeHeightTextBox.TextBox.Select(0, this.selectionDrawModeHeightTextBox.TextBox.Text.Length);
  1089. };
  1090. this.selectionDrawModeHeightTextBox.Leave +=
  1091. delegate (object sender, EventArgs e)
  1092. {
  1093. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeHeightTextBox.Leave)");
  1094. double newHeight;
  1095. if (double.TryParse(this.selectionDrawModeHeightTextBox.Text, out newHeight))
  1096. {
  1097. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewHeight(newHeight);
  1098. }
  1099. else
  1100. {
  1101. this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
  1102. }
  1103. };
  1104. //
  1105. // selectionDrawModeUnits
  1106. //
  1107. this.selectionDrawModeUnits.Name = "selectionDrawModeUnits";
  1108. this.selectionDrawModeUnits.UnitsDisplayType = UnitsDisplayType.Plural;
  1109. this.selectionDrawModeUnits.LowercaseStrings = true;
  1110. this.selectionDrawModeUnits.Size = new Size(90, this.selectionDrawModeUnits.Height);
  1111. //
  1112. // DrawConfigStrip
  1113. //
  1114. this.AutoSize = true;
  1115. this.Items.AddRange(
  1116. new ToolStripItem[]
  1117. {
  1118. this.selectionCombineModeSeparator,
  1119. this.selectionCombineModeLabel,
  1120. this.selectionCombineModeSplitButton,
  1121. this.selectionDrawModeSeparator,
  1122. this.selectionDrawModeModeLabel,
  1123. this.selectionDrawModeSplitButton,
  1124. this.selectionDrawModeWidthLabel,
  1125. this.selectionDrawModeWidthTextBox,
  1126. this.selectionDrawModeSwapButton,
  1127. this.selectionDrawModeHeightLabel,
  1128. this.selectionDrawModeHeightTextBox,
  1129. this.selectionDrawModeUnits,
  1130. this.floodModeSeparator,
  1131. this.floodModeLabel,
  1132. this.floodModeSplitButton,
  1133. this.resamplingSeparator,
  1134. this.resamplingLabel,
  1135. this.resamplingComboBox,
  1136. this.colorPickerSeparator,
  1137. this.colorPickerLabel,
  1138. this.colorPickerComboBox,
  1139. this.fontSeparator,
  1140. this.fontLabel,
  1141. this.fontFamilyComboBox,
  1142. this.fontSizeComboBox,
  1143. this.fontSmoothingComboBox,
  1144. this.fontStyleSeparator,
  1145. this.fontBoldButton,
  1146. this.fontItalicsButton,
  1147. this.fontUnderlineButton,
  1148. this.fontAlignSeparator,
  1149. this.fontAlignLeftButton,
  1150. this.fontAlignCenterButton,
  1151. this.fontAlignRightButton,
  1152. this.shapeSeparator,
  1153. this.shapeButton,
  1154. this.gradientSeparator1,
  1155. this.gradientLinearClampedButton,
  1156. this.gradientLinearReflectedButton,
  1157. this.gradientLinearDiamondButton,
  1158. this.gradientRadialButton,
  1159. this.gradientConicalButton,
  1160. this.gradientSeparator2,
  1161. this.gradientChannelsSplitButton,
  1162. this.penSeparator,
  1163. this.penSizeLabel,
  1164. this.penSizeDecButton,
  1165. this.penSizeComboBox,
  1166. this.penSizeIncButton,
  1167. this.penStyleLabel,
  1168. this.penStartCapSplitButton,
  1169. this.penDashStyleSplitButton,
  1170. this.penEndCapSplitButton,
  1171. this.brushSeparator,
  1172. this.brushStyleLabel,
  1173. this.brushStyleComboBox,
  1174. this.toleranceSeparator,
  1175. this.toleranceLabel,
  1176. this.toleranceSliderStrip,
  1177. this.blendingSeparator,
  1178. this.antiAliasingSplitButton,
  1179. this.alphaBlendingSplitButton
  1180. });
  1181. this.ResumeLayout(false);
  1182. }
  1183. public void CyclePenEndCap()
  1184. {
  1185. PenInfo newPenInfo = PenInfo.Clone();
  1186. newPenInfo.EndCap = NextLineCap(newPenInfo.EndCap);
  1187. PenInfo = newPenInfo;
  1188. }
  1189. public void CyclePenStartCap()
  1190. {
  1191. PenInfo newPenInfo = PenInfo.Clone();
  1192. newPenInfo.StartCap = NextLineCap(newPenInfo.StartCap);
  1193. PenInfo = newPenInfo;
  1194. }
  1195. public void CyclePenDashStyle()
  1196. {
  1197. PenInfo newPenInfo = PenInfo.Clone();
  1198. newPenInfo.DashStyle = NextDashStyle(newPenInfo.DashStyle);
  1199. PenInfo = newPenInfo;
  1200. }
  1201. private DashStyle NextDashStyle(DashStyle oldDash)
  1202. {
  1203. int dashIndex = Array.IndexOf<DashStyle>(this.dashStyles, oldDash);
  1204. int newDashIndex = (dashIndex + 1) % this.dashStyles.Length;
  1205. return this.dashStyles[newDashIndex];
  1206. }
  1207. private LineCap2 NextLineCap(LineCap2 oldCap)
  1208. {
  1209. int capIndex = Array.IndexOf<LineCap2>(this.lineCaps, oldCap);
  1210. int newCapIndex = (capIndex + 1) % this.lineCaps.Length;
  1211. return this.lineCaps[newCapIndex];
  1212. }
  1213. private void GradientTypeButtonClicked(object sender, EventArgs e)
  1214. {
  1215. Tracing.LogFeature("ToolConfigStrip(GradientTypeButtonClicked)");
  1216. GradientType newType = (GradientType)((ToolStripButton)sender).Tag;
  1217. GradientInfo = new GradientInfo(newType, GradientInfo.AlphaOnly);
  1218. }
  1219. private void ComboBoxStyle_SelectedValueChanged(object sender, EventArgs e)
  1220. {
  1221. OnBrushChanged();
  1222. }
  1223. public void PerformBrushChanged()
  1224. {
  1225. OnBrushChanged();
  1226. }
  1227. private void ComboBoxStyle_DrawItem(object sender, DrawItemEventArgs e)
  1228. {
  1229. e.DrawBackground();
  1230. Rectangle r = e.Bounds;
  1231. if (e.Index != -1)
  1232. {
  1233. string itemName = (string)this.brushStyleComboBox.Items[e.Index];
  1234. if (itemName != this.solidBrushText)
  1235. {
  1236. Rectangle rd = r;
  1237. rd.Width = rd.Left + 25;
  1238. Rectangle rt = r;
  1239. r.X = rd.Right;
  1240. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1241. HatchStyle hs = (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(displayText);
  1242. using (HatchBrush b = new HatchBrush(hs, e.ForeColor, e.BackColor))
  1243. {
  1244. e.Graphics.FillRectangle(b, rd);
  1245. }
  1246. StringFormat sf = new StringFormat();
  1247. sf.Alignment = StringAlignment.Near;
  1248. using (SolidBrush sb = new SolidBrush(Color.White))
  1249. {
  1250. if ((e.State & DrawItemState.Focus) == 0)
  1251. {
  1252. sb.Color = SystemColors.Window;
  1253. e.Graphics.FillRectangle(sb, r);
  1254. sb.Color = SystemColors.WindowText;
  1255. e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
  1256. }
  1257. else
  1258. {
  1259. sb.Color = SystemColors.Highlight;
  1260. e.Graphics.FillRectangle(sb, r);
  1261. sb.Color = SystemColors.HighlightText;
  1262. e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
  1263. }
  1264. }
  1265. sf.Dispose();
  1266. sf = null;
  1267. }
  1268. else
  1269. {
  1270. // Solid Brush
  1271. using (SolidBrush sb = new SolidBrush(Color.White))
  1272. {
  1273. if ((e.State & DrawItemState.Focus) == 0)
  1274. {
  1275. sb.Color = SystemColors.Window;
  1276. e.Graphics.FillRectangle(sb, e.Bounds);
  1277. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1278. sb.Color = SystemColors.WindowText;
  1279. e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
  1280. }
  1281. else
  1282. {
  1283. sb.Color = SystemColors.Highlight;
  1284. e.Graphics.FillRectangle(sb, e.Bounds);
  1285. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1286. sb.Color = SystemColors.HighlightText;
  1287. e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
  1288. }
  1289. }
  1290. }
  1291. e.DrawFocusRectangle();
  1292. }
  1293. }
  1294. private void ComboBoxStyle_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
  1295. {
  1296. // Work out what the text will be
  1297. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1298. // Get width & height of string
  1299. SizeF stringSize = e.Graphics.MeasureString(displayText, this.Font);
  1300. // set height to text height
  1301. e.ItemHeight = (int)stringSize.Height;
  1302. // set width to text width
  1303. e.ItemWidth = (int)stringSize.Width;
  1304. }
  1305. public event EventHandler ShapeDrawTypeChanged;
  1306. protected virtual void OnShapeDrawTypeChanged()
  1307. {
  1308. if (ShapeDrawTypeChanged != null)
  1309. {
  1310. ShapeDrawTypeChanged(this, EventArgs.Empty);
  1311. }
  1312. }
  1313. public void PerformShapeDrawTypeChanged()
  1314. {
  1315. OnShapeDrawTypeChanged();
  1316. }
  1317. public ShapeDrawType ShapeDrawType
  1318. {
  1319. get
  1320. {
  1321. return shapeDrawType;
  1322. }
  1323. set
  1324. {
  1325. if (shapeDrawType != value)
  1326. {
  1327. shapeDrawType = value;
  1328. // if the user sets the shape the buttons must be updated
  1329. if (shapeDrawType == ShapeDrawType.Outline)
  1330. {
  1331. this.shapeButton.Image = shapeOutlineImage.Reference;
  1332. }
  1333. else if (shapeDrawType == ShapeDrawType.Both)
  1334. {
  1335. this.shapeButton.Image = shapeBothImage.Reference;
  1336. }
  1337. else if (shapeDrawType == ShapeDrawType.Interior)
  1338. {
  1339. this.shapeButton.Image = shapeInteriorImage.Reference;
  1340. }
  1341. else
  1342. {
  1343. // invalid shape
  1344. throw new InvalidOperationException("Shape draw type is invalid");
  1345. }
  1346. this.OnShapeDrawTypeChanged();
  1347. }
  1348. }
  1349. }
  1350. private void SetFontStyleButtons(FontStyle style)
  1351. {
  1352. bool bold = ((style & FontStyle.Bold) != 0);
  1353. bool italic = ((style & FontStyle.Italic) != 0);
  1354. bool underline = ((style & FontStyle.Underline) != 0);
  1355. this.fontBoldButton.Checked = bold;
  1356. this.fontItalicsButton.Checked = italic;
  1357. this.fontUnderlineButton.Checked = underline;
  1358. }
  1359. protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
  1360. {
  1361. if (e.ClickedItem == fontBoldButton)
  1362. {
  1363. Tracing.LogFeature("ToolConfigStrip(fontBoldButton)");
  1364. this.fontStyle ^= FontStyle.Bold;
  1365. SetFontStyleButtons(this.fontStyle);
  1366. this.OnFontInfoChanged();
  1367. }
  1368. else if (e.ClickedItem == fontItalicsButton)
  1369. {
  1370. Tracing.LogFeature("ToolConfigStrip(fontItalicsButton)");
  1371. this.fontStyle ^= FontStyle.Italic;
  1372. SetFontStyleButtons(this.fontStyle);
  1373. this.OnFontInfoChanged();
  1374. }
  1375. else if (e.ClickedItem == fontUnderlineButton)
  1376. {
  1377. Tracing.LogFeature("ToolConfigStrip(fontUnderlineButton)");
  1378. this.fontStyle ^= FontStyle.Underline;
  1379. SetFontStyleButtons(this.fontStyle);
  1380. this.OnFontInfoChanged();
  1381. }
  1382. else if (e.ClickedItem == fontAlignLeftButton)
  1383. {
  1384. Tracing.LogFeature("ToolConfigStrip(fontAlignLeftButton)");
  1385. this.FontAlignment = TextAlignment.Left;
  1386. }
  1387. else if (e.ClickedItem == fontAlignCenterButton)
  1388. {
  1389. Tracing.LogFeature("ToolConfigStrip(fontAlignCenterButton)");
  1390. this.FontAlignment = TextAlignment.Center;
  1391. }
  1392. else if (e.ClickedItem == fontAlignRightButton)
  1393. {
  1394. Tracing.LogFeature("ToolConfigStrip(fontAlignRightButton)");
  1395. this.FontAlignment = TextAlignment.Right;
  1396. }
  1397. base.OnItemClicked(e);
  1398. }
  1399. public event EventHandler PenInfoChanged;
  1400. protected virtual void OnPenChanged()
  1401. {
  1402. if (PenInfoChanged != null)
  1403. {
  1404. PenInfoChanged(this, EventArgs.Empty);
  1405. }
  1406. }
  1407. public void PerformPenChanged()
  1408. {
  1409. OnPenChanged();
  1410. }
  1411. public void AddToPenSize(float delta)
  1412. {
  1413. if ((this.toolBarConfigItems & ToolBarConfigItems.Pen) == ToolBarConfigItems.Pen)
  1414. {
  1415. float newWidth = Utility.Clamp(PenInfo.Width + delta, minPenSize, maxPenSize);
  1416. PenInfo newPenInfo = PenInfo.Clone();
  1417. newPenInfo.Width += delta;
  1418. newPenInfo.Width = (float)Utility.Clamp(newPenInfo.Width, minPenSize, maxPenSize);
  1419. PenInfo = newPenInfo;
  1420. }
  1421. }
  1422. public PenInfo PenInfo
  1423. {
  1424. get
  1425. {
  1426. float width;
  1427. try
  1428. {
  1429. width = float.Parse(this.penSizeComboBox.Text);
  1430. }
  1431. catch (FormatException)
  1432. {
  1433. // TODO: would much rather grab the value from AppEnvironment
  1434. // or in some way that we keep track of the "last good value"
  1435. width = 2;
  1436. }
  1437. LineCap2 startCap;
  1438. try
  1439. {
  1440. startCap = (LineCap2)this.penStartCapSplitButton.Tag;
  1441. }
  1442. catch (Exception)
  1443. {
  1444. startCap = PenInfo.DefaultLineCap;
  1445. }
  1446. LineCap2 endCap;
  1447. try
  1448. {
  1449. endCap = (LineCap2)this.penEndCapSplitButton.Tag;
  1450. }
  1451. catch (Exception)
  1452. {
  1453. endCap = PenInfo.DefaultLineCap;
  1454. }
  1455. DashStyle dashStyle = (DashStyle)this.penDashStyleSplitButton.Tag;
  1456. return new PenInfo(dashStyle, width, startCap, endCap, PenInfo.DefaultCapScale);
  1457. }
  1458. set
  1459. {
  1460. if (this.PenInfo != value)
  1461. {
  1462. this.penSizeComboBox.Text = value.Width.ToString();
  1463. this.penStartCapSplitButton.Tag = value.StartCap;
  1464. this.penStartCapSplitButton.Image = GetLineCapImage(value.StartCap, true).Reference;
  1465. this.penDashStyleSplitButton.Tag = value.DashStyle;
  1466. this.penDashStyleSplitButton.Image = GetDashStyleImage(value.DashStyle);
  1467. this.penEndCapSplitButton.Tag = value.EndCap;
  1468. this.penEndCapSplitButton.Image = GetLineCapImage(value.EndCap, false).Reference;
  1469. OnPenChanged();
  1470. }
  1471. }
  1472. }
  1473. private void SizeComboBox_TextChanged(object sender, System.EventArgs e)
  1474. {
  1475. BrushSizeComboBox_Validating(this, new CancelEventArgs());
  1476. }
  1477. private void BrushSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  1478. {
  1479. float penSize;
  1480. bool valid = float.TryParse(this.penSizeComboBox.Text, out penSize);
  1481. if (!valid)
  1482. {
  1483. this.penSizeComboBox.BackColor = Color.Red;
  1484. this.penSizeComboBox.ToolTipText = PdnResources.GetString("PenConfigWidget.Error.InvalidNumber");
  1485. }
  1486. else
  1487. {
  1488. if (penSize < minPenSize)
  1489. {
  1490. // Set the error if the size is too small.
  1491. this.penSizeComboBox.BackColor = Color.Red;
  1492. string tooSmallFormat = PdnResources.GetString("PenConfigWidget.Error.TooSmall.Format");
  1493. string tooSmall = string.Format(tooSmallFormat, minPenSize);
  1494. this.penSizeComboBox.ToolTipText = tooSmall;
  1495. }
  1496. else if (penSize > maxPenSize)
  1497. {
  1498. // Set the error if the size is too large.
  1499. this.penSizeComboBox.BackColor = Color.Red;
  1500. string tooLargeFormat = PdnResources.GetString("PenConfigWidget.Error.TooLarge.Format");
  1501. string tooLarge = string.Format(tooLargeFormat, maxPenSize);
  1502. this.penSizeComboBox.ToolTipText = tooLarge;
  1503. }
  1504. else
  1505. {
  1506. // Clear the error, if any
  1507. this.penSizeComboBox.BackColor = SystemColors.Window;
  1508. this.penSizeComboBox.ToolTipText = string.Empty;
  1509. OnPenChanged();
  1510. }
  1511. }
  1512. }
  1513. public event EventHandler AlphaBlendingChanged;
  1514. protected virtual void OnAlphaBlendingChanged()
  1515. {
  1516. if (AlphaBlendingChanged != null)
  1517. {
  1518. AlphaBlendingChanged(this, EventArgs.Empty);
  1519. }
  1520. }
  1521. public void PerformAlphaBlendingChanged()
  1522. {
  1523. OnAlphaBlendingChanged();
  1524. }
  1525. private void GradientChannelsSplitButton_DropDownOpening(object sender, EventArgs e)
  1526. {
  1527. ToolStripMenuItem allChannels = new ToolStripMenuItem(
  1528. PdnResources.GetString("GradientChannels.AllColorChannels.Text"),
  1529. this.gradientAllColorChannelsImage.Reference,
  1530. delegate (object sender2, EventArgs e2)
  1531. {
  1532. GradientInfo = new GradientInfo(GradientInfo.GradientType, false);
  1533. });
  1534. ToolStripMenuItem alphaOnly = new ToolStripMenuItem(
  1535. PdnResources.GetString("GradientChannels.AlphaChannelOnly.Text"),
  1536. this.gradientAlphaChannelOnlyImage.Reference,
  1537. delegate (object sender3, EventArgs e3)
  1538. {
  1539. GradientInfo = new GradientInfo(GradientInfo.GradientType, true);
  1540. });
  1541. allChannels.Checked = !GradientInfo.AlphaOnly;
  1542. alphaOnly.Checked = GradientInfo.AlphaOnly;
  1543. this.gradientChannelsSplitButton.DropDownItems.Clear();
  1544. this.gradientChannelsSplitButton.DropDownItems.AddRange(
  1545. new ToolStripItem[]
  1546. {
  1547. allChannels,
  1548. alphaOnly
  1549. });
  1550. }
  1551. private void AlphaBlendingSplitButton_DropDownOpening(object sender, EventArgs e)
  1552. {
  1553. ToolStripMenuItem abEnabled = new ToolStripMenuItem(
  1554. PdnResources.GetString("AlphaBlendingSplitButton.BlendingEnabled.Text"),
  1555. this.alphaBlendingEnabledImage.Reference,
  1556. delegate (object sender2, EventArgs e2)
  1557. {
  1558. AlphaBlending = true;
  1559. });
  1560. ToolStripMenuItem abOverwrite = new ToolStripMenuItem(
  1561. PdnResources.GetString("AlphaBlendingSplitButton.BlendingOverwrite.Text"),
  1562. this.alphaBlendingOverwriteImage.Reference,
  1563. delegate (object sender3, EventArgs e3)
  1564. {
  1565. AlphaBlending = false;
  1566. });
  1567. abEnabled.Checked = AlphaBlending;
  1568. abOverwrite.Checked = !AlphaBlending;
  1569. this.alphaBlendingSplitButton.DropDownItems.Clear();
  1570. this.alphaBlendingSplitButton.DropDownItems.AddRange(
  1571. new ToolStripItem[]
  1572. {
  1573. abEnabled,
  1574. abOverwrite
  1575. });
  1576. }
  1577. public bool AlphaBlending
  1578. {
  1579. get
  1580. {
  1581. return this.alphaBlendingEnabled;
  1582. }
  1583. set
  1584. {
  1585. if (value != this.alphaBlendingEnabled)
  1586. {
  1587. this.alphaBlendingEnabled = value;
  1588. if (value)
  1589. {
  1590. this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
  1591. }
  1592. else
  1593. {
  1594. this.alphaBlendingSplitButton.Image = this.alphaBlendingOverwriteImage.Reference;
  1595. }
  1596. OnAlphaBlendingChanged();
  1597. }
  1598. }
  1599. }
  1600. private void AlphaBlendingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  1601. {
  1602. OnAlphaBlendingChanged();
  1603. }
  1604. public event EventHandler AntiAliasingChanged;
  1605. protected virtual void OnAntiAliasingChanged()
  1606. {
  1607. if (AntiAliasingChanged != null)
  1608. {
  1609. AntiAliasingChanged(this, EventArgs.Empty);
  1610. }
  1611. }
  1612. public void PerformAntiAliasingChanged()
  1613. {
  1614. OnAntiAliasingChanged();
  1615. }
  1616. public bool AntiAliasing
  1617. {
  1618. get
  1619. {
  1620. return this.antiAliasingEnabled;
  1621. }
  1622. set
  1623. {
  1624. if (this.antiAliasingEnabled != value)
  1625. {
  1626. if (value)
  1627. {
  1628. this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
  1629. }
  1630. else
  1631. {
  1632. this.antiAliasingSplitButton.Image = this.antiAliasingDisabledImage.Reference;
  1633. }
  1634. this.antiAliasingEnabled = value;
  1635. OnAntiAliasingChanged();
  1636. }
  1637. }
  1638. }
  1639. private Image GetDashStyleImage(DashStyle dashStyle)
  1640. {
  1641. string nameFormat = "Images.DashStyleButton.{0}.png";
  1642. string name = string.Format(nameFormat, dashStyle.ToString());
  1643. ImageResource imageResource = PdnResources.GetImageResource(name);
  1644. Image returnImage;
  1645. if (UI.GetXScaleFactor() == 1.0f && UI.GetYScaleFactor() == 1.0f)
  1646. {
  1647. returnImage = imageResource.Reference;
  1648. }
  1649. else
  1650. {
  1651. returnImage = new Bitmap(imageResource.Reference, UI.ScaleSize(imageResource.Reference.Size));
  1652. }
  1653. return returnImage;
  1654. }
  1655. private ImageResource GetLineCapImage(LineCap2 lineCap, bool isStartCap)
  1656. {
  1657. string nameFormat = "Images.LineCapButton.{0}.{1}.png";
  1658. string name = string.Format(nameFormat, lineCap.ToString(), isStartCap ? "Start" : "End");
  1659. ImageResource imageResource = PdnResources.GetImageResource(name);
  1660. return imageResource;
  1661. }
  1662. private void PenDashStyleButton_DropDownOpening(object sender, EventArgs e)
  1663. {
  1664. List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
  1665. foreach (DashStyle dashStyle in this.dashStyles)
  1666. {
  1667. ToolStripMenuItem mi = new ToolStripMenuItem(
  1668. this.dashStyleLocalizer.EnumValueToLocalizedName(dashStyle),
  1669. GetDashStyleImage(dashStyle),
  1670. delegate (object sender2, EventArgs e2)
  1671. {
  1672. ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
  1673. DashStyle newDashStyle = (DashStyle)tsmi.Tag;
  1674. PenInfo newPenInfo = PenInfo.Clone();
  1675. newPenInfo.DashStyle = newDashStyle;
  1676. PenInfo = newPenInfo;
  1677. });
  1678. mi.ImageScaling = ToolStripItemImageScaling.None;
  1679. if (dashStyle == PenInfo.DashStyle)
  1680. {
  1681. mi.Checked = true;
  1682. }
  1683. mi.Tag = dashStyle;
  1684. menuItems.Add(mi);
  1685. }
  1686. this.penDashStyleSplitButton.DropDownItems.Clear();
  1687. this.penDashStyleSplitButton.DropDownItems.AddRange(menuItems.ToArray());
  1688. }
  1689. private void PenCapSplitButton_DropDownOpening(object sender, EventArgs e)
  1690. {
  1691. ToolStripSplitButton splitButton = (ToolStripSplitButton)sender;
  1692. List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
  1693. LineCap2 currentLineCap = PenInfo.DefaultLineCap;
  1694. bool isStartCap;
  1695. if (object.ReferenceEquals(splitButton, this.penStartCapSplitButton))
  1696. {
  1697. isStartCap = true;
  1698. currentLineCap = PenInfo.StartCap;
  1699. }
  1700. else if (object.ReferenceEquals(splitButton, this.penEndCapSplitButton))
  1701. {
  1702. isStartCap = false;
  1703. currentLineCap = PenInfo.EndCap;
  1704. }
  1705. else
  1706. {
  1707. throw new InvalidOperationException();
  1708. }
  1709. foreach (LineCap2 lineCap in this.lineCaps)
  1710. {
  1711. ToolStripMenuItem mi = new ToolStripMenuItem(
  1712. this.lineCapLocalizer.EnumValueToLocalizedName(lineCap),
  1713. GetLineCapImage(lineCap, isStartCap).Reference,
  1714. delegate (object sender2, EventArgs e2)
  1715. {
  1716. ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
  1717. Pair<ToolStripSplitButton, LineCap2> data = (Pair<ToolStripSplitButton, LineCap2>)tsmi.Tag;
  1718. PenInfo newPenInfo = PenInfo.Clone();
  1719. if (object.ReferenceEquals(data.First, this.penStartCapSplitButton))
  1720. {
  1721. newPenInfo.StartCap = data.Second;
  1722. }
  1723. else if (object.ReferenceEquals(data.First, this.penEndCapSplitButton))
  1724. {
  1725. newPenInfo.EndCap = data.Second;
  1726. }
  1727. PenInfo = newPenInfo;
  1728. });
  1729. mi.Tag = Pair.Create(splitButton, lineCap);
  1730. if (lineCap == currentLineCap)
  1731. {
  1732. mi.Checked = true;
  1733. }
  1734. menuItems.Add(mi);
  1735. }
  1736. splitButton.DropDownItems.Clear();
  1737. splitButton.DropDownItems.AddRange(menuItems.ToArray());
  1738. }
  1739. private void AntiAliasingSplitButton_DropDownOpening(object sender, EventArgs e)
  1740. {
  1741. ToolStripMenuItem aaEnabled = new ToolStripMenuItem(
  1742. PdnResources.GetString("AntiAliasingSplitButton.Enabled.Text"),
  1743. this.antiAliasingEnabledImage.Reference,
  1744. delegate (object sender2, EventArgs e2)
  1745. {
  1746. AntiAliasing = true;
  1747. });
  1748. ToolStripMenuItem aaDisabled = new ToolStripMenuItem(
  1749. PdnResources.GetString("AntiAliasingSplitButton.Disabled.Text"),
  1750. this.antiAliasingDisabledImage.Reference,
  1751. delegate (object sender3, EventArgs e3)
  1752. {
  1753. AntiAliasing = false;
  1754. });
  1755. aaEnabled.Checked = AntiAliasing;
  1756. aaDisabled.Checked = !AntiAliasing;
  1757. this.antiAliasingSplitButton.DropDownItems.Clear();
  1758. this.antiAliasingSplitButton.DropDownItems.AddRange(
  1759. new ToolStripItem[]
  1760. {
  1761. aaEnabled,
  1762. aaDisabled
  1763. });
  1764. }
  1765. private void SmoothingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  1766. {
  1767. OnFontSmoothingChanged();
  1768. }
  1769. private void PopulateFontsBackgroundThread(object ignored)
  1770. {
  1771. PopulateFontsBackgroundThread();
  1772. }
  1773. private void PopulateFontsBackgroundThread()
  1774. {
  1775. try
  1776. {
  1777. using (new ThreadBackground(ThreadBackgroundFlags.Cpu))
  1778. {
  1779. PopulateFonts();
  1780. }
  1781. }
  1782. finally
  1783. {
  1784. staticFontNamesPopulatedEvent.Set();
  1785. }
  1786. }
  1787. private void PopulateFonts()
  1788. {
  1789. List<string> fontNames = new List<string>();
  1790. using (Graphics g = this.CreateGraphics())
  1791. {
  1792. FontFamily[] families = FontFamily.Families;
  1793. foreach (FontFamily family in families)
  1794. {
  1795. using (FontInfo fi = new FontInfo(family, 10, FontStyle.Regular))
  1796. {
  1797. if (!fontNames.Contains(family.Name) && fi.CanCreateFont())
  1798. {
  1799. fontNames.Add(family.Name);
  1800. }
  1801. }
  1802. }
  1803. }
  1804. staticFontNames = fontNames;
  1805. Tracing.LogFeature("PopulateFonts()");
  1806. }
  1807. public event EventHandler FontInfoChanged;
  1808. protected virtual void OnFontInfoChanged()
  1809. {
  1810. if (FontInfoChanged != null)
  1811. {
  1812. FontInfoChanged(this, EventArgs.Empty);
  1813. }
  1814. }
  1815. public event EventHandler FontAlignmentChanged;
  1816. protected virtual void OnTextAlignmentChanged()
  1817. {
  1818. if (FontAlignmentChanged != null)
  1819. {
  1820. FontAlignmentChanged(this, EventArgs.Empty);
  1821. }
  1822. }
  1823. public event EventHandler FontSmoothingChanged;
  1824. protected virtual void OnFontSmoothingChanged()
  1825. {
  1826. if (FontSmoothingChanged != null)
  1827. {
  1828. FontSmoothingChanged(this, EventArgs.Empty);
  1829. }
  1830. }
  1831. public FontSmoothing FontSmoothing
  1832. {
  1833. get
  1834. {
  1835. return (FontSmoothing)this.fontSmoothingLocalizer.LocalizedNameToEnumValue((string)this.fontSmoothingComboBox.SelectedItem);
  1836. }
  1837. set
  1838. {
  1839. if (value != this.FontSmoothing)
  1840. {
  1841. this.fontSmoothingComboBox.SelectedItem = this.fontSmoothingLocalizer.EnumValueToLocalizedName(value);
  1842. }
  1843. }
  1844. }
  1845. public FontInfo FontInfo
  1846. {
  1847. get
  1848. {
  1849. return new FontInfo(this.FontFamily, this.FontSize, this.FontStyle);
  1850. }
  1851. set
  1852. {
  1853. this.FontFamily = value.FontFamily;
  1854. this.FontSize = value.Size;
  1855. this.FontStyle = value.FontStyle;
  1856. }
  1857. }
  1858. /// <summary>
  1859. /// Gets or sets the font style i.e. bold, italic, and underline
  1860. /// </summary>
  1861. public FontStyle FontStyle
  1862. {
  1863. get
  1864. {
  1865. return this.fontStyle;
  1866. }
  1867. set
  1868. {
  1869. if (this.fontStyle != value)
  1870. {
  1871. this.fontStyle = value;
  1872. SetFontStyleButtons(FontStyle);
  1873. this.OnFontInfoChanged();
  1874. }
  1875. }
  1876. }
  1877. /// <summary>
  1878. /// Gets or sets the size of the font.
  1879. /// </summary>
  1880. public float FontSize
  1881. {
  1882. get
  1883. {
  1884. bool invalid = false;
  1885. float number = oldSizeValue;
  1886. try
  1887. {
  1888. number = float.Parse(fontSizeComboBox.Text);
  1889. }
  1890. catch (FormatException)
  1891. {
  1892. invalid = true;
  1893. }
  1894. catch (OverflowException)
  1895. {
  1896. invalid = true;
  1897. }
  1898. // if the size is valid update the new size else return the last known good size.
  1899. if (!invalid)
  1900. {
  1901. oldSizeValue = number;
  1902. }
  1903. return oldSizeValue;
  1904. }
  1905. set
  1906. {
  1907. bool invalid = false;
  1908. float number = oldSizeValue;
  1909. try
  1910. {
  1911. number = float.Parse(fontSizeComboBox.Text);
  1912. }
  1913. catch (FormatException)
  1914. {
  1915. invalid = true;
  1916. }
  1917. catch (OverflowException)
  1918. {
  1919. invalid = true;
  1920. }
  1921. // if the size is valid update the new size else return the last known good size.
  1922. if (!invalid)
  1923. {
  1924. if (float.Parse(fontSizeComboBox.Text) != value)
  1925. {
  1926. fontSizeComboBox.Text = value.ToString();
  1927. this.OnFontInfoChanged();
  1928. }
  1929. }
  1930. }
  1931. }
  1932. private FontFamily IndexToFontFamily(int i)
  1933. {
  1934. try
  1935. {
  1936. return new FontFamily((string)this.fontFamilyComboBox.Items[i]);
  1937. }
  1938. catch (Exception)
  1939. {
  1940. return FontFamily.GenericSansSerif;
  1941. }
  1942. }
  1943. private Font IndexToFont(int i, float size, FontStyle style)
  1944. {
  1945. using (FontFamily ff = IndexToFontFamily(i))
  1946. {
  1947. return new FontInfo(ff, size, style).CreateFont();
  1948. }
  1949. }
  1950. /// <summary>
  1951. /// Gets or sets the font family.
  1952. /// </summary>
  1953. public FontFamily FontFamily
  1954. {
  1955. get
  1956. {
  1957. try
  1958. {
  1959. return new FontFamily((string)this.fontFamilyComboBox.SelectedItem);
  1960. }
  1961. catch (ArgumentException)
  1962. {
  1963. return FontFamily.GenericSansSerif;
  1964. }
  1965. }
  1966. set
  1967. {
  1968. string current = (string)this.fontFamilyComboBox.SelectedItem;
  1969. if (current != value.Name)
  1970. {
  1971. int index = fontFamilyComboBox.Items.IndexOf(value.Name);
  1972. if (index != -1)
  1973. {
  1974. fontFamilyComboBox.SelectedIndex = index;
  1975. this.OnFontInfoChanged();
  1976. }
  1977. else
  1978. {
  1979. // Maybe they're just specifying a font we didn't add to the list yet? aka pre-list initialization
  1980. FontInfo oldFI = this.FontInfo;
  1981. FontFamily newFF;
  1982. try
  1983. {
  1984. newFF = new FontFamily(value.Name);
  1985. }
  1986. catch (Exception)
  1987. {
  1988. newFF = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
  1989. }
  1990. FontInfo newFI = new FontInfo(newFF, oldFI.Size, oldFI.FontStyle);
  1991. if (newFI.CanCreateFont())
  1992. {
  1993. this.fontFamilyComboBox.Items.Add(value.Name);
  1994. this.fontFamilyComboBox.SelectedItem = value.Name;
  1995. }
  1996. else
  1997. {
  1998. throw new InvalidOperationException("FontFamily is not valid");
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. public TextAlignment FontAlignment
  2005. {
  2006. get
  2007. {
  2008. return this.alignment;
  2009. }
  2010. set
  2011. {
  2012. if (this.alignment != value)
  2013. {
  2014. this.alignment = value;
  2015. // if the user sets the text alignment the buttons must be updated
  2016. if (this.alignment == TextAlignment.Left)
  2017. {
  2018. this.fontAlignLeftButton.Checked = true;
  2019. this.fontAlignCenterButton.Checked = false;
  2020. this.fontAlignRightButton.Checked = false;
  2021. }
  2022. else if (this.alignment == TextAlignment.Center)
  2023. {
  2024. this.fontAlignLeftButton.Checked = false;
  2025. this.fontAlignCenterButton.Checked = true;
  2026. this.fontAlignRightButton.Checked = false;
  2027. }
  2028. else if (this.alignment == TextAlignment.Right)
  2029. {
  2030. this.fontAlignLeftButton.Checked = false;
  2031. this.fontAlignCenterButton.Checked = false;
  2032. this.fontAlignRightButton.Checked = true;
  2033. }
  2034. else
  2035. {
  2036. throw new InvalidOperationException("Text alignment type is invalid");
  2037. }
  2038. this.OnTextAlignmentChanged();
  2039. }
  2040. }
  2041. }
  2042. private void FontFamilyComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
  2043. {
  2044. if (e.Index != -1)
  2045. {
  2046. string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
  2047. SizeF stringSize = e.Graphics.MeasureString(displayText, arialFontBase);
  2048. int size = (int)stringSize.Width;
  2049. // set up two areas to draw
  2050. const int leftMargin = 3;
  2051. Rectangle bounds = e.Bounds;
  2052. bounds.X += leftMargin;
  2053. bounds.Width -= leftMargin;
  2054. Rectangle r = bounds;
  2055. Rectangle rd = r;
  2056. rd.Width = rd.Left + size;
  2057. Rectangle rt = r;
  2058. r.X = rd.Right;
  2059. using (Font myFont = IndexToFont(e.Index, 10, FontStyle.Regular))
  2060. {
  2061. StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone();
  2062. sf.LineAlignment = StringAlignment.Center;
  2063. sf.FormatFlags &= ~StringFormatFlags.LineLimit;
  2064. sf.FormatFlags |= StringFormatFlags.NoWrap;
  2065. bool isSymbol = PaintDotNet.SystemLayer.Fonts.IsSymbolFont(myFont);
  2066. bool isSelected = ((e.State & DrawItemState.Selected) != 0);
  2067. Brush fillBrush;
  2068. Brush textBrush;
  2069. if (isSelected)
  2070. {
  2071. fillBrush = highlightBrush;
  2072. textBrush = highlightTextBrush;
  2073. }
  2074. else
  2075. {
  2076. fillBrush = windowBrush;
  2077. textBrush = windowTextBrush;
  2078. }
  2079. e.Graphics.FillRectangle(fillBrush, e.Bounds);
  2080. if (isSymbol)
  2081. {
  2082. e.Graphics.DrawString(displayText, arialFontBase, textBrush, bounds, sf);
  2083. e.Graphics.DrawString(displayText, myFont, textBrush, r, sf);
  2084. }
  2085. else
  2086. {
  2087. e.Graphics.DrawString(displayText, myFont, textBrush, bounds, sf);
  2088. }
  2089. sf.Dispose();
  2090. sf = null;
  2091. }
  2092. }
  2093. e.DrawFocusRectangle();
  2094. }
  2095. private void FontFamilyComboBox_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
  2096. {
  2097. // Work out what the text will be
  2098. string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
  2099. // Get width & height of string
  2100. SizeF stringSize;
  2101. using (Font font = IndexToFont(e.Index, 10, FontStyle.Regular))
  2102. {
  2103. stringSize = e.Graphics.MeasureString(displayText, font);
  2104. }
  2105. // Account for top margin
  2106. stringSize.Height += UI.ScaleHeight(6);
  2107. // set hight to text height
  2108. e.ItemHeight = (int)stringSize.Height;
  2109. int maxHeight = UI.ScaleHeight(20);
  2110. if (e.ItemHeight > maxHeight)
  2111. {
  2112. e.ItemHeight = maxHeight;
  2113. }
  2114. // set width to text width
  2115. e.ItemWidth = (int)stringSize.Width;
  2116. }
  2117. private void FontSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  2118. {
  2119. try
  2120. {
  2121. bool invalid = false;
  2122. try
  2123. {
  2124. float number = float.Parse(fontSizeComboBox.Text);
  2125. }
  2126. catch (FormatException)
  2127. {
  2128. invalid = true;
  2129. }
  2130. catch (OverflowException)
  2131. {
  2132. invalid = true;
  2133. }
  2134. if (invalid)
  2135. {
  2136. this.fontSizeComboBox.BackColor = Color.Red;
  2137. this.fontSizeComboBox.ToolTipText = PdnResources.GetString("TextConfigWidget.Error.InvalidNumber");
  2138. }
  2139. else
  2140. {
  2141. if ((float.Parse(fontSizeComboBox.Text) < minFontSize))
  2142. {
  2143. // Set the error if the size is too small.
  2144. this.fontSizeComboBox.BackColor = Color.Red;
  2145. string format = PdnResources.GetString("TextConfigWidget.Error.TooSmall.Format");
  2146. string text = string.Format(format, minFontSize);
  2147. this.fontSizeComboBox.ToolTipText = text;
  2148. }
  2149. else if ((float.Parse(fontSizeComboBox.Text) > maxFontSize))
  2150. {
  2151. // Set the error if the size is too large.
  2152. this.fontSizeComboBox.BackColor = Color.Red;
  2153. string format = PdnResources.GetString("TextConfigWidget.Error.TooLarge.Format");
  2154. string text = string.Format(format, maxFontSize);
  2155. this.fontSizeComboBox.ToolTipText = text;
  2156. }
  2157. else
  2158. {
  2159. // Clear the error, if any
  2160. this.fontSizeComboBox.ToolTipText = string.Empty;
  2161. this.fontSizeComboBox.BackColor = SystemColors.Window;
  2162. OnFontInfoChanged();
  2163. }
  2164. }
  2165. }
  2166. catch (FormatException)
  2167. {
  2168. e.Cancel = true;
  2169. }
  2170. }
  2171. private void FontSizeComboBox_TextChanged(object sender, System.EventArgs e)
  2172. {
  2173. FontSizeComboBox_Validating(sender, new CancelEventArgs());
  2174. }
  2175. private void FontFamilyComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
  2176. {
  2177. OnFontInfoChanged();
  2178. }
  2179. private void FontFamilyComboBox_GotFocus(object sender, EventArgs e)
  2180. {
  2181. if (!fontsComboBoxPopulated)
  2182. {
  2183. AsyncInitFontNames();
  2184. using (new WaitCursorChanger(this))
  2185. {
  2186. staticFontNamesPopulatedEvent.WaitOne();
  2187. this.fontFamilyComboBox.ComboBox.BeginUpdate();
  2188. List<string> fontNames = staticFontNames;
  2189. foreach (string name in fontNames)
  2190. {
  2191. if (!this.fontFamilyComboBox.Items.Contains(name))
  2192. {
  2193. this.fontFamilyComboBox.Items.Add(name);
  2194. }
  2195. }
  2196. this.fontFamilyComboBox.ComboBox.EndUpdate();
  2197. }
  2198. fontsComboBoxPopulated = true;
  2199. }
  2200. }
  2201. public ToolBarConfigItems ToolBarConfigItems
  2202. {
  2203. get
  2204. {
  2205. return this.toolBarConfigItems;
  2206. }
  2207. set
  2208. {
  2209. this.toolBarConfigItems = value;
  2210. SuspendLayout();
  2211. bool showPen = ((value & ToolBarConfigItems.Pen) != ToolBarConfigItems.None);
  2212. this.penSeparator.Visible = showPen;
  2213. this.penSizeLabel.Visible = showPen;
  2214. this.penSizeDecButton.Visible = showPen;
  2215. this.penSizeComboBox.Visible = showPen;
  2216. this.penSizeIncButton.Visible = showPen;
  2217. bool showPenCaps = ((value & ToolBarConfigItems.PenCaps) != ToolBarConfigItems.None);
  2218. this.penStyleLabel.Visible = showPenCaps;
  2219. this.penStartCapSplitButton.Visible = showPenCaps;
  2220. this.penDashStyleSplitButton.Visible = showPenCaps;
  2221. this.penEndCapSplitButton.Visible = showPenCaps;
  2222. bool showBrush = ((value & ToolBarConfigItems.Brush) != ToolBarConfigItems.None);
  2223. this.brushSeparator.Visible = showBrush;
  2224. this.brushStyleLabel.Visible = showBrush;
  2225. this.brushStyleComboBox.Visible = showBrush;
  2226. bool showShape = ((value & ToolBarConfigItems.ShapeType) != ToolBarConfigItems.None);
  2227. this.shapeSeparator.Visible = showShape;
  2228. this.shapeButton.Visible = showShape;
  2229. bool showGradient = ((value & ToolBarConfigItems.Gradient) != ToolBarConfigItems.None);
  2230. this.gradientSeparator1.Visible = showGradient;
  2231. this.gradientLinearClampedButton.Visible = showGradient;
  2232. this.gradientLinearReflectedButton.Visible = showGradient;
  2233. this.gradientLinearDiamondButton.Visible = showGradient;
  2234. this.gradientRadialButton.Visible = showGradient;
  2235. this.gradientConicalButton.Visible = showGradient;
  2236. this.gradientSeparator2.Visible = showGradient;
  2237. this.gradientChannelsSplitButton.Visible = showGradient;
  2238. bool showAA = ((value & ToolBarConfigItems.Antialiasing) != ToolBarConfigItems.None);
  2239. this.antiAliasingSplitButton.Visible = showAA;
  2240. bool showAB = ((value & ToolBarConfigItems.AlphaBlending) != ToolBarConfigItems.None);
  2241. this.alphaBlendingSplitButton.Visible = showAB;
  2242. bool showBlendingSep = ((value & (ToolBarConfigItems.AlphaBlending | ToolBarConfigItems.Antialiasing)) != ToolBarConfigItems.None);
  2243. this.blendingSeparator.Visible = showBlendingSep;
  2244. bool showTolerance = ((value & ToolBarConfigItems.Tolerance) != ToolBarConfigItems.None);
  2245. this.toleranceSeparator.Visible = showTolerance;
  2246. this.toleranceLabel.Visible = showTolerance;
  2247. this.toleranceSliderStrip.Visible = showTolerance;
  2248. bool showText = ((value & ToolBarConfigItems.Text) != ToolBarConfigItems.None);
  2249. this.fontSeparator.Visible = showText;
  2250. this.fontLabel.Visible = showText;
  2251. this.fontFamilyComboBox.Visible = showText;
  2252. this.fontSizeComboBox.Visible = showText;
  2253. this.fontSmoothingComboBox.Visible = showText;
  2254. this.fontStyleSeparator.Visible = showText;
  2255. this.fontBoldButton.Visible = showText;
  2256. this.fontItalicsButton.Visible = showText;
  2257. this.fontUnderlineButton.Visible = showText;
  2258. this.fontAlignSeparator.Visible = showText;
  2259. this.fontAlignLeftButton.Visible = showText;
  2260. this.fontAlignCenterButton.Visible = showText;
  2261. this.fontAlignRightButton.Visible = showText;
  2262. if (showText && IsHandleCreated)
  2263. {
  2264. AsyncInitFontNames();
  2265. }
  2266. bool showResampling = ((value & ToolBarConfigItems.Resampling) != ToolBarConfigItems.None);
  2267. this.resamplingSeparator.Visible = showResampling;
  2268. this.resamplingLabel.Visible = showResampling;
  2269. this.resamplingComboBox.Visible = showResampling;
  2270. bool showColorPicker = ((value & ToolBarConfigItems.ColorPickerBehavior) != ToolBarConfigItems.None);
  2271. this.colorPickerSeparator.Visible = showColorPicker;
  2272. this.colorPickerLabel.Visible = showColorPicker;
  2273. this.colorPickerComboBox.Visible = showColorPicker;
  2274. bool showSelectionCombineMode = ((value & ToolBarConfigItems.SelectionCombineMode) != ToolBarConfigItems.None);
  2275. this.selectionCombineModeSeparator.Visible = showSelectionCombineMode;
  2276. this.selectionCombineModeLabel.Visible = showSelectionCombineMode;
  2277. this.selectionCombineModeSplitButton.Visible = showSelectionCombineMode;
  2278. bool showFloodMode = ((value & ToolBarConfigItems.FloodMode) != ToolBarConfigItems.None);
  2279. this.floodModeSeparator.Visible = showFloodMode;
  2280. this.floodModeLabel.Visible = showFloodMode;
  2281. this.floodModeSplitButton.Visible = showFloodMode;
  2282. bool showSelectionDrawMode = ((value & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None);
  2283. this.selectionDrawModeSeparator.Visible = showSelectionDrawMode;
  2284. this.selectionDrawModeModeLabel.Visible = showSelectionDrawMode;
  2285. this.selectionDrawModeSplitButton.Visible = showSelectionDrawMode;
  2286. this.selectionDrawModeWidthLabel.Visible = showSelectionDrawMode;
  2287. this.selectionDrawModeSwapButton.Visible = showSelectionDrawMode;
  2288. this.selectionDrawModeHeightLabel.Visible = showSelectionDrawMode;
  2289. RefreshSelectionDrawModeInfoVisibilities();
  2290. if (value == ToolBarConfigItems.None)
  2291. {
  2292. this.Visible = false;
  2293. }
  2294. else
  2295. {
  2296. this.Visible = true;
  2297. }
  2298. ResumeLayout();
  2299. PerformLayout();
  2300. }
  2301. }
  2302. private void ToleranceSlider_ToleranceChanged(object sender, EventArgs e)
  2303. {
  2304. OnToleranceChanged();
  2305. }
  2306. public void PerformToleranceChanged()
  2307. {
  2308. OnToleranceChanged();
  2309. }
  2310. public float Tolerance
  2311. {
  2312. get
  2313. {
  2314. return this.toleranceSlider.Tolerance;
  2315. }
  2316. set
  2317. {
  2318. if (value != this.toleranceSlider.Tolerance)
  2319. {
  2320. this.toleranceSlider.Tolerance = value;
  2321. }
  2322. }
  2323. }
  2324. public event EventHandler ToleranceChanged;
  2325. protected void OnToleranceChanged()
  2326. {
  2327. if (ToleranceChanged != null)
  2328. {
  2329. ToleranceChanged(this, EventArgs.Empty);
  2330. }
  2331. }
  2332. public event EventHandler ColorPickerClickBehaviorChanged;
  2333. protected void OnColorPickerClickBehaviorChanged()
  2334. {
  2335. if (ColorPickerClickBehaviorChanged != null)
  2336. {
  2337. ColorPickerClickBehaviorChanged(this, EventArgs.Empty);
  2338. }
  2339. }
  2340. public ColorPickerClickBehavior ColorPickerClickBehavior
  2341. {
  2342. get
  2343. {
  2344. string selectedItem = (string)this.colorPickerComboBox.SelectedItem;
  2345. ColorPickerClickBehavior cpcb = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(selectedItem);
  2346. return cpcb;
  2347. }
  2348. set
  2349. {
  2350. if (value != ColorPickerClickBehavior)
  2351. {
  2352. this.colorPickerComboBox.SelectedItem = this.colorPickerBehaviorNames.EnumValueToLocalizedName(value);
  2353. }
  2354. }
  2355. }
  2356. public void PerformColorPickerClickBehaviorChanged()
  2357. {
  2358. OnColorPickerClickBehaviorChanged();
  2359. }
  2360. private void ColorPickerComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2361. {
  2362. OnColorPickerClickBehaviorChanged();
  2363. }
  2364. private void ResamplingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2365. {
  2366. OnResamplingAlgorithmChanged();
  2367. }
  2368. public event EventHandler ResamplingAlgorithmChanged;
  2369. protected void OnResamplingAlgorithmChanged()
  2370. {
  2371. if (ResamplingAlgorithmChanged != null)
  2372. {
  2373. ResamplingAlgorithmChanged(this, EventArgs.Empty);
  2374. }
  2375. }
  2376. public ResamplingAlgorithm ResamplingAlgorithm
  2377. {
  2378. get
  2379. {
  2380. string selectedItem = (string)this.resamplingComboBox.SelectedItem;
  2381. ResamplingAlgorithm ra = (ResamplingAlgorithm)this.resamplingAlgorithmNames.LocalizedNameToEnumValue(selectedItem);
  2382. return ra;
  2383. }
  2384. set
  2385. {
  2386. if (value != ResamplingAlgorithm)
  2387. {
  2388. if (value != ResamplingAlgorithm.NearestNeighbor && value != ResamplingAlgorithm.Bilinear)
  2389. {
  2390. throw new InvalidEnumArgumentException();
  2391. }
  2392. this.resamplingComboBox.SelectedItem = this.resamplingAlgorithmNames.EnumValueToLocalizedName(value);
  2393. }
  2394. }
  2395. }
  2396. public void PerformResamplingAlgorithmChanged()
  2397. {
  2398. OnResamplingAlgorithmChanged();
  2399. }
  2400. public event EventHandler SelectionCombineModeChanged;
  2401. protected void OnSelectionCombineModeChanged()
  2402. {
  2403. if (SelectionCombineModeChanged != null)
  2404. {
  2405. SelectionCombineModeChanged(this, EventArgs.Empty);
  2406. }
  2407. }
  2408. public CombineMode SelectionCombineMode
  2409. {
  2410. get
  2411. {
  2412. object tag = this.selectionCombineModeSplitButton.Tag;
  2413. CombineMode cm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
  2414. return cm;
  2415. }
  2416. set
  2417. {
  2418. object tag = this.selectionCombineModeSplitButton.Tag;
  2419. CombineMode oldCm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
  2420. if (tag == null || (tag != null && value != oldCm))
  2421. {
  2422. this.selectionCombineModeSplitButton.Tag = value;
  2423. UI.SuspendControlPainting(this);
  2424. this.selectionCombineModeSplitButton.Image = GetSelectionCombineModeImage(value).Reference;
  2425. UI.ResumeControlPainting(this);
  2426. OnSelectionCombineModeChanged();
  2427. Invalidate(true);
  2428. }
  2429. }
  2430. }
  2431. public void PerformSelectionCombineModeChanged()
  2432. {
  2433. OnSelectionCombineModeChanged();
  2434. }
  2435. private ImageResource GetSelectionCombineModeImage(CombineMode cm)
  2436. {
  2437. return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionCombineMode." + cm.ToString() + ".png");
  2438. }
  2439. private void SelectionCombineModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2440. {
  2441. this.selectionCombineModeSplitButton.DropDownItems.Clear();
  2442. foreach (CombineMode cm in
  2443. new CombineMode[]
  2444. {
  2445. CombineMode.Replace,
  2446. CombineMode.Union,
  2447. CombineMode.Exclude,
  2448. CombineMode.Intersect,
  2449. CombineMode.Xor
  2450. })
  2451. {
  2452. ToolStripMenuItem cmMI = new ToolStripMenuItem(
  2453. PdnResources.GetString("ToolConfigStrip.SelectionCombineModeSplitButton." + cm.ToString() + ".Text"),
  2454. GetSelectionCombineModeImage(cm).Reference,
  2455. delegate (object sender2, EventArgs e2)
  2456. {
  2457. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2458. CombineMode newCM = (CombineMode)asTSMI.Tag;
  2459. this.SelectionCombineMode = newCM;
  2460. });
  2461. cmMI.Tag = cm;
  2462. cmMI.Checked = (cm == SelectionCombineMode);
  2463. this.selectionCombineModeSplitButton.DropDownItems.Add(cmMI);
  2464. }
  2465. }
  2466. private CombineMode CycleSelectionCombineMode(CombineMode mode)
  2467. {
  2468. CombineMode newMode;
  2469. // Replace -> Union -> Exclude -> Intersect -> Xor -> Replace
  2470. switch (mode)
  2471. {
  2472. default:
  2473. case CombineMode.Complement:
  2474. throw new InvalidEnumArgumentException();
  2475. case CombineMode.Exclude:
  2476. newMode = CombineMode.Intersect;
  2477. break;
  2478. case CombineMode.Intersect:
  2479. newMode = CombineMode.Xor;
  2480. break;
  2481. case CombineMode.Replace:
  2482. newMode = CombineMode.Union;
  2483. break;
  2484. case CombineMode.Union:
  2485. newMode = CombineMode.Exclude;
  2486. break;
  2487. case CombineMode.Xor:
  2488. newMode = CombineMode.Replace;
  2489. break;
  2490. }
  2491. return newMode;
  2492. }
  2493. public event EventHandler FloodModeChanged;
  2494. protected void OnFloodModeChanged()
  2495. {
  2496. if (FloodModeChanged != null)
  2497. {
  2498. FloodModeChanged(this, EventArgs.Empty);
  2499. }
  2500. }
  2501. public FloodMode FloodMode
  2502. {
  2503. get
  2504. {
  2505. object tag = this.floodModeSplitButton.Tag;
  2506. FloodMode fm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
  2507. return fm;
  2508. }
  2509. set
  2510. {
  2511. object tag = this.floodModeSplitButton.Tag;
  2512. FloodMode oldFm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
  2513. if (tag == null || (tag != null && value != oldFm))
  2514. {
  2515. this.floodModeSplitButton.Tag = value;
  2516. this.floodModeSplitButton.Image = GetFloodModeImage(value).Reference;
  2517. OnFloodModeChanged();
  2518. }
  2519. }
  2520. }
  2521. public void PerformFloodModeChanged()
  2522. {
  2523. OnFloodModeChanged();
  2524. }
  2525. private ImageResource GetFloodModeImage(FloodMode cm)
  2526. {
  2527. return PdnResources.GetImageResource("Icons.ToolConfigStrip.FloodMode." + cm.ToString() + ".png");
  2528. }
  2529. private void FloodModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2530. {
  2531. this.floodModeSplitButton.DropDownItems.Clear();
  2532. foreach (FloodMode fm in
  2533. new FloodMode[]
  2534. {
  2535. FloodMode.Local,
  2536. FloodMode.Global
  2537. })
  2538. {
  2539. ToolStripMenuItem fmMI = new ToolStripMenuItem(
  2540. PdnResources.GetString("ToolConfigStrip.FloodModeSplitButton." + fm.ToString() + ".Text"),
  2541. GetFloodModeImage(fm).Reference,
  2542. delegate (object sender2, EventArgs e2)
  2543. {
  2544. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2545. FloodMode newFM = (FloodMode)asTSMI.Tag;
  2546. this.FloodMode = newFM;
  2547. });
  2548. fmMI.Tag = fm;
  2549. fmMI.Checked = (fm == FloodMode);
  2550. this.floodModeSplitButton.DropDownItems.Add(fmMI);
  2551. }
  2552. }
  2553. private FloodMode CycleFloodMode(FloodMode mode)
  2554. {
  2555. FloodMode newMode;
  2556. switch (mode)
  2557. {
  2558. default:
  2559. throw new InvalidEnumArgumentException();
  2560. case FloodMode.Global:
  2561. newMode = FloodMode.Local;
  2562. break;
  2563. case FloodMode.Local:
  2564. newMode = FloodMode.Global;
  2565. break;
  2566. }
  2567. return newMode;
  2568. }
  2569. public event EventHandler SelectionDrawModeInfoChanged;
  2570. protected void OnSelectionDrawModeInfoChanged()
  2571. {
  2572. if (SelectionDrawModeInfoChanged != null)
  2573. {
  2574. SelectionDrawModeInfoChanged(this, EventArgs.Empty);
  2575. }
  2576. }
  2577. // syncs this.SelectionDrawModeInfo into the controls
  2578. private void SyncSelectionDrawModeInfoUI()
  2579. {
  2580. this.selectionDrawModeSplitButton.Text = GetSelectionDrawModeString(this.selectionDrawModeInfo.DrawMode);
  2581. this.selectionDrawModeSplitButton.Image = GetSelectionDrawModeImage(this.selectionDrawModeInfo.DrawMode);
  2582. this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
  2583. this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
  2584. this.selectionDrawModeUnits.UnitsChanged -= SelectionDrawModeUnits_UnitsChanged;
  2585. this.selectionDrawModeUnits.Units = this.selectionDrawModeInfo.Units;
  2586. this.selectionDrawModeUnits.UnitsChanged += SelectionDrawModeUnits_UnitsChanged;
  2587. RefreshSelectionDrawModeInfoVisibilities();
  2588. }
  2589. private void RefreshSelectionDrawModeInfoVisibilities()
  2590. {
  2591. if (this.selectionDrawModeInfo != null)
  2592. {
  2593. SuspendLayout();
  2594. bool anyVisible = (this.ToolBarConfigItems & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None;
  2595. this.selectionDrawModeModeLabel.Visible = false;
  2596. bool showWidthHeight = anyVisible & (this.selectionDrawModeInfo.DrawMode != SelectionDrawMode.Normal);
  2597. this.selectionDrawModeWidthTextBox.Visible = showWidthHeight;
  2598. this.selectionDrawModeHeightTextBox.Visible = showWidthHeight;
  2599. this.selectionDrawModeWidthLabel.Visible = showWidthHeight;
  2600. this.selectionDrawModeHeightLabel.Visible = showWidthHeight;
  2601. this.selectionDrawModeSwapButton.Visible = showWidthHeight;
  2602. this.selectionDrawModeUnits.Visible = anyVisible & (this.selectionDrawModeInfo.DrawMode == SelectionDrawMode.FixedSize);
  2603. ResumeLayout(false);
  2604. PerformLayout();
  2605. }
  2606. }
  2607. public SelectionDrawModeInfo SelectionDrawModeInfo
  2608. {
  2609. get
  2610. {
  2611. return (this.selectionDrawModeInfo ?? SelectionDrawModeInfo.CreateDefault()).Clone();
  2612. }
  2613. set
  2614. {
  2615. if (this.selectionDrawModeInfo == null || !this.selectionDrawModeInfo.Equals(value))
  2616. {
  2617. this.selectionDrawModeInfo = value.Clone();
  2618. OnSelectionDrawModeInfoChanged();
  2619. SyncSelectionDrawModeInfoUI();
  2620. }
  2621. }
  2622. }
  2623. public void PerformSelectionDrawModeInfoChanged()
  2624. {
  2625. OnSelectionDrawModeInfoChanged();
  2626. }
  2627. private string GetSelectionDrawModeString(SelectionDrawMode drawMode)
  2628. {
  2629. return PdnResources.GetString("ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".Text");
  2630. }
  2631. private Image GetSelectionDrawModeImage(SelectionDrawMode drawMode)
  2632. {
  2633. return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".png").Reference;
  2634. }
  2635. private void SelectionDrawModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2636. {
  2637. this.selectionDrawModeSplitButton.DropDownItems.Clear();
  2638. foreach (SelectionDrawMode sdm in
  2639. new SelectionDrawMode[]
  2640. {
  2641. SelectionDrawMode.Normal,
  2642. SelectionDrawMode.FixedRatio,
  2643. SelectionDrawMode.FixedSize
  2644. })
  2645. {
  2646. ToolStripMenuItem sdmTSMI = new ToolStripMenuItem(
  2647. GetSelectionDrawModeString(sdm),
  2648. GetSelectionDrawModeImage(sdm),
  2649. delegate (object sender2, EventArgs e2)
  2650. {
  2651. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2652. SelectionDrawMode newSDM = (SelectionDrawMode)asTSMI.Tag;
  2653. this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
  2654. });
  2655. sdmTSMI.Tag = sdm;
  2656. sdmTSMI.Checked = (sdm == this.SelectionDrawModeInfo.DrawMode);
  2657. this.selectionDrawModeSplitButton.DropDownItems.Add(sdmTSMI);
  2658. }
  2659. }
  2660. private SelectionDrawMode CycleSelectionDrawMode(SelectionDrawMode drawMode)
  2661. {
  2662. SelectionDrawMode newSDM;
  2663. switch (drawMode)
  2664. {
  2665. case SelectionDrawMode.Normal:
  2666. newSDM = SelectionDrawMode.FixedRatio;
  2667. break;
  2668. case SelectionDrawMode.FixedRatio:
  2669. newSDM = SelectionDrawMode.FixedSize;
  2670. break;
  2671. case SelectionDrawMode.FixedSize:
  2672. newSDM = SelectionDrawMode.Normal;
  2673. break;
  2674. default:
  2675. throw new InvalidEnumArgumentException();
  2676. }
  2677. return newSDM;
  2678. }
  2679. private void SelectionDrawModeUnits_UnitsChanged(object sender, EventArgs e)
  2680. {
  2681. OnSelectionDrawModeUnitsChanging();
  2682. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewUnits(this.selectionDrawModeUnits.Units);
  2683. OnSelectionDrawModeUnitsChanged();
  2684. }
  2685. }
  2686. }