How do you fill patterns in MonoMac - cgcontext

Does anybody know how to fill patterns in MonoMac, this code does nothing unfortunately. It doesn't even call draw pattern. Any help would be awesome :D
void DrawPattern (CGContext NewContext)
{
Console.WriteLine("Drawing Pattern?");
NewContext.SetFillColor(new CGColor(1,0,0));
NewContext.FillRect(new RectangleF(0,0,5,5));
}
public void FillPatternPath (CGContext MyCanvas,CGPath Path)
{
MyCanvas.SaveState();
CGPath NewPath=Path.GetCGPath ();
MyCanvas.AddPath (NewPath);
RectangleF PBounds=MyCanvas.GetPathBoundingBox();
MyCanvas.EOClip();
CGColorSpace patternSpace = CGColorSpace.CreatePattern(null);
MyCanvas.SetFillColorSpace(patternSpace);
CGPattern Pat=new CGPattern(PBounds,CGAffineTransform.MakeIdentity(),10,10,CGPatternTiling.ConstantSpacing,true,new CGPattern.DrawPattern(DrawPattern));
MyCanvas.SetFillPattern(Pat,new float[]{1f});
MyCanvas.FillRect (PBounds);
patternSpace.Dispose();
MyCanvas.RestoreState();
}

I solved this in the end by drawing the pattern in a clipped area using a simple for{} routine. I never managed to get CGPattern to work.

Related

Hololens2 Correct Usage of SpatialAnchors

I am trying to implement an Hololens 2 App using SpatialAnchors but it seems that I am not quite understanding the concept right. I am able to create, save and restore SpatialAnchors of the Windows.Perception.Spatial namespace, but whenever I restore them they are placed relative to the start position of the headset.
I use this snippet to create an anchor:
SpatialAnchor thisAnchor = SpatialAnchor.TryCreateRelativeTo(coord);
And this to get the relative SpatialCoordinateSystem (from this post)
public static bool UseSGIPSceneCoordinateSystem(out SpatialCoordinateSystem sGIPSceneCoordinateSystem)
{
// gain access to the scene object
SceneObserverAccessStatus accessStatus = Task.Run(RequestAccess).GetAwaiter().GetResult();
if (accessStatus == SceneObserverAccessStatus.Allowed)
{
Scene scene = Task.Run(GetSceneAsync).GetAwaiter().GetResult();
sGIPSceneCoordinateSystem = SpatialGraphInteropPreview.CreateCoordinateSystemForNode(scene.OriginSpatialGraphNodeId);
return true;
}
else
{
sGIPSceneCoordinateSystem = null;
return false;
}
}
I use this method to restore the SpatialAnchor I need:
public bool GetAnchor(string id, out SpatialAnchor anchor)
{
[...]
_anchors = _anchorStore.GetAllSavedAnchors();
foreach (var kvp in _anchors)
{
if(kvp.Key == id)
{
anchor = kvp.Value;
return true;
}
}
anchor = null;
return false;
}
And this to process the restored Anchor and get a place in the scene for it:
public void SomeOtherMethod(SpatialAnchor anchor)
{
SpatialCoordinateSystem showcaseCoordinateSystem = anchor.CoordinateSystem;
//get the reference SpatialCoordinateSystem
if (!UseSGIPSceneCoordinateSystem(out SpatialCoordinateSystem referenceCoordinateSystem))
return;
_anchorMatrix = showcaseCoordinateSystem.TryGetTransformTo(referenceCoordinateSystem);
System.Numerics.Matrix4x4 _notNullMatrix = _anchorMatrix.Value;
Matrix4x4 unityAnchorMatrix = _notNullMatrix.ToUnity();
anchorGameObject.transform.FromMatrix(unityAnchorMatrix);
}
I think that I am using the wrong SpatialCoordinateSystem but canĀ“t find information on how to get a SpatialCoordinateSystem which the HoloLens2 generates for the physical spatial surrounding of the user that is persistent.
I am using:
Unity 2020.3.13f1
OpenXR Plugin 1.3.1
MRTK 2.7.3
MRTK-OpenXR 1.2.1
MRTK SceneUnderstanding 0.6.0
I am also confused of the amount of different SpatialAnchor-Systems, reference coordinatesystems and the documentation. Every post I find about SpatialAnchors seems to use a different approach. There seems to be SpatialAnchor-Systems for the Unity WLT, UnityEngine.VR.WSA with WorldManager, Azure Spatial Anchors,
UnityEngine.XR.WindowsMR.WindowsMREnvironment, etc.
And unless I havent overseen it, the microsoft documentation is not really clear about which one to use and how to use it right.
I would be really thankful if someone could bring some light into this issue.
I posted this question also on forum.unity.com

Create Uniform Buffers in Vulkan

i hava a problem with drawing meshes in Vulkan.
I want to bind a UniformBufferObject in the following form to a Object.
void mainLoop() {
..
vulkanDrawing.Draw();
plane.UpdateUniformBuffers();
..
}
To get the currentImage, I created a method SetCurrentImage(uint32_t currentImage).
SetCurrentImage is set from VulkanDrawing::Draw() Method.
This current image is used in the UpdateUniformBuffers().
I get only a black screen if I run this application.
Since, I want to see a square.
In the past, I called the UpdateUniformBuffers Method with an imageIndex parameter in VulkanDrawing::Draw().
I think it could be a problem with the fences or semaphores. But I don't know how I shall fix it.
Does I use eventually a wrong Architecture?
I have attached important Methods:
void CVulkanDrawing::Draw()
{
vkWaitForFences(m_LogicalDevice.getDevice(), 1, &inFlightFences[currentFrame], VK_TRUE, std::numeric_limits<uint64_t>::max());
vkResetFences(m_LogicalDevice.getDevice(), 1,inFlightFences[currentFrame]);
uint32_t imageIndex;
vkAcquireNextImageKHR(m_LogicalDevice.getDevice(), m_Presentation.GetSwapChain(), std::numeric_limits<uint64_t>::max(), imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
for(unsigned int i = 0; i < m_VulkanMesh.size(); i++)
{
//m_VulkanMesh.at(i).UpdateUniformBuffers(imageIndex);
m_VulkanMesh.at(i).SetCurrentImage(imageIndex);
}
VkSubmitInfo submitInfo = {};
...
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
}
void CVulkanMesh::UpdateUniformBuffers()
{
...
vkMapMemory(m_LogicalDevice.getDevice(), uniformBuffersMemory[this->m_CurrentImage], 0, sizeof(ubo), 0, &data);
memcpy(data, &ubo, sizeof(ubo));
vkUnmapMemory(m_LogicalDevice.getDevice(), uniformBuffersMemory[this->m_CurrentImage]);
}
void CVulkanMesh::SetCurrentImage(uint32_t currentImage)
{
this->m_CurrentImage = currentImage;
}
I have additionally created a branch named: https://github.com/dekorlp/VulkanWrapper/tree/VulkanTest
I hope you can help me :)
Best regards
Pixma

Strange font effect after when appending text to CEdit control

After noticing the slowness of the interface updating, I followed the advice on CEdit SetWindowText rediculously slow for appending text to a CEdit control.
Then I replaced
void CMyPropertyPage::Log(const CString& sLog)
{
CString str;
m_cLogEdit.GetWindowText(str);
if (!str.IsEmpty())
str += _T("\r\n");
str += sLog;
m_cLogEdit.SetWindowText(str);
m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());
}
by
void CMyPropertyPage::Log(const CString& sLog)
{
m_cLogEdit.SetSel(-1,-1);
m_cLogEdit.ReplaceSel(sLog + L"\r\n");
//m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());
UpdateData(FALSE);
UpdateWindow();
}
Now, when I run it, I notice a strange font blurring, as it is visible in the first two lines of the Log text box in the image.
What is the cause and how can I fix it?
I solved it :)
void CMyPropertyPage::Log(const CString& sLog)
{
m_cLogEdit.SetRedraw(FALSE);
m_cLogEdit.SetSel(-1,-1);
m_cLogEdit.ReplaceSel(sLog + L"\r\n");
m_cLogEdit.SetRedraw(TRUE);
m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());
UpdateData(FALSE);
m_cLogEdit.UpdateWindow();
}
Seems if I disable the redraw temporarily the issue is gone!

Could I Intercept Exit FullScreen event from octane.xam.VideoPlayer plugin (XAMARIN FORMS)?

My application works portait, ma i want fullscreen video playback even in landscape mode using the plugin mentionend above.
For this purpose I create a customrenderer to take access to native AVPlayerViewController Ios Control.
I tried in many many ways, but seems to be impossible to handle exit fullscreen event. In that method i want to force layout portrait. I have the code for reset orientation already implemented but the problem is to put the code in the right place.
Any other that faced the same issue??
I tried to search for something useful in AVPlayerView(not accessible), AVPlayerVideoController, AVPlayerCurrentItem etc
Any ideas?
Thanks you in advance.
I have translated the OC code to C# in this link for you, see the following codes:
using Foundation;
using CoreGraphics;
playerViewController = new AVPlayerViewController();
playerViewController.ContentOverlayView.AddObserver(this, new NSString("bounds"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old , IntPtr.Zero);
public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
base.ObserveValue(keyPath, ofObject, change, context);
if(ofObject == playerViewController.ContentOverlayView)
{
if(keyPath == "bounds")
{
NSValue oldRect = change.ValueForKey(new NSString("NSKeyValueChangeOldKey")) as NSValue;
NSValue newRect = change.ValueForKey(new NSString("NSKeyValueChangeNewKey")) as NSValue;
CGRect oldBounds = oldRect.CGRectValue;
CGRect newBounds = newRect.CGRectValue;
bool wasFullscreen = CGRect.Equals(oldBounds, UIScreen.MainScreen.Bounds);
bool isFullscreen = CGRect.Equals(newBounds, UIScreen.MainScreen.Bounds);
if(isFullscreen && !wasFullscreen)
{
if(CGRect.Equals(oldBounds,new CGRect(0,0,newBounds.Size.Height, newBounds.Size.Width)))
{
Console.WriteLine("rotated fullscreen");
}
else
{
Console.WriteLine("entered fullscreen");
}
}
else if(!isFullscreen && wasFullscreen)
{
Console.WriteLine("exited fullscreen");
}
}
}
}

How to find when a transition has finished

I've been playing with the code from this website
And now what I'm wanting to do is listen for when a transition has completed so that I can start another transition in sequence. For example...
import "dart:html";
num rotatePos = 0;
void main() {
query("#buttonRotate").onClick.listen(rotateElement);
}
void rotateElement(Event e) {
rotatePos += 360;
Element element = e.target;
element.style.transition = "1s";
element.style.transform = "rotate(${rotatePos}deg)";
//Thank you for the help, here is my code for anyone else having
//questions about this...
element.onTransitionEnd.listen(transitionFinished);
}
void transitionFinished(Event e) {
query("#text").text = "Event Finished!";
}
How would I then go about setting up a listen for when the transform, or transition is complete? Or am I simply going about this the wrong way? Basically what I ultimately want to do is play a series of transitions in sequence, and also be able to pause and continue the animation. I thought maybe the animationEvent class might be what I'm needing to use but so far the examples I've found seem to use this with the canvas, and I'm only wanting to animate dom elements.
use onwebkitTransitionEnd Event

Resources