aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2017-01-24 12:46:43 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2017-01-24 12:46:43 +0100
commitd8acaa909ce73e150827db9846cd8690fb93d68e (patch)
treec22aab77a5851aad79505a49dc6ac91ca4b0a106 /src/GraphicObjects
parente39ac936765e88382d858ee6922293315a18b60d (diff)
parent1a4fe8bd37ed4a3e3324a134df4f90c14b315918 (diff)
Merge branch 'master' into CrowIDE
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/ColorSelector.cs30
-rw-r--r--src/GraphicObjects/GraphicObject.cs33
-rw-r--r--src/GraphicObjects/HueSelector.cs12
-rw-r--r--src/GraphicObjects/Label.cs135
-rw-r--r--src/GraphicObjects/SaturationValueSelector.cs15
5 files changed, 111 insertions, 114 deletions
diff --git a/src/GraphicObjects/ColorSelector.cs b/src/GraphicObjects/ColorSelector.cs
index 13a588ce..672eea73 100644
--- a/src/GraphicObjects/ColorSelector.cs
+++ b/src/GraphicObjects/ColorSelector.cs
@@ -54,36 +54,10 @@ namespace Crow
mousePos = mPos - r.Position;
mousePos.X = Math.Max(cb.X, mousePos.X);
- mousePos.X = Math.Min(cb.Right-1, mousePos.X);
+ mousePos.X = Math.Min(cb.Right, mousePos.X);
mousePos.Y = Math.Max(cb.Y, mousePos.Y);
- mousePos.Y = Math.Min(cb.Bottom-1, mousePos.Y);
+ mousePos.Y = Math.Min(cb.Bottom, mousePos.Y);
}
-// virtual protected void updateColorFromPicking(bool redraw = true){
-// SelectedColor = new SolidColor(getPixelAt(mousePos.X, mousePos.Y));
-//
-// updateHSV ();
-//
-// NotifyValueChanged ("R", R);
-// NotifyValueChanged ("G", G);
-// NotifyValueChanged ("B", B);
-// NotifyValueChanged ("A", A);
-//
-// if (redraw)
-// RegisterForRedraw ();
-// }
-//
-// protected Color getPixelAt(int x, int y){
-// if (bmp == null)
-// return Color.Transparent;
-//
-// int ptr = y * Slot.Width * 4 + x * 4;
-//
-// return new Color(
-// (double)bmp[ptr + 2] * colDiv,
-// (double)bmp[ptr + 1] * colDiv,
-// (double)bmp[ptr] * colDiv,
-// (double)bmp[ptr + 3] * colDiv);
-// }
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index e7ff3d81..070a221a 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -82,6 +82,7 @@ namespace Crow
bool clipToClientRect = true;
protected object dataSource;
string style;
+ object tag;
#endregion
#region public fields
@@ -103,8 +104,6 @@ namespace Crow
public Rectangle LastPaintedSlot;
/// <summary>Prevent requeuing multiple times the same widget</summary>
public bool IsQueueForRedraw = false;
- /// <summary>Random value placeholder</summary>
- public object Tag;
/// <summary>drawing Cache, if null, a redraw is done, cached or not</summary>
public byte[] bmp;
public bool IsDirty = true;
@@ -195,7 +194,22 @@ namespace Crow
#endregion
#region public properties
- [XmlAttributeAttribute()][DefaultValue(true)]
+ /// <summary>Random value placeholder</summary>
+ [XmlAttributeAttribute]
+ public object Tag {
+ get { return tag; }
+ set {
+ if (tag == value)
+ return;
+ tag = value;
+ NotifyValueChanged ("Tag", tag);
+ }
+ }
+ /// <summary>
+ /// If enabled, resulting bitmap of graphic object is cached in an byte array
+ /// speeding up rendering of complex object. Default is enabled.
+ /// </summary>
+ [XmlAttributeAttribute][DefaultValue(true)]
public virtual bool CacheEnabled {
get { return cacheEnabled; }
set {
@@ -205,7 +219,10 @@ namespace Crow
NotifyValueChanged ("CacheEnabled", cacheEnabled);
}
}
- [XmlAttributeAttribute()][DefaultValue(true)]
+ /// <summary>
+ /// If true, rendering of GraphicObject is clipped inside client rectangle
+ /// </summary>
+ [XmlAttributeAttribute][DefaultValue(true)]
public virtual bool ClipToClientRect {
get { return clipToClientRect; }
set {
@@ -216,7 +233,10 @@ namespace Crow
this.RegisterForRedraw ();
}
}
- [XmlAttributeAttribute()][DefaultValue(null)]
+ /// <summary>
+ /// Name is used in binding to reference other GraphicObjects inside the graphic tree
+ /// </summary>
+ [XmlAttributeAttribute][DefaultValue(null)]
public virtual string Name {
get {
#if DEBUG
@@ -682,7 +702,7 @@ namespace Crow
string expression;
if (!getDefaultEvent(ei, styling, out expression))
continue;
- //TODO:dynEventHandler could be cached somewhere, maybe a style instanciato class holding the styling delegate and bound to it.
+ //TODO:dynEventHandler could be cached somewhere, maybe a style instanciator class holding the styling delegate and bound to it.
foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) {
string trimed = exp.Trim();
if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)){
@@ -695,6 +715,7 @@ namespace Crow
il.Emit (OpCodes.Call, CompilerServices.miGetEvent);
//push expression as 2nd arg of compile
il.Emit (OpCodes.Ldstr, trimed.Substring (1, trimed.Length - 2));
+ //push null as 3rd arg, currentNode, not known when instanciing
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Callvirt, CompilerServices.miCompileDynEventHandler);
il.Emit (OpCodes.Castclass, ei.EventHandlerType);
diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs
index ec0a6f2c..ba1d856b 100644
--- a/src/GraphicObjects/HueSelector.cs
+++ b/src/GraphicObjects/HueSelector.cs
@@ -53,9 +53,9 @@ namespace Crow
if (hue == value)
return;
hue = value;
-
notifyHueChanged ();
updateMousePosFromHue ();
+ RegisterForRedraw ();
}
}
protected override void onDraw (Cairo.Context gr)
@@ -95,11 +95,11 @@ namespace Crow
ctx.SetSourceColor (Color.White);
Rectangle r = ClientRectangle;
if (Orientation == Orientation.Horizontal) {
- r.Width = 5;
- r.X = mousePos.X;
+ r.Width = 4;
+ r.X = mousePos.X - 2;
} else {
- r.Height = 5;
- r.Y = mousePos.Y;
+ r.Height = 4;
+ r.Y = mousePos.Y - 2;
}
CairoHelpers.CairoRectangle (ctx, r, 2);
@@ -126,13 +126,13 @@ namespace Crow
else
hue = (double)mousePos.Y / (double)ClientRectangle.Height;
notifyHueChanged ();
+ RegisterForRedraw ();
}
void updateMousePosFromHue(){
if (Orientation == Orientation.Horizontal)
mousePos.X = (int)Math.Floor(hue * (double)ClientRectangle.Width);
else
mousePos.Y = (int)Math.Floor(hue * (double)ClientRectangle.Height);
- CurrentInterface.EnqueueForRepaint (this);
}
void notifyHueChanged(){
NotifyValueChanged ("Hue", hue);
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)
diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs
index b71fa7ef..a1ddc5b4 100644
--- a/src/GraphicObjects/SaturationValueSelector.cs
+++ b/src/GraphicObjects/SaturationValueSelector.cs
@@ -42,7 +42,7 @@ namespace Crow
NotifyValueChanged ("V", v);
mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height);
- CurrentInterface.EnqueueForRepaint (this);
+ RegisterForRedraw ();
}
}
[XmlAttributeAttribute()]
@@ -54,7 +54,8 @@ namespace Crow
s = value;
NotifyValueChanged ("S", s);
mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width);
- CurrentInterface.EnqueueForRepaint (this);
+
+ RegisterForRedraw ();
}
}
protected override void onDraw (Cairo.Context gr)
@@ -62,8 +63,6 @@ namespace Crow
base.onDraw (gr);
Rectangle r = ClientRectangle;
- Rectangle rGrad = r;
- rGrad.Inflate (-1);
if (Foreground != null) {//TODO:test if null should be removed
Foreground.SetAsSource (gr, r);
@@ -74,13 +73,13 @@ namespace Crow
Crow.Gradient grad = new Gradient (Gradient.Type.Horizontal);
grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 1, 1, 1)));
grad.Stops.Add (new Gradient.ColorStop (1, new Color (1, 1, 1, 0)));
- grad.SetAsSource (gr, rGrad);
+ grad.SetAsSource (gr, r);
CairoHelpers.CairoRectangle (gr, r, CornerRadius);
gr.Fill();
grad = new Gradient (Gradient.Type.Vertical);
grad.Stops.Add (new Gradient.ColorStop (0, new Color (0, 0, 0, 0)));
grad.Stops.Add (new Gradient.ColorStop (1, new Color (0, 0, 0, 1)));
- grad.SetAsSource (gr, rGrad);
+ grad.SetAsSource (gr, r);
CairoHelpers.CairoRectangle (gr, r, CornerRadius);
gr.Fill();
}
@@ -95,7 +94,7 @@ namespace Crow
ctx.Translate (rb.X, rb.Y);
ctx.SetSourceColor (Color.White);
- ctx.Arc (mousePos.X, mousePos.Y, 3.0, 0, Math.PI * 2.0);
+ ctx.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0);
ctx.LineWidth = 1.0;
ctx.Stroke ();
@@ -111,6 +110,8 @@ namespace Crow
v = 1.0 - (double)mousePos.Y / (double)cb.Height;
NotifyValueChanged ("S", s);
NotifyValueChanged ("V", v);
+
+ RegisterForRedraw ();
}
public override void OnLayoutChanges (LayoutingType layoutType)
{