comparison FBGUI.cs @ 26:7f0b7a53a000

FBGUI: Allow derived classes to access some internals
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 15 Apr 2013 20:29:02 +0200
parents 644a923bca98
children 5bfc6c68591e
comparison
equal deleted inserted replaced
25:5d8fe6b2189c 26:7f0b7a53a000
116 protected void RaiseEvent(EventHandler eh, EventArgs ea) { if (eh != null) eh(this, ea); } 116 protected void RaiseEvent(EventHandler eh, EventArgs ea) { if (eh != null) eh(this, ea); }
117 protected void RaiseEvent(EventHandler eh) { if (eh != null) eh(this, new EventArgs()); } 117 protected void RaiseEvent(EventHandler eh) { if (eh != null) eh(this, new EventArgs()); }
118 } 118 }
119 public class FBGContainerControl : FBGControl, IFBGContainerControl { 119 public class FBGContainerControl : FBGControl, IFBGContainerControl {
120 protected List<IFBGControl> controls = new List<IFBGControl>(); 120 protected List<IFBGControl> controls = new List<IFBGControl>();
121 private IFBGControl mouseCaptureControl = null; 121 protected IFBGControl mouseCaptureControl = null;
122 private IFBGControl keyboardCaptureControl = null; 122 protected IFBGControl keyboardCaptureControl = null;
123 private Rectangle childarea = Rectangle.Empty; 123 private Rectangle childarea = Rectangle.Empty;
124 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } } 124 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } }
125 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } 125 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { }
126 Size IFBGContainerControl.Size { get { return childarea.IsEmpty ? Bounds.Size : childarea.Size; } } 126 Size IFBGContainerControl.Size { get { return childarea.IsEmpty ? Bounds.Size : childarea.Size; } }
127 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } 127 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); }
510 } 510 }
511 public class FBGRenderer : FBGContainerControl, IDisposable { 511 public class FBGRenderer : FBGContainerControl, IDisposable {
512 private FBGCursor cursor = null; 512 private FBGCursor cursor = null;
513 private Point cursorposition = Point.Empty; 513 private Point cursorposition = Point.Empty;
514 public IFramebuffer Framebuffer { get; private set; } 514 public IFramebuffer Framebuffer { get; private set; }
515 private Bitmap Frontbuffer; 515 private Bitmap Frontbuffer = null;
516 private Object RenderLock = new object(); 516 protected Object RenderLock = new object();
517 public event EventHandler<InvalidateEventArgs> Painted; 517 public event EventHandler<InvalidateEventArgs> Painted;
518 private Size size; 518 protected Size size = Size.Empty;
519 private ThreadingTimer PaintTimer = null; 519 private ThreadingTimer PaintTimer = null;
520 private Boolean PaintScheduled = false; 520 private Boolean PaintScheduled = false;
521 private int PaintDelay = 0; 521 private int PaintDelay = 0;
522 public Boolean SuspendDrawing { 522 public Boolean SuspendDrawing {
523 get { return suspenddrawing; } 523 get { return suspenddrawing; }
586 public FBGRenderer(Bitmap bmp) : base(null) { 586 public FBGRenderer(Bitmap bmp) : base(null) {
587 Frontbuffer = bmp; 587 Frontbuffer = bmp;
588 BackColor = SystemColors.Control; 588 BackColor = SystemColors.Control;
589 size = Frontbuffer.Size; 589 size = Frontbuffer.Size;
590 } 590 }
591 protected FBGRenderer() : base(null) {
592 BackColor = SystemColors.Control;
593 }
591 public override void Invalidate(Rectangle rect) { 594 public override void Invalidate(Rectangle rect) {
592 if (rect.Width == 0 || rect.Height == 0) return; 595 if (rect.Width == 0 || rect.Height == 0) return;
593 lock (RenderLock) { 596 lock (RenderLock) {
594 if (SuspendDrawing || PaintTimer != null) { 597 if (SuspendDrawing || PaintTimer != null) {
595 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); 598 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect);
609 Refresh(DirtyRectangle); 612 Refresh(DirtyRectangle);
610 DirtyRectangle = Rectangle.Empty; 613 DirtyRectangle = Rectangle.Empty;
611 } 614 }
612 } catch { } 615 } catch { }
613 } 616 }
614 private void Refresh(Rectangle rect) { 617 protected virtual void Refresh(Rectangle rect) {
615 lock (RenderLock) { 618 lock (RenderLock) {
616 rect.Intersect(Bounds); 619 rect.Intersect(Bounds);
617 if (rect.Width == 0 || rect.Height == 0) return; 620 if (rect.Width == 0 || rect.Height == 0) return;
618 using (Graphics g = Graphics.FromImage(Frontbuffer)) { 621 if (Frontbuffer != null) {
619 g.SetClip(rect); 622 using (Graphics g = Graphics.FromImage(Frontbuffer)) {
620 Paint(g); 623 g.SetClip(rect);
621 } 624 Paint(g);
622 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); 625 }
626 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location);
627 }
623 RaiseEvent(Painted, new InvalidateEventArgs(rect)); 628 RaiseEvent(Painted, new InvalidateEventArgs(rect));
624 } 629 }
625 } 630 }
626 protected override void Paint(Graphics g) { 631 protected override void Paint(Graphics g) {
627 base.Paint(g); 632 base.Paint(g);
635 return true; 640 return true;
636 } 641 }
637 protected override Boolean CaptureKeyboard(bool capture) { 642 protected override Boolean CaptureKeyboard(bool capture) {
638 return true; 643 return true;
639 } 644 }
640 public void Dispose() { 645 public virtual void Dispose() {
641 lock (RenderLock) { 646 lock (RenderLock) {
642 if (PaintTimer != null) PaintTimer.Dispose(); 647 if (PaintTimer != null) PaintTimer.Dispose();
643 PaintTimer = null; 648 PaintTimer = null;
644 } 649 }
645 Orphaned(); 650 Orphaned();