public void OnCreate(Control pc) { pc.Text = "Edit_Options"; PSI_Button button = pc as PSI_Button; if (button != null) { core_common.GetGlareSetAttributes("Utility Button", DefaultAttributes); button.gs = new GlareSet("Default", "Utility Button"); } }
void IReflectorCopyPaste.OnPaste(Object o) { PSI_Button original = o as PSI_Button; if (original != null) { this.gs = new GlareSet(original.gs); this.FontTracker = original.FontTracker; this.Text = original.Text; } //throw new Exception( "The method or operation is not implemented." ); }
public PSI_ButtonProperties(PSI_Button _that, Canvas _canvas) { that = _that; canvas = _canvas; InitializeComponent(); }
public void OutputGlareSet(PSI_Button c, PaintEventArgs e, RenderText render, GlareState type) { System.Drawing.Imaging.ImageAttributes ia = new ImageAttributes(); //ia. //if (set != 0) if (images.mask != null) { if (images.mask_rect != null) { Control parent; Canvas canvas = null; for (parent = c.Parent; parent != null; parent = parent.Parent) { canvas = parent as Canvas; if (canvas != null) { break; } } if (images.mask != null) { //colored_mask = new Bitmap( images.mask.Width, images.mask.Height ); composite = new Bitmap(c.Width, c.Height); } Graphics gout = Graphics.FromImage(composite); //Color r, g, b; //r = Color.FromArgb(unchecked((Int32)0xFF000000)); //g = Color.FromArgb(unchecked((Int32)0xFF9332c3)); //b = Color.FromArgb(unchecked((Int32)0x80b7ac23)); gout.Clear(Color.Transparent); if (type == GlareState.NormalHightlight || type == GlareState.PressedHightlight) { images.ColorMask(images.mask, gout, composite, attrib, true); } else { images.ColorMask(images.mask, gout, composite, attrib, false); } if (c._decal != null) { Rectangle r = c.ClientRectangle; r.X += (r.Width * (100 - c.DecalScale)) / 200; r.Y += (r.Height * (100 - c.DecalScale)) / 200; r.Width -= r.X * 2; r.Height -= r.Y * 2; gout.DrawImage(c._decal, r , c._decal_rect, GraphicsUnit.Pixel ); } if (!render(c, gout)) { if (c.Text != null) { int offset = 0; String realtext = variables.Variables.ResolveVariables(c, c.Text); List <SizeF> output_size; List <string> output; output = new List <string>(); output_size = new List <SizeF>(); int idx; do { idx = realtext.IndexOf('_', offset); if (idx >= 0) { output.Add(realtext.Substring(offset, idx - offset)); offset = idx + 1; } else { output.Add(realtext.Substring(offset, realtext.Length - offset)); } } while(idx >= 0); int height = 0; int lineheight = 0; foreach (string s in output) { SizeF size; if (canvas != null) { output_size.Add(size = c.FontTracker.MeasureString(gout, s, canvas.font_scale_x, canvas.font_scale_y)); } else { output_size.Add(size = c.FontTracker.MeasureString(gout, s)); } //output_size.Add( size = new SizeF( gout.MeasureString( s, c.FontTracker ) ) ); height += (int)((lineheight = (int)size.Height) + (height > 0 ? 0 : 0)); } Point _point = new Point(c.Size); Point point = new Point(); //SizeF size = new SizeF(gout.MeasureString(realtext, c.Font)); _point.X /= 2; _point.Y /= 2; _point.Y -= (int)((height - lineheight) / 2); point.Y = _point.Y; int n = 0; foreach (string s in output) { point.X = _point.X /*- (int)(output_size[n].Width / 2)*/; if (canvas != null) { c.FontTracker.DrawString(gout, s, attrib.text_output, point, canvas.font_scale_x, canvas.font_scale_y); } else { c.FontTracker.DrawString(gout, s, attrib.text_output, point, new Fraction(1, 1), new Fraction(1, 1)); } //gout.DrawString( s // , c.FontTracker // , attrib.text_output // , point ); point.Y += (int)(output_size[n].Height) + ((n > 0) ? 2 : 0); n++; } } } /* * Draw the top layer over the text/decal above... * */ if (images.depressed != null && (type == GlareState.Normal || type == GlareState.NormalHightlight)) { if (type == GlareState.NormalHightlight && images.highlight_depressed != null) { gout.DrawImage(images.highlight_depressed , c.ClientRectangle , new Rectangle(0, 0, images.highlight_depressed.Width, images.highlight_depressed.Height) , GraphicsUnit.Pixel); } else { gout.DrawImage(images.depressed , c.ClientRectangle , new Rectangle(0, 0, images.depressed.Width, images.depressed.Height) , GraphicsUnit.Pixel); } } else if (type == GlareState.Pressed || type == GlareState.PressedHightlight) { if (type == GlareState.PressedHightlight && images.highlight_pressed != null) { gout.DrawImage(images.highlight_pressed , c.ClientRectangle , new Rectangle(0, 0, images.highlight_pressed.Width, images.highlight_pressed.Height) , GraphicsUnit.Pixel); } else if (images.pressed != null) { gout.DrawImage(images.pressed , c.ClientRectangle , new Rectangle(0, 0, images.pressed.Width, images.pressed.Height) , GraphicsUnit.Pixel); } } else { if (images.glare != null) { gout.DrawImage(images.glare , c.ClientRectangle , new Rectangle(0, 0, images.glare.Width, images.glare.Height) , GraphicsUnit.Pixel); } } // output the final composit image... e.Graphics.DrawImage(composite , c.ClientRectangle , c.ClientRectangle , GraphicsUnit.Pixel ); } } }
/// <summary> /// Create a control somwehere on the canvas... /// </summary> /// <param name="t">Type of the control to create ( should be either a Control type... )</param> /// <param name="i">(IReflectorCanvas, IReflectorButton, null...</param> /// <param name="rectangle">rectangle in canvas corrdinates</param> /// <returns>The control tracker that represents this control</returns> public ControlTracker MakeControl(Type t, Type i, Rectangle rectangle) { object widget_object = null; object o = null; rect.Width = canvas.Width; rect.Height = canvas.Height; Rectangle where = //this.GetScaledBounds( new Rectangle(PARTX(rectangle.X), PARTY(rectangle.Y) , PARTW(rectangle.X, rectangle.Width), PARTH(rectangle.Y, rectangle.Height)) //((Form)this.Parent).AutoScaleDimensions, BoundsSpecified.Location //) ; { Type[] types = new Type[1]; { //Type new_t = osalot.OverloadControl( t ); types[0] = typeof(Canvas); ConstructorInfo m = t.GetConstructor(types); if (m != null) { object[] paramlist = new object[1]; paramlist[0] = canvas; o = Activator.CreateInstance(t, paramlist); } } if (o == null) { types[0] = typeof(PSI_Button); ConstructorInfo m = t.GetConstructor(types); if (m != null) { object[] paramlist = new object[1]; PSI_Button button = new PSI_Button(canvas); widget_object = paramlist[0] = button; o = Activator.CreateInstance(t, paramlist); button.click_hook = (o as IReflectorButton); } } } if (o == null) { Type[] types = new Type[5]; types[0] = typeof(Canvas); // parent window handle types[1] = typeof(int); // x, y, w, h... types[2] = typeof(int); // types[3] = typeof(int); // types[4] = typeof(int); // ConstructorInfo m = t.GetConstructor(types); if (m != null) { object[] paramlist = new object[5]; paramlist[0] = canvas; paramlist[1] = where.X; paramlist[2] = where.Y; paramlist[3] = where.Width; paramlist[4] = where.Height; o = Activator.CreateInstance(t, paramlist); } } if (o == null) { //Type real_type = osalot.OverloadControl( t ); //t = real_type; ConstructorInfo m = t.GetConstructor(System.Type.EmptyTypes); if (m != null) { try { o = Activator.CreateInstance(t); if (t.IsSubclassOf(typeof(IReflectorScale))) { IReflectorScale tmp = o as IReflectorScale; tmp.SetScale(canvas.font_scale_x, canvas.font_scale_y); } if (osalot.IsAControl(t)) { widget_object = o; } } catch (Exception e) { Log.log(e.Message + "\n" + e.StackTrace); } } } //c = new System.Windows.Forms.Button(); //System.Windows.Forms. //((ToolStrip)e.ClickedItem.Container) { Control created_object; if (o == null) { return(null); } bool real = false; if ((t != typeof(PSI_Button)) && (i == typeof(IReflectorButton))) { if (widget_object != null) { created_object = widget_object as Control; } else { created_object = new PSI_Button(canvas, o as IReflectorButton); } } else if ((t != typeof(Canvas)) && i == typeof(IReflectorCanvas)) { created_object = new Canvas(o as IReflectorCanvas); } else { created_object = o as Control; if (created_object == null) { if (i == typeof(IReflectorCreate)) { created_object = new Control(); } } } Form form = (created_object as Form); if (form != null) { form.TopLevel = false; } //osalot.CreateWidget( where, "Button(1)", where.Size, c, created_object.Location = where.Location; created_object.Size = where.Size; created_object.Name = o.GetType().ToString() + "(" + (canvas.Controls.Count + 1) + ")"; created_object.TabIndex = 0; try { // web browser, is a control, but overrides text to 'not supported' exception? if (created_object.Text == null || created_object.Text == "") { created_object.Text = "A Control"; } } catch { } canvas.Controls.Add(created_object); created_object.Parent = canvas; created_object.Visible = false; ControlTracker tracker; { Control c = o as Control; if (c != null) { c.Paint += new PaintEventHandler(c_Paint); } } Add(tracker = new ControlTracker(created_object, rectangle, i, t, o, real)); return(tracker); } }