1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320 |
- /*****************************************************************************************
- ** ***************************************** **
- ** **********File name:Ge.cs, Version 1.0, 8 November 2004** **
- ** *************************Authors: MingZhang and Mayank Bansal******************** **
- ** ***************************************** **
- ** **
- ** This class provides an interface between user and functions. The form gets loaded **
- ** when software is opened. It captures various actions performed by user and it calls **
- ** corresponding functions to be implemented for the actions. **
- ** The following classes are defined here: **
- ** 1.GE: This class loads the form and it is the main entry point of software. **
- ** 2.Canvas: All the drawing in Graphical Editor is done on the canvas. **
- ** Canvas class is used to define the drawing area **
- ** 3.GraEditStackMgr: This class is used to perform Redo and Undo operations **
- ** **
- ******************************************************************************************/
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Drawing.Printing;
- using System.Diagnostics;
- using DockToolbar;
- using GraEditor.DrawTools;
- using GraEditor.Elements;
- namespace GraEditor
- {
- /// <summary>
- ///Main windows of Graphic Editor
- /// </summary>
- public class GE : System.Windows.Forms.Form
- {
- private MainView mainView; //Inherit from System.Windows.Forms.Panel
- private System.Windows.Forms.ContextMenu contextMenu1;
- private System.Windows.Forms.ToolBarButton tlBtnLine;
- private System.Windows.Forms.ToolBarButton tlBtnFrameRect;
- private System.Windows.Forms.ToolBarButton tlBtnFillRect;
- private System.Windows.Forms.ToolBarButton tlBtnZoomIn;
- private System.Windows.Forms.ToolBarButton tlBtnZoomOut;
- private System.Windows.Forms.ToolBarButton tlBtnZoomResume;
- private System.Windows.Forms.MenuItem pasteMenuItem;
- private System.Windows.Forms.ToolBarButton tlBtnFrameEllipse;
- private System.Windows.Forms.ToolBarButton tlBtnFillEllipse;
- private System.Windows.Forms.ToolBarButton tlBtnImage;
- private System.Windows.Forms.ToolBarButton tlBtnText;
- private System.Windows.Forms.ToolBarButton tlBtnLines;
- private System.Windows.Forms.MainMenu mainMenu1;
- private System.Windows.Forms.MenuItem menuItem12;
- private System.Windows.Forms.MenuItem menuNew;
- private System.Windows.Forms.MenuItem menuFile;
- private System.Windows.Forms.MenuItem menuOpen;
- private System.Windows.Forms.MenuItem menuSave;
- private System.Windows.Forms.MenuItem menuSaveAs;
- private System.Windows.Forms.MenuItem menuExit;
- private System.Windows.Forms.MenuItem menuUndo;
- private System.Windows.Forms.MenuItem menuRedo;
- private System.Windows.Forms.MenuItem menuCopy;
- private System.Windows.Forms.MenuItem menuCut;
- private System.Windows.Forms.MenuItem menuView;
- private System.Windows.Forms.MenuItem menuImgSetting;
- private System.Windows.Forms.MenuItem menuHelp;
- private System.Windows.Forms.ToolBarButton tlBtnErase;
- private System.Windows.Forms.MenuItem menuItemCanvasBackColor;
- private System.Windows.Forms.ToolBarButton sep2;
- private System.Windows.Forms.ToolBarButton sep3;
- private System.Windows.Forms.ToolBarButton sep4;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem menuItem5;
- private System.Windows.Forms.MenuItem menuItem4;
- private System.Windows.Forms.MenuItem menuItem24;
- private System.Windows.Forms.MenuItem menuPrint;
- private System.Windows.Forms.MenuItem menuRecentFiles;
- private System.Windows.Forms.MenuItem menuEdit;
- private System.Windows.Forms.MenuItem menuZoom;
- private System.Windows.Forms.MenuItem menuZoomIn;
- private System.Windows.Forms.MenuItem menuZoomOut;
- private System.Windows.Forms.MenuItem menuResume;
- private System.Windows.Forms.MenuItem menuColorSettings;
- private System.Windows.Forms.MenuItem menuHelpIndex;
- private System.Windows.Forms.MenuItem menuAboutGE;
- private System.Windows.Forms.MenuItem menuStatusBar;
- private System.Windows.Forms.ImageList GE_imageList;
- private System.Windows.Forms.ToolBar GE_toolBar;
- private System.Windows.Forms.StatusBar GE_statusBar;
- private System.ComponentModel.IContainer components;
- private Chris.Beckett.MenuImageLib.MenuImage _menuImages;
- private System.Windows.Forms.MenuItem menuToolbar;
- private System.Windows.Forms.ToolBar GE_toolBar1;
- private System.Windows.Forms.ToolBarButton tlBtnNew;
- private System.Windows.Forms.ToolBarButton tlBtnOpen;
- private System.Windows.Forms.ToolBarButton tlBtnSave;
- private System.Windows.Forms.ToolBarButton sp1;
- private System.Windows.Forms.ToolBarButton tlBtnSelect;
- private System.Windows.Forms.ToolBarButton tlBtnCopy;
- private System.Windows.Forms.ToolBarButton tlBtnCut;
- private System.Windows.Forms.ToolBarButton sp2;
- private System.Windows.Forms.ToolBarButton sp5;
- private System.Windows.Forms.ToolBarButton tlBtnUndo;
- private System.Windows.Forms.ToolBarButton tlBtnRedo;
- private System.Windows.Forms.ToolBarButton tlBtnFont;
- private System.Windows.Forms.ToolBarButton tlBtnColor;
- private System.Drawing.Printing.PrintDocument printDocument1;
- private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
- private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
- private System.Windows.Forms.MenuItem menuPrintPreview;
- private System.Windows.Forms.MenuItem menuPageSetting;
- private System.Windows.Forms.ToolBarButton tlBtnPenWidth;
- private System.Windows.Forms.ContextMenu muPenWidth;
- private System.Windows.Forms.StatusBarPanel sbPanelTip;
- private System.Windows.Forms.StatusBarPanel sbPanelViewScale;
- private System.Windows.Forms.StatusBarPanel sbPanelMousePos;
- private System.Windows.Forms.MenuItem menuItemCanvasSize;
- private System.Windows.Forms.ToolBarButton tlBtnFreehand;
- private System.Windows.Forms.StatusBarPanel sbPanelFont;
- ToolBarManager _toolBarManager;
- public GE()
- {
- //
- // Required for Windows Form Designer support.
- //
- InitializeComponent();
- InitPenWidthToolBarButton();
- //
- // TODO: InitializeComponent
- //
-
- this.sbPanelViewScale.Text ="100%";
-
- Canvas canvas = Canvas.Instance;
- canvas.MainView = this.mainView;
- canvas.Modified +=new EventHandler(canvas_Modified);
- canvas.Init(null,new Size(600,600),Color.White);
-
- // The parameter to the constructor sets the form where the toolbars can be docked.
- // This would be your application main form
- _toolBarManager = new ToolBarManager(this, this);
-
- // The control Text property is used to draw the bar name while floating
- // and on view/hide menu.
- //_toolBar1.Text = "Bar #1";
- GE_toolBar.Text = "Drawing Toolbar";
- GE_toolBar1.Text = "File Operations";
- _toolBarManager.AddControl(GE_toolBar, DockStyle.Left);
-
- _toolBarManager.AddControl(GE_toolBar1,DockStyle.Top);
-
- InitGraDrawTool();
- UpdateColorBtnImage(DrawEnvMgr.Instance.Color);
- InitRecentFilesMgr();
- GraDrawTool.ActiveStateChanged +=new EventHandler(GraDrawTool_ActiveStateChanged);
- this.mainView.MouseMove += new MouseEventHandler(mainView_MouseMove);
- InitEditStackMgr();
- UpdateFontPanel();
-
- //Set Freehand draw tool as default
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Freehand);
- this.tlBtnFreehand.Pushed = true;
- }
- /// <summary>
- /// Clean up any resources being used
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GE));
- this.GE_toolBar = new System.Windows.Forms.ToolBar();
- this.tlBtnErase = new System.Windows.Forms.ToolBarButton();
- this.sep2 = new System.Windows.Forms.ToolBarButton();
- this.tlBtnLine = new System.Windows.Forms.ToolBarButton();
- this.tlBtnLines = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFreehand = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFrameRect = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFillRect = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFrameEllipse = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFillEllipse = new System.Windows.Forms.ToolBarButton();
- this.tlBtnImage = new System.Windows.Forms.ToolBarButton();
- this.tlBtnText = new System.Windows.Forms.ToolBarButton();
- this.sep3 = new System.Windows.Forms.ToolBarButton();
- this.tlBtnZoomIn = new System.Windows.Forms.ToolBarButton();
- this.tlBtnZoomOut = new System.Windows.Forms.ToolBarButton();
- this.tlBtnZoomResume = new System.Windows.Forms.ToolBarButton();
- this.sep4 = new System.Windows.Forms.ToolBarButton();
- this.GE_imageList = new System.Windows.Forms.ImageList(this.components);
- this.mainView = new GraEditor.MainView();
- this.contextMenu1 = new System.Windows.Forms.ContextMenu();
- this.pasteMenuItem = new System.Windows.Forms.MenuItem();
- this.menuItemCanvasBackColor = new System.Windows.Forms.MenuItem();
- this.menuItemCanvasSize = new System.Windows.Forms.MenuItem();
- this.GE_statusBar = new System.Windows.Forms.StatusBar();
- this.sbPanelTip = new System.Windows.Forms.StatusBarPanel();
- this.sbPanelFont = new System.Windows.Forms.StatusBarPanel();
- this.sbPanelViewScale = new System.Windows.Forms.StatusBarPanel();
- this.sbPanelMousePos = new System.Windows.Forms.StatusBarPanel();
- this.mainMenu1 = new System.Windows.Forms.MainMenu();
- this.menuFile = new System.Windows.Forms.MenuItem();
- this.menuNew = new System.Windows.Forms.MenuItem();
- this.menuOpen = new System.Windows.Forms.MenuItem();
- this.menuSave = new System.Windows.Forms.MenuItem();
- this.menuSaveAs = new System.Windows.Forms.MenuItem();
- this.menuItem5 = new System.Windows.Forms.MenuItem();
- this.menuPrint = new System.Windows.Forms.MenuItem();
- this.menuPrintPreview = new System.Windows.Forms.MenuItem();
- this.menuPageSetting = new System.Windows.Forms.MenuItem();
- this.menuItem4 = new System.Windows.Forms.MenuItem();
- this.menuRecentFiles = new System.Windows.Forms.MenuItem();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.menuExit = new System.Windows.Forms.MenuItem();
- this.menuEdit = new System.Windows.Forms.MenuItem();
- this.menuUndo = new System.Windows.Forms.MenuItem();
- this.menuRedo = new System.Windows.Forms.MenuItem();
- this.menuItem12 = new System.Windows.Forms.MenuItem();
- this.menuCut = new System.Windows.Forms.MenuItem();
- this.menuCopy = new System.Windows.Forms.MenuItem();
- this.menuView = new System.Windows.Forms.MenuItem();
- this.menuToolbar = new System.Windows.Forms.MenuItem();
- this.menuStatusBar = new System.Windows.Forms.MenuItem();
- this.menuItem24 = new System.Windows.Forms.MenuItem();
- this.menuZoom = new System.Windows.Forms.MenuItem();
- this.menuZoomIn = new System.Windows.Forms.MenuItem();
- this.menuZoomOut = new System.Windows.Forms.MenuItem();
- this.menuResume = new System.Windows.Forms.MenuItem();
- this.menuImgSetting = new System.Windows.Forms.MenuItem();
- this.menuColorSettings = new System.Windows.Forms.MenuItem();
- this.menuHelp = new System.Windows.Forms.MenuItem();
- this.menuHelpIndex = new System.Windows.Forms.MenuItem();
- this.menuAboutGE = new System.Windows.Forms.MenuItem();
- this._menuImages = new Chris.Beckett.MenuImageLib.MenuImage(this.components);
- this.GE_toolBar1 = new System.Windows.Forms.ToolBar();
- this.tlBtnNew = new System.Windows.Forms.ToolBarButton();
- this.tlBtnOpen = new System.Windows.Forms.ToolBarButton();
- this.tlBtnSave = new System.Windows.Forms.ToolBarButton();
- this.sp1 = new System.Windows.Forms.ToolBarButton();
- this.tlBtnSelect = new System.Windows.Forms.ToolBarButton();
- this.tlBtnCopy = new System.Windows.Forms.ToolBarButton();
- this.tlBtnCut = new System.Windows.Forms.ToolBarButton();
- this.sp2 = new System.Windows.Forms.ToolBarButton();
- this.sp5 = new System.Windows.Forms.ToolBarButton();
- this.tlBtnUndo = new System.Windows.Forms.ToolBarButton();
- this.tlBtnRedo = new System.Windows.Forms.ToolBarButton();
- this.tlBtnFont = new System.Windows.Forms.ToolBarButton();
- this.tlBtnColor = new System.Windows.Forms.ToolBarButton();
- this.tlBtnPenWidth = new System.Windows.Forms.ToolBarButton();
- this.muPenWidth = new System.Windows.Forms.ContextMenu();
- this.printDocument1 = new System.Drawing.Printing.PrintDocument();
- this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
- this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelTip)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelFont)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelViewScale)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelMousePos)).BeginInit();
- this.SuspendLayout();
- //
- // GE_toolBar
- //
- this.GE_toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tlBtnErase,
- this.sep2,
- this.tlBtnLine,
- this.tlBtnLines,
- this.tlBtnFreehand,
- this.tlBtnFrameRect,
- this.tlBtnFillRect,
- this.tlBtnFrameEllipse,
- this.tlBtnFillEllipse,
- this.tlBtnImage,
- this.tlBtnText,
- this.sep3,
- this.tlBtnZoomIn,
- this.tlBtnZoomOut,
- this.tlBtnZoomResume,
- this.sep4});
- this.GE_toolBar.DropDownArrows = true;
- this.GE_toolBar.ImageList = this.GE_imageList;
- this.GE_toolBar.Location = new System.Drawing.Point(0, 0);
- this.GE_toolBar.Name = "GE_toolBar";
- this.GE_toolBar.ShowToolTips = true;
- this.GE_toolBar.Size = new System.Drawing.Size(591, 28);
- this.GE_toolBar.TabIndex = 0;
- this.GE_toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.GE_toolBar_ButtonClick);
- //
- // tlBtnErase
- //
- this.tlBtnErase.ImageIndex = 23;
- this.tlBtnErase.ToolTipText = "Erase";
- //
- // sep2
- //
- this.sep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tlBtnLine
- //
- this.tlBtnLine.ImageIndex = 6;
- this.tlBtnLine.ToolTipText = "Draw Line";
- //
- // tlBtnLines
- //
- this.tlBtnLines.ImageIndex = 19;
- this.tlBtnLines.ToolTipText = "Draw Multiple Lines, double click to stop";
- //
- // tlBtnFreehand
- //
- this.tlBtnFreehand.ImageIndex = 32;
- this.tlBtnFreehand.ToolTipText = "Free Hand Drawing";
- //
- // tlBtnFrameRect
- //
- this.tlBtnFrameRect.ImageIndex = 4;
- this.tlBtnFrameRect.ToolTipText = "Draw Rectangle";
- //
- // tlBtnFillRect
- //
- this.tlBtnFillRect.ImageIndex = 3;
- this.tlBtnFillRect.ToolTipText = "Draw Filled Rectangle";
- //
- // tlBtnFrameEllipse
- //
- this.tlBtnFrameEllipse.ImageIndex = 15;
- this.tlBtnFrameEllipse.ToolTipText = "Draw Ellipse";
- //
- // tlBtnFillEllipse
- //
- this.tlBtnFillEllipse.ImageIndex = 16;
- this.tlBtnFillEllipse.ToolTipText = "Draw Filled Ellipse";
- //
- // tlBtnImage
- //
- this.tlBtnImage.ImageIndex = 17;
- this.tlBtnImage.ToolTipText = "Insert Image";
- //
- // tlBtnText
- //
- this.tlBtnText.ImageIndex = 18;
- this.tlBtnText.ToolTipText = "Insert Text";
- //
- // sep3
- //
- this.sep3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tlBtnZoomIn
- //
- this.tlBtnZoomIn.ImageIndex = 12;
- this.tlBtnZoomIn.ToolTipText = "ZoomIn";
- //
- // tlBtnZoomOut
- //
- this.tlBtnZoomOut.ImageIndex = 13;
- this.tlBtnZoomOut.ToolTipText = "ZoomOut";
- //
- // tlBtnZoomResume
- //
- this.tlBtnZoomResume.ImageIndex = 14;
- this.tlBtnZoomResume.ToolTipText = "Resume";
- //
- // sep4
- //
- this.sep4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // GE_imageList
- //
- this.GE_imageList.ImageSize = new System.Drawing.Size(16, 16);
- this.GE_imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("GE_imageList.ImageStream")));
- this.GE_imageList.TransparentColor = System.Drawing.Color.Transparent;
- //
- // mainView
- //
- this.mainView.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(192)));
- this.mainView.ContextMenu = this.contextMenu1;
- this.mainView.Dock = System.Windows.Forms.DockStyle.Fill;
- this.mainView.Location = new System.Drawing.Point(0, 56);
- this.mainView.Name = "mainView";
- this.mainView.Size = new System.Drawing.Size(591, 353);
- this.mainView.TabIndex = 3;
- this.mainView.Paint += new System.Windows.Forms.PaintEventHandler(this.mainView_Paint);
- //
- // contextMenu1
- //
- this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.pasteMenuItem,
- this.menuItemCanvasBackColor,
- this.menuItemCanvasSize});
- this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
- //
- // pasteMenuItem
- //
- this.pasteMenuItem.Index = 0;
- this._menuImages.SetMenuImage(this.pasteMenuItem, null);
- this.pasteMenuItem.OwnerDraw = true;
- this.pasteMenuItem.Text = "Paste";
- this.pasteMenuItem.Click += new System.EventHandler(this.pasteMenuItem_Click);
- //
- // menuItemCanvasBackColor
- //
- this.menuItemCanvasBackColor.Index = 1;
- this._menuImages.SetMenuImage(this.menuItemCanvasBackColor, null);
- this.menuItemCanvasBackColor.OwnerDraw = true;
- this.menuItemCanvasBackColor.Text = "CanvasBackColor";
- this.menuItemCanvasBackColor.Click += new System.EventHandler(this.menuItemCanvasBackColor_Click);
- //
- // menuItemCanvasSize
- //
- this.menuItemCanvasSize.Index = 2;
- this._menuImages.SetMenuImage(this.menuItemCanvasSize, null);
- this.menuItemCanvasSize.OwnerDraw = true;
- this.menuItemCanvasSize.Text = "CanvasSize";
- this.menuItemCanvasSize.Click += new System.EventHandler(this.menuItemCanvasSize_Click);
- //
- // GE_statusBar
- //
- this.GE_statusBar.Location = new System.Drawing.Point(0, 409);
- this.GE_statusBar.Name = "GE_statusBar";
- this.GE_statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
- this.sbPanelTip,
- this.sbPanelFont,
- this.sbPanelViewScale,
- this.sbPanelMousePos});
- this.GE_statusBar.ShowPanels = true;
- this.GE_statusBar.Size = new System.Drawing.Size(591, 23);
- this.GE_statusBar.TabIndex = 2;
- //
- // sbPanelTip
- //
- this.sbPanelTip.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
- this.sbPanelTip.Width = 265;
- //
- // sbPanelFont
- //
- this.sbPanelFont.Width = 150;
- //
- // sbPanelViewScale
- //
- this.sbPanelViewScale.Width = 60;
- //
- // mainMenu1
- //
- this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuFile,
- this.menuEdit,
- this.menuView,
- this.menuImgSetting,
- this.menuHelp});
- //
- // menuFile
- //
- this.menuFile.Index = 0;
- this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuNew,
- this.menuOpen,
- this.menuSave,
- this.menuSaveAs,
- this.menuItem5,
- this.menuPrint,
- this.menuPrintPreview,
- this.menuPageSetting,
- this.menuItem4,
- this.menuRecentFiles,
- this.menuItem1,
- this.menuExit});
- this.menuFile.Text = "File";
- //
- // menuNew
- //
- this.menuNew.Index = 0;
- this._menuImages.SetMenuImage(this.menuNew, "36");
- this.menuNew.OwnerDraw = true;
- this.menuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
- this.menuNew.Text = "New";
- this.menuNew.Click += new System.EventHandler(this.menuNew_Click);
- //
- // menuOpen
- //
- this.menuOpen.Index = 1;
- this._menuImages.SetMenuImage(this.menuOpen, "33");
- this.menuOpen.OwnerDraw = true;
- this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
- this.menuOpen.Text = "Open";
- this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);
- //
- // menuSave
- //
- this.menuSave.Index = 2;
- this._menuImages.SetMenuImage(this.menuSave, "35");
- this.menuSave.OwnerDraw = true;
- this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
- this.menuSave.Text = "Save";
- this.menuSave.Click += new System.EventHandler(this.menuSave_Click);
- //
- // menuSaveAs
- //
- this.menuSaveAs.Index = 3;
- this._menuImages.SetMenuImage(this.menuSaveAs, "35");
- this.menuSaveAs.OwnerDraw = true;
- this.menuSaveAs.Text = "Save as...";
- this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click);
- //
- // menuItem5
- //
- this.menuItem5.Index = 4;
- this._menuImages.SetMenuImage(this.menuItem5, null);
- this.menuItem5.OwnerDraw = true;
- this.menuItem5.Text = "-";
- //
- // menuPrint
- //
- this.menuPrint.Index = 5;
- this._menuImages.SetMenuImage(this.menuPrint, "31");
- this.menuPrint.OwnerDraw = true;
- this.menuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP;
- this.menuPrint.Text = "Print";
- this.menuPrint.Click += new System.EventHandler(this.menuPrint_Click);
- //
- // menuPrintPreview
- //
- this.menuPrintPreview.Index = 6;
- this._menuImages.SetMenuImage(this.menuPrintPreview, null);
- this.menuPrintPreview.OwnerDraw = true;
- this.menuPrintPreview.Text = "PrintPreview";
- this.menuPrintPreview.Click += new System.EventHandler(this.menuPrintPreview_Click);
- //
- // menuPageSetting
- //
- this.menuPageSetting.Index = 7;
- this._menuImages.SetMenuImage(this.menuPageSetting, null);
- this.menuPageSetting.OwnerDraw = true;
- this.menuPageSetting.Text = "PageSetting";
- this.menuPageSetting.Click += new System.EventHandler(this.menuPageSetting_Click);
- //
- // menuItem4
- //
- this.menuItem4.Index = 8;
- this._menuImages.SetMenuImage(this.menuItem4, null);
- this.menuItem4.OwnerDraw = true;
- this.menuItem4.Text = "-";
- //
- // menuRecentFiles
- //
- this.menuRecentFiles.Index = 9;
- this._menuImages.SetMenuImage(this.menuRecentFiles, null);
- this.menuRecentFiles.OwnerDraw = true;
- this.menuRecentFiles.Text = "Recent Files";
- //
- // menuItem1
- //
- this.menuItem1.Index = 10;
- this._menuImages.SetMenuImage(this.menuItem1, null);
- this.menuItem1.OwnerDraw = true;
- this.menuItem1.Text = "-";
- //
- // menuExit
- //
- this.menuExit.Index = 11;
- this._menuImages.SetMenuImage(this.menuExit, "34");
- this.menuExit.OwnerDraw = true;
- this.menuExit.Text = "Exit";
- this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
- //
- // menuEdit
- //
- this.menuEdit.Index = 1;
- this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuUndo,
- this.menuRedo,
- this.menuItem12,
- this.menuCut,
- this.menuCopy});
- this.menuEdit.Text = "Edit";
- //
- // menuUndo
- //
- this.menuUndo.Index = 0;
- this._menuImages.SetMenuImage(this.menuUndo, "11");
- this.menuUndo.OwnerDraw = true;
- this.menuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
- this.menuUndo.Text = "Undo";
- this.menuUndo.Click += new System.EventHandler(this.menuUndo_Click);
- //
- // menuRedo
- //
- this.menuRedo.Index = 1;
- this._menuImages.SetMenuImage(this.menuRedo, "9");
- this.menuRedo.OwnerDraw = true;
- this.menuRedo.Shortcut = System.Windows.Forms.Shortcut.CtrlY;
- this.menuRedo.Text = "Redo";
- this.menuRedo.Click += new System.EventHandler(this.menuRedo_Click);
- //
- // menuItem12
- //
- this.menuItem12.Index = 2;
- this._menuImages.SetMenuImage(this.menuItem12, null);
- this.menuItem12.OwnerDraw = true;
- this.menuItem12.Text = "-";
- //
- // menuCut
- //
- this.menuCut.Index = 3;
- this._menuImages.SetMenuImage(this.menuCut, "1");
- this.menuCut.OwnerDraw = true;
- this.menuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
- this.menuCut.Text = "Cut";
- this.menuCut.Click += new System.EventHandler(this.menuCut_Click);
- //
- // menuCopy
- //
- this.menuCopy.Index = 4;
- this._menuImages.SetMenuImage(this.menuCopy, "0");
- this.menuCopy.OwnerDraw = true;
- this.menuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
- this.menuCopy.Text = "Copy";
- this.menuCopy.Click += new System.EventHandler(this.menuCopy_Click);
- //
- // menuView
- //
- this.menuView.Index = 2;
- this.menuView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuToolbar,
- this.menuStatusBar,
- this.menuItem24,
- this.menuZoom,
- this.menuResume});
- this.menuView.Text = "View";
- this.menuView.Popup += new System.EventHandler(this.menuView_Popup);
- //
- // menuToolbar
- //
- this.menuToolbar.Index = 0;
- this._menuImages.SetMenuImage(this.menuToolbar, null);
- this.menuToolbar.OwnerDraw = true;
- this.menuToolbar.Text = "Toolbar";
- this.menuToolbar.Click += new System.EventHandler(this.menuToolbar_Click_1);
- //
- // menuStatusBar
- //
- this.menuStatusBar.Checked = true;
- this.menuStatusBar.Index = 1;
- this._menuImages.SetMenuImage(this.menuStatusBar, null);
- this.menuStatusBar.OwnerDraw = true;
- this.menuStatusBar.Text = "Status Bar";
- this.menuStatusBar.Click += new System.EventHandler(this.menuStatusBar_Click);
- //
- // menuItem24
- //
- this.menuItem24.Index = 2;
- this._menuImages.SetMenuImage(this.menuItem24, null);
- this.menuItem24.OwnerDraw = true;
- this.menuItem24.Text = "-";
- //
- // menuZoom
- //
- this.menuZoom.Index = 3;
- this._menuImages.SetMenuImage(this.menuZoom, null);
- this.menuZoom.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuZoomIn,
- this.menuZoomOut});
- this.menuZoom.OwnerDraw = true;
- this.menuZoom.Text = "Zoom";
- //
- // menuZoomIn
- //
- this.menuZoomIn.Index = 0;
- this._menuImages.SetMenuImage(this.menuZoomIn, "12");
- this.menuZoomIn.OwnerDraw = true;
- this.menuZoomIn.Text = "Zoom In";
- this.menuZoomIn.Click += new System.EventHandler(this.menuZoomIn_Click);
- //
- // menuZoomOut
- //
- this.menuZoomOut.Index = 1;
- this._menuImages.SetMenuImage(this.menuZoomOut, "13");
- this.menuZoomOut.OwnerDraw = true;
- this.menuZoomOut.Text = "Zoom Out";
- this.menuZoomOut.Click += new System.EventHandler(this.menuZoomOut_Click);
- //
- // menuResume
- //
- this.menuResume.Index = 4;
- this._menuImages.SetMenuImage(this.menuResume, "14");
- this.menuResume.OwnerDraw = true;
- this.menuResume.Text = "Resume";
- this.menuResume.Click += new System.EventHandler(this.menuResume_Click);
- //
- // menuImgSetting
- //
- this.menuImgSetting.Index = 3;
- this.menuImgSetting.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuColorSettings});
- this.menuImgSetting.Text = "Image Settings";
- //
- // menuColorSettings
- //
- this.menuColorSettings.Index = 0;
- this._menuImages.SetMenuImage(this.menuColorSettings, "27");
- this.menuColorSettings.OwnerDraw = true;
- this.menuColorSettings.Text = "Color Settings";
- this.menuColorSettings.Click += new System.EventHandler(this.menuColorSettings_Click);
- //
- // menuHelp
- //
- this.menuHelp.Index = 4;
- this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuHelpIndex,
- this.menuAboutGE});
- this.menuHelp.Text = "Help";
- //
- // menuHelpIndex
- //
- this.menuHelpIndex.Index = 0;
- this._menuImages.SetMenuImage(this.menuHelpIndex, "29");
- this.menuHelpIndex.OwnerDraw = true;
- this.menuHelpIndex.Shortcut = System.Windows.Forms.Shortcut.F1;
- this.menuHelpIndex.Text = "Help Index";
- this.menuHelpIndex.Click += new System.EventHandler(this.menuHelpIndex_Click);
- //
- // menuAboutGE
- //
- this.menuAboutGE.Index = 1;
- this._menuImages.SetMenuImage(this.menuAboutGE, "30");
- this.menuAboutGE.OwnerDraw = true;
- this.menuAboutGE.Text = "About Graphical Editor";
- this.menuAboutGE.Click += new System.EventHandler(this.menuAboutGE_Click);
- //
- // _menuImages
- //
- this._menuImages.ImageList = this.GE_imageList;
- //
- // GE_toolBar1
- //
- this.GE_toolBar1.AutoSize = false;
- this.GE_toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tlBtnNew,
- this.tlBtnOpen,
- this.tlBtnSave,
- this.sp1,
- this.tlBtnSelect,
- this.tlBtnCopy,
- this.tlBtnCut,
- this.sp2,
- this.sp5,
- this.tlBtnUndo,
- this.tlBtnRedo,
- this.tlBtnFont,
- this.tlBtnColor,
- this.tlBtnPenWidth});
- this.GE_toolBar1.DropDownArrows = true;
- this.GE_toolBar1.ImageList = this.GE_imageList;
- this.GE_toolBar1.Location = new System.Drawing.Point(0, 28);
- this.GE_toolBar1.Name = "GE_toolBar1";
- this.GE_toolBar1.ShowToolTips = true;
- this.GE_toolBar1.Size = new System.Drawing.Size(591, 28);
- this.GE_toolBar1.TabIndex = 4;
- this.GE_toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.GE_toolBar1_ButtonClick);
- //
- // tlBtnNew
- //
- this.tlBtnNew.ImageIndex = 36;
- this.tlBtnNew.ToolTipText = "New";
- //
- // tlBtnOpen
- //
- this.tlBtnOpen.ImageIndex = 33;
- this.tlBtnOpen.ToolTipText = "Open";
- //
- // tlBtnSave
- //
- this.tlBtnSave.ImageIndex = 35;
- this.tlBtnSave.ToolTipText = "Save";
- //
- // sp1
- //
- this.sp1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tlBtnSelect
- //
- this.tlBtnSelect.ImageIndex = 10;
- this.tlBtnSelect.ToolTipText = "Select";
- //
- // tlBtnCopy
- //
- this.tlBtnCopy.ImageIndex = 0;
- this.tlBtnCopy.ToolTipText = "Copy";
- //
- // tlBtnCut
- //
- this.tlBtnCut.ImageIndex = 1;
- this.tlBtnCut.ToolTipText = "Cut";
- //
- // sp2
- //
- this.sp2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // sp5
- //
- this.sp5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tlBtnUndo
- //
- this.tlBtnUndo.ImageIndex = 11;
- this.tlBtnUndo.ToolTipText = "Undo";
- //
- // tlBtnRedo
- //
- this.tlBtnRedo.ImageIndex = 9;
- this.tlBtnRedo.ToolTipText = "Redo";
- //
- // tlBtnFont
- //
- this.tlBtnFont.ImageIndex = 25;
- this.tlBtnFont.ToolTipText = "Font";
- //
- // tlBtnColor
- //
- this.tlBtnColor.ImageIndex = 24;
- this.tlBtnColor.ToolTipText = "Color";
- //
- // tlBtnPenWidth
- //
- this.tlBtnPenWidth.DropDownMenu = this.muPenWidth;
- this.tlBtnPenWidth.ImageIndex = 37;
- this.tlBtnPenWidth.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
- this.tlBtnPenWidth.ToolTipText = "Line Width ";
- //
- // printDocument1
- //
- this.printDocument1.OriginAtMargins = true;
- this.printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_BeginPrint);
- this.printDocument1.EndPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_EndPrint);
- this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
- //
- // printPreviewDialog1
- //
- this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
- this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
- this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
- this.printPreviewDialog1.Document = this.printDocument1;
- this.printPreviewDialog1.Enabled = true;
- this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
- this.printPreviewDialog1.Location = new System.Drawing.Point(22, 22);
- this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
- this.printPreviewDialog1.Name = "printPreviewDialog1";
- this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
- this.printPreviewDialog1.Visible = false;
- this.printPreviewDialog1.Paint += new System.Windows.Forms.PaintEventHandler(this.printPreviewDialog1_Paint);
- //
- // pageSetupDialog1
- //
- this.pageSetupDialog1.Document = this.printDocument1;
- this.pageSetupDialog1.MinMargins = new System.Drawing.Printing.Margins(0, 20, 0, 20);
- //
- // GE
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(591, 432);
- this.Controls.Add(this.mainView);
- this.Controls.Add(this.GE_toolBar1);
- this.Controls.Add(this.GE_statusBar);
- this.Controls.Add(this.GE_toolBar);
- this.Menu = this.mainMenu1;
- this.Name = "GE";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Graphic Editor";
- this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
- this.Closing += new System.ComponentModel.CancelEventHandler(this.GE_Closing);
- this.Load += new System.EventHandler(this.GE_Load);
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelTip)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelFont)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelViewScale)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.sbPanelMousePos)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new GE());
- }
-
- /// <summary>
- /// Initial draw tool types
- /// </summary>
- private void InitGraDrawTool()
- {
- //Get the instance of GraDrawToolMgr
- GraDrawToolMgr drawToolMgr = GraDrawToolMgr.Instance;
-
- //Add Select draw tool type into GraDrawToolMgr
- SelectDrawTool selectTool = SelectDrawTool.Instance;
- selectTool.TblBtn = this.tlBtnSelect;
- selectTool.StateChanged +=new EventHandler(selectTool_StateChanged);
- this.selectTool_StateChanged(selectTool,EventArgs.Empty);
- GraDrawToolMgr.Instance.AddDrawTool(selectTool);
- //Add line draw tool type into GraDrawToolMgr
- LineDrawTool lineTool = new LineDrawTool();
- lineTool.TblBtn = this.tlBtnLine;
- GraDrawToolMgr.Instance.AddDrawTool(lineTool);
- //Add lines draw tool type into GraDrawToolMgr
- LinesDrawTool linesTool = new LinesDrawTool();
- linesTool.TblBtn = this.tlBtnLines;
- GraDrawToolMgr.Instance.AddDrawTool(linesTool);
- //Add freehand draw tool type into GraDrawToolMgr
- FreehandDrawTool freehandTool = new FreehandDrawTool();
- freehandTool.TblBtn = this.tlBtnFreehand;
- GraDrawToolMgr.Instance.AddDrawTool(freehandTool);
- //Add erase draw tool type into GraDrawToolMgr
- EraseDrawTool eraseTool = new EraseDrawTool();
- eraseTool.TblBtn = this.tlBtnErase;
- GraDrawToolMgr.Instance.AddDrawTool(eraseTool);
- //Add frame rectangle draw tool type into GraDrawToolMgr
- FrameRectDrawTool frameRectTool = new FrameRectDrawTool();
- frameRectTool.TblBtn = this.tlBtnFrameRect;
- GraDrawToolMgr.Instance.AddDrawTool(frameRectTool);
- //Add solid rectangle draw tool type into GraDrawToolMgr
- FillRectDrawTool fillRectTool = new FillRectDrawTool();
- fillRectTool.TblBtn = this.tlBtnFillRect;
- GraDrawToolMgr.Instance.AddDrawTool(fillRectTool);
- //Add frame ellipse draw tool type into GraDrawToolMgr
- FrameEllipseDrawTool frameEllipseTool = new FrameEllipseDrawTool();
- frameEllipseTool.TblBtn = this.tlBtnFrameEllipse;
- GraDrawToolMgr.Instance.AddDrawTool(frameEllipseTool);
- //Add solid ellipse draw tool type into GraDrawToolMgr
- FillEllipseDrawTool fillEllipseTool = new FillEllipseDrawTool();
- fillEllipseTool.TblBtn = this.tlBtnFillEllipse;
- GraDrawToolMgr.Instance.AddDrawTool(fillEllipseTool);
- //Add insert image draw tool type into GraDrawToolMgr
- ImageDrawTool imageDrawTool = new ImageDrawTool();
- imageDrawTool.TblBtn = this.tlBtnImage;
- GraDrawToolMgr.Instance.AddDrawTool(imageDrawTool);
- //Add insert text draw tool type into GraDrawToolMgr
- TextDrawTool textDrawTool = TextDrawTool.Instance;
- textDrawTool.TblBtn = this.tlBtnText;
- GraDrawToolMgr.Instance.AddDrawTool(textDrawTool);
- }
- private void GE_toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)//Toolbar button click events
- {
-
- ToolBarButton b = e.Button;//clicked Toolbar button
- if(b != this.tlBtnText)
- TextDrawTool.Instance.EndTextEditing(true);
-
- if(b == this.tlBtnLine)//Line button is clicked
- tlBtnLine_Click();
- else if(b == this.tlBtnLines)//Lines button is clicked
- tlBtnLines_Click();
- else if(b == this.tlBtnFreehand)//Freehand button is clicked
- tlBtnFreehand_Click();
- else if(b == this.tlBtnFrameRect)//Frame rectangle button is clicked
- tlBtnFrameRect_Click();
- else if(b == this.tlBtnFillRect)//Solid rectangle button is clicked
- tlBtnFillRect_Click();
- else if(b == this.tlBtnFrameEllipse)//Frame ellipse button is clicked
- tlBtnFrameEllipse_Click();
- else if(b == this.tlBtnFillEllipse)//Solid ellipse button is clicked
- tlBtnFillEllipse_Click();
- else if(b == this.tlBtnZoomIn)//Zoom in button is clicked
- tlBtnZoomIn_Click();
- else if(b == this.tlBtnZoomOut)//Zoom out button is clicked
- tlBtnZoomOut_Click();
- else if(b == this.tlBtnZoomResume)//Zoom resume button is clicked
- tlBtnZoomResume_Click();
- else if(b == this.tlBtnImage)//Zoom resume button is clicked
- tlBtnImage_Click();
- else if(b == this.tlBtnText)//Zoom resume button is clicked
- tlBtnText_Click();
- else if(b == this.tlBtnErase) // erase button is clicked
- tlBtnErase_Click();
-
- }
- private void tlBtnFont_Click()
- {
- FontDialog dlg = new FontDialog(); //instantiating a new fontdialog box
- dlg.Font = DrawEnvMgr.Instance.Font;
- if(DialogResult.OK == dlg.ShowDialog(this))
- {
- DrawEnvMgr.Instance.Font = dlg.Font; // assigning the font selected by the user to DrawEnvMgr.Instance.Font
- UpdateFontPanel();
- }
- }
- private void UpdateFontPanel()
- {
- Font f = DrawEnvMgr.Instance.Font;
- string info = string.Format("{0} -- {1}",f.Name,f.Size);
- this.sbPanelFont.Text = info;
- }
- private MenuItem selectedPenWidthMenuItem;
- private void InitPenWidthToolBarButton()
- {
- MenuItem[] items = new MenuItem[16];//6
- for(int i=0; i< items.Length; i++)
- {
- items[i] = new MenuItem(i.ToString());//
- items[i].MeasureItem += new MeasureItemEventHandler(GE_MeasureItem);
- items[i].DrawItem +=new DrawItemEventHandler(PenWidthMenu_DrawItem);
- items[i].Click +=new EventHandler(PenWidthMenu_Click);
- items[i].OwnerDraw = true;
- }
- this.muPenWidth.MenuItems.AddRange(items);
- this.selectedPenWidthMenuItem = items[0];
- this.selectedPenWidthMenuItem.Checked = true;
- }
- private void GE_MeasureItem(object sender, MeasureItemEventArgs e)
- {
- e.ItemHeight = 20;
- e.ItemWidth = 80;//(int)stringSize.Width;
- }
- /// <summary>
- /// OwnerDraw PenWidth toolBar button menu
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PenWidthMenu_DrawItem(object sender, DrawItemEventArgs e)
- {
- Point pt1 = new Point(e.Bounds.X+6,e.Bounds.Y+e.Bounds.Height/2);
- Point pt2 = new Point(e.Bounds.Right-6,pt1.Y);
- MenuItem item = sender as MenuItem;
- using(Pen p = new Pen(Color.Black,item.Index+1))
- {
- e.Graphics.DrawLine(p,pt1,pt2);
- }
- if(item.Checked)
- {
- Rectangle r = e.Bounds;
- r.Inflate(-4,0);
- e.Graphics.DrawRectangle(Pens.Red,r);
-
- }
- }
- private void PenWidthMenu_Click(object sender, EventArgs e)
- {
- MenuItem item = sender as MenuItem;
- if(item == this.selectedPenWidthMenuItem)
- return;
- this.selectedPenWidthMenuItem.Checked = false;
- this.selectedPenWidthMenuItem = item;
- this.selectedPenWidthMenuItem.Checked = true;
- DrawEnvMgr.Instance.PenWidth = item.Index +1;
- }
-
- //Assigns an image to the button from the image list
- private void UpdateColorBtnImage(Color color)
- {
- int imageIndex = tlBtnColor.ImageIndex;
- Image image = this.GE_imageList.Images[imageIndex];
- using(Graphics g = Graphics.FromImage(image))
- {
- using(SolidBrush b = new SolidBrush(color))
- {
- g.FillRectangle(b,new Rectangle(2,11,12,4));
- }
- }
- this.GE_imageList.Images[imageIndex]=image;
- tlBtnColor.ImageIndex = 0;
- tlBtnColor.ImageIndex = imageIndex;
- }
-
- // Shows the color dialog box and gets the color selection of the user
- private void tlBtnColor_Click()
- {
- ColorDialog dlg = new ColorDialog(); // instantiating new color dialog box
- dlg.Color = DrawEnvMgr.Instance.Color; //assigning the DrawEnvMgr.Instance.Color to the dialog
- if(DialogResult.OK == dlg.ShowDialog())
- {
- DrawEnvMgr.Instance.Color = dlg.Color;
- UpdateColorBtnImage(dlg.Color); //updating the image with the color selected by user in the dialog box
- }
- }
- // select button is clicked
- private void tlBtnSelect_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Select);//Set SelectDrawTool as active
- }
- // line button is clicked
- private void tlBtnLine_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Line);//Set LineDrawTool as active
- }
- // lines button is clicked
- private void tlBtnLines_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Lines);//Set LineDrawTool as active
- }
- // freehand button is clicked
- private void tlBtnFreehand_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Freehand);//Set FreehandDrawTool as active
- }
- // erase button is clicked
- private void tlBtnErase_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Erase);//Set SelectDrawTool as active
- }
- // frame rectangle button is clicked
- private void tlBtnFrameRect_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FrameRect);//Set FrameRectDrawTool as active
- }
- // solid button is clicked
- private void tlBtnFillRect_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FillRect);//Set FillRectDrawTool as active
- }
- // frame ellipse button is clicked
- private void tlBtnFrameEllipse_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FrameEllipse);//Set FrameEllipseDrawTool as active
- }
- // solid ellipse button is clicked
- private void tlBtnFillEllipse_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FillEllipse);//Set FillEllipseDrawTool as active
- }
-
- // sets the insert image as the active tool
- private void tlBtnImage_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Image);//Set FillEllipseDrawTool as active
- }
-
- // sets the insert text as the active tool
- private void tlBtnText_Click()
- {
- GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Text);//Set FillEllipseDrawTool as active
- }
- // cut button is clicked
- private void tlBtnCut_Click( )
- {
- SelectDrawTool.Instance.Cut();//cut operation
- }
- // move button is clicked
- private void tlBtnMove_Click( )
- {
- // to be added
- }
-
-
- // zoom in button is clicked
- private void tlBtnZoomIn_Click()
- {
- this.mainView.ScaleView(1.2f);//Zoom in 1.2 times
- OnViewZoomChanged();
- }
- // zoom out button is clicked
- private void tlBtnZoomOut_Click()
- {
- this.mainView.ScaleView(0.8f);//Zoom out 0.8 time
- OnViewZoomChanged();
-
- }
- private void OnViewZoomChanged()
- {
- float scale = this.mainView.ViewMatrix.Elements[0];
- string text = scale.ToString("p0");
- this.sbPanelViewScale.Text = text;
- }
- // zoom resume button is clicked
- private void tlBtnZoomResume_Click()
- {
- this.mainView.ResetScale();//Resume to original size
- OnViewZoomChanged();
- }
- // copy button is clicked
- private void tlBtnCopy_Click( )
- {
- SelectDrawTool.Instance.Copy();
- }
- // paste button is clicked
- // private void tlBtnPaste_Click( )
- // {
- //
- // }
- // undo button is clicked
- private void tlBtnUndo_Click( )
- {
- GraEditStackMgr.Instance.Undo();//Undo operation
- if(Canvas.Instance.GraList.Count == 0)
- {
- this.tlBtnUndo.Enabled = false;
- this.menuUndo.Enabled = false;
- }
- if(GraEditStackMgr.Instance.GraRedoList.Count > 0)
- {
- this.tlBtnRedo.Enabled = true;
- this.menuRedo.Enabled = true;
- }
- }
- // redo button is clicked
- private void tlBtnRedo_Click( )
- {
- GraEditStackMgr.Instance.Redo();//Redo operation
- if(GraEditStackMgr.Instance.GraRedoList.Count == 0)
- {
- this.tlBtnRedo.Enabled = false;
- this.menuRedo.Enabled = false;
- }
- if(Canvas.Instance.GraList.Count > 0)
- {
- this.tlBtnUndo.Enabled = true;
- this.menuUndo.Enabled = true;
- }
- }
- private void InitEditStackMgr()
- {
- this.tlBtnUndo.Enabled = false;
- this.tlBtnRedo.Enabled = false;
- this.menuRedo.Enabled = false;
- this.menuUndo.Enabled = false;
- GraEditStackMgr.Instance.Clear();
- GraDrawTool tool = GraDrawToolMgr.Instance.ActiveDrawTool;
- if(tool != null)
- tool.IsActive = false;
- }
- // new file button is clicked
- private void tlBtnNew_Click()
- {
- if(!this.SaveFile(true))
- return;
- Canvas.Instance.Close();
- NewCanvasCfg dlg = new NewCanvasCfg();
- dlg.Text ="Create New Canvas";
- if(DialogResult.OK != dlg.ShowDialog())
- return;
- SelectDrawTool.Instance.IsActive = false;
- Canvas.Instance.Init(null,dlg.CanvasSize,dlg.CanvasBackColor);
- InitEditStackMgr();
- Canvas.Instance.Update();
- }
- // open file button is clicked
- private void tlBtnOpen_Click()
- {
- if(!Canvas.Instance.Open())
- return;
- SelectDrawTool.Instance.IsActive = false;
- InitEditStackMgr();
-
- }
-
- // save file button is clicked
- private void tlBtnSave_Click()
- {
-
- this.SaveFile(false);
- }
- private bool SaveFile(bool isNeedWarning)
- {
- if(!Canvas.Instance.IsModified)
- return true;
- if(isNeedWarning)
- {
- DialogResult r = MessageBox.Show(this,"The file has been modified,do you need save it?","Warning",
- MessageBoxButtons.YesNoCancel);
- if( r == DialogResult.Cancel)
- return false;
- if(r == DialogResult.No)
- return true;
- }
- SaveFileDialog dlg = new SaveFileDialog();
- dlg.Filter = this.fileFilter;
- dlg.RestoreDirectory = true ;
- if(Canvas.Instance.Name == null ||
- Canvas.Instance.Name.Length == 0)
- {
- dlg.FilterIndex = 1 ;
- if(dlg.ShowDialog() == DialogResult.OK)
- {
- Canvas.Instance.Name = dlg.FileName;
- this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
- }
- else
- return false;
- }
- else if(!Canvas.Instance.IsSavedOnce)
- {
- dlg.FileName = Canvas.Instance.Name;
- dlg.FilterIndex = GetFilterIndexByFileName(dlg.FileName);
- if(dlg.ShowDialog() == DialogResult.OK)
- {
- Canvas.Instance.Name = dlg.FileName;
- this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
- }
- else
- return false;
- }
- Canvas.Instance.Save();
- return true;
- }
-
- private string fileFilter ="Bitmap files (*.bmp)|*.bmp|Jpg files (*.jpg)|*.jpg|Gif files (*.gif)|*.gif" ;
- private int GetFilterIndexByFileName(string fileName)
- {
- string ext = Path.GetExtension(fileName);
- if(ext == ".bmp")
- return 1;
- else if(ext ==".jpg")
- return 2;
- else if(ext ==".5gif")
- return 3;
- else
- return 1;
- }
-
- // pop-up menu is clicked
- private void pasteMenuItem_Click(object sender, System.EventArgs e)
- {
-
- //Console.WriteLine("{0} {1}",pt.X,pt.Y);
- SelectDrawTool.Instance.Paste();//paste operation
- }
- //Pop-up menu
- private void contextMenu1_Popup(object sender, System.EventArgs e)
- {
- this.mainView.contextMenu1_Popup(sender,e);//Get the click item in pop-up menu
- // Point pt = Cursor.Position;
- // pt = this.PointToClient(pt);
- // SelectDrawTool.Instance.ContextMenuMousePos = pt;
- }
-
- //Main menu items
- //Exit
- private void menuExit_Click(object sender, System.EventArgs e)
- {
- //Application.Exit();
- this.Close();
- }
-
- //Undo
- private void menuUndo_Click(object sender, System.EventArgs e)
- {
- this.tlBtnUndo_Click();
- }
- //Open
- private void menuOpen_Click(object sender, System.EventArgs e)
- {
- this.tlBtnOpen_Click();
- }
- //New
- private void menuNew_Click(object sender, System.EventArgs e)
- {
- this.tlBtnNew_Click();
- }
- //Save as
- private void menuSaveAs_Click(object sender, System.EventArgs e)
- {
- SaveFileDialog dlg = new SaveFileDialog();
- dlg.Filter = this.fileFilter;
- //dlg.FilterIndex = 1 ;
- dlg.RestoreDirectory = true ;
- dlg.FileName = Canvas.Instance.Name;
- dlg.FilterIndex = GetFilterIndexByFileName(dlg.FileName);
- if(dlg.ShowDialog() == DialogResult.OK)
- {
- Canvas.Instance.Name = dlg.FileName;
- this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
- Canvas.Instance.Save();
- }
-
-
- }
- //Save
- private void menuSave_Click(object sender, System.EventArgs e)
- {
- this.tlBtnSave_Click();
- }
- //Redo
- private void menuRedo_Click(object sender, System.EventArgs e)
- {
- this.tlBtnRedo_Click();
- }
- //Copy
- private void menuCopy_Click(object sender, System.EventArgs e)
- {
- this.tlBtnCopy_Click();
- }
- //Cut
- private void menuCut_Click(object sender, System.EventArgs e)
- {
- this.tlBtnCut_Click();
- }
- // Paste
- private void menuPaste_Click(object sender, System.EventArgs e)
- {
- // this.tlBtnPaste_Click();
- }
-
- // Zoom In
- private void menuZoomIn_Click(object sender, System.EventArgs e)
- {
- this.tlBtnZoomIn_Click();
- }
- //ZoomOut
- private void menuZoomOut_Click(object sender, System.EventArgs e)
- {
- this.tlBtnZoomOut_Click();
- }
- //Resume
- private void menuResume_Click(object sender, System.EventArgs e)
- {
- this.tlBtnZoomResume_Click();
- }
- // Assigns the pen width to the DrawEnvMgr.Instance.PenWidth from the selection in the combo box
- // private void cboPenWidth_SelectedIndexChanged(object sender, EventArgs e)
- // {
- // int penWidth = (int)this.cboPenWidth.SelectedItem;
- // DrawEnvMgr.Instance.PenWidth = penWidth;
- // }
- //Gets the background color for the image from the user using Color DialogBox
- private void menuItemCanvasBackColor_Click(object sender, System.EventArgs e)
- {
- ColorDialog dlg = new ColorDialog();
- dlg.Color = Canvas.Instance.BackColor;
- if(DialogResult.OK == dlg.ShowDialog())
- {
-
- foreach(GraElement gra in Canvas.Instance.GraList)
- {
- if(gra is EraseLinesGra)
- {
- gra.PenExt.Color = dlg.Color;
- }
- if(gra is EraseRectGra)
- {
- gra.PenExt.Color = dlg.Color;
- gra.BrushExt.Color = dlg.Color;
- }
- }
- Canvas.Instance.BackColor = dlg.Color;
- }
- }
- // Shows the help Dialog box
- // private void menuHelp_Click(object sender, System.EventArgs e)
- // {
- //
- //
- // }
-
- private void GE_toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- ToolBarButton b = e.Button;//clicked Toolbar button
-
- if(b != this.tlBtnText)
- TextDrawTool.Instance.EndTextEditing(true);
- if(b == this.tlBtnNew) // new image button is clicked
- tlBtnNew_Click();
- else if(b == this.tlBtnOpen) // open an existing image button is clicked
- tlBtnOpen_Click();
- else if(b == this.tlBtnSave) // save the current image button is clicked
- tlBtnSave_Click();
- else if(b == this.tlBtnUndo)//Undo button is clicked
- tlBtnUndo_Click();
- else if(b == this.tlBtnRedo)//Redo button is clicked
- tlBtnRedo_Click();
- else if(b == this.tlBtnColor)
- tlBtnColor_Click();
- else if(b == this.tlBtnFont)
- tlBtnFont_Click();
- else if(b == this.tlBtnCut)//Cut button is clicked
- tlBtnCut_Click( );
- // else if(b == this.tlBtnMove)//Move button is clicked
- // tlBtnMove_Click( );
- else if(b == this.tlBtnCopy)//Copy button is clicked
- tlBtnCopy_Click( );
- // else if(b == this.tlBtnPaste)//Paste button is clicked
- // tlBtnPaste_Click( );
-
- else if(b == this.tlBtnSelect)//Select button is clicked
- tlBtnSelect_Click();
- }
- private void menuView_Popup(object sender, System.EventArgs e)
- {
- menuToolbar.MenuItems.Clear();
- foreach (Control c in _toolBarManager.GetControls())
- {
- ToolBarDockHolder holder = _toolBarManager.GetHolder(c);
- MenuItem mi = new MenuItem(holder.ToolbarTitle, new EventHandler(this.menuToolbar_Click));
- mi.Checked = holder.Visible;
- menuToolbar.MenuItems.Add(mi);
- }
- }
-
- private void GE_Load(object sender, System.EventArgs e)
- {
-
- }
- private void menuToolbar_Click(object sender, System.EventArgs e)
- {
- MenuItem mi = sender as MenuItem;
- ToolBarDockHolder holder = _toolBarManager.GetHolder(mi.Text);
- _toolBarManager.ShowControl(holder.Control, !holder.Control.Visible);
- }
- private void menuColorToolbox_Click(object sender, System.EventArgs e)
- {
- tlBtnColor_Click();
- }
- private void menuColorSettings_Click(object sender, System.EventArgs e)
- {
- tlBtnColor_Click();
- }
- private void menuToolbar_Click_1(object sender, System.EventArgs e)
- {
- MenuItem mi = sender as MenuItem;
- ToolBarDockHolder holder = _toolBarManager.GetHolder(mi.Text);
- _toolBarManager.ShowControl(holder.Control, !holder.Control.Visible);
- }
- private void menuAboutGE_Click(object sender, System.EventArgs e)
- {
- AboutDialog dlg = new AboutDialog();
- dlg.ShowDialog();
- }
- private void printPreviewDialog1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
- {
-
-
- }
- private void menuPrintPreview_Click(object sender, System.EventArgs e)
- {
- this.printPreviewDialog1.ShowDialog();
- }
- private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
- {
-
- }
- private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
- {
-
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- //e.p
- try
- {
-
- Graphics g = e.Graphics;
- Region r = new Region(new Rectangle(new Point(0,0),Canvas.Instance.Size));
- Region old = g.Clip;
- g.Clip = r;
- ArrayList list = Canvas.Instance.GraList;
- foreach(GraElement gra in list)
- {
- if(gra is EraseLinesGra)
- {
- gra.PenExt.Color = Color.White;
- gra.Draw(g);
- gra.PenExt.Color = Canvas.Instance.BackColor;
- }
- else if(gra is EraseRectGra)
- {
- gra.PenExt.Color = Color.White;
- gra.BrushExt.Color = Color.White;
- gra.Draw(g);
- gra.PenExt.Color = Canvas.Instance.BackColor;
- gra.BrushExt.Color = Canvas.Instance.BackColor;
- }
- else
- gra.Draw(g);
- }
- g.Clip = old;
- }
- catch(Exception ex)
- {
- MessageBox.Show("Error when print document - " + ex.Message);
- }
- }
- private void menuPageSetting_Click(object sender, System.EventArgs e)
- {
- try
- {
-
- this.pageSetupDialog1.ShowDialog();
- }
- catch(Exception ex)
- {
- MessageBox.Show("Error - " + ex.Message);
- }
-
- }
- private void menuItem2_Click(object sender, System.EventArgs e)
- {
-
- }
- private RecentFilesMgr recentFilesMgr;
- private void InitRecentFilesMgr()
- {
- string path = Application.StartupPath;
- string logFileName = path +"/RecentFiles.txt";
- this.recentFilesMgr = new RecentFilesMgr(logFileName);
- this.recentFilesMgr.ReadRecentFiles();
- if(this.recentFilesMgr.FilesList.Count == 0)
- return;
- MenuItem[] items = new MenuItem[this.recentFilesMgr.FilesList.Count];
- for(int i=0; i< items.Length; i++)
- {
- items[i] = new MenuItem(this.recentFilesMgr.FilesList[i] as string);
- items[i].Click +=new EventHandler(RecentFileMenuItem_Click);
- }
- this.menuRecentFiles.MenuItems.AddRange(items);
-
- }
- private void RecentFileMenuItem_Click(object sender, EventArgs e)
- {
- MenuItem item = sender as MenuItem;
- if(!Canvas.Instance.OpenFile(item.Text))
- return;
- InitEditStackMgr();
- }
- private void GE_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- DialogResult r = MessageBox.Show(this,"Do you want exit?","Warning",MessageBoxButtons.OKCancel);
- if(r == DialogResult.Cancel)
- {
- e.Cancel = true;
- return;
- }
- this.tlBtnSave_Click();
- Canvas.Instance.Close();
- this.recentFilesMgr.SaveRecentFiles();
- }
- private void menuStatusBar_Click(object sender, System.EventArgs e)
- {
- MenuItem item = sender as MenuItem;
- item.Checked = !item.Checked;
- this.GE_statusBar.Visible = item.Checked;
- }
- private class RecentFilesMgr
- {
- public RecentFilesMgr(string logFileName)
- {
- this.filesList = new ArrayList();
- this.logFileName = logFileName;
- }
- private ArrayList filesList;
- public ArrayList FilesList
- {
- get { return filesList; }
- }
- private string logFileName;
-
- public void ReadRecentFiles()
- {
- FileInfo fi = new FileInfo(logFileName);
- if(!fi.Exists)
- return;
- StreamReader s = fi.OpenText();
- string line = null;
- while(( line = s.ReadLine()) != null)
- {
- FileInfo f = new FileInfo(line);
- if(!f.Exists)
- continue;
-
- filesList.Add(line);
- if(filesList.Count == 10)
- break;
- }
-
- }
- public void SaveRecentFiles( )
- {
- using (StreamWriter sw = new StreamWriter(this.logFileName,false))
- {
- foreach(string line in this.filesList)
- {
- sw.WriteLine(line);
- }
- }
-
- }
- }
- private void GraDrawTool_ActiveStateChanged(object sender, EventArgs e)
- {
- GraDrawTool drawTool = sender as GraDrawTool;
- this.sbPanelTip.Text = drawTool.Tip;
- }
- private void mainView_MouseMove(object sender, MouseEventArgs e)
- {
- Point pos = new Point(e.X,e.Y);//Temporary end point
- pos = GraDrawTool.GetRoundPoint(pos);//Round the end point. The min mouse movement distance is 6.
- string text =string.Format("X= {0} Y= {1}",pos.X,pos.Y);
- this.sbPanelMousePos.Text = text;
- }
- private void canvas_Modified(object sender, EventArgs e)
- {
- Canvas c = Canvas.Instance;
- string title = "Graphic Editor -- ";
- if(c.Name != null && c.Name.Length >0)
- title += c.Name;
- else
- title += "Unnamed.bmp";
- if(c.IsModified)
- title +="*";
- this.Text = title;
- if(Canvas.Instance.GraList.Count > 0)
- {
- this.tlBtnUndo.Enabled = true;
- this.menuUndo.Enabled = true;
- }
- }
- private void selectTool_StateChanged(object sender, EventArgs e)
- {
- SelectDrawTool tool = sender as SelectDrawTool;
- if(tool.SelectRectGra != null)
- {
- this.tlBtnCut.Enabled = true;
- this.tlBtnCopy.Enabled = true;
- this.menuCopy.Enabled = true;
- this.menuCut.Enabled = true;
- }
- else
- {
- this.tlBtnCut.Enabled = false;
- this.tlBtnCopy.Enabled = false;
- this.menuCopy.Enabled = false;
- this.menuCut.Enabled = false;
- }
- if(tool.CopyImage != null)
- {
- this.pasteMenuItem.Enabled = true;
- //this.menuPaste.Enabled = true;
- }
- else
- {
- this.pasteMenuItem.Enabled = false;
- //this.menuPaste.Enabled = false;
- }
- }
- private void menuItemCanvasSize_Click(object sender, System.EventArgs e)
- {
- NewCanvasCfg dlg = new NewCanvasCfg();
- dlg.Text ="Change Canvas Size";
- dlg.CanvasSize = Canvas.Instance.Size;
- if(DialogResult.OK == dlg.ShowDialog())
- {
- Canvas.Instance.Size = dlg.CanvasSize;
- Canvas.Instance.Update();
- }
- }
- private void menuPrint_Click(object sender, System.EventArgs e)
- {
- try
- {
- this.printDocument1.Print();
- }
- catch(Exception ex)
- {
- MessageBox.Show("Print file error - " + ex.Message);
- }
- }
- private void menuHelpIndex_Click(object sender, System.EventArgs e)
- {
- try
- {
- string s = Application.ExecutablePath;
- s = s.Replace("GE.exe","help.chm");
- Process.Start(s);
- }
- catch(Exception e1)
- {
- MessageBox.Show(e1.Message);
- }
-
- }
- private void mainView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
- {
-
- }
- }
- /// <summary>
- /// All the drawing in Graphical Editor is done on the canvas.
- /// Canvas class is used to define the drawing area.
- /// </summary>
- public class Canvas
- {
- //Construct graList to save the drawing actions
- protected Canvas()
- {
- this.graList = new ArrayList(); // define an arraylist with name gralist for saving all the drawing actions
- }
- //Initialize the canvas. Set name,size and background color of canvas
- public void Init(string name, Size size,Color backColor)
-
- {
- this.name = name;//Set name of canvas
- this.Size = size;//Set size of canvas
- this.backColor = backColor;//Set background color of canvas
- this.graList.Clear();//Clear all the elements in graList
- //this.mainView.AutoScrollMinSize = this.Size;//this.Size;//Set the size of mainView as canvas size
-
- this.isSavedOnce = false;
- this.IsModified = false;
-
- }
- private static Canvas _single;
- public static Canvas Instance
- {
- //Get canvas instance
- get
- {
- if( _single == null)
- _single = new Canvas();
- return _single;
- }
- }
- public event EventHandler Modified;
- protected void OnModified()
- {
- if(Modified != null)
- Modified(this,EventArgs.Empty);
- }
- //Dirty flag
- private bool isModified;
- public bool IsModified
- {
- get { return this.isModified; }
- set
- {
- this.isModified = value;
- OnModified();
- }
- }
- private bool isSavedOnce;
- public bool IsSavedOnce
- {
- get { return this.isSavedOnce; }
- set { this.isSavedOnce = value;}
- }
- private MainView mainView;//private Mainview variable of canvas
- public MainView MainView
- {
- get { return mainView; }
- set { mainView = value;}
- }
-
-
- public void Update()//Refresh canvas
- {
- this.mainView.UpdateView();
- }
- private string name;//canvas name
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- private Size size;//canvas size
- public Size Size
- {
- get { return size; }
- set
- {
- size = value;
- this.mainView.AutoScrollMinSize = this.size;//this.Size;//Set the size of mainView as canvas size
- }
- }
- private Color backColor;//canvas color i.e. background color of the image
- public Color BackColor
- {
- get { return backColor; }
- set
- {
- backColor = value;
- this.Update();
- }
- }
- private ArrayList graList;//Save drawing action on canvas
- public ArrayList GraList
- {
- get { return graList; }
- }
- public void AddGra(GraElement gra)
- {
- this.graList.Add(gra);
- this.IsModified = true;
- this.Update();
- }
- public void DelGra(GraElement gra)
- {
- this.graList.Remove(gra);
- this.IsModified = true;
- this.Update();
- }
- //Draw function of canvas
- public void Draw(Graphics g)
- {
- foreach(GraElement gra in graList)//Draw all the element in the graList
- gra.Draw(g);
- }
- public bool Open()
- {
- OpenFileDialog dlg = new OpenFileDialog(); // new open dialog box is instantiated
- dlg.Filter = "Image files (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif" ;
- dlg.FilterIndex = 1 ;
- dlg.RestoreDirectory = true ;
- bool bRtn = false;
- if(dlg.ShowDialog() == DialogResult.OK)
- {
- try
- {
- bRtn = this.OpenFile(dlg.FileName);
- }
- catch(Exception ex)
- {
- MessageBox.Show("Open file error - " + ex.Message);
- }
- }
- return bRtn;
- }
- private FileStream canvasStream;
- public bool OpenFile(string fileName)
- {
- FileInfo fi = new FileInfo(fileName);
- if(!fi.Exists)
- {
- MessageBox.Show("Can't find this file!","Open File");
- return false;
- }
-
- try
- {
- canvasStream = File.Open(fileName,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
- }
- catch(Exception ex)
- {
- MessageBox.Show("Open File Error - " + ex.Message);
- }
- Bitmap bmp = new Bitmap(canvasStream);
- //fs.Close();
- if(bmp != null)
- {
- Canvas.Instance.Init(fileName,bmp.Size,Color.White);
- ImageGra imageGra = new ImageGra(bmp,new Rectangle(new Point(0,0),bmp.Size));
- Canvas.Instance.GraList.Add(imageGra);//Add to GraList
- Canvas.Instance.Update();//Update canvas
- }
- return true;
- }
- private ImageFormat GetImageFormatByFileName(string fileName)
- {
- string ext = Path.GetExtension(fileName);
- ImageFormat format = ImageFormat.Bmp;
- switch(ext)
- {
- case ".jpg":
- format =ImageFormat.Jpeg;
- break;
- case ".gif":
- format = ImageFormat.Gif;
- break;
- default:
- format = ImageFormat.Bmp;
- break;
- }
- return format;
- }
- public void Save()
- {
- //if(this.canvasStream == null)
- // return;
- if(this.name == null ||
- this.name.Length == 0)
- {
- MessageBox.Show("Invalid file name!","Warning");
- return;
- }
- Size s = Canvas.Instance.Size;
- Bitmap bmp = new Bitmap(s.Width,s.Height);
- Graphics gBmp = Graphics.FromImage(bmp);
- gBmp.Clear(Canvas.Instance.BackColor);
- this.Draw(gBmp);
- try
- {
- if(this.canvasStream != null)
- this.canvasStream.Close();
- ImageFormat format = GetImageFormatByFileName(Canvas.Instance.Name);
- bmp.Save(Canvas.Instance.Name,format);
- bmp.Dispose();
- this.IsModified = false;
- this.IsSavedOnce = true;
- this.canvasStream = File.Open(this.name,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
- }
- catch(Exception ex)
- {
- MessageBox.Show("Save file error - " + ex.Message);
- }
-
- }
- public bool Close()
- {
- if(canvasStream != null)
- {
- canvasStream.Close();
- canvasStream = null;
- }
- return true;
- }
- }
- //Redo & Undo operation
- public class GraEditStackMgr
- {
-
- private GraEditStackMgr()//construct a redo list
- {
- this.graRedoList = new ArrayList();
- }
- private static GraEditStackMgr instance;
- public static GraEditStackMgr Instance
- {
- get
- {
- if(instance == null)
- instance = new GraEditStackMgr();
- return instance;
- }
- }
- private ArrayList graRedoList;//Redo list
- public ArrayList GraRedoList
- {
- get { return graRedoList;}
- }
- public void Clear()
- {
- this.graRedoList.Clear();
- }
- //Redo operation
- public void Redo()
- {
- if(this.graRedoList.Count == 0)//no undo happen
- return;
- int lastIndex = this.graRedoList.Count -1;//Get the last undo action
- //Save last undo action to graLast
- GraElement graLast = this.graRedoList[lastIndex] as GraElement;
- this.graRedoList.RemoveAt(lastIndex);//Remove the last undo action from redo list
- //Canvas.Instance.GraList.Add(graLast);//Save the last undo action to GraList
- //Canvas.Instance.Update();//Update canvas
- Canvas.Instance.AddGra(graLast);
- }
- //Undo operation
- public void Undo()
- {
- ArrayList graList = Canvas.Instance.GraList;//Get the GraList of Canvas
- if(graList.Count == 0)//No drawing action happen
- return;
- int lastIndex = graList.Count -1;//Last drawing action position in graList
-
- //Save the last drawing action to graLast
- GraElement graLast = graList[lastIndex] as GraElement;
- graList.RemoveAt(lastIndex);//Remove the last drawing action
- this.graRedoList.Add(graLast);//Add the last drawing action to redo list
- Canvas.Instance.Update();//Update canvas
- Canvas.Instance.IsModified = true;
- }
-
- }
- }
|