diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-11 17:01:00 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-12 10:33:24 +0100 |
| commit | 0f813f1c3d1bc3e4deeee089d771eb0443949e3f (patch) | |
| tree | edd60eedf4e78439bb04bd906f5bc5f2ca46f99f | |
| parent | 44caf51048bde7e9daf78acc779278642c798748 (diff) | |
temp save to make test in master
| -rw-r--r-- | Crow.csproj | 2 | ||||
| -rw-r--r-- | Tests/GOLIBTests.cs | 2 | ||||
| -rwxr-xr-x | Tests/Interfaces/clip0.crow | 10 | ||||
| -rwxr-xr-x | Tests/Interfaces/clip1.crow | 25 | ||||
| -rw-r--r-- | Tests/Tests.csproj | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 68 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 65 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 9 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 2 | ||||
| -rw-r--r-- | src/OpenTKGameWindow.cs | 46 | ||||
| -rw-r--r-- | src/Rectangles.cs | 2 |
13 files changed, 135 insertions, 111 deletions
diff --git a/Crow.csproj b/Crow.csproj index 64eab6c9..9ae27230 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -46,7 +46,7 @@ </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <OutputPath>bin\Debug</OutputPath> - <DefineConstants>DEBUG_LAYOUTING0;TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants> + <DefineConstants>DEBUG_LAYOUTING0;TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE</DefineConstants> </PropertyGroup> <!-- <PropertyGroup Condition=" '$(Platform)' == 'Linux_x86' "> <DefineConstants>__linux__</DefineConstants> diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index fbf76ea2..45bf6392 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -37,6 +37,8 @@ namespace test int frameCpt = 0; int idx = 0; string[] testFiles = { + "clip1.crow", + "clip0.crow", "0.crow", "5.crow", "testCombobox.goml", diff --git a/Tests/Interfaces/clip0.crow b/Tests/Interfaces/clip0.crow new file mode 100755 index 00000000..2ebea9ff --- /dev/null +++ b/Tests/Interfaces/clip0.crow @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Container Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="false" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseEnter="{Background=Gray}" + MouseLeave="{Background=LimeGreen}"> + <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="false" + MouseEnter="{Background=DimGray}" Width="100" + MouseLeave="{Background=BlueCrayola}" + Margin="10" Text="{drawing}" Background="BlueCrayola"/> + </Container>
\ No newline at end of file diff --git a/Tests/Interfaces/clip1.crow b/Tests/Interfaces/clip1.crow new file mode 100755 index 00000000..a4f42b10 --- /dev/null +++ b/Tests/Interfaces/clip1.crow @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<Container Fit="true" Margin="20" Background="SkyBlue" CacheEnabled="true" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseEnter="{Background=LightGray}" + MouseLeave="{Background=SkyBlue}"> + <Container Fit="true" Margin="20" Background="Red" CacheEnabled="true" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseEnter="{Background=White}" + MouseLeave="{Background=Red}"> + <Container Fit="true" Margin="20" Background="Yellow" CacheEnabled="true" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseEnter="{Background=Blue}" + MouseLeave="{Background=Yellow}"> + <Container Margin="50" Background="LimeGreen" CacheEnabled="false" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseEnter="{Background=Gray}" + MouseLeave="{Background=LimeGreen}"> + <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true" + MouseEnter="{Background=DimGray}" + MouseLeave="{Background=BlueCrayola}" + Margin="1" Text="{drawing}" Background="BlueCrayola"/> + </Container> + </Container> + </Container> + </Container>
\ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index cbb628a7..0fe3ffa1 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -224,6 +224,12 @@ <None Include="Interfaces\testStacks.crow"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="Interfaces\clip0.crow"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Interfaces\clip1.crow"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Folder Include="Interfaces\" /> diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 14516dba..699d39a9 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -31,6 +31,9 @@ namespace Crow internal List<Binding> Bindings = new List<Binding> (); internal int layoutingTries = 0; + Rectangles _clipping = new Rectangles(); + public Rectangles Clipping { get { return _clipping; }} + #region IValueChange implementation public event EventHandler<ValueChangeEventArgs> ValueChanged; public virtual void NotifyValueChanged(string MemberName, object _value) @@ -121,15 +124,7 @@ namespace Crow [XmlIgnore]public ILayoutable Parent { get { return _parent; } set { -// if (_parent == value) -// return; -// if (_parent != null) -// ClearBinding (); -// _parent = value; -// -// if (DataSource != null) -// ResolveBindings (); } } @@ -150,20 +145,14 @@ namespace Crow } public virtual Rectangle ContextCoordinates(Rectangle r){ return - Parent.ContextCoordinates (r);// + ClientRectangle.Position; + Parent.ContextCoordinates (r); } public virtual Rectangle ScreenCoordinates (Rectangle r){ return Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position; } - public virtual Rectangle getSlot() - { - return Slot; - } - public virtual Rectangle getBounds() - { - return Bounds; - } + public virtual Rectangle getSlot() => Slot; + public virtual Rectangle getBounds() => Bounds; #endregion #region EVENT HANDLERS @@ -478,14 +467,22 @@ namespace Crow public virtual bool Contains(GraphicObject goToFind){ return false; } - - public virtual void registerClipRect() - { - HostContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); + public void RegisterClip(Rectangle clip){ + Rectangle r = Slot + Parent.ClientRectangle; + if (CacheEnabled && bmp != null) + Clipping.AddRectangle (r); + Parent.RegisterClip (r); + } +// public virtual void registerClipRect(Rectangle clip) +// { +// Rectangle tmp = ContextCoordinates (clip); +// if (CacheEnabled) { +// } + //HostContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); //this clipping should take only last painted slots on each level in ancestor tree which //is not the case for now. - HostContainer.redrawClip.AddRectangle (ScreenCoordinates(LastPaintedSlot)); - } + //HostContainer.redrawClip.AddRectangle (ScreenCoordinates(LastPaintedSlot)); + //} /// <summary> /// Clear chached object and add clipping region in redraw list of interface /// </summary> @@ -754,7 +751,7 @@ namespace Crow } /// <summary> Chained painting routine on the parent context of the actual cached version /// of the widget </summary> - public virtual void Paint (ref Context ctx, Rectangles clip = null) + public virtual void Paint (ref Context ctx) { if (!Visible) return; @@ -771,24 +768,25 @@ namespace Crow if (cacheEnabled) { if (bmp == null) UpdateGraphic (); - using (ImageSurface source = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { - //TODO:improve equality test for basic color and Fill - if (this.Background is SolidColor) { - if ((this.Background as SolidColor).Equals (Color.Clear)) { - ctx.Save (); - ctx.Operator = Operator.Clear; - ctx.Rectangle (rb); - ctx.Fill (); - ctx.Restore (); - } - } +// //TODO:improve equality test for basic color and Fill +// if (this.Background is SolidColor) { +// if ((this.Background as SolidColor).Equals (Color.Clear)) { +// ctx.Save (); +// ctx.Operator = Operator.Clear; +// ctx.Rectangle (rb); +// ctx.Fill (); +// ctx.Restore (); +// } +// } ctx.SetSourceSurface (source, rb.X, rb.Y); ctx.Paint (); } return; } ctx.Save (); + + Clipping.clearAndClip (ctx); ctx.Translate (rb.X, rb.Y); onDraw (ctx); ctx.Restore (); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 9d9abbc6..33fe006d 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -217,53 +217,42 @@ namespace Crow } } - public override void Paint(ref Context ctx, Rectangles clip = null) + public override void Paint(ref Context ctx) { if ( !Visible ) return; - if (bmp == null) - UpdateGraphic (); - else { - if (clip != null) - clip.Rebase (this); - else { - clip = new Rectangles (); - //TODO:added lately slot to empty clip, - //should rework this precise case causing expandable not - //to show image changes - clip.AddRectangle (ContextCoordinates (Slot.Size)); - } - - if (!DrawingIsValid || clip != null) {//false when 1 child has changed - //child having their content changed has to be repainted - //and those with slot intersecting clip rectangle have also to be repainted + if (CacheEnabled) { + if (bmp == null) + RecreateCache (); + } - using (ImageSurface cache = - new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, Slot.Width * 4)) { - Context gr = new Context (cache); - clip.clearAndClip (gr); + if (Clipping.count > 0) { + using (ImageSurface cache = + new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, Slot.Width * 4)) { + Context gr = new Context (cache); - Rectangle rBack = Slot.Size; - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); - gr.Fill (); + Clipping.clearAndClip (gr); + Rectangle rBack = Slot.Size; + Background.SetAsSource (gr, rBack); + CairoHelpers.CairoRectangle (gr, rBack, CornerRadius); + gr.Fill (); - #if DEBUG_CLIP_RECTANGLE - clip.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); - #endif - foreach (GraphicObject c in children.Where(ch=>ch.Visible)) { - Rectangles childClip = clip.intersectingRects (ContextCoordinates(c.Slot)); - if (!c.DrawingIsValid || childClip.count > 0) - c.Paint (ref gr, childClip);//, localClip); - } - - gr.Dispose (); + foreach (GraphicObject c in children) { + if (!c.Visible) + continue; + Rectangles childClip = Clipping.intersectingRects (ContextCoordinates (c.Slot)); + if (childClip.count > 0) + c.Paint (ref ctx); } + #if DEBUG_CLIP_RECTANGLE + Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); + #endif + + gr.Dispose (); } - } - - base.Paint (ref ctx, clip); + } + base.Paint (ref ctx); } #endregion diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 54e54f03..bbf1b4a6 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -21,6 +21,7 @@ namespace Crow LayoutingType RegisteredLayoutings { get; set; } void RegisterForLayouting(LayoutingType layoutType); + void RegisterClip(Rectangle clip); bool UpdateLayout(LayoutingType layoutType); diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 9f787eac..63f4f02a 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -139,24 +139,21 @@ namespace Crow return Parent.ContextCoordinates(r) + Slot.Position + ClientRectangle.Position; } - public override void Paint(ref Cairo.Context ctx, Rectangles clip = null) + public override void Paint(ref Cairo.Context ctx) { if (!Visible)//check if necessary?? return; ctx.Save(); - if (clip != null) - clip.clip(ctx); - - base.Paint(ref ctx, clip); + base.Paint(ref ctx); //clip to client zone CairoHelpers.CairoRectangle (ctx, Parent.ContextCoordinates(ClientRectangle + Slot.Position), CornerRadius); ctx.Clip(); if (child != null) - child.Paint(ref ctx, clip); + child.Paint(ref ctx); ctx.Restore(); } diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 3ac8d66c..599f951f 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -188,10 +188,10 @@ namespace Crow return base.ScreenCoordinates (r) - new Point((int)ScrollX,(int)ScrollY); } - public override void registerClipRect () - { - HostContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot)); - } +// public override void registerClipRect () +// { +// HostContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot)); +// } } diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index d98d296c..726f858a 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -89,7 +89,7 @@ namespace Crow if (!HasFocus) return; - otkgw.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot)); + //otkgw.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot)); int currentLeft = this.Left; int currentTop = this.Top; diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 16362c6c..e6fc9681 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -90,7 +90,7 @@ namespace Crow { GraphicObjects.Remove(g); GraphicObjects.Insert(0, g); - g.registerClipRect (); + //g.registerClipRect (); } } public void Quit () @@ -282,14 +282,15 @@ namespace Crow gobjsToRedraw.Clear (); foreach (GraphicObject p in gotr) { p.IsQueuedForRedraw = false; - p.registerClipRect (); + p.RegisterClip (p.LastPaintedSlot); + p.RegisterClip (p.getSlot()); } #if MEASURE_TIME updateTime.Stop (); drawingTime.Start (); #endif - + Debug.WriteLine (redrawClip.ToString ()); lock (redrawClip) { if (redrawClip.count > 0) { #if DEBUG_CLIP_RECTANGLE @@ -299,17 +300,18 @@ namespace Crow //Link.draw (ctx); foreach (GraphicObject p in invGOList) { - if (p.Visible) { + if (!p.Visible) + continue; + + ctx.Save (); + + Rectangles clip = redrawClip.intersectingRects (p.Slot); - ctx.Save (); - if (redrawClip.count > 0) { - Rectangles clip = redrawClip.intersectingRects (p.Slot); + if (clip.count > 0) + p.Paint (ref ctx); + + ctx.Restore (); - if (clip.count > 0) - p.Paint (ref ctx, clip); - } - ctx.Restore (); - } } ctx.ResetClip (); #if DEBUG_CLIP_RECTANGLE @@ -549,6 +551,9 @@ namespace Crow #endregion #region ILayoutable implementation + public void RegisterClip(Rectangle r){ + redrawClip.AddRectangle (r); + } public int LayoutingTries { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } @@ -559,17 +564,13 @@ namespace Crow } public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); } public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } - public Rectangle ContextCoordinates (Rectangle r) - { - return r; - } + public Rectangle ContextCoordinates (Rectangle r) => r; public Rectangle ScreenCoordinates (Rectangle r) => r; public ILayoutable Parent { get { return null; } set { throw new NotImplementedException (); } } - public ILayoutable LogicalParent { get { return null; } set { throw new NotImplementedException (); } @@ -581,15 +582,8 @@ namespace Crow public IGOLibHost HostContainer { get { return this; } } - - public Rectangle getSlot () - { - return ClientRectangle; - } - public Rectangle getBounds ()//redundant but fill ILayoutable implementation - { - return ClientRectangle; - } + public Rectangle getSlot () => ClientRectangle; + public Rectangle getBounds () => ClientRectangle; #endregion } }
\ No newline at end of file diff --git a/src/Rectangles.cs b/src/Rectangles.cs index dbb4118b..c507b2ba 100644 --- a/src/Rectangles.cs +++ b/src/Rectangles.cs @@ -147,6 +147,8 @@ namespace Crow } public void clearAndClip(Context ctx) { + if (list.Count == 0) + return; foreach (Rectangle r in list) ctx.Rectangle(r); |