[longomatch] Add new Interfaces for drawing backends
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add new Interfaces for drawing backends
- Date: Mon, 7 Jul 2014 11:21:09 +0000 (UTC)
commit b9ddfe8c59d2953238f5f1240bec8e00cb5149fe
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed May 14 19:16:04 2014 +0200
Add new Interfaces for drawing backends
LongoMatch.Core/Common/Area.cs | 48 +++++++++++++++++++
LongoMatch.Core/Common/Color.cs | 33 +++++--------
LongoMatch.Core/Common/Enums.cs | 32 +++++++++++++
LongoMatch.Core/Handlers/Drawing.cs | 28 +++++++++++
.../Interfaces/Drawing/ICanvasObject.cs | 35 ++++++++++++++
LongoMatch.Core/Interfaces/Drawing/IDrawable.cs | 31 ++++++++++++
.../Interfaces/Drawing/IDrawingToolkit.cs | 49 ++++++++++++++++++++
LongoMatch.Core/Interfaces/Drawing/IWidget.cs | 39 ++++++++++++++++
LongoMatch.Core/LongoMatch.Core.mdp | 7 +++
9 files changed, 282 insertions(+), 20 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Area.cs b/LongoMatch.Core/Common/Area.cs
new file mode 100644
index 0000000..0e7fee1
--- /dev/null
+++ b/LongoMatch.Core/Common/Area.cs
@@ -0,0 +1,48 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Common;
+
+namespace LongoMatch.Common
+{
+ public class Area
+ {
+ public Area (Point start, double width, double height)
+ {
+ Start = start;
+ Width = width;
+ Height = height;
+ }
+
+ public Point Start {
+ get;
+ set;
+ }
+
+ public double Width {
+ get;
+ set;
+ }
+
+ public double Height {
+ get;
+ set;
+ }
+ }
+}
+
diff --git a/LongoMatch.Core/Common/Color.cs b/LongoMatch.Core/Common/Color.cs
index 102556b..04b7ac7 100644
--- a/LongoMatch.Core/Common/Color.cs
+++ b/LongoMatch.Core/Common/Color.cs
@@ -21,7 +21,7 @@ namespace LongoMatch.Common
{
public class Color
{
- public Color (short r, short g, short b, short a)
+ public Color (ushort r, ushort g, ushort b, ushort a=ushort.MaxValue)
{
R = r;
G = g;
@@ -29,22 +29,22 @@ namespace LongoMatch.Common
A = a;
}
- public short R {
+ public ushort R {
get;
set;
}
- public short G {
+ public ushort G {
get;
set;
}
- public short B {
+ public ushort B {
get;
set;
}
- public short A {
+ public ushort A {
get;
set;
}
@@ -62,27 +62,20 @@ namespace LongoMatch.Common
{
return (Int32)R<<24 | (Int32)G<<16 | (Int32)B<<8 | (Int32)A;
}
- }
-
- public class ColorHelper
- {
-
- static public ushort ByteToShort (Byte val) {
+
+ static public ushort ByteToUShort (Byte val) {
var ret = (ushort) (((float)val) / byte.MaxValue * ushort.MaxValue);
return ret;
}
-
- static public byte ShortToByte (ushort val) {
- return (byte) (((float)val) / ushort.MaxValue * byte.MaxValue);
+
+ static Color ColorFromRGB (byte r, byte g, byte b) {
+ return new Color (ByteToUShort (r), ByteToUShort (g), ByteToUShort (b));
}
- static public double ShortToDouble (ushort val) {
- return (double) (val) / ushort.MaxValue;
- }
- static public double ByteToDouble (byte val) {
- return (double) (val) / byte.MaxValue;
- }
+ static public Color Black = new Color (0, 0, 0);
+ static public Color White = new Color (ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
+ static public Color Grey = ColorFromRGB (190, 190, 190);
}
}
diff --git a/LongoMatch.Core/Common/Enums.cs b/LongoMatch.Core/Common/Enums.cs
index 4c1ba72..77de8d6 100644
--- a/LongoMatch.Core/Common/Enums.cs
+++ b/LongoMatch.Core/Common/Enums.cs
@@ -176,4 +176,36 @@ namespace LongoMatch.Common
DoubleArrow,
Rounded
}
+
+ public enum FontSlant {
+ Italic,
+ Normal,
+ Oblique,
+ }
+
+ public enum FontWeight {
+ Normal,
+ Bold
+ }
+
+ public enum ButtonType {
+ None,
+ Left,
+ Center,
+ Right
+ }
+
+ public enum ButtonModifier {
+ None,
+ Shift,
+ Control
+ }
+
+ public enum CursorType {
+ Arrow,
+ DoubleArrow,
+ Selection,
+ Cross,
+ }
}
+
diff --git a/LongoMatch.Core/Handlers/Drawing.cs b/LongoMatch.Core/Handlers/Drawing.cs
new file mode 100644
index 0000000..7615b4c
--- /dev/null
+++ b/LongoMatch.Core/Handlers/Drawing.cs
@@ -0,0 +1,28 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Common;
+
+namespace LongoMatch.Handlers.Drawing
+{
+ public delegate void DrawingHandler (object context, Area area);
+ public delegate void ButtonPressedHandler (Point coords, uint time, ButtonType type, ButtonModifier
modifier);
+ public delegate void ButtonReleasedHandler (Point coords, ButtonType type, ButtonModifier modifier);
+ public delegate void MotionHandler (Point coords);
+}
+
diff --git a/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
b/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
new file mode 100644
index 0000000..e7396f0
--- /dev/null
+++ b/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
@@ -0,0 +1,35 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Interfaces;
+using LongoMatch.Common;
+using LongoMatch.Store.Drawables;
+using LongoMatch.Interfaces.Drawing;
+
+namespace LongoMatch.Interfaces.Drawing
+{
+ public interface ICanvasObject
+ {
+ void Draw (IDrawingToolkit tk, Area area);
+ }
+
+ public interface ICanvasSelectableObject: ICanvasObject, IDrawable
+ {
+ }
+}
+
diff --git a/LongoMatch.Core/Interfaces/Drawing/IDrawable.cs b/LongoMatch.Core/Interfaces/Drawing/IDrawable.cs
new file mode 100644
index 0000000..88a6b6e
--- /dev/null
+++ b/LongoMatch.Core/Interfaces/Drawing/IDrawable.cs
@@ -0,0 +1,31 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Store.Drawables;
+using LongoMatch.Common;
+
+namespace LongoMatch.Interfaces.Drawing
+{
+ public interface IDrawable
+ {
+ bool Selected {get;set;}
+ Selection GetSelection (Point point, double precision);
+ void Move (Selection s, Point dst, Point start);
+ }
+}
+
diff --git a/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
b/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
new file mode 100644
index 0000000..df4a3a3
--- /dev/null
+++ b/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
@@ -0,0 +1,49 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Common;
+using System.Collections.Generic;
+
+namespace LongoMatch.Interfaces
+{
+ public interface IDrawingToolkit
+ {
+ object Context {set;}
+ int LineWidth {set;}
+ Color StrokeColor {set;}
+ Color FillColor {set;}
+ Point Translation {set;}
+ string FontFamily {set;}
+ FontSlant FontSlant {set;}
+ FontWeight FontWeight {set;}
+
+ void Begin();
+ void End();
+ void DrawLine (Point start, Point stop);
+ void DrawTriangle (Point corner, double width, double height);
+ void DrawRectangle (Point start, double width, double height);
+ void DrawRoundedRectangle (Point start, double width, double height, double radius);
+ void DrawArea (List<Point> vertices);
+ void DrawPoint (Point point);
+ void DrawCircle (Point center, double radius);
+ void DrawEllipse (Point center, double axisX, double axisY);
+ void DrawText (Point point, double width, double height, string text);
+ void DrawImage (Point start, double width, double height, Image image);
+ }
+}
+
diff --git a/LongoMatch.Core/Interfaces/Drawing/IWidget.cs b/LongoMatch.Core/Interfaces/Drawing/IWidget.cs
new file mode 100644
index 0000000..d2f8277
--- /dev/null
+++ b/LongoMatch.Core/Interfaces/Drawing/IWidget.cs
@@ -0,0 +1,39 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Handlers.Drawing;
+using LongoMatch.Common;
+
+namespace LongoMatch.Interfaces.Drawing
+{
+ public interface IWidget
+ {
+ event DrawingHandler DrawEvent;
+ event ButtonPressedHandler ButtonPressEvent;
+ event ButtonReleasedHandler ButtonReleasedEvent;
+ event MotionHandler MotionEvent;
+
+ double Width {get;set;}
+ double Height {get;set;}
+ void QueueDraw ();
+ void Redraw (Area area = null);
+ void Redraw (ICanvasObject obj);
+ void SetCursor (CursorType type);
+ }
+}
+
diff --git a/LongoMatch.Core/LongoMatch.Core.mdp b/LongoMatch.Core/LongoMatch.Core.mdp
index 52b6089..bcd125f 100644
--- a/LongoMatch.Core/LongoMatch.Core.mdp
+++ b/LongoMatch.Core/LongoMatch.Core.mdp
@@ -129,6 +129,13 @@
<File subtype="Code" buildaction="Compile" name="Store/Coordinates.cs" />
<File subtype="Code" buildaction="Compile" name="Store/Point.cs" />
<File subtype="Code" buildaction="Compile" name="Store/Drawables/Circle.cs" />
+ <File subtype="Code" buildaction="Compile" name="Common/Area.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Interfaces/Drawing" />
+ <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/IDrawingToolkit.cs" />
+ <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/IWidget.cs" />
+ <File subtype="Code" buildaction="Compile" name="Handlers/Drawing.cs" />
+ <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/IDrawable.cs" />
+ <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/ICanvasObject.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]