public static int Main2(string[] args) { DrawingObject[] dObj = new DrawingObject[4]; dObj[0] = new Line(); dObj[1] = new Circle(); dObj[2] = new Square(); dObj[3] = new DrawingObject(); foreach (DrawingObject drawObj in dObj) { drawObj.Draw(); } Console.ReadKey(); return 0; }
public static int Main( ) { DrawingObject[] dObj = new DrawingObject[4]; dObj[0] = new Line(); dObj[1] = new Circle(); dObj[2] = new Square(); dObj[3] = new DrawingObject(); foreach (DrawingObject drawObj in dObj) { drawObj.Draw(); } return 0; }
public void AddDrawingObject(DrawingObject obj) { if (drawing_objects == null) drawing_objects = new List <DrawingObject> (); drawing_objects.Add (obj); }
void DrawObjects(CairoContextEx gr, DrawingObject [] drawing_objects, int? option) { if (drawing_objects == null) return; foreach (DrawingObject draw_object in drawing_objects) { if (draw_object is OptionDrawingObject) continue; if (draw_object is TextDrawingObject) { string text; TextDrawingObject draw_string = draw_object as TextDrawingObject; text = CatalogGetString (draw_string.Text); text = ReplaceVariables (text); switch (draw_string.Size) { case TextDrawingObject.Sizes.Small: gr.SetPangoFontSize (0.018); break; case TextDrawingObject.Sizes.Medium: gr.SetPangoNormalFontSize (); // 0.022 break; case TextDrawingObject.Sizes.Large: gr.SetPangoLargeFontSize (); // 0.0325 break; case TextDrawingObject.Sizes.XLarge: gr.SetPangoFontSize (0.06); break; case TextDrawingObject.Sizes.XXLarge: gr.SetPangoFontSize (0.08); break; default: throw new InvalidOperationException ("Invalid value"); } if (draw_string.Centered) { gr.DrawTextCentered (draw_string.X, draw_string.Y, text); } else { gr.MoveTo (draw_string.X, draw_string.Y); if (option == null) gr.ShowPangoText (text); else gr.ShowPangoText (GetOptionPrefix (text, (int) option)); gr.Stroke (); } } else if (draw_object is ImageDrawingObject) { ImageDrawingObject image = draw_object as ImageDrawingObject; if (String.IsNullOrEmpty (image.Filename) == false) { string dir; IConfiguration config; config = ServiceLocator.Instance.GetService <IConfiguration> (); dir = config.Get <string> (ConfigurationKeys.GamesGraphics); gr.DrawImageFromFile (Path.Combine (dir, image.Filename), image.X, image.Y, image.Width, image.Height); } } } }
public void CreateDrawingObjects(DrawingObject [] drawing_objects) { OptionDrawingObject option; double x = 0, y = 0, width = 0, height = 0; bool first = true; int randomized_options = 0; if (drawing_objects == null) return; // Calculate the size of container from the options and count the number of random options foreach (DrawingObject draw_object in drawing_objects) { option = draw_object as OptionDrawingObject; if (option == null) continue; if (option.RandomizedOrder) randomized_options++; if (first == true) { x = option.X; y = option.Y; width = option.Width; height = option.Height; first = false; continue; } if (option.X < x) x = option.X; if (option.Y < y) y = option.Y; if (option.X + option.Width > width) width = option.X + option.Width; if (option.Y + option.Height > height) height = option.Y + option.Height; } if (first == true) return; RandomizeOptions (drawing_objects, randomized_options); Container container = new Container (x, y, width - x, height - y); game_xml.AddWidget (container); if (Options == null) Options = new List <OptionDrawingObject> (); // Create drawing widgets objects int idx = 0; foreach (DrawingObject draw_object in drawing_objects) { option = draw_object as OptionDrawingObject; if (option == null) continue; DrawableArea drawable_area = new DrawableArea (option.Width, option.Height); drawable_area.X = option.X; drawable_area.Y = option.Y; // + i * 0.15; container.AddChild (drawable_area); drawable_area.Data = idx; drawable_area.DataEx = game_xml.Answer.GetMultiOption (idx); Options.Add (option); idx++; drawable_area.DrawEventHandler += DrawOption; } }
public override void Select(DrawingObject obj) { obj.ChangeState(StaticState.GetInstance()); }
void RandomizeOptions(DrawingObject [] drawing_objects, int randomized_options) { OptionDrawingObject option; // Randomize the order of the options if (randomized_options > 0) { OptionDrawingObject [] originals; ArrayListIndicesRandom random_indices; int index = 0; random_indices = new ArrayListIndicesRandom (randomized_options); originals = new OptionDrawingObject [randomized_options]; random_indices.Initialize (); // Backup originals for (int i = 0; i < drawing_objects.Length; i++) { option = drawing_objects[i] as OptionDrawingObject; if (option == null) continue; originals[index] = option.Copy (); index++; } // Swap index = 0; for (int i = 0; i < drawing_objects.Length; i++) { option = drawing_objects[i] as OptionDrawingObject; if (option == null) continue; option.CopyRandomizedProperties (originals [random_indices [index]]); index++; } } }
public void removeComponent(DrawingObject child) { this.listChildObject.Remove(child); child.parentRectangle = null; }
public override void Draw(DrawingObject obj) { obj.RenderOnPreview(); }
public void addComponent(DrawingObject child) { this.listChildObject.Add(child); child.parentRectangle = this; }
public Tower(int x, int y, int z) { DrawingObject side1 = new DrawingObject() { Matrix = new int[, ] { { 0, -14, 0, 1 }, // Первая сторона { 0, 10, 0, 1 }, { 0, 10, 0, 1 }, { 2, 10, 0, 1 }, { 2, 10, 0, 1 }, { 2, 8, 0, 1 }, { 2, 8, 0, 1 }, { 6, 8, 0, 1 }, { 6, 8, 0, 1 }, { 6, 10, 0, 1 }, { 6, 10, 0, 1 }, { 8, 10, 0, 1 }, { 8, 10, 0, 1 }, { 8, -14, 0, 1 }, { 8, -14, 0, 1 }, { 0, -14, 0, 1 }, } }; DrawingObject side2 = new DrawingObject() { Matrix = new int[, ] { { 0, -14, 0, 1 }, // Вторая сторона { 0, -14, 8, 1 }, { 0, -14, 8, 1 }, { 0, 10, 8, 1 }, { 0, 10, 8, 1 }, { 0, 10, 6, 1 }, { 0, 10, 6, 1 }, { 0, 8, 6, 1 }, { 0, 8, 6, 1 }, { 0, 8, 2, 1 }, { 0, 8, 2, 1 }, { 0, 10, 2, 1 }, { 0, 10, 2, 1 }, { 0, 10, 0, 1 }, } }; DrawingObject side3 = new DrawingObject() { Matrix = new int[, ] { { 8, -14, 0, 1 }, // Третья сторона { 8, -14, 8, 1 }, { 8, -14, 8, 1 }, { 8, 10, 8, 1 }, { 8, 10, 8, 1 }, { 8, 10, 6, 1 }, { 8, 10, 6, 1 }, { 8, 8, 6, 1 }, { 8, 8, 6, 1 }, { 8, 8, 2, 1 }, { 8, 8, 2, 1 }, { 8, 10, 2, 1 }, { 8, 10, 2, 1 }, { 8, 10, 0, 1 }, } }; DrawingObject side4 = new DrawingObject() { Matrix = new int[, ] { { 8, -14, 8, 1 }, // Четвертая сторона { 0, -14, 8, 1 }, { 6, 10, 8, 1 }, { 6, 8, 8, 1 }, { 8, 10, 8, 1 }, { 6, 10, 8, 1 }, { 6, 8, 8, 1 }, { 2, 8, 8, 1 }, { 2, 8, 8, 1 }, { 2, 10, 8, 1 }, { 2, 10, 8, 1 }, { 0, 10, 8, 1 }, } }; DrawingObject side5a = new DrawingObject() { Matrix = new int[, ] { { 2, 10, 2, 1 }, // Блоки { 0, 10, 2, 1 }, { 2, 10, 2, 1 }, { 2, 10, 0, 1 }, } }; DrawingObject side5b = new DrawingObject() { Matrix = new int[, ] { { 2, 10, 2, 1 }, { 2, 10, 0, 1 }, { 2, 10, 2, 1 }, { 2, 8, 2, 1 }, } }; DrawingObject side5c = new DrawingObject() { Matrix = new int[, ] { { 2, 8, 2, 1 }, { 2, 8, 0, 1 }, { 2, 8, 2, 1 }, { 0, 8, 2, 1 }, } }; DrawingObject side6a = new DrawingObject() { Matrix = new int[, ] { { 2, 10, 6, 1 }, // Блоки { 0, 10, 6, 1 }, { 2, 10, 6, 1 }, { 2, 10, 8, 1 }, } }; DrawingObject side6b = new DrawingObject() { Matrix = new int[, ] { { 2, 10, 6, 1 }, { 2, 10, 8, 1 }, { 2, 10, 6, 1 }, { 2, 8, 6, 1 }, } }; DrawingObject side6c = new DrawingObject() { Matrix = new int[, ] { { 2, 8, 6, 1 }, { 2, 8, 8, 1 }, { 2, 8, 6, 1 }, { 0, 8, 6, 1 }, } }; DrawingObject side7a = new DrawingObject() { Matrix = new int[, ] { { 6, 10, 6, 1 }, // Блоки { 8, 10, 6, 1 }, { 6, 10, 6, 1 }, { 6, 10, 8, 1 }, } }; DrawingObject side7b = new DrawingObject() { Matrix = new int[, ] { { 6, 10, 6, 1 }, { 6, 10, 8, 1 }, { 6, 10, 6, 1 }, { 6, 8, 6, 1 }, } }; DrawingObject side7c = new DrawingObject() { Matrix = new int[, ] { { 6, 8, 6, 1 }, { 6, 8, 8, 1 }, { 6, 8, 6, 1 }, { 8, 8, 6, 1 }, } }; DrawingObject side8a = new DrawingObject() { Matrix = new int[, ] { { 6, 10, 2, 1 }, // Блоки { 8, 10, 2, 1 }, { 6, 10, 2, 1 }, { 6, 10, 0, 1 }, } }; DrawingObject side8b = new DrawingObject() { Matrix = new int[, ] { { 6, 10, 2, 1 }, { 6, 10, 0, 1 }, { 6, 10, 2, 1 }, { 6, 8, 2, 1 }, } }; DrawingObject side8c = new DrawingObject() { Matrix = new int[, ] { { 6, 8, 2, 1 }, { 8, 8, 2, 1 }, { 6, 8, 2, 1 }, { 6, 8, 0, 1 }, } }; drawingObjects = new DrawingObject[] { side1, side2, side3, side4, side5a, side6a, side7a, side8a, side5b, side6b, side7b, side8b, side5c, side6c, side7c, side8c, }; foreach (var item in drawingObjects) { int length = item.Matrix.GetLength(0); for (int i = 0; i < length; i++) { item.Matrix[i, 0] += x; item.Matrix[i, 1] += y; item.Matrix[i, 2] += z; } } }
/// <summary> /// Создает отрисовываемые объекты /// </summary> public Castle() { DrawingObject wall1a = new DrawingObject() { Matrix = new int[, ] { { -7, 0, 15, 1 }, { 7, 0, 15, 1 }, { 7, 0, 15, 1 }, { 7, -14, 15, 1 }, { 7, -14, 15, 1 }, { -7, -14, 15, 1 }, { -7, -14, 15, 1 }, { -7, 0, 15, 1 }, } }; DrawingObject wall1b = new DrawingObject() { Matrix = new int[, ] { { -7, 0, 14, 1 }, { 7, 0, 14, 1 }, { 7, 0, 14, 1 }, { 7, -14, 14, 1 }, { 7, -14, 14, 1 }, { -7, -14, 14, 1 }, { -7, -14, 14, 1 }, { -7, 0, 14, 1 }, } }; DrawingObject wall1c = new DrawingObject() { Matrix = new int[, ] { { -7, 0, 14, 1 }, { -7, 0, 15, 1 }, { 7, 0, 14, 1 }, { 7, 0, 15, 1 }, } }; DrawingObject wall2a = new DrawingObject() { Matrix = new int[, ] { { -7, 0, -15, 1 }, { 7, 0, -15, 1 }, { 7, 0, -15, 1 }, { 7, -14, -15, 1 }, { 7, -14, -15, 1 }, { 4, -14, -15, 1 }, { 4, -14, -15, 1 }, { 4, -4, -15, 1 }, { 4, -4, -15, 1 }, { -4, -4, -15, 1 }, { -4, -4, -15, 1 }, { -4, -14, -15, 1 }, { -4, -14, -15, 1 }, { -7, -14, -15, 1 }, { -7, -14, -15, 1 }, { -7, 0, -15, 1 }, } }; DrawingObject wall2b = new DrawingObject() { Matrix = new int[, ] { { -7, 0, -14, 1 }, { 7, 0, -14, 1 }, { 7, 0, -14, 1 }, { 7, -14, -14, 1 }, { 7, -14, -14, 1 }, { 4, -14, -14, 1 }, { 4, -14, -14, 1 }, { 4, -4, -14, 1 }, { 4, -4, -14, 1 }, { -4, -4, -14, 1 }, { -4, -4, -14, 1 }, { -4, -14, -14, 1 }, { -4, -14, -14, 1 }, { -7, -14, -14, 1 }, { -7, -14, -14, 1 }, { -7, 0, -14, 1 }, } }; DrawingObject wall2c = new DrawingObject() { Matrix = new int[, ] { { -7, 0, -14, 1 }, { -7, 0, -15, 1 }, { 7, 0, -14, 1 }, { 7, 0, -15, 1 }, } }; DrawingObject wall3a = new DrawingObject() { Matrix = new int[, ] { { -15, 0, -7, 1 }, { -15, 0, 7, 1 }, { -15, 0, 7, 1 }, { -15, -14, 7, 1 }, { -15, -14, 7, 1 }, { -15, -14, -7, 1 }, { -15, -14, -7, 1 }, { -15, 0, -7, 1 }, } }; DrawingObject wall3b = new DrawingObject() { Matrix = new int[, ] { { -14, 0, -7, 1 }, { -14, 0, 7, 1 }, { -14, 0, 7, 1 }, { -14, -14, 7, 1 }, { -14, -14, 7, 1 }, { -14, -14, -7, 1 }, { -14, -14, -7, 1 }, { -14, 0, -7, 1 }, } }; DrawingObject wall3c = new DrawingObject() { Matrix = new int[, ] { { -14, 0, -7, 1 }, { -15, 0, -7, 1 }, { -14, 0, 7, 1 }, { -15, 0, 7, 1 }, } }; DrawingObject wall4a = new DrawingObject() { Matrix = new int[, ] { { 15, 0, -7, 1 }, { 15, 0, 7, 1 }, { 15, 0, 7, 1 }, { 15, -14, 7, 1 }, { 15, -14, 7, 1 }, { 15, -14, -7, 1 }, { 15, -14, -7, 1 }, { 15, 0, -7, 1 }, } }; DrawingObject wall4b = new DrawingObject() { Matrix = new int[, ] { { 14, 0, -7, 1 }, { 14, 0, 7, 1 }, { 14, 0, 7, 1 }, { 14, -14, 7, 1 }, { 14, -14, 7, 1 }, { 14, -14, -7, 1 }, { 14, -14, -7, 1 }, { 14, 0, -7, 1 }, } }; DrawingObject wall4c = new DrawingObject() { Matrix = new int[, ] { { 14, 0, -7, 1 }, { 15, 0, -7, 1 }, { 14, 0, 7, 1 }, { 15, 0, 7, 1 }, } }; DrawingObject flag = new DrawingObject() { Matrix = new int[, ] { { 11, 8, 15, 1 }, { 11, 14, 15, 1 }, { 11, 14, 15, 1 }, { 13, 13, 15, 1 }, { 13, 13, 15, 1 }, { 11, 12, 15, 1 } } }; drawingObjects = new DrawingObject[] { new Tower(-15, 0, 7), new Tower(-15, 0, -15), new Tower(7, 0, 7), new Tower(7, 0, -15), wall1a, wall2b, wall3c, wall4a, wall1b, wall2c, wall3a, wall4b, wall1c, wall2a, wall3b, wall4c, flag, new Window(-12, 6, 15), new Window(10, 6, 15), new Window(-12, -4, 15), new Window(10, -4, 15), new Window(-12, 6, -15), new Window(10, 6, -15), new Window(-12, -4, -15), new Window(10, -4, -15), }; }
internal void SetSelectionEndItem(Point location) { if (!this.HasSelection) { return; } MessageListItem hoverItem = _owner.GetItemAtPosition(location) as MessageListItem; if (hoverItem == null) { //鼠标移动到其他地方了,算了,不选了 this.Clear(); return; } if (hoverItem != this._selectingTextItem) { //当前的选择的不是上面一个 this.Clear(); return; } Rectangle rect = this._selectingTextItem.Bounds; for (int i = 0; i < this._selectingTextItem.DrawingObjects.Count; i++) { DrawingObject dobj = this._selectingTextItem.DrawingObjects[i]; if (dobj.Type == DrawingObjectType.TextBlock) { Rectangle bounds = dobj.Offset(rect.X, rect.Y); TextBlockObj tb = dobj.Tag as TextBlockObj; if (bounds.Contains(location)) { StringPart sp = tb.StringPart; using (Graphics g = _owner.CreateGraphics()) { tb.SelectionEnd = StringMeasurer.GetCharIndex(g, sp.Font, location.X - (int)dobj.X, sp.String); this._selectEndDoIndex = i; break; } } } } //开始与结束直接的所有TextBlock都设定为全选中 int startIndex = Math.Min(this._selectStartDoIndex, this._selectEndDoIndex); int endIndex = Math.Max(this._selectStartDoIndex, this._selectEndDoIndex); List <TextBlockObj> selObj = new List <TextBlockObj>(); for (int i = startIndex; i <= endIndex; i++) { DrawingObject dobj = this._selectingTextItem.DrawingObjects[i]; if (dobj.Type == DrawingObjectType.TextBlock) { TextBlockObj tbObj = dobj.Tag as TextBlockObj; if (this._selectStartDoIndex < this._selectEndDoIndex) { //从上往下选择时 if (i == this._selectStartDoIndex) { tbObj.SelectionEnd = tbObj.Length - 1; } else if (i == this._selectEndDoIndex) { tbObj.SelectionStart = 0; } } else if (this._selectStartDoIndex > this._selectEndDoIndex) { //从下往上选择时 if (i == this._selectStartDoIndex) { tbObj.SelectionEnd = 0; } else if (i == this._selectEndDoIndex) { tbObj.SelectionStart = tbObj.Length - 1; } } if (i != this._selectStartDoIndex && i != this._selectEndDoIndex) { tbObj.SelectAll(); } selObj.Add(tbObj); this._prevSelection.Remove(tbObj); } } //清除选择 foreach (TextBlockObj item in this._prevSelection) { item.ClearSelection(); } this._prevSelection = selObj; }
public override void deselect(DrawingObject drawingObject) { drawingObject.setState(StaticState.getInstance()); }