12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113 |
- using PaintDotNet.Measurement.Enum;
- using PaintDotNet.Measurement.Interface;
- using PaintDotNet.Measurement.ObjInfo;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Threading;
- using System.Windows.Forms;
- namespace PaintDotNet.Measurement
- {
- public class ToolConfigStrip : ToolStripEx,
- IBrushConfig,
- IShapeTypeConfig,
- IPenConfig,
- IAntiAliasingConfig,
- IAlphaBlendingConfig,
- ITextConfig,
- IToleranceConfig,
- IColorPickerConfig,
- IGradientConfig,
- IResamplingConfig,
- ISelectionCombineModeConfig,
- IFloodModeConfig,
- ISelectionDrawModeConfig
- {
- private ToolBarConfigItems toolBarConfigItems = ToolBarConfigItems.None;
- private EnumLocalizer hatchStyleNames = EnumLocalizer.Create(typeof(HatchStyle));
- private string solidBrushText;
- private ImageResource shapeOutlineImage = PdnResources.GetImageResource("Icons.ShapeOutlineIcon.png");
- private ImageResource shapeInteriorImage = PdnResources.GetImageResource("Icons.ShapeInteriorIcon.png");
- private ImageResource shapeBothImage = PdnResources.GetImageResource("Icons.ShapeBothIcon.png");
- private ToolStripSeparator brushSeparator;
- private ToolStripLabel brushStyleLabel;
- private ToolStripComboBox brushStyleComboBox;
- private ToolStripSeparator shapeSeparator;
- private ToolStripSplitButton shapeButton;
- private ToolStripSeparator penSeparator;
- private ToolStripLabel penSizeLabel;
- private ToolStripButton penSizeDecButton;
- private ToolStripComboBox penSizeComboBox;
- private ToolStripButton penSizeIncButton;
- private ToolStripLabel penStyleLabel;
- private ToolStripSplitButton penStartCapSplitButton; // Tag property is used to store chosen LineCap value
- private ToolStripSplitButton penDashStyleSplitButton; // Tag property is used to store chosen DashStyle value
- private ToolStripSplitButton penEndCapSplitButton; // Tag property is used to store chosen LineCap value
- private EnumLocalizer lineCapLocalizer = EnumLocalizer.Create(typeof(LineCap2));
- private EnumLocalizer dashStyleLocalizer = EnumLocalizer.Create(typeof(DashStyle));
- private ToolStripSeparator blendingSeparator;
- private ToolStripSplitButton alphaBlendingSplitButton;
- private bool alphaBlendingEnabled = true;
- private ImageResource alphaBlendingEnabledImage;
- private ImageResource alphaBlendingOverwriteImage;
- private ToolStripSplitButton antiAliasingSplitButton;
- private bool antiAliasingEnabled = true;
- private ImageResource antiAliasingEnabledImage;
- private ImageResource antiAliasingDisabledImage;
- private EnumLocalizer resamplingAlgorithmNames = EnumLocalizer.Create(typeof(ResamplingAlgorithm));
- private ToolStripSeparator resamplingSeparator;
- private ToolStripLabel resamplingLabel;
- private ToolStripComboBox resamplingComboBox;
- private EnumLocalizer colorPickerBehaviorNames = EnumLocalizer.Create(typeof(ColorPickerClickBehavior));
- private ToolStripSeparator colorPickerSeparator;
- private ToolStripLabel colorPickerLabel;
- private ToolStripComboBox colorPickerComboBox;
- private ToolStripSeparator toleranceSeparator;
- private ToolStripLabel toleranceLabel;
- private ToolStripControlHost toleranceSliderStrip;
- private ToleranceSliderControl toleranceSlider;
- private LineCap2[] lineCaps =
- new LineCap2[]
- {
- LineCap2.Flat,
- LineCap2.Arrow,
- LineCap2.ArrowFilled,
- LineCap2.Rounded
- };
- private DashStyle[] dashStyles =
- new DashStyle[]
- {
- DashStyle.Solid,
- DashStyle.Dash,
- DashStyle.DashDot,
- DashStyle.DashDotDot,
- DashStyle.Dot
- };
- private const float minPenSize = 1.0f;
- private const float maxPenSize = 500.0f;
- private int[] brushSizes =
- new int[]
- {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 20, 25, 30,
- 35, 40, 45, 50, 55, 60, 65, 70,
- 75, 80, 85, 90, 95, 100, 125,
- 150, 175, 200, 225, 250, 275, 300,
- 325, 350, 375, 400, 425, 450, 475,
- 500
- };
- private ShapeDrawType shapeDrawType;
- private EnumLocalizer gradientTypeNames = EnumLocalizer.Create(typeof(GradientType));
- private GradientInfo gradientInfo = new GradientInfo(GradientType.LinearClamped, false);
- private ToolStripSeparator gradientSeparator1;
- private ToolStripButton gradientLinearClampedButton;
- private ToolStripButton gradientLinearReflectedButton;
- private ToolStripButton gradientLinearDiamondButton;
- private ToolStripButton gradientRadialButton;
- private ToolStripButton gradientConicalButton;
- private ToolStripSeparator gradientSeparator2;
- private ToolStripSplitButton gradientChannelsSplitButton;
- private ImageResource gradientAllColorChannelsImage;
- private ImageResource gradientAlphaChannelOnlyImage;
- private EnumLocalizer fontSmoothingLocalizer = EnumLocalizer.Create(typeof(FontSmoothing));
- private const int maxFontSize = 2000;
- private const int minFontSize = 1;
- private const int initialFontSize = 12;
- private FontFamily arialFontFamily;
- private FontStyle fontStyle;
- private TextAlignment alignment;
- private float oldSizeValue;
- private Brush highlightBrush;
- private Brush highlightTextBrush;
- private Brush windowBrush;
- private Brush windowTextBrush;
- private Font arialFontBase;
- private const string arialName = "Arial";
- private static ManualResetEvent staticFontNamesPopulatedEvent = new ManualResetEvent(false);
- private static List<string> staticFontNames = null;
- private bool fontsComboBoxPopulated = false;
- private ToolStripSeparator fontSeparator;
- private ToolStripLabel fontLabel;
- private ToolStripComboBox fontFamilyComboBox;
- private ToolStripComboBox fontSizeComboBox;
- private ToolStripComboBox fontSmoothingComboBox;
- private ToolStripSeparator fontStyleSeparator;
- private ToolStripButton fontBoldButton;
- private ToolStripButton fontItalicsButton;
- private ToolStripButton fontUnderlineButton;
- private ToolStripSeparator fontAlignSeparator;
- private ToolStripButton fontAlignLeftButton;
- private ToolStripButton fontAlignCenterButton;
- private ToolStripButton fontAlignRightButton;
- private int[] defaultFontSizes =
- new int[]
- {
- 8, 9, 10, 11, 12, 14, 16, 18, 20,
- 22, 24, 26, 28, 36, 48, 72, 84, 96,
- 108, 144, 192, 216, 288
- };
- private ToolStripSeparator selectionCombineModeSeparator;
- private ToolStripLabel selectionCombineModeLabel;
- private ToolStripSplitButton selectionCombineModeSplitButton;
- private ToolStripSeparator floodModeSeparator;
- private ToolStripLabel floodModeLabel;
- private ToolStripSplitButton floodModeSplitButton;
- private SelectionDrawModeInfo selectionDrawModeInfo;
- private ToolStripSeparator selectionDrawModeSeparator;
- private ToolStripLabel selectionDrawModeModeLabel;
- private ToolStripSplitButton selectionDrawModeSplitButton;
- private ToolStripLabel selectionDrawModeWidthLabel;
- private ToolStripTextBox selectionDrawModeWidthTextBox;
- private ToolStripButton selectionDrawModeSwapButton;
- private ToolStripLabel selectionDrawModeHeightLabel;
- private ToolStripTextBox selectionDrawModeHeightTextBox;
- private UnitsComboBoxStrip selectionDrawModeUnits;
- public event EventHandler SelectionDrawModeUnitsChanging;
- protected void OnSelectionDrawModeUnitsChanging()
- {
- if (SelectionDrawModeUnitsChanging != null)
- {
- SelectionDrawModeUnitsChanging(this, EventArgs.Empty);
- }
- }
- public event EventHandler SelectionDrawModeUnitsChanged;
- protected void OnSelectionDrawModeUnitsChanged()
- {
- if (SelectionDrawModeUnitsChanged != null)
- {
- SelectionDrawModeUnitsChanged(this, EventArgs.Empty);
- }
- }
- public void LoadFromAppEnvironment(IAppEnvironment appEnvironment)
- {
- AlphaBlending = appEnvironment.AlphaBlending();
- AntiAliasing = appEnvironment.AntiAliasing();
- BrushInfo = appEnvironment.BrushInfo();
- ColorPickerClickBehavior = appEnvironment.ColorPickerClickBehavior();
- GradientInfo = appEnvironment.GradientInfo();
- PenInfo = appEnvironment.PenInfo();
- ResamplingAlgorithm = appEnvironment.ResamplingAlgorithm();
- ShapeDrawType = appEnvironment.ShapeDrawType();
- FontInfo = appEnvironment.FontInfo();
- FontSmoothing = appEnvironment.FontSmoothing();
- FontAlignment = appEnvironment.TextAlignment();
- Tolerance = appEnvironment.Tolerance();
- SelectionCombineMode = appEnvironment.SelectionCombineMode();
- FloodMode = appEnvironment.FloodMode();
- SelectionDrawModeInfo = appEnvironment.SelectionDrawModeInfo();
- }
- public event EventHandler BrushInfoChanged;
- protected virtual void OnBrushChanged()
- {
- if (BrushInfoChanged != null)
- {
- BrushInfoChanged(this, EventArgs.Empty);
- }
- }
- public BrushInfo BrushInfo
- {
- get
- {
- if (this.brushStyleComboBox.SelectedItem.ToString() == this.solidBrushText)
- {
- return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
- }
- if (this.brushStyleComboBox.SelectedIndex == -1)
- {
- return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
- }
- else
- {
- return new BrushInfo(
- BrushType.Hatch,
- (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(this.brushStyleComboBox.SelectedItem.ToString()));
- }
- }
- set
- {
- if (value.BrushType == BrushType.Solid)
- {
- this.brushStyleComboBox.SelectedItem = this.solidBrushText;
- }
- else
- {
- this.brushStyleComboBox.SelectedItem = this.hatchStyleNames.EnumValueToLocalizedName(value.HatchStyle);
- }
- }
- }
- public event EventHandler GradientInfoChanged;
- protected virtual void OnGradientInfoChanged()
- {
- if (GradientInfoChanged != null)
- {
- GradientInfoChanged(this, EventArgs.Empty);
- }
- }
- public void PerformGradientInfoChanged()
- {
- OnGradientInfoChanged();
- }
- public GradientInfo GradientInfo
- {
- get
- {
- return this.gradientInfo;
- }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException();
- }
- this.gradientInfo = value;
- OnGradientInfoChanged();
- SyncGradientInfo();
- }
- }
- private void SyncGradientInfo()
- {
- this.gradientConicalButton.Checked = false;
- this.gradientRadialButton.Checked = false;
- this.gradientLinearClampedButton.Checked = false;
- this.gradientLinearReflectedButton.Checked = false;
- this.gradientLinearDiamondButton.Checked = false;
- switch (this.gradientInfo.GradientType)
- {
- case GradientType.Conical:
- this.gradientConicalButton.Checked = true;
- break;
- case GradientType.LinearClamped:
- this.gradientLinearClampedButton.Checked = true;
- break;
- case GradientType.LinearReflected:
- this.gradientLinearReflectedButton.Checked = true;
- break;
- case GradientType.LinearDiamond:
- this.gradientLinearDiamondButton.Checked = true;
- break;
- case GradientType.Radial:
- this.gradientRadialButton.Checked = true;
- break;
- default:
- throw new InvalidEnumArgumentException();
- }
- if (this.gradientInfo.AlphaOnly)
- {
- this.gradientChannelsSplitButton.Image = this.gradientAlphaChannelOnlyImage.Reference;
- }
- else
- {
- this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
- }
- }
- private void ShapeButton_DropDownOpening(object sender, EventArgs e)
- {
- ToolStripMenuItem outlineMI = new ToolStripMenuItem();
- outlineMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.OutlineButton.ToolTipText");
- outlineMI.Image = this.shapeOutlineImage.Reference;
- outlineMI.Tag = (object)ShapeDrawType.Outline;
- outlineMI.Click += new EventHandler(ShapeMI_Click);
- ToolStripMenuItem interiorMI = new ToolStripMenuItem();
- interiorMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.InteriorButton.ToolTipText");
- interiorMI.Image = this.shapeInteriorImage.Reference;
- interiorMI.Tag = (object)ShapeDrawType.Interior;
- interiorMI.Click += new EventHandler(ShapeMI_Click);
- ToolStripMenuItem bothMI = new ToolStripMenuItem();
- bothMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.BothButton.ToolTipText");
- bothMI.Image = this.shapeBothImage.Reference;
- bothMI.Tag = (object)ShapeDrawType.Both;
- bothMI.Click += new EventHandler(ShapeMI_Click);
- switch (this.shapeDrawType)
- {
- case ShapeDrawType.Outline:
- outlineMI.Checked = true;
- break;
- case ShapeDrawType.Interior:
- interiorMI.Checked = true;
- break;
- case ShapeDrawType.Both:
- bothMI.Checked = true;
- break;
- default:
- throw new InvalidEnumArgumentException();
- }
- this.shapeButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- outlineMI,
- interiorMI,
- bothMI
- });
- }
- private void ShapeMI_Click(object sender, EventArgs e)
- {
- ShapeDrawType sdt = (ShapeDrawType)((ToolStripMenuItem)sender).Tag;
- Tracing.LogFeature("ToolConfigStrip(" + sdt.ToString() + ")");
- this.ShapeDrawType = sdt;
- }
- public ToolConfigStrip()
- {
- SuspendLayout();
- InitializeComponent();
- this.solidBrushText = PdnResources.GetString("BrushConfigWidget.SolidBrush.Text"); // "Solid Brush"
- this.brushStyleComboBox.Items.Add(this.solidBrushText);
- string[] styleNames = this.hatchStyleNames.GetLocalizedNames();
- Array.Sort(styleNames);
- foreach (string styleName in styleNames)
- {
- brushStyleComboBox.Items.Add(styleName);
- }
- brushStyleComboBox.SelectedIndex = 0;
- this.brushStyleLabel.Text = PdnResources.GetString("BrushConfigWidget.FillStyleLabel.Text");
- this.shapeDrawType = ShapeDrawType.Outline;
- this.shapeButton.Image = this.shapeOutlineImage.Reference;
- this.penSizeLabel.Text = PdnResources.GetString("PenConfigWidget.BrushWidthLabel");
- this.penSizeComboBox.ComboBox.SuspendLayout();
- for (int i = 0; i < this.brushSizes.Length; ++i)
- {
- this.penSizeComboBox.Items.Add(this.brushSizes[i].ToString());
- }
- this.penSizeComboBox.ComboBox.ResumeLayout(false);
- this.penSizeComboBox.SelectedIndex = 1; // default to brush size of 2
- this.penSizeDecButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeDecButton.ToolTipText");
- this.penSizeDecButton.Image = PdnResources.GetImageResource("Icons.MinusButtonIcon.png").Reference;
- this.penSizeIncButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeIncButton.ToolTipText");
- this.penSizeIncButton.Image = PdnResources.GetImageResource("Icons.PlusButtonIcon.png").Reference;
- this.penStyleLabel.Text = PdnResources.GetString("ToolConfigStrip.PenStyleLabel.Text");
- this.penStartCapSplitButton.Tag = PenInfo.DefaultLineCap;
- this.penStartCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, true).Reference;
- this.penStartCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenStartCapSplitButton.ToolTipText");
- this.penDashStyleSplitButton.Tag = PenInfo.DefaultDashStyle;
- this.penDashStyleSplitButton.Image = GetDashStyleImage(PenInfo.DefaultDashStyle);
- this.penDashStyleSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenDashStyleSplitButton.ToolTipText");
- this.penEndCapSplitButton.Tag = PenInfo.DefaultLineCap;
- this.penEndCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, false).Reference;
- this.penEndCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenEndCapSplitButton.ToolTipText");
- this.gradientLinearClampedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearClamped);
- this.gradientLinearClampedButton.Image = PdnResources.GetImageResource("Icons.LinearClampedGradientIcon.png").Reference;
- this.gradientLinearReflectedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearReflected);
- this.gradientLinearReflectedButton.Image = PdnResources.GetImageResource("Icons.LinearReflectedGradientIcon.png").Reference;
- this.gradientLinearDiamondButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearDiamond);
- this.gradientLinearDiamondButton.Image = PdnResources.GetImageResource("Icons.LinearDiamondGradientIcon.png").Reference;
- this.gradientRadialButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Radial);
- this.gradientRadialButton.Image = PdnResources.GetImageResource("Icons.RadialGradientIcon.png").Reference;
- this.gradientConicalButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Conical);
- this.gradientConicalButton.Image = PdnResources.GetImageResource("Icons.ConicalGradientIcon.png").Reference;
- this.gradientAllColorChannelsImage = PdnResources.GetImageResource("Icons.AllColorChannelsIcon.png");
- this.gradientAlphaChannelOnlyImage = PdnResources.GetImageResource("Icons.AlphaChannelOnlyIcon.png");
- this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
- this.antiAliasingEnabledImage = PdnResources.GetImageResource("Icons.AntiAliasingEnabledIcon.png");
- this.antiAliasingDisabledImage = PdnResources.GetImageResource("Icons.AntiAliasingDisabledIcon.png");
- this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
- this.alphaBlendingEnabledImage = PdnResources.GetImageResource("Icons.BlendingEnabledIcon.png");
- this.alphaBlendingOverwriteImage = PdnResources.GetImageResource("Icons.BlendingOverwriteIcon.png");
- this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
- this.penSizeComboBox.Size = new Size(UI.ScaleWidth(this.penSizeComboBox.Width), penSizeComboBox.Height);
- this.brushStyleComboBox.Size = new Size(UI.ScaleWidth(this.brushStyleComboBox.Width), brushStyleComboBox.Height);
- this.brushStyleComboBox.DropDownWidth = UI.ScaleWidth(this.brushStyleComboBox.DropDownWidth);
- this.brushStyleComboBox.DropDownHeight = UI.ScaleHeight(this.brushStyleComboBox.DropDownHeight);
- this.toleranceLabel.Text = PdnResources.GetString("ToleranceConfig.ToleranceLabel.Text");
- this.toleranceSlider.Tolerance = 0.5f;
- this.fontSizeComboBox.ComboBox.SuspendLayout();
- for (int i = 0; i < this.defaultFontSizes.Length; ++i)
- {
- this.fontSizeComboBox.Items.Add(this.defaultFontSizes[i].ToString());
- }
- this.fontSizeComboBox.ComboBox.ResumeLayout(false);
- this.fontSmoothingComboBox.Items.AddRange(
- new object[]
- {
- this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Smooth),
- this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Sharp)
- });
- this.fontSmoothingComboBox.SelectedIndex = 0;
- this.fontLabel.Text = PdnResources.GetString("TextConfigWidget.FontLabel.Text");
- try
- {
- this.arialFontFamily = new FontFamily(arialName);
- }
- catch (Exception)
- {
- this.arialFontFamily = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
- }
- try
- {
- this.arialFontBase = new Font(arialFontFamily, initialFontSize, FontStyle.Regular);
- }
- catch (Exception)
- {
- this.arialFontBase = new Font(FontFamily.GenericSansSerif, initialFontSize, FontStyle.Regular);
- }
- this.fontFamilyComboBox.ComboBox.DropDownHeight = 600;
- this.alignment = TextAlignment.Left;
- this.fontAlignLeftButton.Checked = true;
- this.oldSizeValue = initialFontSize;
- this.highlightBrush = new SolidBrush(SystemColors.Highlight);
- this.highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
- this.windowBrush = new SolidBrush(SystemColors.Window);
- this.windowTextBrush = new SolidBrush(SystemColors.WindowText);
- // These buttons need a color key to maintain consistency with v2.5 language packs
- this.fontBoldButton.ImageTransparentColor = Utility.TransparentKey;
- this.fontItalicsButton.ImageTransparentColor = Utility.TransparentKey;
- this.fontUnderlineButton.ImageTransparentColor = Utility.TransparentKey;
- this.fontBoldButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontBoldIcon");
- this.fontItalicsButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontItalicIcon");
- this.fontUnderlineButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontUnderlineIcon");
- this.fontAlignLeftButton.Image = PdnResources.GetImageResource("Icons.TextAlignLeftIcon.png").Reference;
- this.fontAlignCenterButton.Image = PdnResources.GetImageResource("Icons.TextAlignCenterIcon.png").Reference;
- this.fontAlignRightButton.Image = PdnResources.GetImageResource("Icons.TextAlignRightIcon.png").Reference;
- this.fontBoldButton.ToolTipText = PdnResources.GetString("TextConfigWidget.BoldButton.ToolTipText");
- this.fontItalicsButton.ToolTipText = PdnResources.GetString("TextConfigWidget.ItalicButton.ToolTipText");
- this.fontUnderlineButton.ToolTipText = PdnResources.GetString("TextConfigWidget.UnderlineButton.ToolTipText");
- this.fontAlignLeftButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignLeftButton.ToolTipText");
- this.fontAlignCenterButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignCenterButton.ToolTipText");
- this.fontAlignRightButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignRightButton.ToolTipText");
- this.fontFamilyComboBox.Size = new Size(UI.ScaleWidth(this.fontFamilyComboBox.Width), fontFamilyComboBox.Height);
- this.fontFamilyComboBox.DropDownWidth = UI.ScaleWidth(this.fontFamilyComboBox.DropDownWidth);
- this.fontSizeComboBox.Size = new Size(UI.ScaleWidth(this.fontSizeComboBox.Width), fontSizeComboBox.Height);
- this.fontSmoothingComboBox.Size = new Size(UI.ScaleWidth(this.fontSmoothingComboBox.Width), fontSmoothingComboBox.Height);
- this.fontSmoothingComboBox.DropDownWidth = UI.ScaleWidth(this.fontSmoothingComboBox.DropDownWidth);
- this.resamplingLabel.Text = PdnResources.GetString("ToolConfigStrip.ResamplingLabel.Text");
- this.resamplingComboBox.BeginUpdate();
- this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.Bilinear));
- this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.NearestNeighbor));
- this.resamplingComboBox.EndUpdate();
- this.resamplingComboBox.SelectedIndex = 0; // bilinear
- this.resamplingComboBox.Size = new Size(UI.ScaleWidth(this.resamplingComboBox.Width), resamplingComboBox.Height);
- this.resamplingComboBox.DropDownWidth = UI.ScaleWidth(this.resamplingComboBox.DropDownWidth);
- this.colorPickerLabel.Text = PdnResources.GetString("ToolConfigStrip.ColorPickerLabel.Text");
- string[] colorPickerBehaviorNames = this.colorPickerBehaviorNames.GetLocalizedNames();
- // Make sure these items are sorted to be in the order specified by the enumeration
- Array.Sort<string>(
- colorPickerBehaviorNames,
- delegate (string lhs, string rhs)
- {
- ColorPickerClickBehavior lhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(lhs);
- ColorPickerClickBehavior rhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(rhs);
- if ((int)lhsE < (int)rhsE)
- {
- return -1;
- }
- else if ((int)lhsE > (int)rhsE)
- {
- return +1;
- }
- else
- {
- return 0;
- }
- });
- this.colorPickerComboBox.Items.AddRange(colorPickerBehaviorNames);
- this.colorPickerComboBox.SelectedIndex = 0;
- this.colorPickerComboBox.Size = new Size(UI.ScaleWidth(this.colorPickerComboBox.Width), colorPickerComboBox.Height);
- this.colorPickerComboBox.DropDownWidth = UI.ScaleWidth(this.colorPickerComboBox.DropDownWidth);
- this.toleranceSlider.Size = UI.ScaleSize(this.toleranceSlider.Size);
- this.selectionCombineModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionCombineModeLabel.Text");
- this.floodModeLabel.Text = PdnResources.GetString("ToolConfigStrip.FloodModeLabel.Text");
- this.selectionDrawModeModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeLabel.Text");
- this.selectionDrawModeWidthLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeWidthLabel.Text");
- this.selectionDrawModeHeightLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeHeightLabel.Text");
- this.selectionDrawModeSwapButton.Image = PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSwapButton.png").Reference;
- this.selectionDrawModeWidthTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeWidthTextBox.Width), this.selectionDrawModeWidthTextBox.Height);
- this.selectionDrawModeHeightTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeHeightTextBox.Width), this.selectionDrawModeHeightTextBox.Height);
- this.selectionDrawModeUnits.Size = new Size(UI.ScaleWidth(this.selectionDrawModeUnits.Width), this.selectionDrawModeUnits.Height);
- ToolBarConfigItems = ToolBarConfigItems.None;
- ResumeLayout(false);
- }
- private void AsyncInitFontNames()
- {
- if (!IsHandleCreated)
- {
- CreateControl();
- }
- if (!this.fontFamilyComboBox.ComboBox.IsHandleCreated)
- {
- this.fontFamilyComboBox.ComboBox.CreateControl();
- }
- if (staticFontNames == null)
- {
- ThreadPool.QueueUserWorkItem(new WaitCallback(this.PopulateFontsBackgroundThread), null);
- }
- }
- protected override void OnHandleCreated(EventArgs e)
- {
- if ((this.toolBarConfigItems & ToolBarConfigItems.Text) == ToolBarConfigItems.Text)
- {
- AsyncInitFontNames();
- }
- base.OnHandleCreated(e);
- }
- private void InitializeComponent()
- {
- this.brushSeparator = new ToolStripSeparator();
- this.brushStyleLabel = new ToolStripLabel();
- this.brushStyleComboBox = new ToolStripComboBox();
- this.shapeSeparator = new ToolStripSeparator();
- this.shapeButton = new ToolStripSplitButton();
- this.gradientSeparator1 = new ToolStripSeparator();
- this.gradientLinearClampedButton = new ToolStripButton();
- this.gradientLinearReflectedButton = new ToolStripButton();
- this.gradientLinearDiamondButton = new ToolStripButton();
- this.gradientRadialButton = new ToolStripButton();
- this.gradientConicalButton = new ToolStripButton();
- this.gradientSeparator2 = new ToolStripSeparator();
- this.gradientChannelsSplitButton = new ToolStripSplitButton();
- this.penSeparator = new ToolStripSeparator();
- this.penSizeLabel = new ToolStripLabel();
- this.penSizeDecButton = new ToolStripButton();
- this.penSizeComboBox = new ToolStripComboBox();
- this.penSizeIncButton = new ToolStripButton();
- this.penStyleLabel = new ToolStripLabel();
- this.penStartCapSplitButton = new ToolStripSplitButton();
- this.penDashStyleSplitButton = new ToolStripSplitButton();
- this.penEndCapSplitButton = new ToolStripSplitButton();
- this.blendingSeparator = new ToolStripSeparator();
- this.antiAliasingSplitButton = new ToolStripSplitButton();
- this.alphaBlendingSplitButton = new ToolStripSplitButton();
- this.toleranceSeparator = new ToolStripSeparator();
- this.toleranceLabel = new ToolStripLabel();
- this.toleranceSlider = new ToleranceSliderControl();
- this.toleranceSliderStrip = new ToolStripControlHost(this.toleranceSlider);
- this.fontSeparator = new ToolStripSeparator();
- this.fontLabel = new ToolStripLabel();
- this.fontFamilyComboBox = new ToolStripComboBox();
- this.fontSizeComboBox = new ToolStripComboBox();
- this.fontSmoothingComboBox = new ToolStripComboBox();
- this.fontStyleSeparator = new ToolStripSeparator();
- this.fontBoldButton = new ToolStripButton();
- this.fontItalicsButton = new ToolStripButton();
- this.fontUnderlineButton = new ToolStripButton();
- this.fontAlignSeparator = new ToolStripSeparator();
- this.fontAlignLeftButton = new ToolStripButton();
- this.fontAlignCenterButton = new ToolStripButton();
- this.fontAlignRightButton = new ToolStripButton();
- this.resamplingSeparator = new ToolStripSeparator();
- this.resamplingLabel = new ToolStripLabel();
- this.resamplingComboBox = new ToolStripComboBox();
- this.colorPickerSeparator = new ToolStripSeparator();
- this.colorPickerLabel = new ToolStripLabel();
- this.colorPickerComboBox = new ToolStripComboBox();
- this.selectionCombineModeSeparator = new ToolStripSeparator();
- this.selectionCombineModeLabel = new ToolStripLabel();
- this.selectionCombineModeSplitButton = new ToolStripSplitButton();
- this.floodModeSeparator = new ToolStripSeparator();
- this.floodModeLabel = new ToolStripLabel();
- this.floodModeSplitButton = new ToolStripSplitButton();
- this.selectionDrawModeSeparator = new ToolStripSeparator();
- this.selectionDrawModeModeLabel = new ToolStripLabel();
- this.selectionDrawModeSplitButton = new ToolStripSplitButton();
- this.selectionDrawModeWidthLabel = new ToolStripLabel();
- this.selectionDrawModeWidthTextBox = new ToolStripTextBox();
- this.selectionDrawModeSwapButton = new ToolStripButton();
- this.selectionDrawModeHeightLabel = new ToolStripLabel();
- this.selectionDrawModeHeightTextBox = new ToolStripTextBox();
- this.selectionDrawModeUnits = new UnitsComboBoxStrip();
- this.SuspendLayout();
- //
- // brushStyleLabel
- //
- this.brushStyleLabel.Name = "fillStyleLabel";
- //
- // brushStyleComboBox
- //
- this.brushStyleComboBox.Name = "styleComboBox";
- this.brushStyleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.brushStyleComboBox.DropDownWidth = 234;
- this.brushStyleComboBox.AutoSize = true;
- //
- // brushStyleComboBox.ComboBox
- //
- this.brushStyleComboBox.ComboBox.DrawMode = DrawMode.OwnerDrawVariable;
- this.brushStyleComboBox.ComboBox.MeasureItem += ComboBoxStyle_MeasureItem;
- this.brushStyleComboBox.ComboBox.SelectedValueChanged += ComboBoxStyle_SelectedValueChanged;
- this.brushStyleComboBox.ComboBox.DrawItem += ComboBoxStyle_DrawItem;
- //
- // shapeButton
- //
- this.shapeButton.Name = "shapeButton";
- this.shapeButton.DropDownOpening += new EventHandler(ShapeButton_DropDownOpening);
- this.shapeButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.shapeButton.DropDownItems.Clear();
- };
- this.shapeButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(shapeButton)");
- switch (ShapeDrawType)
- {
- case ShapeDrawType.Outline:
- ShapeDrawType = ShapeDrawType.Interior;
- break;
- case ShapeDrawType.Interior:
- ShapeDrawType = ShapeDrawType.Both;
- break;
- case ShapeDrawType.Both:
- ShapeDrawType = ShapeDrawType.Outline;
- break;
- default:
- throw new InvalidEnumArgumentException();
- }
- };
- //
- // gradientSeparator
- //
- this.gradientSeparator1.Name = "gradientSeparator";
- //
- // gradientLinearClampedButton
- //
- this.gradientLinearClampedButton.Name = "gradientLinearClampedButton";
- this.gradientLinearClampedButton.Click += GradientTypeButtonClicked;
- this.gradientLinearClampedButton.Tag = GradientType.LinearClamped;
- //
- // gradientLinearReflectedButton
- //
- this.gradientLinearReflectedButton.Name = "gradientLinearReflectedButton";
- this.gradientLinearReflectedButton.Click += GradientTypeButtonClicked;
- this.gradientLinearReflectedButton.Tag = GradientType.LinearReflected;
- //
- // gradientLinearDiamondButton
- //
- this.gradientLinearDiamondButton.Name = "gradientLinearDiamondButton";
- this.gradientLinearDiamondButton.Click += GradientTypeButtonClicked;
- this.gradientLinearDiamondButton.Tag = GradientType.LinearDiamond;
- //
- // gradientRadialButton
- //
- this.gradientRadialButton.Name = "gradientRadialButton";
- this.gradientRadialButton.Click += GradientTypeButtonClicked;
- this.gradientRadialButton.Tag = GradientType.Radial;
- //
- // gradientConicalButton
- //
- this.gradientConicalButton.Name = "gradientConicalButton";
- this.gradientConicalButton.Click += GradientTypeButtonClicked;
- this.gradientConicalButton.Tag = GradientType.Conical;
- //
- // gradientSeparator2
- //
- this.gradientSeparator2.Name = "gradientSeparator2";
- //
- // gradientChannelsSplitButton
- //
- this.gradientChannelsSplitButton.Name = "gradientChannelsSplitButton";
- this.gradientChannelsSplitButton.DropDownOpening += new EventHandler(GradientChannelsSplitButton_DropDownOpening);
- this.gradientChannelsSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.gradientChannelsSplitButton.DropDownItems.Clear();
- };
- this.gradientChannelsSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(gradientChannelsSplitButton)");
- GradientInfo = new GradientInfo(GradientInfo.GradientType, !GradientInfo.AlphaOnly);
- };
- //
- // penSeparator
- //
- this.penSeparator.Name = "penSeparator";
- //
- // penSizeLabel
- //
- this.penSizeLabel.Name = "brushSizeLabel";
- //
- // penSizeDecButton
- //
- this.penSizeDecButton.Name = "penSizeDecButton";
- this.penSizeDecButton.Click +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(penSizeDecButton)");
- float amount = -1.0f;
- if ((Control.ModifierKeys & Keys.Control) != 0)
- {
- amount *= 5.0f;
- }
- AddToPenSize(amount);
- };
- //
- // penSizeComboBox
- //
- this.penSizeComboBox.Name = "penSizeComboBox";
- this.penSizeComboBox.Validating += new CancelEventHandler(this.BrushSizeComboBox_Validating);
- this.penSizeComboBox.TextChanged += new EventHandler(this.SizeComboBox_TextChanged);
- this.penSizeComboBox.AutoSize = false;
- this.penSizeComboBox.Width = 44;
- //
- // penSizeIncButton
- //
- this.penSizeIncButton.Name = "penSizeIncButton";
- this.penSizeIncButton.Click +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(penSizeIncButton)");
- float amount = 1.0f;
- if ((Control.ModifierKeys & Keys.Control) != 0)
- {
- amount *= 5.0f;
- }
- AddToPenSize(amount);
- };
- //
- // penStartCapLabel
- //
- this.penStyleLabel.Name = "penStartCapLabel";
- //
- // penStartCapSplitButton
- //
- this.penStartCapSplitButton.Name = "penStartCapSplitButton";
- this.penStartCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
- this.penStartCapSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.penStartCapSplitButton.DropDownItems.Clear();
- };
- this.penStartCapSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(penStartCapSplitButton)");
- CyclePenStartCap();
- };
- //
- // penDashStyleSplitButton
- //
- this.penDashStyleSplitButton.Name = "penDashStyleSplitButton";
- this.penDashStyleSplitButton.ImageScaling = ToolStripItemImageScaling.None;
- this.penDashStyleSplitButton.DropDownOpening += PenDashStyleButton_DropDownOpening;
- this.penDashStyleSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.penDashStyleSplitButton.DropDownItems.Clear();
- };
- this.penDashStyleSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(penDashStyleSplitButton)");
- CyclePenDashStyle();
- };
- //
- // penEndCapSplitButton
- //
- this.penEndCapSplitButton.Name = "penEndCapSplitButton";
- this.penEndCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
- this.penEndCapSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.penEndCapSplitButton.DropDownItems.Clear();
- };
- this.penEndCapSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(penEndCapSplitButton)");
- CyclePenEndCap();
- };
- //
- // antiAliasingSplitButton
- //
- this.antiAliasingSplitButton.Name = "antiAliasingSplitButton";
- this.antiAliasingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- this.antiAliasingSplitButton.DropDownOpening += AntiAliasingSplitButton_DropDownOpening;
- this.antiAliasingSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.antiAliasingSplitButton.DropDownItems.Clear();
- };
- this.antiAliasingSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(antiAliasingSplitButton)");
- AntiAliasing = !AntiAliasing;
- };
- //
- // alphaBlendingSplitButton
- //
- this.alphaBlendingSplitButton.Name = "alphaBlendingSplitButton";
- this.alphaBlendingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- this.alphaBlendingSplitButton.DropDownOpening += new EventHandler(AlphaBlendingSplitButton_DropDownOpening);
- this.alphaBlendingSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.alphaBlendingSplitButton.DropDownItems.Clear();
- };
- this.alphaBlendingSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(alphaBlendingSplitButton)");
- AlphaBlending = !AlphaBlending;
- };
- //
- // toleranceLabel
- //
- this.toleranceLabel.Name = "toleranceLabel";
- //
- // toleranceSlider
- //
- this.toleranceSlider.Name = "toleranceSlider";
- this.toleranceSlider.ToleranceChanged += new EventHandler(ToleranceSlider_ToleranceChanged);
- this.toleranceSlider.Size = new Size(150, 16);
- //
- // toleranceSliderStrip
- //
- this.toleranceSliderStrip.Name = "toleranceSliderStrip";
- this.toleranceSliderStrip.AutoSize = false;
- //
- // fontLabel
- //
- this.fontLabel.Name = "fontLabel";
- //
- // fontFamilyComboBox
- //
- this.fontFamilyComboBox.Name = "fontComboBox";
- this.fontFamilyComboBox.DropDownWidth = 240;
- this.fontFamilyComboBox.MaxDropDownItems = 12;
- this.fontFamilyComboBox.Sorted = true;
- this.fontFamilyComboBox.GotFocus += new EventHandler(FontFamilyComboBox_GotFocus);
- this.fontFamilyComboBox.Items.Add(arialName);
- this.fontFamilyComboBox.SelectedItem = arialName;
- this.fontFamilyComboBox.SelectedIndexChanged += FontFamilyComboBox_SelectedIndexChanged;
- this.fontFamilyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- //
- // fontFamilyComboBox.ComboBox
- //
- this.fontFamilyComboBox.ComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
- this.fontFamilyComboBox.ComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.FontFamilyComboBox_MeasureItem);
- this.fontFamilyComboBox.ComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.FontFamilyComboBox_DrawItem);
- //
- // fontSizeComboBox
- //
- this.fontSizeComboBox.Name = "fontSizeComboBox";
- this.fontSizeComboBox.AutoSize = false;
- this.fontSizeComboBox.TextChanged += new EventHandler(FontSizeComboBox_TextChanged);
- this.fontSizeComboBox.Validating += new CancelEventHandler(FontSizeComboBox_Validating);
- this.fontSizeComboBox.Text = initialFontSize.ToString();
- this.fontSizeComboBox.Width = 44;
- //
- // fontSmoothingComboBox
- //
- this.fontSmoothingComboBox.Name = "smoothingComboBOx";
- this.fontSmoothingComboBox.AutoSize = false;
- this.fontSmoothingComboBox.Sorted = false;
- this.fontSmoothingComboBox.Width = 70;
- this.fontSmoothingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- this.fontSmoothingComboBox.SelectedIndexChanged += new EventHandler(SmoothingComboBox_SelectedIndexChanged);
- //
- // fontBoldButton
- //
- this.fontBoldButton.Name = "boldButton";
- //
- // fontItalicsButton
- //
- this.fontItalicsButton.Name = "italicsButton";
- //
- // fontUnderlineButton
- //
- this.fontUnderlineButton.Name = "underlineButton";
- //
- // fontAlignLeftButton
- //
- this.fontAlignLeftButton.Name = "alignLeftButton";
- //
- // fontAlignCenterButton
- //
- this.fontAlignCenterButton.Name = "alignCenterButton";
- //
- // fontAlignRightButton
- //
- this.fontAlignRightButton.Name = "alignRightButton";
- //
- // resamplingSeparator
- //
- this.resamplingSeparator.Name = "resamplingSeparator";
- //
- // resamplingLabel
- //
- this.resamplingLabel.Name = "resamplingLabel";
- //
- // resamplingComboBox
- //
- this.resamplingComboBox.Name = "resamplingComboBox";
- this.resamplingComboBox.AutoSize = true;
- this.resamplingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- this.resamplingComboBox.Sorted = false;
- this.resamplingComboBox.Width = 100;
- this.resamplingComboBox.DropDownWidth = 100;
- this.resamplingComboBox.SelectedIndexChanged += new EventHandler(ResamplingComboBox_SelectedIndexChanged);
- //
- // colorPickerSeparator
- //
- this.colorPickerSeparator.Name = "colorPickerSeparator";
- //
- // colorPickerLabel
- //
- this.colorPickerLabel.Name = "colorPickerLabel";
- //
- // colorPickerComboBox
- //
- this.colorPickerComboBox.Name = "colorPickerComboBox";
- this.colorPickerComboBox.AutoSize = true;
- this.colorPickerComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- this.colorPickerComboBox.Width = 200;
- this.colorPickerComboBox.DropDownWidth = 200;
- this.colorPickerComboBox.Sorted = false;
- this.colorPickerComboBox.SelectedIndexChanged += new EventHandler(ColorPickerComboBox_SelectedIndexChanged);
- //
- // selectionCombineModeSeparator
- //
- this.selectionCombineModeSeparator.Name = "selectionCombineModeSeparator";
- //
- // selectionCombineModeLabel
- //
- this.selectionCombineModeLabel.Name = "selectionCombineModeLabel";
- //
- // selectionCombineModeSplitButton
- //
- this.selectionCombineModeSplitButton.Name = "selectionCombineModeSplitButton";
- this.selectionCombineModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- this.selectionCombineModeSplitButton.DropDownOpening += new EventHandler(SelectionCombineModeSplitButton_DropDownOpening);
- this.selectionCombineModeSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.selectionCombineModeSplitButton.DropDownItems.Clear();
- };
- this.selectionCombineModeSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(selectionCombineModeSplitButton)");
- this.SelectionCombineMode = CycleSelectionCombineMode(this.SelectionCombineMode);
- };
- //
- // floodModeSeparator
- //
- this.floodModeSeparator.Name = "floodModeSeparator";
- //
- // floodModeLabel
- //
- this.floodModeLabel.Name = "floodModeLabel";
- //
- // floodModeSplitButton
- //
- this.floodModeSplitButton.Name = "floodModeSplitButton";
- this.floodModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- this.floodModeSplitButton.DropDownOpening += new EventHandler(FloodModeSplitButton_DropDownOpening);
- this.floodModeSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.floodModeSplitButton.DropDownItems.Clear();
- };
- this.floodModeSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(floodModeSplitButton)");
- this.FloodMode = CycleFloodMode(this.FloodMode);
- };
- //
- // selectionDrawModeSeparator
- //
- this.selectionDrawModeSeparator.Name = "selectionDrawModeSeparator";
- //
- // selectionDrawModeModeLabel
- //
- this.selectionDrawModeModeLabel.Name = "selectionDrawModeModeLabel";
- //
- // selectionDrawModeSplitButton
- //
- this.selectionDrawModeSplitButton.Name = "selectionDrawModeSplitButton";
- this.selectionDrawModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
- this.selectionDrawModeSplitButton.DropDownOpening += new EventHandler(SelectionDrawModeSplitButton_DropDownOpening);
- this.selectionDrawModeSplitButton.DropDownClosed +=
- delegate (object sender, EventArgs e)
- {
- this.selectionDrawModeSplitButton.DropDownItems.Clear();
- };
- this.selectionDrawModeSplitButton.ButtonClick +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSplitButton)");
- SelectionDrawMode newSDM = CycleSelectionDrawMode(this.SelectionDrawModeInfo.DrawMode);
- this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
- };
- //
- // selectionDrawModeWidthLabel
- //
- this.selectionDrawModeWidthLabel.Name = "selectionDrawModeWidthLabel";
- //
- // selectionDrawModeWidthTextBox
- //
- this.selectionDrawModeWidthTextBox.Name = "selectionDrawModeWidthTextBox";
- this.selectionDrawModeWidthTextBox.TextBox.Width = 50;
- this.selectionDrawModeWidthTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
- this.selectionDrawModeWidthTextBox.Enter +=
- delegate (object sender, EventArgs e)
- {
- this.selectionDrawModeWidthTextBox.TextBox.Select(0, this.selectionDrawModeWidthTextBox.TextBox.Text.Length);
- };
- this.selectionDrawModeWidthTextBox.Leave +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeWidthTextBox.Leave)");
- double newWidth;
- if (double.TryParse(this.selectionDrawModeWidthTextBox.Text, out newWidth))
- {
- this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewWidth(newWidth);
- }
- else
- {
- this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
- }
- };
- //
- // selectionDrawModeSwapButton
- //
- this.selectionDrawModeSwapButton.Name = "selectionDrawModeSwapButton";
- this.selectionDrawModeSwapButton.Click +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSwapButton)");
- SelectionDrawModeInfo oldSDMI = this.SelectionDrawModeInfo;
- SelectionDrawModeInfo newSDMI = new SelectionDrawModeInfo(oldSDMI.DrawMode, oldSDMI.Height, oldSDMI.Width, oldSDMI.Units);
- this.SelectionDrawModeInfo = newSDMI;
- };
- //
- // selectionDrawModeHeightLabel
- //
- this.selectionDrawModeHeightLabel.Name = "selectionDrawModeHeightLabel";
- //
- // selectionDrawModeHeightTextBox
- //
- this.selectionDrawModeHeightTextBox.Name = "selectionDrawModeHeightTextBox";
- this.selectionDrawModeHeightTextBox.TextBox.Width = 50;
- this.selectionDrawModeHeightTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
- this.selectionDrawModeHeightTextBox.Enter +=
- delegate (object sender, EventArgs e)
- {
- this.selectionDrawModeHeightTextBox.TextBox.Select(0, this.selectionDrawModeHeightTextBox.TextBox.Text.Length);
- };
- this.selectionDrawModeHeightTextBox.Leave +=
- delegate (object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeHeightTextBox.Leave)");
- double newHeight;
- if (double.TryParse(this.selectionDrawModeHeightTextBox.Text, out newHeight))
- {
- this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewHeight(newHeight);
- }
- else
- {
- this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
- }
- };
- //
- // selectionDrawModeUnits
- //
- this.selectionDrawModeUnits.Name = "selectionDrawModeUnits";
- this.selectionDrawModeUnits.UnitsDisplayType = UnitsDisplayType.Plural;
- this.selectionDrawModeUnits.LowercaseStrings = true;
- this.selectionDrawModeUnits.Size = new Size(90, this.selectionDrawModeUnits.Height);
- //
- // DrawConfigStrip
- //
- this.AutoSize = true;
- this.Items.AddRange(
- new ToolStripItem[]
- {
- this.selectionCombineModeSeparator,
- this.selectionCombineModeLabel,
- this.selectionCombineModeSplitButton,
- this.selectionDrawModeSeparator,
- this.selectionDrawModeModeLabel,
- this.selectionDrawModeSplitButton,
- this.selectionDrawModeWidthLabel,
- this.selectionDrawModeWidthTextBox,
- this.selectionDrawModeSwapButton,
- this.selectionDrawModeHeightLabel,
- this.selectionDrawModeHeightTextBox,
- this.selectionDrawModeUnits,
- this.floodModeSeparator,
- this.floodModeLabel,
- this.floodModeSplitButton,
- this.resamplingSeparator,
- this.resamplingLabel,
- this.resamplingComboBox,
- this.colorPickerSeparator,
- this.colorPickerLabel,
- this.colorPickerComboBox,
- this.fontSeparator,
- this.fontLabel,
- this.fontFamilyComboBox,
- this.fontSizeComboBox,
- this.fontSmoothingComboBox,
- this.fontStyleSeparator,
- this.fontBoldButton,
- this.fontItalicsButton,
- this.fontUnderlineButton,
- this.fontAlignSeparator,
- this.fontAlignLeftButton,
- this.fontAlignCenterButton,
- this.fontAlignRightButton,
- this.shapeSeparator,
- this.shapeButton,
- this.gradientSeparator1,
- this.gradientLinearClampedButton,
- this.gradientLinearReflectedButton,
- this.gradientLinearDiamondButton,
- this.gradientRadialButton,
- this.gradientConicalButton,
- this.gradientSeparator2,
- this.gradientChannelsSplitButton,
- this.penSeparator,
- this.penSizeLabel,
- this.penSizeDecButton,
- this.penSizeComboBox,
- this.penSizeIncButton,
- this.penStyleLabel,
- this.penStartCapSplitButton,
- this.penDashStyleSplitButton,
- this.penEndCapSplitButton,
- this.brushSeparator,
- this.brushStyleLabel,
- this.brushStyleComboBox,
- this.toleranceSeparator,
- this.toleranceLabel,
- this.toleranceSliderStrip,
- this.blendingSeparator,
- this.antiAliasingSplitButton,
- this.alphaBlendingSplitButton
- });
- this.ResumeLayout(false);
- }
- public void CyclePenEndCap()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.EndCap = NextLineCap(newPenInfo.EndCap);
- PenInfo = newPenInfo;
- }
- public void CyclePenStartCap()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.StartCap = NextLineCap(newPenInfo.StartCap);
- PenInfo = newPenInfo;
- }
- public void CyclePenDashStyle()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.DashStyle = NextDashStyle(newPenInfo.DashStyle);
- PenInfo = newPenInfo;
- }
- private DashStyle NextDashStyle(DashStyle oldDash)
- {
- int dashIndex = Array.IndexOf<DashStyle>(this.dashStyles, oldDash);
- int newDashIndex = (dashIndex + 1) % this.dashStyles.Length;
- return this.dashStyles[newDashIndex];
- }
- private LineCap2 NextLineCap(LineCap2 oldCap)
- {
- int capIndex = Array.IndexOf<LineCap2>(this.lineCaps, oldCap);
- int newCapIndex = (capIndex + 1) % this.lineCaps.Length;
- return this.lineCaps[newCapIndex];
- }
- private void GradientTypeButtonClicked(object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(GradientTypeButtonClicked)");
- GradientType newType = (GradientType)((ToolStripButton)sender).Tag;
- GradientInfo = new GradientInfo(newType, GradientInfo.AlphaOnly);
- }
- private void ComboBoxStyle_SelectedValueChanged(object sender, EventArgs e)
- {
- OnBrushChanged();
- }
- public void PerformBrushChanged()
- {
- OnBrushChanged();
- }
- private void ComboBoxStyle_DrawItem(object sender, DrawItemEventArgs e)
- {
- e.DrawBackground();
- Rectangle r = e.Bounds;
- if (e.Index != -1)
- {
- string itemName = (string)this.brushStyleComboBox.Items[e.Index];
- if (itemName != this.solidBrushText)
- {
- Rectangle rd = r;
- rd.Width = rd.Left + 25;
- Rectangle rt = r;
- r.X = rd.Right;
- string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
- HatchStyle hs = (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(displayText);
- using (HatchBrush b = new HatchBrush(hs, e.ForeColor, e.BackColor))
- {
- e.Graphics.FillRectangle(b, rd);
- }
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Near;
- using (SolidBrush sb = new SolidBrush(Color.White))
- {
- if ((e.State & DrawItemState.Focus) == 0)
- {
- sb.Color = SystemColors.Window;
- e.Graphics.FillRectangle(sb, r);
- sb.Color = SystemColors.WindowText;
- e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
- }
- else
- {
- sb.Color = SystemColors.Highlight;
- e.Graphics.FillRectangle(sb, r);
- sb.Color = SystemColors.HighlightText;
- e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
- }
- }
- sf.Dispose();
- sf = null;
- }
- else
- {
- // Solid Brush
- using (SolidBrush sb = new SolidBrush(Color.White))
- {
- if ((e.State & DrawItemState.Focus) == 0)
- {
- sb.Color = SystemColors.Window;
- e.Graphics.FillRectangle(sb, e.Bounds);
- string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
- sb.Color = SystemColors.WindowText;
- e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
- }
- else
- {
- sb.Color = SystemColors.Highlight;
- e.Graphics.FillRectangle(sb, e.Bounds);
- string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
- sb.Color = SystemColors.HighlightText;
- e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
- }
- }
- }
- e.DrawFocusRectangle();
- }
- }
- private void ComboBoxStyle_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
- {
- // Work out what the text will be
- string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
- // Get width & height of string
- SizeF stringSize = e.Graphics.MeasureString(displayText, this.Font);
- // set height to text height
- e.ItemHeight = (int)stringSize.Height;
- // set width to text width
- e.ItemWidth = (int)stringSize.Width;
- }
- public event EventHandler ShapeDrawTypeChanged;
- protected virtual void OnShapeDrawTypeChanged()
- {
- if (ShapeDrawTypeChanged != null)
- {
- ShapeDrawTypeChanged(this, EventArgs.Empty);
- }
- }
- public void PerformShapeDrawTypeChanged()
- {
- OnShapeDrawTypeChanged();
- }
- public ShapeDrawType ShapeDrawType
- {
- get
- {
- return shapeDrawType;
- }
- set
- {
- if (shapeDrawType != value)
- {
- shapeDrawType = value;
- // if the user sets the shape the buttons must be updated
- if (shapeDrawType == ShapeDrawType.Outline)
- {
- this.shapeButton.Image = shapeOutlineImage.Reference;
- }
- else if (shapeDrawType == ShapeDrawType.Both)
- {
- this.shapeButton.Image = shapeBothImage.Reference;
- }
- else if (shapeDrawType == ShapeDrawType.Interior)
- {
- this.shapeButton.Image = shapeInteriorImage.Reference;
- }
- else
- {
- // invalid shape
- throw new InvalidOperationException("Shape draw type is invalid");
- }
- this.OnShapeDrawTypeChanged();
- }
- }
- }
- private void SetFontStyleButtons(FontStyle style)
- {
- bool bold = ((style & FontStyle.Bold) != 0);
- bool italic = ((style & FontStyle.Italic) != 0);
- bool underline = ((style & FontStyle.Underline) != 0);
- this.fontBoldButton.Checked = bold;
- this.fontItalicsButton.Checked = italic;
- this.fontUnderlineButton.Checked = underline;
- }
- protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
- {
- if (e.ClickedItem == fontBoldButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontBoldButton)");
- this.fontStyle ^= FontStyle.Bold;
- SetFontStyleButtons(this.fontStyle);
- this.OnFontInfoChanged();
- }
- else if (e.ClickedItem == fontItalicsButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontItalicsButton)");
- this.fontStyle ^= FontStyle.Italic;
- SetFontStyleButtons(this.fontStyle);
- this.OnFontInfoChanged();
- }
- else if (e.ClickedItem == fontUnderlineButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontUnderlineButton)");
- this.fontStyle ^= FontStyle.Underline;
- SetFontStyleButtons(this.fontStyle);
- this.OnFontInfoChanged();
- }
- else if (e.ClickedItem == fontAlignLeftButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignLeftButton)");
- this.FontAlignment = TextAlignment.Left;
- }
- else if (e.ClickedItem == fontAlignCenterButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignCenterButton)");
- this.FontAlignment = TextAlignment.Center;
- }
- else if (e.ClickedItem == fontAlignRightButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignRightButton)");
- this.FontAlignment = TextAlignment.Right;
- }
- base.OnItemClicked(e);
- }
- public event EventHandler PenInfoChanged;
- protected virtual void OnPenChanged()
- {
- if (PenInfoChanged != null)
- {
- PenInfoChanged(this, EventArgs.Empty);
- }
- }
- public void PerformPenChanged()
- {
- OnPenChanged();
- }
- public void AddToPenSize(float delta)
- {
- if ((this.toolBarConfigItems & ToolBarConfigItems.Pen) == ToolBarConfigItems.Pen)
- {
- float newWidth = Utility.Clamp(PenInfo.Width + delta, minPenSize, maxPenSize);
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.Width += delta;
- newPenInfo.Width = (float)Utility.Clamp(newPenInfo.Width, minPenSize, maxPenSize);
- PenInfo = newPenInfo;
- }
- }
- public PenInfo PenInfo
- {
- get
- {
- float width;
- try
- {
- width = float.Parse(this.penSizeComboBox.Text);
- }
- catch (FormatException)
- {
- // TODO: would much rather grab the value from AppEnvironment
- // or in some way that we keep track of the "last good value"
- width = 2;
- }
- LineCap2 startCap;
- try
- {
- startCap = (LineCap2)this.penStartCapSplitButton.Tag;
- }
- catch (Exception)
- {
- startCap = PenInfo.DefaultLineCap;
- }
- LineCap2 endCap;
- try
- {
- endCap = (LineCap2)this.penEndCapSplitButton.Tag;
- }
- catch (Exception)
- {
- endCap = PenInfo.DefaultLineCap;
- }
- DashStyle dashStyle = (DashStyle)this.penDashStyleSplitButton.Tag;
- return new PenInfo(dashStyle, width, startCap, endCap, PenInfo.DefaultCapScale);
- }
- set
- {
- if (this.PenInfo != value)
- {
- this.penSizeComboBox.Text = value.Width.ToString();
- this.penStartCapSplitButton.Tag = value.StartCap;
- this.penStartCapSplitButton.Image = GetLineCapImage(value.StartCap, true).Reference;
- this.penDashStyleSplitButton.Tag = value.DashStyle;
- this.penDashStyleSplitButton.Image = GetDashStyleImage(value.DashStyle);
- this.penEndCapSplitButton.Tag = value.EndCap;
- this.penEndCapSplitButton.Image = GetLineCapImage(value.EndCap, false).Reference;
- OnPenChanged();
- }
- }
- }
- private void SizeComboBox_TextChanged(object sender, System.EventArgs e)
- {
- BrushSizeComboBox_Validating(this, new CancelEventArgs());
- }
- private void BrushSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- float penSize;
- bool valid = float.TryParse(this.penSizeComboBox.Text, out penSize);
- if (!valid)
- {
- this.penSizeComboBox.BackColor = Color.Red;
- this.penSizeComboBox.ToolTipText = PdnResources.GetString("PenConfigWidget.Error.InvalidNumber");
- }
- else
- {
- if (penSize < minPenSize)
- {
- // Set the error if the size is too small.
- this.penSizeComboBox.BackColor = Color.Red;
- string tooSmallFormat = PdnResources.GetString("PenConfigWidget.Error.TooSmall.Format");
- string tooSmall = string.Format(tooSmallFormat, minPenSize);
- this.penSizeComboBox.ToolTipText = tooSmall;
- }
- else if (penSize > maxPenSize)
- {
- // Set the error if the size is too large.
- this.penSizeComboBox.BackColor = Color.Red;
- string tooLargeFormat = PdnResources.GetString("PenConfigWidget.Error.TooLarge.Format");
- string tooLarge = string.Format(tooLargeFormat, maxPenSize);
- this.penSizeComboBox.ToolTipText = tooLarge;
- }
- else
- {
- // Clear the error, if any
- this.penSizeComboBox.BackColor = SystemColors.Window;
- this.penSizeComboBox.ToolTipText = string.Empty;
- OnPenChanged();
- }
- }
- }
- public event EventHandler AlphaBlendingChanged;
- protected virtual void OnAlphaBlendingChanged()
- {
- if (AlphaBlendingChanged != null)
- {
- AlphaBlendingChanged(this, EventArgs.Empty);
- }
- }
- public void PerformAlphaBlendingChanged()
- {
- OnAlphaBlendingChanged();
- }
- private void GradientChannelsSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- ToolStripMenuItem allChannels = new ToolStripMenuItem(
- PdnResources.GetString("GradientChannels.AllColorChannels.Text"),
- this.gradientAllColorChannelsImage.Reference,
- delegate (object sender2, EventArgs e2)
- {
- GradientInfo = new GradientInfo(GradientInfo.GradientType, false);
- });
- ToolStripMenuItem alphaOnly = new ToolStripMenuItem(
- PdnResources.GetString("GradientChannels.AlphaChannelOnly.Text"),
- this.gradientAlphaChannelOnlyImage.Reference,
- delegate (object sender3, EventArgs e3)
- {
- GradientInfo = new GradientInfo(GradientInfo.GradientType, true);
- });
- allChannels.Checked = !GradientInfo.AlphaOnly;
- alphaOnly.Checked = GradientInfo.AlphaOnly;
- this.gradientChannelsSplitButton.DropDownItems.Clear();
- this.gradientChannelsSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- allChannels,
- alphaOnly
- });
- }
- private void AlphaBlendingSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- ToolStripMenuItem abEnabled = new ToolStripMenuItem(
- PdnResources.GetString("AlphaBlendingSplitButton.BlendingEnabled.Text"),
- this.alphaBlendingEnabledImage.Reference,
- delegate (object sender2, EventArgs e2)
- {
- AlphaBlending = true;
- });
- ToolStripMenuItem abOverwrite = new ToolStripMenuItem(
- PdnResources.GetString("AlphaBlendingSplitButton.BlendingOverwrite.Text"),
- this.alphaBlendingOverwriteImage.Reference,
- delegate (object sender3, EventArgs e3)
- {
- AlphaBlending = false;
- });
- abEnabled.Checked = AlphaBlending;
- abOverwrite.Checked = !AlphaBlending;
- this.alphaBlendingSplitButton.DropDownItems.Clear();
- this.alphaBlendingSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- abEnabled,
- abOverwrite
- });
- }
- public bool AlphaBlending
- {
- get
- {
- return this.alphaBlendingEnabled;
- }
- set
- {
- if (value != this.alphaBlendingEnabled)
- {
- this.alphaBlendingEnabled = value;
- if (value)
- {
- this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
- }
- else
- {
- this.alphaBlendingSplitButton.Image = this.alphaBlendingOverwriteImage.Reference;
- }
- OnAlphaBlendingChanged();
- }
- }
- }
- private void AlphaBlendingComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- OnAlphaBlendingChanged();
- }
- public event EventHandler AntiAliasingChanged;
- protected virtual void OnAntiAliasingChanged()
- {
- if (AntiAliasingChanged != null)
- {
- AntiAliasingChanged(this, EventArgs.Empty);
- }
- }
- public void PerformAntiAliasingChanged()
- {
- OnAntiAliasingChanged();
- }
- public bool AntiAliasing
- {
- get
- {
- return this.antiAliasingEnabled;
- }
- set
- {
- if (this.antiAliasingEnabled != value)
- {
- if (value)
- {
- this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
- }
- else
- {
- this.antiAliasingSplitButton.Image = this.antiAliasingDisabledImage.Reference;
- }
- this.antiAliasingEnabled = value;
- OnAntiAliasingChanged();
- }
- }
- }
- private Image GetDashStyleImage(DashStyle dashStyle)
- {
- string nameFormat = "Images.DashStyleButton.{0}.png";
- string name = string.Format(nameFormat, dashStyle.ToString());
- ImageResource imageResource = PdnResources.GetImageResource(name);
- Image returnImage;
- if (UI.GetXScaleFactor() == 1.0f && UI.GetYScaleFactor() == 1.0f)
- {
- returnImage = imageResource.Reference;
- }
- else
- {
- returnImage = new Bitmap(imageResource.Reference, UI.ScaleSize(imageResource.Reference.Size));
- }
- return returnImage;
- }
- private ImageResource GetLineCapImage(LineCap2 lineCap, bool isStartCap)
- {
- string nameFormat = "Images.LineCapButton.{0}.{1}.png";
- string name = string.Format(nameFormat, lineCap.ToString(), isStartCap ? "Start" : "End");
- ImageResource imageResource = PdnResources.GetImageResource(name);
- return imageResource;
- }
- private void PenDashStyleButton_DropDownOpening(object sender, EventArgs e)
- {
- List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
- foreach (DashStyle dashStyle in this.dashStyles)
- {
- ToolStripMenuItem mi = new ToolStripMenuItem(
- this.dashStyleLocalizer.EnumValueToLocalizedName(dashStyle),
- GetDashStyleImage(dashStyle),
- delegate (object sender2, EventArgs e2)
- {
- ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
- DashStyle newDashStyle = (DashStyle)tsmi.Tag;
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.DashStyle = newDashStyle;
- PenInfo = newPenInfo;
- });
- mi.ImageScaling = ToolStripItemImageScaling.None;
- if (dashStyle == PenInfo.DashStyle)
- {
- mi.Checked = true;
- }
- mi.Tag = dashStyle;
- menuItems.Add(mi);
- }
- this.penDashStyleSplitButton.DropDownItems.Clear();
- this.penDashStyleSplitButton.DropDownItems.AddRange(menuItems.ToArray());
- }
- private void PenCapSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- ToolStripSplitButton splitButton = (ToolStripSplitButton)sender;
- List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
- LineCap2 currentLineCap = PenInfo.DefaultLineCap;
- bool isStartCap;
- if (object.ReferenceEquals(splitButton, this.penStartCapSplitButton))
- {
- isStartCap = true;
- currentLineCap = PenInfo.StartCap;
- }
- else if (object.ReferenceEquals(splitButton, this.penEndCapSplitButton))
- {
- isStartCap = false;
- currentLineCap = PenInfo.EndCap;
- }
- else
- {
- throw new InvalidOperationException();
- }
- foreach (LineCap2 lineCap in this.lineCaps)
- {
- ToolStripMenuItem mi = new ToolStripMenuItem(
- this.lineCapLocalizer.EnumValueToLocalizedName(lineCap),
- GetLineCapImage(lineCap, isStartCap).Reference,
- delegate (object sender2, EventArgs e2)
- {
- ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
- Pair<ToolStripSplitButton, LineCap2> data = (Pair<ToolStripSplitButton, LineCap2>)tsmi.Tag;
- PenInfo newPenInfo = PenInfo.Clone();
- if (object.ReferenceEquals(data.First, this.penStartCapSplitButton))
- {
- newPenInfo.StartCap = data.Second;
- }
- else if (object.ReferenceEquals(data.First, this.penEndCapSplitButton))
- {
- newPenInfo.EndCap = data.Second;
- }
- PenInfo = newPenInfo;
- });
- mi.Tag = Pair.Create(splitButton, lineCap);
- if (lineCap == currentLineCap)
- {
- mi.Checked = true;
- }
- menuItems.Add(mi);
- }
- splitButton.DropDownItems.Clear();
- splitButton.DropDownItems.AddRange(menuItems.ToArray());
- }
- private void AntiAliasingSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- ToolStripMenuItem aaEnabled = new ToolStripMenuItem(
- PdnResources.GetString("AntiAliasingSplitButton.Enabled.Text"),
- this.antiAliasingEnabledImage.Reference,
- delegate (object sender2, EventArgs e2)
- {
- AntiAliasing = true;
- });
- ToolStripMenuItem aaDisabled = new ToolStripMenuItem(
- PdnResources.GetString("AntiAliasingSplitButton.Disabled.Text"),
- this.antiAliasingDisabledImage.Reference,
- delegate (object sender3, EventArgs e3)
- {
- AntiAliasing = false;
- });
- aaEnabled.Checked = AntiAliasing;
- aaDisabled.Checked = !AntiAliasing;
- this.antiAliasingSplitButton.DropDownItems.Clear();
- this.antiAliasingSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- aaEnabled,
- aaDisabled
- });
- }
- private void SmoothingComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- OnFontSmoothingChanged();
- }
- private void PopulateFontsBackgroundThread(object ignored)
- {
- PopulateFontsBackgroundThread();
- }
- private void PopulateFontsBackgroundThread()
- {
- try
- {
- using (new ThreadBackground(ThreadBackgroundFlags.Cpu))
- {
- PopulateFonts();
- }
- }
- finally
- {
- staticFontNamesPopulatedEvent.Set();
- }
- }
- private void PopulateFonts()
- {
- List<string> fontNames = new List<string>();
- using (Graphics g = this.CreateGraphics())
- {
- FontFamily[] families = FontFamily.Families;
- foreach (FontFamily family in families)
- {
- using (FontInfo fi = new FontInfo(family, 10, FontStyle.Regular))
- {
- if (!fontNames.Contains(family.Name) && fi.CanCreateFont())
- {
- fontNames.Add(family.Name);
- }
- }
- }
- }
- staticFontNames = fontNames;
- Tracing.LogFeature("PopulateFonts()");
- }
- public event EventHandler FontInfoChanged;
- protected virtual void OnFontInfoChanged()
- {
- if (FontInfoChanged != null)
- {
- FontInfoChanged(this, EventArgs.Empty);
- }
- }
- public event EventHandler FontAlignmentChanged;
- protected virtual void OnTextAlignmentChanged()
- {
- if (FontAlignmentChanged != null)
- {
- FontAlignmentChanged(this, EventArgs.Empty);
- }
- }
- public event EventHandler FontSmoothingChanged;
- protected virtual void OnFontSmoothingChanged()
- {
- if (FontSmoothingChanged != null)
- {
- FontSmoothingChanged(this, EventArgs.Empty);
- }
- }
- public FontSmoothing FontSmoothing
- {
- get
- {
- return (FontSmoothing)this.fontSmoothingLocalizer.LocalizedNameToEnumValue((string)this.fontSmoothingComboBox.SelectedItem);
- }
- set
- {
- if (value != this.FontSmoothing)
- {
- this.fontSmoothingComboBox.SelectedItem = this.fontSmoothingLocalizer.EnumValueToLocalizedName(value);
- }
- }
- }
- public FontInfo FontInfo
- {
- get
- {
- return new FontInfo(this.FontFamily, this.FontSize, this.FontStyle);
- }
- set
- {
- this.FontFamily = value.FontFamily;
- this.FontSize = value.Size;
- this.FontStyle = value.FontStyle;
- }
- }
- /// <summary>
- /// Gets or sets the font style i.e. bold, italic, and underline
- /// </summary>
- public FontStyle FontStyle
- {
- get
- {
- return this.fontStyle;
- }
- set
- {
- if (this.fontStyle != value)
- {
- this.fontStyle = value;
- SetFontStyleButtons(FontStyle);
- this.OnFontInfoChanged();
- }
- }
- }
- /// <summary>
- /// Gets or sets the size of the font.
- /// </summary>
- public float FontSize
- {
- get
- {
- bool invalid = false;
- float number = oldSizeValue;
- try
- {
- number = float.Parse(fontSizeComboBox.Text);
- }
- catch (FormatException)
- {
- invalid = true;
- }
- catch (OverflowException)
- {
- invalid = true;
- }
- // if the size is valid update the new size else return the last known good size.
- if (!invalid)
- {
- oldSizeValue = number;
- }
- return oldSizeValue;
- }
- set
- {
- bool invalid = false;
- float number = oldSizeValue;
- try
- {
- number = float.Parse(fontSizeComboBox.Text);
- }
- catch (FormatException)
- {
- invalid = true;
- }
- catch (OverflowException)
- {
- invalid = true;
- }
- // if the size is valid update the new size else return the last known good size.
- if (!invalid)
- {
- if (float.Parse(fontSizeComboBox.Text) != value)
- {
- fontSizeComboBox.Text = value.ToString();
- this.OnFontInfoChanged();
- }
- }
- }
- }
- private FontFamily IndexToFontFamily(int i)
- {
- try
- {
- return new FontFamily((string)this.fontFamilyComboBox.Items[i]);
- }
- catch (Exception)
- {
- return FontFamily.GenericSansSerif;
- }
- }
- private Font IndexToFont(int i, float size, FontStyle style)
- {
- using (FontFamily ff = IndexToFontFamily(i))
- {
- return new FontInfo(ff, size, style).CreateFont();
- }
- }
- /// <summary>
- /// Gets or sets the font family.
- /// </summary>
- public FontFamily FontFamily
- {
- get
- {
- try
- {
- return new FontFamily((string)this.fontFamilyComboBox.SelectedItem);
- }
- catch (ArgumentException)
- {
- return FontFamily.GenericSansSerif;
- }
- }
- set
- {
- string current = (string)this.fontFamilyComboBox.SelectedItem;
- if (current != value.Name)
- {
- int index = fontFamilyComboBox.Items.IndexOf(value.Name);
- if (index != -1)
- {
- fontFamilyComboBox.SelectedIndex = index;
- this.OnFontInfoChanged();
- }
- else
- {
- // Maybe they're just specifying a font we didn't add to the list yet? aka pre-list initialization
- FontInfo oldFI = this.FontInfo;
- FontFamily newFF;
- try
- {
- newFF = new FontFamily(value.Name);
- }
- catch (Exception)
- {
- newFF = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
- }
- FontInfo newFI = new FontInfo(newFF, oldFI.Size, oldFI.FontStyle);
- if (newFI.CanCreateFont())
- {
- this.fontFamilyComboBox.Items.Add(value.Name);
- this.fontFamilyComboBox.SelectedItem = value.Name;
- }
- else
- {
- throw new InvalidOperationException("FontFamily is not valid");
- }
- }
- }
- }
- }
- public TextAlignment FontAlignment
- {
- get
- {
- return this.alignment;
- }
- set
- {
- if (this.alignment != value)
- {
- this.alignment = value;
- // if the user sets the text alignment the buttons must be updated
- if (this.alignment == TextAlignment.Left)
- {
- this.fontAlignLeftButton.Checked = true;
- this.fontAlignCenterButton.Checked = false;
- this.fontAlignRightButton.Checked = false;
- }
- else if (this.alignment == TextAlignment.Center)
- {
- this.fontAlignLeftButton.Checked = false;
- this.fontAlignCenterButton.Checked = true;
- this.fontAlignRightButton.Checked = false;
- }
- else if (this.alignment == TextAlignment.Right)
- {
- this.fontAlignLeftButton.Checked = false;
- this.fontAlignCenterButton.Checked = false;
- this.fontAlignRightButton.Checked = true;
- }
- else
- {
- throw new InvalidOperationException("Text alignment type is invalid");
- }
- this.OnTextAlignmentChanged();
- }
- }
- }
- private void FontFamilyComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
- {
- if (e.Index != -1)
- {
- string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
- SizeF stringSize = e.Graphics.MeasureString(displayText, arialFontBase);
- int size = (int)stringSize.Width;
- // set up two areas to draw
- const int leftMargin = 3;
- Rectangle bounds = e.Bounds;
- bounds.X += leftMargin;
- bounds.Width -= leftMargin;
- Rectangle r = bounds;
- Rectangle rd = r;
- rd.Width = rd.Left + size;
- Rectangle rt = r;
- r.X = rd.Right;
- using (Font myFont = IndexToFont(e.Index, 10, FontStyle.Regular))
- {
- StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone();
- sf.LineAlignment = StringAlignment.Center;
- sf.FormatFlags &= ~StringFormatFlags.LineLimit;
- sf.FormatFlags |= StringFormatFlags.NoWrap;
- bool isSymbol = PaintDotNet.SystemLayer.Fonts.IsSymbolFont(myFont);
- bool isSelected = ((e.State & DrawItemState.Selected) != 0);
- Brush fillBrush;
- Brush textBrush;
- if (isSelected)
- {
- fillBrush = highlightBrush;
- textBrush = highlightTextBrush;
- }
- else
- {
- fillBrush = windowBrush;
- textBrush = windowTextBrush;
- }
- e.Graphics.FillRectangle(fillBrush, e.Bounds);
- if (isSymbol)
- {
- e.Graphics.DrawString(displayText, arialFontBase, textBrush, bounds, sf);
- e.Graphics.DrawString(displayText, myFont, textBrush, r, sf);
- }
- else
- {
- e.Graphics.DrawString(displayText, myFont, textBrush, bounds, sf);
- }
- sf.Dispose();
- sf = null;
- }
- }
- e.DrawFocusRectangle();
- }
- private void FontFamilyComboBox_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
- {
- // Work out what the text will be
- string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
- // Get width & height of string
- SizeF stringSize;
- using (Font font = IndexToFont(e.Index, 10, FontStyle.Regular))
- {
- stringSize = e.Graphics.MeasureString(displayText, font);
- }
- // Account for top margin
- stringSize.Height += UI.ScaleHeight(6);
- // set hight to text height
- e.ItemHeight = (int)stringSize.Height;
- int maxHeight = UI.ScaleHeight(20);
- if (e.ItemHeight > maxHeight)
- {
- e.ItemHeight = maxHeight;
- }
- // set width to text width
- e.ItemWidth = (int)stringSize.Width;
- }
- private void FontSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- {
- bool invalid = false;
- try
- {
- float number = float.Parse(fontSizeComboBox.Text);
- }
- catch (FormatException)
- {
- invalid = true;
- }
- catch (OverflowException)
- {
- invalid = true;
- }
- if (invalid)
- {
- this.fontSizeComboBox.BackColor = Color.Red;
- this.fontSizeComboBox.ToolTipText = PdnResources.GetString("TextConfigWidget.Error.InvalidNumber");
- }
- else
- {
- if ((float.Parse(fontSizeComboBox.Text) < minFontSize))
- {
- // Set the error if the size is too small.
- this.fontSizeComboBox.BackColor = Color.Red;
- string format = PdnResources.GetString("TextConfigWidget.Error.TooSmall.Format");
- string text = string.Format(format, minFontSize);
- this.fontSizeComboBox.ToolTipText = text;
- }
- else if ((float.Parse(fontSizeComboBox.Text) > maxFontSize))
- {
- // Set the error if the size is too large.
- this.fontSizeComboBox.BackColor = Color.Red;
- string format = PdnResources.GetString("TextConfigWidget.Error.TooLarge.Format");
- string text = string.Format(format, maxFontSize);
- this.fontSizeComboBox.ToolTipText = text;
- }
- else
- {
- // Clear the error, if any
- this.fontSizeComboBox.ToolTipText = string.Empty;
- this.fontSizeComboBox.BackColor = SystemColors.Window;
- OnFontInfoChanged();
- }
- }
- }
- catch (FormatException)
- {
- e.Cancel = true;
- }
- }
- private void FontSizeComboBox_TextChanged(object sender, System.EventArgs e)
- {
- FontSizeComboBox_Validating(sender, new CancelEventArgs());
- }
- private void FontFamilyComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- OnFontInfoChanged();
- }
- private void FontFamilyComboBox_GotFocus(object sender, EventArgs e)
- {
- if (!fontsComboBoxPopulated)
- {
- AsyncInitFontNames();
- using (new WaitCursorChanger(this))
- {
- staticFontNamesPopulatedEvent.WaitOne();
- this.fontFamilyComboBox.ComboBox.BeginUpdate();
- List<string> fontNames = staticFontNames;
- foreach (string name in fontNames)
- {
- if (!this.fontFamilyComboBox.Items.Contains(name))
- {
- this.fontFamilyComboBox.Items.Add(name);
- }
- }
- this.fontFamilyComboBox.ComboBox.EndUpdate();
- }
- fontsComboBoxPopulated = true;
- }
- }
- public ToolBarConfigItems ToolBarConfigItems
- {
- get
- {
- return this.toolBarConfigItems;
- }
- set
- {
- this.toolBarConfigItems = value;
- SuspendLayout();
- bool showPen = ((value & ToolBarConfigItems.Pen) != ToolBarConfigItems.None);
- this.penSeparator.Visible = showPen;
- this.penSizeLabel.Visible = showPen;
- this.penSizeDecButton.Visible = showPen;
- this.penSizeComboBox.Visible = showPen;
- this.penSizeIncButton.Visible = showPen;
- bool showPenCaps = ((value & ToolBarConfigItems.PenCaps) != ToolBarConfigItems.None);
- this.penStyleLabel.Visible = showPenCaps;
- this.penStartCapSplitButton.Visible = showPenCaps;
- this.penDashStyleSplitButton.Visible = showPenCaps;
- this.penEndCapSplitButton.Visible = showPenCaps;
- bool showBrush = ((value & ToolBarConfigItems.Brush) != ToolBarConfigItems.None);
- this.brushSeparator.Visible = showBrush;
- this.brushStyleLabel.Visible = showBrush;
- this.brushStyleComboBox.Visible = showBrush;
- bool showShape = ((value & ToolBarConfigItems.ShapeType) != ToolBarConfigItems.None);
- this.shapeSeparator.Visible = showShape;
- this.shapeButton.Visible = showShape;
- bool showGradient = ((value & ToolBarConfigItems.Gradient) != ToolBarConfigItems.None);
- this.gradientSeparator1.Visible = showGradient;
- this.gradientLinearClampedButton.Visible = showGradient;
- this.gradientLinearReflectedButton.Visible = showGradient;
- this.gradientLinearDiamondButton.Visible = showGradient;
- this.gradientRadialButton.Visible = showGradient;
- this.gradientConicalButton.Visible = showGradient;
- this.gradientSeparator2.Visible = showGradient;
- this.gradientChannelsSplitButton.Visible = showGradient;
- bool showAA = ((value & ToolBarConfigItems.Antialiasing) != ToolBarConfigItems.None);
- this.antiAliasingSplitButton.Visible = showAA;
- bool showAB = ((value & ToolBarConfigItems.AlphaBlending) != ToolBarConfigItems.None);
- this.alphaBlendingSplitButton.Visible = showAB;
- bool showBlendingSep = ((value & (ToolBarConfigItems.AlphaBlending | ToolBarConfigItems.Antialiasing)) != ToolBarConfigItems.None);
- this.blendingSeparator.Visible = showBlendingSep;
- bool showTolerance = ((value & ToolBarConfigItems.Tolerance) != ToolBarConfigItems.None);
- this.toleranceSeparator.Visible = showTolerance;
- this.toleranceLabel.Visible = showTolerance;
- this.toleranceSliderStrip.Visible = showTolerance;
- bool showText = ((value & ToolBarConfigItems.Text) != ToolBarConfigItems.None);
- this.fontSeparator.Visible = showText;
- this.fontLabel.Visible = showText;
- this.fontFamilyComboBox.Visible = showText;
- this.fontSizeComboBox.Visible = showText;
- this.fontSmoothingComboBox.Visible = showText;
- this.fontStyleSeparator.Visible = showText;
- this.fontBoldButton.Visible = showText;
- this.fontItalicsButton.Visible = showText;
- this.fontUnderlineButton.Visible = showText;
- this.fontAlignSeparator.Visible = showText;
- this.fontAlignLeftButton.Visible = showText;
- this.fontAlignCenterButton.Visible = showText;
- this.fontAlignRightButton.Visible = showText;
- if (showText && IsHandleCreated)
- {
- AsyncInitFontNames();
- }
- bool showResampling = ((value & ToolBarConfigItems.Resampling) != ToolBarConfigItems.None);
- this.resamplingSeparator.Visible = showResampling;
- this.resamplingLabel.Visible = showResampling;
- this.resamplingComboBox.Visible = showResampling;
- bool showColorPicker = ((value & ToolBarConfigItems.ColorPickerBehavior) != ToolBarConfigItems.None);
- this.colorPickerSeparator.Visible = showColorPicker;
- this.colorPickerLabel.Visible = showColorPicker;
- this.colorPickerComboBox.Visible = showColorPicker;
- bool showSelectionCombineMode = ((value & ToolBarConfigItems.SelectionCombineMode) != ToolBarConfigItems.None);
- this.selectionCombineModeSeparator.Visible = showSelectionCombineMode;
- this.selectionCombineModeLabel.Visible = showSelectionCombineMode;
- this.selectionCombineModeSplitButton.Visible = showSelectionCombineMode;
- bool showFloodMode = ((value & ToolBarConfigItems.FloodMode) != ToolBarConfigItems.None);
- this.floodModeSeparator.Visible = showFloodMode;
- this.floodModeLabel.Visible = showFloodMode;
- this.floodModeSplitButton.Visible = showFloodMode;
- bool showSelectionDrawMode = ((value & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None);
- this.selectionDrawModeSeparator.Visible = showSelectionDrawMode;
- this.selectionDrawModeModeLabel.Visible = showSelectionDrawMode;
- this.selectionDrawModeSplitButton.Visible = showSelectionDrawMode;
- this.selectionDrawModeWidthLabel.Visible = showSelectionDrawMode;
- this.selectionDrawModeSwapButton.Visible = showSelectionDrawMode;
- this.selectionDrawModeHeightLabel.Visible = showSelectionDrawMode;
- RefreshSelectionDrawModeInfoVisibilities();
- if (value == ToolBarConfigItems.None)
- {
- this.Visible = false;
- }
- else
- {
- this.Visible = true;
- }
- ResumeLayout();
- PerformLayout();
- }
- }
- private void ToleranceSlider_ToleranceChanged(object sender, EventArgs e)
- {
- OnToleranceChanged();
- }
- public void PerformToleranceChanged()
- {
- OnToleranceChanged();
- }
- public float Tolerance
- {
- get
- {
- return this.toleranceSlider.Tolerance;
- }
- set
- {
- if (value != this.toleranceSlider.Tolerance)
- {
- this.toleranceSlider.Tolerance = value;
- }
- }
- }
- public event EventHandler ToleranceChanged;
- protected void OnToleranceChanged()
- {
- if (ToleranceChanged != null)
- {
- ToleranceChanged(this, EventArgs.Empty);
- }
- }
- public event EventHandler ColorPickerClickBehaviorChanged;
- protected void OnColorPickerClickBehaviorChanged()
- {
- if (ColorPickerClickBehaviorChanged != null)
- {
- ColorPickerClickBehaviorChanged(this, EventArgs.Empty);
- }
- }
- public ColorPickerClickBehavior ColorPickerClickBehavior
- {
- get
- {
- string selectedItem = (string)this.colorPickerComboBox.SelectedItem;
- ColorPickerClickBehavior cpcb = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(selectedItem);
- return cpcb;
- }
- set
- {
- if (value != ColorPickerClickBehavior)
- {
- this.colorPickerComboBox.SelectedItem = this.colorPickerBehaviorNames.EnumValueToLocalizedName(value);
- }
- }
- }
- public void PerformColorPickerClickBehaviorChanged()
- {
- OnColorPickerClickBehaviorChanged();
- }
- private void ColorPickerComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- OnColorPickerClickBehaviorChanged();
- }
- private void ResamplingComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- OnResamplingAlgorithmChanged();
- }
- public event EventHandler ResamplingAlgorithmChanged;
- protected void OnResamplingAlgorithmChanged()
- {
- if (ResamplingAlgorithmChanged != null)
- {
- ResamplingAlgorithmChanged(this, EventArgs.Empty);
- }
- }
- public ResamplingAlgorithm ResamplingAlgorithm
- {
- get
- {
- string selectedItem = (string)this.resamplingComboBox.SelectedItem;
- ResamplingAlgorithm ra = (ResamplingAlgorithm)this.resamplingAlgorithmNames.LocalizedNameToEnumValue(selectedItem);
- return ra;
- }
- set
- {
- if (value != ResamplingAlgorithm)
- {
- if (value != ResamplingAlgorithm.NearestNeighbor && value != ResamplingAlgorithm.Bilinear)
- {
- throw new InvalidEnumArgumentException();
- }
- this.resamplingComboBox.SelectedItem = this.resamplingAlgorithmNames.EnumValueToLocalizedName(value);
- }
- }
- }
- public void PerformResamplingAlgorithmChanged()
- {
- OnResamplingAlgorithmChanged();
- }
- public event EventHandler SelectionCombineModeChanged;
- protected void OnSelectionCombineModeChanged()
- {
- if (SelectionCombineModeChanged != null)
- {
- SelectionCombineModeChanged(this, EventArgs.Empty);
- }
- }
- public CombineMode SelectionCombineMode
- {
- get
- {
- object tag = this.selectionCombineModeSplitButton.Tag;
- CombineMode cm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
- return cm;
- }
- set
- {
- object tag = this.selectionCombineModeSplitButton.Tag;
- CombineMode oldCm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
- if (tag == null || (tag != null && value != oldCm))
- {
- this.selectionCombineModeSplitButton.Tag = value;
- UI.SuspendControlPainting(this);
- this.selectionCombineModeSplitButton.Image = GetSelectionCombineModeImage(value).Reference;
- UI.ResumeControlPainting(this);
- OnSelectionCombineModeChanged();
- Invalidate(true);
- }
- }
- }
- public void PerformSelectionCombineModeChanged()
- {
- OnSelectionCombineModeChanged();
- }
- private ImageResource GetSelectionCombineModeImage(CombineMode cm)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionCombineMode." + cm.ToString() + ".png");
- }
- private void SelectionCombineModeSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- this.selectionCombineModeSplitButton.DropDownItems.Clear();
- foreach (CombineMode cm in
- new CombineMode[]
- {
- CombineMode.Replace,
- CombineMode.Union,
- CombineMode.Exclude,
- CombineMode.Intersect,
- CombineMode.Xor
- })
- {
- ToolStripMenuItem cmMI = new ToolStripMenuItem(
- PdnResources.GetString("ToolConfigStrip.SelectionCombineModeSplitButton." + cm.ToString() + ".Text"),
- GetSelectionCombineModeImage(cm).Reference,
- delegate (object sender2, EventArgs e2)
- {
- ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
- CombineMode newCM = (CombineMode)asTSMI.Tag;
- this.SelectionCombineMode = newCM;
- });
- cmMI.Tag = cm;
- cmMI.Checked = (cm == SelectionCombineMode);
- this.selectionCombineModeSplitButton.DropDownItems.Add(cmMI);
- }
- }
- private CombineMode CycleSelectionCombineMode(CombineMode mode)
- {
- CombineMode newMode;
- // Replace -> Union -> Exclude -> Intersect -> Xor -> Replace
- switch (mode)
- {
- default:
- case CombineMode.Complement:
- throw new InvalidEnumArgumentException();
- case CombineMode.Exclude:
- newMode = CombineMode.Intersect;
- break;
- case CombineMode.Intersect:
- newMode = CombineMode.Xor;
- break;
- case CombineMode.Replace:
- newMode = CombineMode.Union;
- break;
- case CombineMode.Union:
- newMode = CombineMode.Exclude;
- break;
- case CombineMode.Xor:
- newMode = CombineMode.Replace;
- break;
- }
- return newMode;
- }
- public event EventHandler FloodModeChanged;
- protected void OnFloodModeChanged()
- {
- if (FloodModeChanged != null)
- {
- FloodModeChanged(this, EventArgs.Empty);
- }
- }
- public FloodMode FloodMode
- {
- get
- {
- object tag = this.floodModeSplitButton.Tag;
- FloodMode fm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
- return fm;
- }
- set
- {
- object tag = this.floodModeSplitButton.Tag;
- FloodMode oldFm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
- if (tag == null || (tag != null && value != oldFm))
- {
- this.floodModeSplitButton.Tag = value;
- this.floodModeSplitButton.Image = GetFloodModeImage(value).Reference;
- OnFloodModeChanged();
- }
- }
- }
- public void PerformFloodModeChanged()
- {
- OnFloodModeChanged();
- }
- private ImageResource GetFloodModeImage(FloodMode cm)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.FloodMode." + cm.ToString() + ".png");
- }
- private void FloodModeSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- this.floodModeSplitButton.DropDownItems.Clear();
- foreach (FloodMode fm in
- new FloodMode[]
- {
- FloodMode.Local,
- FloodMode.Global
- })
- {
- ToolStripMenuItem fmMI = new ToolStripMenuItem(
- PdnResources.GetString("ToolConfigStrip.FloodModeSplitButton." + fm.ToString() + ".Text"),
- GetFloodModeImage(fm).Reference,
- delegate (object sender2, EventArgs e2)
- {
- ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
- FloodMode newFM = (FloodMode)asTSMI.Tag;
- this.FloodMode = newFM;
- });
- fmMI.Tag = fm;
- fmMI.Checked = (fm == FloodMode);
- this.floodModeSplitButton.DropDownItems.Add(fmMI);
- }
- }
- private FloodMode CycleFloodMode(FloodMode mode)
- {
- FloodMode newMode;
- switch (mode)
- {
- default:
- throw new InvalidEnumArgumentException();
- case FloodMode.Global:
- newMode = FloodMode.Local;
- break;
- case FloodMode.Local:
- newMode = FloodMode.Global;
- break;
- }
- return newMode;
- }
- public event EventHandler SelectionDrawModeInfoChanged;
- protected void OnSelectionDrawModeInfoChanged()
- {
- if (SelectionDrawModeInfoChanged != null)
- {
- SelectionDrawModeInfoChanged(this, EventArgs.Empty);
- }
- }
- // syncs this.SelectionDrawModeInfo into the controls
- private void SyncSelectionDrawModeInfoUI()
- {
- this.selectionDrawModeSplitButton.Text = GetSelectionDrawModeString(this.selectionDrawModeInfo.DrawMode);
- this.selectionDrawModeSplitButton.Image = GetSelectionDrawModeImage(this.selectionDrawModeInfo.DrawMode);
- this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
- this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
- this.selectionDrawModeUnits.UnitsChanged -= SelectionDrawModeUnits_UnitsChanged;
- this.selectionDrawModeUnits.Units = this.selectionDrawModeInfo.Units;
- this.selectionDrawModeUnits.UnitsChanged += SelectionDrawModeUnits_UnitsChanged;
- RefreshSelectionDrawModeInfoVisibilities();
- }
- private void RefreshSelectionDrawModeInfoVisibilities()
- {
- if (this.selectionDrawModeInfo != null)
- {
- SuspendLayout();
- bool anyVisible = (this.ToolBarConfigItems & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None;
- this.selectionDrawModeModeLabel.Visible = false;
- bool showWidthHeight = anyVisible & (this.selectionDrawModeInfo.DrawMode != SelectionDrawMode.Normal);
- this.selectionDrawModeWidthTextBox.Visible = showWidthHeight;
- this.selectionDrawModeHeightTextBox.Visible = showWidthHeight;
- this.selectionDrawModeWidthLabel.Visible = showWidthHeight;
- this.selectionDrawModeHeightLabel.Visible = showWidthHeight;
- this.selectionDrawModeSwapButton.Visible = showWidthHeight;
- this.selectionDrawModeUnits.Visible = anyVisible & (this.selectionDrawModeInfo.DrawMode == SelectionDrawMode.FixedSize);
- ResumeLayout(false);
- PerformLayout();
- }
- }
- public SelectionDrawModeInfo SelectionDrawModeInfo
- {
- get
- {
- return (this.selectionDrawModeInfo ?? SelectionDrawModeInfo.CreateDefault()).Clone();
- }
- set
- {
- if (this.selectionDrawModeInfo == null || !this.selectionDrawModeInfo.Equals(value))
- {
- this.selectionDrawModeInfo = value.Clone();
- OnSelectionDrawModeInfoChanged();
- SyncSelectionDrawModeInfoUI();
- }
- }
- }
- public void PerformSelectionDrawModeInfoChanged()
- {
- OnSelectionDrawModeInfoChanged();
- }
- private string GetSelectionDrawModeString(SelectionDrawMode drawMode)
- {
- return PdnResources.GetString("ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".Text");
- }
- private Image GetSelectionDrawModeImage(SelectionDrawMode drawMode)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".png").Reference;
- }
- private void SelectionDrawModeSplitButton_DropDownOpening(object sender, EventArgs e)
- {
- this.selectionDrawModeSplitButton.DropDownItems.Clear();
- foreach (SelectionDrawMode sdm in
- new SelectionDrawMode[]
- {
- SelectionDrawMode.Normal,
- SelectionDrawMode.FixedRatio,
- SelectionDrawMode.FixedSize
- })
- {
- ToolStripMenuItem sdmTSMI = new ToolStripMenuItem(
- GetSelectionDrawModeString(sdm),
- GetSelectionDrawModeImage(sdm),
- delegate (object sender2, EventArgs e2)
- {
- ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
- SelectionDrawMode newSDM = (SelectionDrawMode)asTSMI.Tag;
- this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
- });
- sdmTSMI.Tag = sdm;
- sdmTSMI.Checked = (sdm == this.SelectionDrawModeInfo.DrawMode);
- this.selectionDrawModeSplitButton.DropDownItems.Add(sdmTSMI);
- }
- }
- private SelectionDrawMode CycleSelectionDrawMode(SelectionDrawMode drawMode)
- {
- SelectionDrawMode newSDM;
- switch (drawMode)
- {
- case SelectionDrawMode.Normal:
- newSDM = SelectionDrawMode.FixedRatio;
- break;
- case SelectionDrawMode.FixedRatio:
- newSDM = SelectionDrawMode.FixedSize;
- break;
- case SelectionDrawMode.FixedSize:
- newSDM = SelectionDrawMode.Normal;
- break;
- default:
- throw new InvalidEnumArgumentException();
- }
- return newSDM;
- }
- private void SelectionDrawModeUnits_UnitsChanged(object sender, EventArgs e)
- {
- OnSelectionDrawModeUnitsChanging();
- this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewUnits(this.selectionDrawModeUnits.Units);
- OnSelectionDrawModeUnitsChanged();
- }
- }
- }
|