aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-01-15 08:43:28 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-01-15 08:43:28 +0100
commitf5122870d6e6535937b8026e47fd2efa87e02bc0 (patch)
tree599460bd6132562584578de9e3cfde77aa94f401
parente4b3f163986955b39913d1e4ff1456bb0b299252 (diff)
move unproject into ProjectiveIFaceCtrl, debug
-rw-r--r--Templates/MenuItem.template2
-rw-r--r--Tests/CrowWindow.cs8
-rw-r--r--Tests/InterfaceControler.cs33
-rw-r--r--Tests/OpenGL/Extensions.cs23
-rw-r--r--src/GraphicObjects/Label.cs135
5 files changed, 108 insertions, 93 deletions
diff --git a/Templates/MenuItem.template b/Templates/MenuItem.template
index b814e2c6..2f4400ec 100644
--- a/Templates/MenuItem.template
+++ b/Templates/MenuItem.template
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<Popper Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}"
+<Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}"
Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
IsPopped="{²./IsOpened}">
<Template>
diff --git a/Tests/CrowWindow.cs b/Tests/CrowWindow.cs
index 25211744..d46f9ccb 100644
--- a/Tests/CrowWindow.cs
+++ b/Tests/CrowWindow.cs
@@ -186,6 +186,14 @@ namespace Crow
new Rectangle (0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height)));
return ifaceControl [interfaceIdx].CrowInterface.LoadInterface (path);
}
+ public GraphicObject FindByName (string nameToFind){
+ for (int i = 0; i < ifaceControl.Count; i++) {
+ GraphicObject tmp = ifaceControl [i].CrowInterface.FindByName (nameToFind);
+ if (tmp != null)
+ return tmp;
+ }
+ return null;
+ }
public void ClearInterface (int interfaceIdx = 0){
ifaceControl [interfaceIdx].CrowInterface.ClearInterface ();
}
diff --git a/Tests/InterfaceControler.cs b/Tests/InterfaceControler.cs
index 6cb13b2f..12ddf7d8 100644
--- a/Tests/InterfaceControler.cs
+++ b/Tests/InterfaceControler.cs
@@ -53,7 +53,12 @@ namespace Crow
public override void ProcessResize (Rectangle newSize)
{
}
-
+ public override void OpenGLDraw ()
+ {
+ GL.Enable (EnableCap.DepthTest);
+ base.OpenGLDraw ();
+ GL.Disable (EnableCap.DepthTest);
+ }
public void UpdateView (Matrix4 _projection, Matrix4 _modelview, int[] _viewport, Vector3 _vEyePosition)
{
projection = _projection;
@@ -64,7 +69,7 @@ namespace Crow
public override bool ProcessMouseMove (int x, int y)
{
Matrix4 mv = ifaceModelMat * modelview;
- Vector3 vMouse = Extensions.UnProject(ref projection, ref mv, viewport, new Vector2 (x, y)).Xyz;
+ Vector3 vMouse = UnProject(ref projection, ref mv, viewport, new Vector2 (x, y)).Xyz;
Vector3 vE = vEyePosition.Transform (ifaceModelMat.Inverted());
Vector3 vMouseRay = Vector3.Normalize(vMouse - vE);
float a = vE.Z / vMouseRay.Z;
@@ -76,6 +81,30 @@ namespace Crow
return mouseIsInInterface ? CrowInterface.ProcessMouseMove (localMousePos.X, localMousePos.Y) : false;
}
+ Vector4 UnProject(ref Matrix4 projection, ref Matrix4 view, int[] viewport, Vector2 mouse)
+ {
+ Vector4 vec;
+
+ vec.X = 2.0f * mouse.X / (float)viewport[2] - 1;
+ vec.Y = -(2.0f * mouse.Y / (float)viewport[3] - 1);
+ vec.Z = 0f;
+ vec.W = 1.0f;
+
+ Matrix4 viewInv = Matrix4.Invert(view);
+ Matrix4 projInv = Matrix4.Invert(projection);
+
+ Vector4.Transform(ref vec, ref projInv, out vec);
+ Vector4.Transform(ref vec, ref viewInv, out vec);
+
+ if (vec.W > float.Epsilon || vec.W < float.Epsilon)
+ {
+ vec.X /= vec.W;
+ vec.Y /= vec.W;
+ vec.Z /= vec.W;
+ }
+
+ return vec;
+ }
}
public class InterfaceControler {
public Interface CrowInterface;
diff --git a/Tests/OpenGL/Extensions.cs b/Tests/OpenGL/Extensions.cs
index 17fe6086..0dd1cca6 100644
--- a/Tests/OpenGL/Extensions.cs
+++ b/Tests/OpenGL/Extensions.cs
@@ -35,30 +35,7 @@ namespace Crow
public static bool IsInBetween(this int v, int min, int max){
return v >= min & v <= max;
}
- public static Vector4 UnProject(ref Matrix4 projection, ref Matrix4 view, int[] viewport, Vector2 mouse)
- {
- Vector4 vec;
- vec.X = 2.0f * mouse.X / (float)viewport[2] - 1;
- vec.Y = -(2.0f * mouse.Y / (float)viewport[3] - 1);
- vec.Z = 0f;
- vec.W = 1.0f;
-
- Matrix4 viewInv = Matrix4.Invert(view);
- Matrix4 projInv = Matrix4.Invert(projection);
-
- Vector4.Transform(ref vec, ref projInv, out vec);
- Vector4.Transform(ref vec, ref viewInv, out vec);
-
- if (vec.W > float.Epsilon || vec.W < float.Epsilon)
- {
- vec.X /= vec.W;
- vec.Y /= vec.W;
- vec.Z /= vec.W;
- }
-
- return vec;
- }
}
}
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index e55a4b18..38367348 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -29,12 +29,12 @@ using System.Xml.Serialization;
using System.ComponentModel;
namespace Crow
-{
+{
public class Label : GraphicObject
{
#region CTOR
public Label()
- {
+ {
}
public Label(string _text)
@@ -45,7 +45,7 @@ namespace Crow
#endregion
//TODO:change protected to private
-
+
#region private and protected fields
string _text = "label";
Alignment _textAlignment;
@@ -55,7 +55,7 @@ namespace Crow
bool _multiline;
Color selBackground;
Color selForeground;
- Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked
+ Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked
int _currentCol; //0 based cursor position in string
int _currentLine;
Point _selBegin = -1; //selection start (row,column)
@@ -98,10 +98,10 @@ namespace Crow
public Alignment TextAlignment
{
get { return _textAlignment; }
- set {
+ set {
if (value == _textAlignment)
return;
- _textAlignment = value;
+ _textAlignment = value;
RegisterForRedraw ();
NotifyValueChanged ("TextAlignment", _textAlignment);
}
@@ -112,7 +112,7 @@ namespace Crow
set {
if (horizontalStretch == value)
return;
- horizontalStretch = value;
+ horizontalStretch = value;
RegisterForRedraw ();
NotifyValueChanged ("HorizontalStretch", horizontalStretch);
}
@@ -123,23 +123,23 @@ namespace Crow
set {
if (verticalStretch == value)
return;
- verticalStretch = value;
+ verticalStretch = value;
RegisterForRedraw ();
NotifyValueChanged ("VerticalStretch", verticalStretch);
}
- }
+ }
[XmlAttributeAttribute][DefaultValue("label")]
public string Text
{
- get {
- return lines == null ?
+ get {
+ return lines == null ?
_text : lines.Aggregate((i, j) => i + Interface.LineBreak + j);
}
set
{
if (string.Equals (value, _text, StringComparison.Ordinal))
return;
-
+
_text = value;
if (string.IsNullOrEmpty(_text))
@@ -182,7 +182,7 @@ namespace Crow
[XmlAttributeAttribute][DefaultValue(0)]
public int CurrentColumn{
get { return _currentCol; }
- set {
+ set {
if (value == _currentCol)
return;
if (value < 0)
@@ -197,11 +197,11 @@ namespace Crow
[XmlAttributeAttribute][DefaultValue(0)]
public int CurrentLine{
get { return _currentLine; }
- set {
+ set {
if (value == _currentLine)
return;
if (value >= lines.Count)
- _currentLine = lines.Count-1;
+ _currentLine = lines.Count-1;
else if (value < 0)
_currentLine = 0;
else
@@ -232,7 +232,7 @@ namespace Crow
NotifyValueChanged ("SelBegin", _selBegin);
NotifyValueChanged ("SelectedText", SelectedText);
}
- }
+ }
[XmlAttributeAttribute][DefaultValue("-1")]
public Point SelRelease {
get {
@@ -260,24 +260,24 @@ namespace Crow
/// </summary>
[XmlIgnore]protected Point selectionStart
{
- get {
- return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin :
+ get {
+ return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin :
SelBegin.Y > SelRelease.Y ? SelRelease :
SelBegin.X < SelRelease.X ? SelBegin : SelRelease;
}
}
[XmlIgnore]public Point selectionEnd
- {
- get {
- return SelRelease < 0 || SelBegin.Y > SelRelease.Y ? SelBegin :
+ {
+ get {
+ return SelRelease < 0 || SelBegin.Y > SelRelease.Y ? SelBegin :
SelBegin.Y < SelRelease.Y ? SelRelease :
SelBegin.X > SelRelease.X ? SelBegin : SelRelease;
- }
+ }
}
[XmlIgnore]public string SelectedText
- {
+ {
get {
-
+
if (SelRelease < 0 || SelBegin < 0)
return "";
if (selectionStart.Y == selectionEnd.Y)
@@ -289,14 +289,14 @@ namespace Crow
}
tmp += Interface.LineBreak + lines [selectionEnd.Y].Substring (0, selectionEnd.X);
return tmp;
- }
+ }
}
[XmlIgnore]public bool selectionIsEmpty
{ get { return SelRelease < 0; } }
List<string> lines;
List<string> getLines {
- get {
+ get {
return _multiline ?
Regex.Split (_text, "\r\n|\r|\n|\\\\n").ToList() :
new List<string>(new string[] { _text });
@@ -355,7 +355,7 @@ namespace Crow
}
public void DeleteChar()
{
- if (selectionIsEmpty) {
+ if (selectionIsEmpty) {
if (CurrentColumn == 0) {
if (CurrentLine == 0 && lines.Count == 1)
return;
@@ -368,7 +368,7 @@ namespace Crow
}
CurrentColumn--;
lines [CurrentLine] = lines [CurrentLine].Remove (CurrentColumn, 1);
- } else {
+ } else {
int linesToRemove = selectionEnd.Y - selectionStart.Y + 1;
int l = selectionStart.Y;
@@ -380,7 +380,7 @@ namespace Crow
lines.RemoveAt (l);
CurrentLine = selectionStart.Y;
CurrentColumn = selectionStart.X;
- } else
+ } else
lines [l] = lines [l].Remove (selectionStart.X, selectionEnd.X - selectionStart.X);
CurrentColumn = selectionStart.X;
SelBegin = -1;
@@ -425,10 +425,10 @@ namespace Crow
#region GraphicObject overrides
protected override int measureRawSize(LayoutingType lt)
- {
+ {
if (lines == null)
lines = getLines;
-
+
using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
@@ -444,8 +444,8 @@ namespace Crow
int lc = lines.Count;
//ensure minimal height = text line height
if (lc == 0)
- lc = 1;
-
+ lc = 1;
+
return (int)Math.Ceiling(fe.Height * lc) + Margin * 2;
}
@@ -494,7 +494,7 @@ namespace Crow
if (!horizontalStretch)
widthRatio = heightRatio;
}
-
+
rText.Width = (int)(widthRatio * (float)rText.Width);
rText.Height = (int)(heightRatio * (float)rText.Height);
@@ -504,7 +504,7 @@ namespace Crow
rText.X = cb.X;
rText.Y = cb.Y;
break;
- case Alignment.Top: //ok
+ case Alignment.Top: //ok
rText.Y = cb.Y;
rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
break;
@@ -560,7 +560,7 @@ namespace Crow
SelRelease = -1;
else
SelEndCursorPos = textCursorPos;
- }
+ }
}
}else
computeTextCursorPosition(gr);
@@ -578,8 +578,8 @@ namespace Crow
// gr.Color = Color.Green;
// Rectangle R = new Rectangle (
// rText.X + (int)SelEndCursorPos - 2,
-// rText.Y + (int)(SelRelease.Y * fe.Height),
-// 4,
+// rText.Y + (int)(SelRelease.Y * fe.Height),
+// 4,
// (int)fe.Height);
// gr.Rectangle (R);
// gr.Fill ();
@@ -588,20 +588,20 @@ namespace Crow
// gr.Color = Color.UnmellowYellow;
// Rectangle R = new Rectangle (
// rText.X + (int)SelStartCursorPos - 2,
-// rText.Y + (int)(SelBegin.Y * fe.Height),
-// 4,
+// rText.Y + (int)(SelBegin.Y * fe.Height),
+// 4,
// (int)fe.Height);
// gr.Rectangle (R);
// gr.Fill ();
// }
//*******************
- for (int i = 0; i < lines.Count; i++) {
+ for (int i = 0; i < lines.Count; i++) {
string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
int lineLength = (int)gr.TextExtents (l).XAdvance;
Rectangle lineRect = new Rectangle (
rText.X,
- rText.Y + (int)Math.Ceiling(i * fe.Height),
+ rText.Y + (int)Math.Ceiling(i * fe.Height),
lineLength,
(int)Math.Ceiling(fe.Height));
@@ -613,35 +613,36 @@ namespace Crow
// TextAlignment == Alignment.TopRight ||
// TextAlignment == Alignment.BottomRight)
// lineRect.X += (rText.Width - lineLength);
-
- if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
- gr.SetSourceColor(selBackground);
+ if (Selectable) {
+ if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
+ gr.SetSourceColor (selBackground);
- Rectangle selRect = lineRect ;
+ Rectangle selRect = lineRect;
- int cpStart = (int)SelStartCursorPos,
+ int cpStart = (int)SelStartCursorPos,
cpEnd = (int)SelEndCursorPos;
- if (SelBegin.Y > SelRelease.Y) {
- cpStart = cpEnd;
- cpEnd = (int)SelStartCursorPos;
- }
+ if (SelBegin.Y > SelRelease.Y) {
+ cpStart = cpEnd;
+ cpEnd = (int)SelStartCursorPos;
+ }
- if (i == selectionStart.Y) {
- selRect.Width -= cpStart;
- selRect.Left += cpStart;
- }
- if (i == selectionEnd.Y)
- selRect.Width -= (lineLength - cpEnd);
+ if (i == selectionStart.Y) {
+ selRect.Width -= cpStart;
+ selRect.Left += cpStart;
+ }
+ if (i == selectionEnd.Y)
+ selRect.Width -= (lineLength - cpEnd);
- gr.Rectangle (selRect);
- gr.Fill ();
- }
+ gr.Rectangle (selRect);
+ gr.Fill ();
+ }
+ }
if (string.IsNullOrWhiteSpace (l))
continue;
- Foreground.SetAsSource (gr);
+ Foreground.SetAsSource (gr);
gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
gr.ShowText (l);
gr.Fill ();
@@ -698,14 +699,14 @@ namespace Crow
RegisterForRedraw();
}
public override void onMouseDown (object sender, MouseButtonEventArgs e)
- {
+ {
if (this.HasFocus && _selectable){
updatemouseLocalPos (e.Position);
SelBegin = -1;
SelRelease = -1;
SelectionInProgress = true;
RegisterForRedraw();//TODO:should put it in properties
- }
+ }
//done at the end to set 'hasFocus' value after testing it
base.onMouseDown (sender, e);
@@ -716,7 +717,7 @@ namespace Crow
if (!SelectionInProgress)
return;
-
+
updatemouseLocalPos (e.Position);
SelectionInProgress = false;
RegisterForRedraw ();
@@ -739,7 +740,7 @@ namespace Crow
/// from mouseLocalPos
/// </summary>
void computeTextCursor(Context gr)
- {
+ {
TextExtents te;
double cPos = 0f;
@@ -755,7 +756,7 @@ namespace Crow
string c = lines [CurrentLine].Substring (i, 1);
if (c == "\t")
c = new string (' ', Interface.TabSize);
-
+
te = gr.TextExtents(c);
double halfWidth = te.XAdvance / 2;
@@ -778,7 +779,7 @@ namespace Crow
}
/// <summary> Computes offsets in cairo units </summary>
void computeTextCursorPosition(Context gr)
- {
+ {
if (SelBegin >= 0)
SelStartCursorPos = GetXFromTextPointer (gr, SelBegin);
if (SelRelease >= 0)