while (true) {
CrowInterface.Update ();
- Thread.Sleep (1);
+ Thread.Sleep (10);
}
}
shader.Enable ();
lock (CrowInterface.RenderMutex) {
if (CrowInterface.IsDirty) {
- byte[] tmp = new byte[4 * CrowInterface.DirtyRect.Width * CrowInterface.DirtyRect.Height];
- for (int y = 0; y < CrowInterface.DirtyRect.Height; y++) {
- Array.Copy (CrowInterface.bmp,
- ((CrowInterface.DirtyRect.Top + y) * ClientRectangle.Width * 4) + CrowInterface.DirtyRect.Left * 4,
- tmp, y * CrowInterface.DirtyRect.Width * 4, CrowInterface.DirtyRect.Width * 4);
- }
GL.TexSubImage2D (TextureTarget.Texture2D, 0,
CrowInterface.DirtyRect.Left, CrowInterface.DirtyRect.Top,
CrowInterface.DirtyRect.Width, CrowInterface.DirtyRect.Height,
- OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, tmp);
+ OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, CrowInterface.dirtyBmp);
CrowInterface.IsDirty = false;
}
}
foreach (GraphicObject c in Children) {
if (!c.Visible)
continue;
- if (c.QueuedLayoutings.HasFlag (LayoutingType.Width))
+ if (c.RegisteredLayoutings.HasFlag (LayoutingType.Width))
return -1;
tmp += c.Slot.Width + Spacing;
}
foreach (GraphicObject c in Children) {
if (!c.Visible)
continue;
- if (c.QueuedLayoutings.HasFlag (LayoutingType.Height))
+ if (c.RegisteredLayoutings.HasFlag (LayoutingType.Height))
return -1;
tmp += c.Slot.Height + Spacing;
}
continue;
c.Slot.X = d;
d += c.Slot.Width + Spacing;
- c.EnqueueForLayouting (LayoutingType.Y);
+ c.RegisterForLayouting (LayoutingType.Y);
}
} else {
foreach (GraphicObject c in Children) {
continue;
c.Slot.Y = d;
d += c.Slot.Height + Spacing;
- c.EnqueueForLayouting (LayoutingType.X);
+ c.RegisterForLayouting (LayoutingType.X);
}
}
bmp = null;
public override bool UpdateLayout (LayoutingType layoutType)
{
- QueuedLayoutings &= (~layoutType);
+ RegisteredLayoutings &= (~layoutType);
if (layoutType == LayoutingType.ArrangeChildren) {
//allow 1 child to have size to 0 if stack has fixed or streched size policy,
if (!Children [i].Visible)
continue;
//requeue Positionning if child is not layouted
- if (Children [i].QueuedLayoutings.HasFlag (LayoutingType.Width))
+ if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
cptChildren++;
if (Children [i].Width == 0) {
for (int i = 0; i < Children.Count; i++) {
if (!Children [i].Visible)
continue;
- if (Children [i].QueuedLayoutings.HasFlag (LayoutingType.Height))
+ if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
cptChildren++;
if (Children [i].Height == 0) {
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
- if (QueuedLayoutings == LayoutingType.None && bmp==null)
+ if (RegisteredLayoutings == LayoutingType.None && bmp==null)
this.AddToRedrawList ();
return true;
case LayoutingType.Width:
if (Orientation == Orientation.Horizontal) {
if (this.Bounds.Width < 0)
- this.EnqueueForLayouting (LayoutingType.Width);
- this.EnqueueForLayouting (LayoutingType.ArrangeChildren);
+ this.RegisterForLayouting (LayoutingType.Width);
+ this.RegisterForLayouting (LayoutingType.ArrangeChildren);
}
break;
case LayoutingType.Height:
if (Orientation == Orientation.Vertical) {
if (this.Bounds.Height < 0)
- this.EnqueueForLayouting (LayoutingType.Height);
- this.EnqueueForLayouting (LayoutingType.ArrangeChildren);
+ this.RegisterForLayouting (LayoutingType.Height);
+ this.RegisterForLayouting (LayoutingType.ArrangeChildren);
}
break;
}
#endregion
#region private fields
- LayoutingType queuedLayoutings = LayoutingType.None;
+ LayoutingType registeredLayoutings = LayoutingType.None;
ILayoutable logicalParent;
ILayoutable _parent;
string _name = "unamed";
/// IDEA is to add a ScreenCoordinates function that use only lastPaintedSlots
/// </summary>
public Rectangle LastPaintedSlot;
- public LayoutingType RegisteredLayoutings = LayoutingType.None;
public object Tag;
public byte[] bmp;
#endregion
#region ILayoutable
- [XmlIgnore]public LayoutingType QueuedLayoutings { get { return queuedLayoutings; } set { queuedLayoutings = value; } }
+ [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } }
//TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject
// or we could add to the interface the mouse events
/// <summary>
{
Interface.RegisterForGraphicUpdate (this);
}
- public void RegisterForLayouting(LayoutingType lt)
- {
- Interface.RegisterForLayouting (this, lt);
- }
internal bool IsInRedrawList = false;
/// <summary>
/// Add clipping region in redraw list of interface, dont update cached object content
}
public virtual bool ArrangeChildren { get { return false; } }
- public virtual void EnqueueForLayouting(LayoutingType layoutType){
+ public virtual void RegisterForLayouting(LayoutingType layoutType){
if (Parent == null)
return;
- //dont set position for stretched item
- if (Width == 0)
- layoutType &= (~LayoutingType.X);
- if (Height == 0)
- layoutType &= (~LayoutingType.Y);
-
- if (!ArrangeChildren)
- layoutType &= (~LayoutingType.ArrangeChildren);
+ lock (Interface.CurrentInterface.LayoutingQueue) {
+ //dont set position for stretched item
+ if (Width == 0)
+ layoutType &= (~LayoutingType.X);
+ if (Height == 0)
+ layoutType &= (~LayoutingType.Y);
- //apply constraints depending on parent type
- if (Parent is GraphicObject)
- (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType);
+ if (!ArrangeChildren)
+ layoutType &= (~LayoutingType.ArrangeChildren);
- //prevent queueing same LayoutingType for this
- layoutType &= (~QueuedLayoutings);
+ //apply constraints depending on parent type
+ if (Parent is GraphicObject)
+ (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType);
- if (layoutType == LayoutingType.None)
- return;
+ //prevent queueing same LayoutingType for this
+ layoutType &= (~RegisteredLayoutings);
- #if DEBUG_LAYOUTING
- Debug.WriteLine ("REGLayout => {1}->{0}", layoutType, this.ToString());
- #endif
+ if (layoutType == LayoutingType.None)
+ return;
- //enqueue LQI LayoutingTypes separately
- if (layoutType.HasFlag (LayoutingType.Width))
- Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this));
- if (layoutType.HasFlag (LayoutingType.Height))
- Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this));
- if (layoutType.HasFlag (LayoutingType.X))
- Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this));
- if (layoutType.HasFlag (LayoutingType.Y))
- Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this));
- if (layoutType.HasFlag (LayoutingType.ArrangeChildren))
- Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this));
+ #if DEBUG_LAYOUTING
+ Debug.WriteLine ("REGLayout => {1}->{0}", layoutType, this.ToString());
+ #endif
+ //enqueue LQI LayoutingTypes separately
+ if (layoutType.HasFlag (LayoutingType.Width))
+ Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this));
+ if (layoutType.HasFlag (LayoutingType.Height))
+ Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this));
+ if (layoutType.HasFlag (LayoutingType.X))
+ Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this));
+ if (layoutType.HasFlag (LayoutingType.Y))
+ Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this));
+ if (layoutType.HasFlag (LayoutingType.ArrangeChildren))
+ Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this));
+ }
}
/// <summary> trigger dependant sizing component update </summary>
switch (layoutType) {
case LayoutingType.Width:
- EnqueueForLayouting (LayoutingType.X);
+ RegisterForLayouting (LayoutingType.X);
break;
case LayoutingType.Height:
- EnqueueForLayouting (LayoutingType.Y);
+ RegisterForLayouting (LayoutingType.Y);
break;
}
LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType));
public virtual bool UpdateLayout (LayoutingType layoutType)
{
//unset bit, it would be reset if LQI is re-queued
- queuedLayoutings &= (~layoutType);
+ registeredLayoutings &= (~layoutType);
switch (layoutType) {
case LayoutingType.X:
if (Bounds.X == 0) {
- if (Parent.QueuedLayoutings.HasFlag (LayoutingType.Width) ||
- QueuedLayoutings.HasFlag (LayoutingType.Width))
+ if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) ||
+ RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
switch (HorizontalAlignment) {
case LayoutingType.Y:
if (Bounds.Y == 0) {
- if (Parent.QueuedLayoutings.HasFlag (LayoutingType.Height) ||
- QueuedLayoutings.HasFlag (LayoutingType.Height))
+ if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height) ||
+ RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
switch (VerticalAlignment) {
Slot.Width = Width;
else if (Width < 0) {
Slot.Width = measureRawSize (LayoutingType.Width);
- }else if (Parent.QueuedLayoutings.HasFlag (LayoutingType.Width))
+ }else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
else
Slot.Width = Parent.ClientRectangle.Width;
Slot.Height = Height;
else if (Height < 0){
Slot.Height = measureRawSize (LayoutingType.Height);
- }else if (Parent.QueuedLayoutings.HasFlag (LayoutingType.Height))
+ }else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
else
Slot.Height = Parent.ClientRectangle.Height;
}
//if no layouting remains in queue for item, registre for redraw
- if (this.queuedLayoutings == LayoutingType.None && bmp == null)
+ if (this.registeredLayoutings == LayoutingType.None && bmp == null)
this.AddToRedrawList ();
return true;
public override bool UpdateLayout (LayoutingType layoutType)
{
- QueuedLayoutings &= (~layoutType);
+ RegisteredLayoutings &= (~layoutType);
if (layoutType == LayoutingType.ArrangeChildren) {
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
- if (QueuedLayoutings == LayoutingType.None && bmp==null)
+ if (RegisteredLayoutings == LayoutingType.None && bmp==null)
this.AddToRedrawList ();
return true;
foreach (GraphicObject c in Children) {
if (!c.Visible)
continue;
- c.EnqueueForLayouting (LayoutingType.X | LayoutingType.Width);
+ c.RegisterForLayouting (LayoutingType.X | LayoutingType.Width);
}
break;
case LayoutingType.Height:
foreach (GraphicObject c in Children) {
if (!c.Visible)
continue;
- c.EnqueueForLayouting (LayoutingType.Y | LayoutingType.Height); }
+ c.RegisterForLayouting (LayoutingType.Y | LayoutingType.Height); }
break;
}
}
maxChildrenWidth = g.Slot.Width;
largestChild = g;
if (this.Bounds.Width < 0)
- this.EnqueueForLayouting (LayoutingType.Width);
+ this.RegisterForLayouting (LayoutingType.Width);
} else if (g == largestChild) {
largestChild = null;
maxChildrenWidth = 0;
if (this.Bounds.Width < 0)
- this.EnqueueForLayouting (LayoutingType.Width);
+ this.RegisterForLayouting (LayoutingType.Width);
}
break;
case LayoutingType.Height:
maxChildrenHeight = g.Slot.Height;
tallestChild = g;
if (this.Bounds.Height < 0)
- this.EnqueueForLayouting (LayoutingType.Height);
+ this.RegisterForLayouting (LayoutingType.Height);
} else if (g == tallestChild) {
tallestChild = null;
maxChildrenHeight = 0;
if (this.Bounds.Height < 0)
- this.EnqueueForLayouting (LayoutingType.Height);
+ this.RegisterForLayouting (LayoutingType.Height);
}
break;
}
for (int i = 0; i < Children.Count; i++) {
if (!Children [i].Visible)
continue;
- if (children [i].QueuedLayoutings.HasFlag (LayoutingType.Width))
+ if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
continue;
if (Children [i].Slot.Width > maxChildrenWidth) {
maxChildrenWidth = Children [i].Slot.Width;
for (int i = 0; i < Children.Count; i++) {
if (!Children [i].Visible)
continue;
- if (children [i].QueuedLayoutings.HasFlag (LayoutingType.Height))
+ if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
continue;
if (Children [i].Slot.Height > maxChildrenHeight) {
maxChildrenHeight = Children [i].Slot.Height;
Rectangle getBounds();
bool ArrangeChildren { get; }
- LayoutingType QueuedLayoutings { get; set; }
- void EnqueueForLayouting(LayoutingType layoutType);
+ LayoutingType RegisteredLayoutings { get; set; }
+ void RegisterForLayouting(LayoutingType layoutType);
void RegisterClip(Rectangle clip);
bool UpdateLayout(LayoutingType layoutType);
if (child == null)
return base.measureRawSize (lt);
if (lt == LayoutingType.Width)
- return child.QueuedLayoutings.HasFlag(LayoutingType.Width) ?
+ return child.RegisteredLayoutings.HasFlag(LayoutingType.Width) ?
-1 : child.Slot.Size.Width + 2 * Margin;
else
- return child.QueuedLayoutings.HasFlag(LayoutingType.Height) ?
+ return child.RegisteredLayoutings.HasFlag(LayoutingType.Height) ?
-1 : child.Slot.Size.Height + 2 * Margin;
}
public override bool UpdateLayout (LayoutingType layoutType)
case LayoutingType.Width:
if (child != null) {
if (child.Visible)
- child.EnqueueForLayouting (LayoutingType.X | LayoutingType.Width);
+ child.RegisterForLayouting (LayoutingType.X | LayoutingType.Width);
}
break;
case LayoutingType.Height:
if (child != null) {
if (child.Visible)
- child.EnqueueForLayouting (LayoutingType.Y | LayoutingType.Height);
+ child.RegisterForLayouting (LayoutingType.Y | LayoutingType.Height);
}
break;
}
break;
case LayoutingType.Width:
if (this.Bounds.Width < 0)
- this.EnqueueForLayouting (LayoutingType.Width);
+ this.RegisterForLayouting (LayoutingType.Width);
break;
case LayoutingType.Height:
if (this.Bounds.Height < 0)
- this.EnqueueForLayouting (LayoutingType.Height);
+ this.RegisterForLayouting (LayoutingType.Height);
break;
}
}
public override bool ArrangeChildren { get { return true; } }
public override bool UpdateLayout (LayoutingType layoutType)
{
- QueuedLayoutings &= (~layoutType);
+ RegisteredLayoutings &= (~layoutType);
if (layoutType == LayoutingType.ArrangeChildren) {
int curOffset = Spacing;
TabItem ti = Children [i] as TabItem;
ti.TabOffset = curOffset;
if (Orientation == Orientation.Horizontal) {
- if (ti.TabTitle.QueuedLayoutings.HasFlag (LayoutingType.Width))
+ if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
curOffset += ti.TabTitle.Slot.Width + Spacing;
} else {
- if (ti.TabTitle.QueuedLayoutings.HasFlag (LayoutingType.Height))
+ if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
curOffset += ti.TabTitle.Slot.Height + Spacing;
}
}
//if no layouting remains in queue for item, registre for redraw
- if (QueuedLayoutings == LayoutingType.None && bmp==null)
+ if (RegisteredLayoutings == LayoutingType.None && bmp==null)
this.AddToRedrawList ();
return true;
public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem>();
public Queue<GraphicObject> GraphicUpdateQueue = new Queue<GraphicObject>();
- public Queue<GraphicObject> UpdateLayoutQueue = new Queue<GraphicObject>();
- public static void RegisterForLayouting(GraphicObject g, LayoutingType lt){
-
- lock (CurrentInterface.UpdateLayoutQueue) {
- if (CurrentInterface == null)
- return;
- if (g.RegisteredLayoutings == LayoutingType.None)
- CurrentInterface.UpdateLayoutQueue.Enqueue (g);
- g.RegisteredLayoutings |= lt;
- }
- }
public static void RegisterForGraphicUpdate(GraphicObject g)
{
lock (CurrentInterface.GraphicUpdateQueue) {
if (g.IsQueueForGraphicUpdate)
- return;
+ return;
if (CurrentInterface == null)
return;
CurrentInterface.GraphicUpdateQueue.Enqueue (g);
if (Interface.CurrentInterface == null)
return;
Interface.CurrentInterface.RedrawList.Add (g);
- g.IsInRedrawList = true;
+ g.IsInRedrawList = true;
}
#region default values loading helpers
}
public GraphicObject LoadInterface (string path)
- {
- lock (this) {
+ {
+ lock (this) {
GraphicObject tmp = Interface.Load (path, this);
AddWidget (tmp);
return tmp;
- }
+ }
}
#endregion
Context ctx;
Surface surf;
- volatile public byte[] bmp;
+ public byte[] bmp;
+ public byte[] dirtyBmp;
public bool IsDirty = false;
public Rectangle DirtyRect;
public object RenderMutex = new object();
+ public object UpdateMutex = new object();
#region focus
GraphicObject _activeWidget; //button is pressed on widget
processDrawing ();
}
+
#if MEASURE_TIME
updateTime.Stop ();
#endif
#if MEASURE_TIME
layoutTime.Restart();
#endif
- lock (Interface.CurrentInterface.UpdateLayoutQueue) {
- while(Interface.CurrentInterface.UpdateLayoutQueue.Count>0){
- GraphicObject g = Interface.CurrentInterface.UpdateLayoutQueue.Dequeue();
- g.EnqueueForLayouting (g.RegisteredLayoutings);
- g.RegisteredLayoutings = LayoutingType.None;
- }
- }
- //Debug.WriteLine ("======= Layouting queue start =======");
- LayoutingQueueItem lqi = null;
- while (Interface.CurrentInterface.LayoutingQueue.Count > 0) {
+ lock (Interface.CurrentInterface.LayoutingQueue) {
+ //Debug.WriteLine ("======= Layouting queue start =======");
+ LayoutingQueueItem lqi = null;
+ while (Interface.CurrentInterface.LayoutingQueue.Count > 0) {
lqi = Interface.CurrentInterface.LayoutingQueue.Dequeue ();
lqi.ProcessLayouting ();
+ }
}
#if MEASURE_TIME
layoutTime.Stop ();
DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height);
DirtyRect.Width = Math.Max (0, DirtyRect.Width);
DirtyRect.Height = Math.Max (0, DirtyRect.Height);
+
+ dirtyBmp = new byte[4 * DirtyRect.Width * DirtyRect.Height];
+ for (int y = 0; y < DirtyRect.Height; y++) {
+ Array.Copy (bmp,
+ ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4,
+ dirtyBmp, y * DirtyRect.Width * 4, DirtyRect.Width * 4);
+ }
}
clipping.Reset ();
}
public void ProcessResize(Rectangle bounds){
- lock (RenderMutex) {
+ lock (CurrentInterface) {
clientRectangle = bounds;
int stride = 4 * ClientRectangle.Width;
foreach (GraphicObject g in GraphicObjects)
g.RegisterForLayouting (LayoutingType.All);
+
clipping.AddRectangle (clientRectangle);
}
}
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
- public LayoutingType QueuedLayoutings {
+ public LayoutingType RegisteredLayoutings {
get { return LayoutingType.None; }
set { throw new NotImplementedException (); }
}
- public void EnqueueForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); }
+ public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); }
public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); }
public Rectangle ContextCoordinates (Rectangle r) => r;
public Rectangle ScreenCoordinates (Rectangle r) => r;
{
LayoutType = _layoutType;
GraphicObject = _graphicObject;
- GraphicObject.QueuedLayoutings |= LayoutType;
+ GraphicObject.RegisteredLayoutings |= LayoutType;
}
public void ProcessLayouting()
#endif
GraphicObject.LayoutingTries ++;
if (GraphicObject.LayoutingTries < Interface.MaxLayoutingTries) {
- GraphicObject.QueuedLayoutings |= LayoutType;
+ GraphicObject.RegisteredLayoutings |= LayoutType;
Interface.CurrentInterface.LayoutingQueue.Enqueue (this);
}
} else {