-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2019 from cwensley/curtis/mac-add-nsimage-templat…
…e-drawing Mac: Add ability to draw NSImage via Graphics when it is a template
- Loading branch information
Showing
7 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using Eto.Test.UnitTests; | ||
using NUnit.Framework; | ||
|
||
#if XAMMAC2 | ||
using AppKit; | ||
using CoreGraphics; | ||
#else | ||
using MonoMac.AppKit; | ||
using MonoMac.CoreGraphics; | ||
#endif | ||
|
||
namespace Eto.Test.Mac.UnitTests | ||
{ | ||
[TestFixture] | ||
public class BitmapTests : TestBase | ||
{ | ||
[TestCase(null)] | ||
[TestCase("Blue")] | ||
[TestCase("White")] | ||
[TestCase("Black")] | ||
[ManualTest] | ||
public void TemplateImagesShouldDrawCorrectly(string color) | ||
{ | ||
ManualForm("Both images should be the same in both light and dark mode", | ||
form => { | ||
Color? backgroundColor = color != null ? Color.Parse(color) : (Color?)null; | ||
var bmp = new Bitmap(200, 200, PixelFormat.Format32bppRgba); | ||
var img = bmp.ControlObject as NSImage; | ||
img.Template = true; | ||
using (var g = new Graphics(bmp)) | ||
{ | ||
g.PixelOffsetMode = PixelOffsetMode.Half; | ||
g.FillRectangle(new Color(Colors.Black, .5f), 39, 39, 120, 120); | ||
g.DrawRectangle(Colors.Red, 4.5f, 4.5f, 191, 191); | ||
g.FillRectangle(Colors.Red, 49, 49, 100, 100); | ||
g.DrawRectangle(Colors.Black, 0.5f, 0.5f, 199, 199); | ||
g.FillRectangle(Colors.Black, 59, 59, 80, 80); | ||
} | ||
var drawable = new Drawable { Size = bmp.Size }; | ||
drawable.Paint += (sender, e) => { | ||
if (backgroundColor != null) | ||
e.Graphics.Clear(backgroundColor.Value); | ||
e.Graphics.DrawImage(bmp, 0, 0); | ||
// e.Graphics.DrawImage(bmp, 50, 50, 100, 100); | ||
// e.Graphics.DrawImage(bmp, new RectangleF(99, 99, 100, 100), new Rectangle(0, 0, 200, 200)); | ||
}; | ||
var imageView = new ImageView(); | ||
imageView.Image = bmp; | ||
if (backgroundColor != null) | ||
imageView.BackgroundColor = backgroundColor.Value; | ||
var content = new DynamicLayout(); | ||
content.AddRow(drawable, imageView, null); | ||
content.AddSpace(); | ||
return content; | ||
} | ||
); | ||
} | ||
} | ||
} |