<SchemaVersion>2.0</SchemaVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ReleaseVersion>0.4</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
public event EventHandler<ValueChangeEventArgs> ValueChanged;
public virtual void NotifyValueChanged(string MemberName, object _value)
{
- ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));
+ if (ValueChanged != null)
+ ValueChanged.Invoke(this, new ValueChangeEventArgs(MemberName, _value));
}
#endregion
3,3,OpenTK.Graphics.GraphicsContextFlags.Debug)
// public OpenTKGameWindow(int _width, int _height, string _title="golib")
// : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)
+ {
+ Thread t = new Thread (interfaceThread);
+ t.IsBackground = true;
+ t.Start ();
+
+// interfaceThread ();
+ }
+ #endregion
+
+ void interfaceThread()
{
CrowInterface = new Interface ();
+ Interface.CurrentInterface = CrowInterface;
CrowInterface.Quit += Quit;
CrowInterface.MouseCursorChanged += CrowInterface_MouseCursorChanged;
+
+ while (true) {
+ CrowInterface.Update ();
+ Thread.Sleep (1);
+ }
}
- #endregion
public void Quit (object sender, EventArgs e)
{
GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height);
shader.Enable ();
-
- 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);
+ 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);
+ CrowInterface.IsDirty = false;
}
- 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);
- CrowInterface.IsDirty = false;
}
-
uiQuad.Render (PrimitiveType.TriangleStrip);
GL.BindTexture(TextureTarget.Texture2D, 0);
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
- fps = (int)RenderFrequency;
-
-
- if (frameCpt > 50) {
- resetFps ();
- frameCpt = 0;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
- }
- frameCpt++;
- CrowInterface.Update ();
+// fps = (int)RenderFrequency;
+//
+//
+// if (frameCpt > 50) {
+// resetFps ();
+// frameCpt = 0;
+// GC.Collect();
+// GC.WaitForPendingFinalizers();
+// NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
+// }
+// frameCpt++;
+ //CrowInterface.Update ();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
protected override void OnResize(EventArgs e)
{
base.OnResize (e);
- CrowInterface.ProcessResize(
+ CrowInterface.ResizeDelegate.Invoke(
new Rectangle(
this.ClientRectangle.X,
this.ClientRectangle.Y,
}
#endregion
- #region Mouse Handling
+ #region Mouse Handling
void update_mouseButtonStates(ref MouseState e, OpenTK.Input.MouseState otk_e){
for (int i = 0; i < MouseState.MaxButtons; i++) {
if (otk_e.IsButtonDown ((OpenTK.Input.MouseButton)i))
}
#endregion
- #region keyboard Handling
+ #region keyboard Handling
KeyboardState Keyboad = new KeyboardState ();
void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e)
- {
+ {
// if (_focusedWidget == null) {
KeyboardKeyDown.Raise (this, otk_e);
// return;
};
- public int intValue = 25;
+ volatile public int intValue = 25;
public int IntValue {
get {
return;
NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption));
}
- public IList<String> List2 = new List<string>(new string[]
+ volatile public IList<String> List2 = new List<string>(new string[]
{
"string1",
"string2",
"string9"
}
);
- IList<Color> testList = Color.ColorDic.ToList();
+ volatile IList<Color> testList = Color.ColorDic.ToList();
public IList<Color> TestList {
set{
testList = value;
//this.AddWidget(new test4());
KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1;;
- GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
- obj.DataSource = this;
+ CrowInterface.LoadInterfaceDelegate.Invoke ("Interfaces/" + testFiles [idx]);
+ //GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
+ //obj.DataSource = this;
}
void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
return;
if (Interface.CurrentInterface == null)
return;
- Interface.CurrentInterface.gobjsToRedraw.Add (this);
+ lock(Interface.CurrentInterface.RenderMutex)
+ Interface.CurrentInterface.gobjsToRedraw.Add (this);
IsQueuedForRedraw = true;
}
Debug.WriteLine ("REGLayout => {1}->{0}", layoutType, this.ToString());
#endif
- //enqueue LQI LayoutingTypes separately
- if (layoutType.HasFlag (LayoutingType.Width))
- Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this));
- if (layoutType.HasFlag (LayoutingType.Height))
- Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this));
- if (layoutType.HasFlag (LayoutingType.X))
- Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this));
- if (layoutType.HasFlag (LayoutingType.Y))
- Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this));
- if (layoutType.HasFlag (LayoutingType.ArrangeChildren))
- Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this));
+ lock (Interface.LayoutingQueue) {
+ //enqueue LQI LayoutingTypes separately
+ if (layoutType.HasFlag (LayoutingType.Width))
+ Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this));
+ if (layoutType.HasFlag (LayoutingType.Height))
+ Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this));
+ if (layoutType.HasFlag (LayoutingType.X))
+ Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this));
+ if (layoutType.HasFlag (LayoutingType.Y))
+ Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this));
+ if (layoutType.HasFlag (LayoutingType.ArrangeChildren))
+ Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this));
+ }
}
/// <summary> trigger dependant sizing component update </summary>
{
public class Interface : ILayoutable
{
+ public delegate void ResizeDelegatePrototype(Rectangle bounds);
+ public delegate void LoaderDelegatePrototype (string path);
+ public ResizeDelegatePrototype ResizeDelegate;
+ public LoaderDelegatePrototype LoadInterfaceDelegate;
+
#region CTOR
- static Interface(){
+ static Interface(){
Interface.LoadCursors ();
}
+ public Interface(){
+ Interface.CurrentInterface = this;
+
+ LoadInterfaceDelegate = new LoaderDelegatePrototype(InterfaceLoad);
+ ResizeDelegate = new ResizeDelegatePrototype (ProcessResize);
+ }
#endregion
#region Static and constants
return result;
}
+ public void InterfaceLoad(string path){
+ GraphicObject tmp = Interface.Load (path, this);
+ AddWidget (tmp);
+ }
+
public GraphicObject LoadInterface (string path)
{
GraphicObject tmp = Interface.Load (path, this);
Context ctx;
Surface surf;
- public byte[] bmp;
+ volatile public byte[] bmp;
public bool IsDirty = false;
public Rectangle DirtyRect;
+ public object RenderMutex = new object();
#region focus
GraphicObject _activeWidget; //button is pressed on widget
layoutTime.Start ();
#endif
//Debug.WriteLine ("======= Layouting queue start =======");
-
- while (Interface.LayoutingQueue.Count > 0) {
- LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+ int queueCount = 0;
+ LayoutingQueueItem lqi = null;
+
+ lock (Interface.LayoutingQueue)
+ queueCount = Interface.LayoutingQueue.Count;
+
+ while (queueCount > 0) {
+ lock (Interface.LayoutingQueue)
+ lqi = Interface.LayoutingQueue.Dequeue ();
lqi.ProcessLayouting ();
+ lock (Interface.LayoutingQueue)
+ queueCount = Interface.LayoutingQueue.Count;
}
+
#if MEASURE_TIME
layoutTime.Stop ();
#endif
//Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
//final redraw clips should be added only when layout is completed among parents,
//that's why it take place in a second pass
- GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count];
- gobjsToRedraw.CopyTo (gotr);
- gobjsToRedraw.Clear ();
+ GraphicObject[] gotr = null;
+ lock (Interface.CurrentInterface.RenderMutex) {
+ gotr = new GraphicObject[gobjsToRedraw.Count];
+ gobjsToRedraw.CopyTo (gotr);
+ gobjsToRedraw.Clear ();
+ }
foreach (GraphicObject p in gotr) {
try {
p.IsQueuedForRedraw = false;
clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
#endif
- if (IsDirty)
- DirtyRect += clipping.Bounds;
- else
- DirtyRect = clipping.Bounds;
- IsDirty = true;
-
- DirtyRect.Left = Math.Max (0, DirtyRect.Left);
- DirtyRect.Top = Math.Max (0, DirtyRect.Top);
- DirtyRect.Width = Math.Min (ClientRectangle.Width - DirtyRect.Left, DirtyRect.Width);
- DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height);
+ lock (RenderMutex) {
+ if (IsDirty)
+ DirtyRect += clipping.Bounds;
+ else
+ DirtyRect = clipping.Bounds;
+ IsDirty = true;
+
+ DirtyRect.Left = Math.Max (0, DirtyRect.Left);
+ DirtyRect.Top = Math.Max (0, DirtyRect.Top);
+ DirtyRect.Width = Math.Min (ClientRectangle.Width - DirtyRect.Left, DirtyRect.Width);
+ DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height);
+ }
clipping.Reset ();
}
}
return null;
}
+
+
+
public void ProcessResize(Rectangle bounds){
clientRectangle = bounds;