CA overlay on UISegmentedControl is overwritten in iOS5 - c#

I have the following code, which in iOS 4 produces the look of a "disabled" UISegmentedControl. As the attentive reader will notice, I am developing in MonoTouch, thus the c# syntax.
private void MakeOverlayOnLastRatingSegment()
{
RemoveOverlayOnLastRatingSegment();
lastRatingDisabledLayer = new CALayer();
lastRatingDisabledLayer.Frame = new RectangleF(new PointF(0, 0), segmLastRating.Frame.Size);
lastRatingDisabledLayer.CornerRadius = 10.0f;
lastRatingDisabledLayer.BackgroundColor = UIColor.FromRGBA(0.5f, 0.5f, 0.5f, 0.2f).CGColor;
segmLastRating.Layer.AddSublayer(lastRatingDisabledLayer);
}
And the result is:
But on iOS5 the result is a bit different. The segment before the selected cell is written on top of my gray layer. It takes a bit close look - more evident on a real device instead of simulator. For some reason the screendump from the simulator is very light.
Has anyone else experienced this, and do somebody have a workaround?
Best regards
/Anders

Could you add your overlay layer to the layer of the segmented control’s superview? Or perhaps the segmented control’s layer’s superlayer?

Related

c# SharpDX ScaleEffect Interpolation question

i've been using this wonderful library for low impact screen recording software however im at a point where i need to use a DirectX Scale Effect to scale the image down with anisotropic filtering.
I can create the effect just fine and set up most of its parameters, however im not able to set the most important one for me scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
As soon as the program runs it crashes at that line with an invalid parameter exception.
I've searched and couldnt find anything wrong with the code, but then again i have almost 0 experience with anything Direct2D.
Here is the full code for that specific effect for reference:
SharpDX.Direct2D1.Effect scaleEffect = new D2D.Effect(textureDc, D2D.Effect.Scale);
scaleEffect.Cached = true;
scaleEffect.SetInput(0, frameBitmap, false);
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleEffect.SetValue((int)ScaleProperties.CenterPoint, centerPoint);
scaleEffect.SetValue((int)ScaleProperties.Scale, newSize);
//Crashes Here: scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
Error Message: SharpDX.SharpDXException: 'HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.'
textureDc.BeginDraw();
textureDc.DrawImage(scaleEffect, InterpolationMode.Anisotropic);
textureDc.EndDraw();
Thank you very much in advance for any help!
UPDATE:
As per #Simon Mourier comment, the solution to avoid this bug somewhere in the SharpDX API, is to use the SharpDX.Direct2D1.Effects.Scale instead.
This way, i can confirm the InterpolationMode does no longer crash and works as intended!
Here is the new, working code for anyone running into the same issue.
SharpDX.Direct2D1.Effects.Scale scaleClass = new D2D.Effects.Scale(textureDc);
scaleClass.SetInput(0, frameBitmap,false);
scaleClass.Cached = true;
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleClass.CenterPoint = centerPoint;
scaleClass.ScaleAmount = newSize;
scaleClass.InterpolationMode = InterpolationMode.Anisotropic;
textureDc.BeginDraw();
textureDc.DrawImage(scaleClass);
textureDc.EndDraw();
PS: For anyone wondering about casting the value to uint instead using the first method, it returns the following error:
(Argument1 cannot convert from uint to int)
So it semms that there might be some underlying bug in this specific scenario.
One solution is to use the SharpDX.Direct2D1.Effects.Scale directly which is a wrapper over the Effect class and comes with an InterpolationMode property.

C# Managed DirectX sprite2D locating bug?

I want to draw 2D sprite.
And here is strange thing: if i Sprite.Draw2D with first overload:
using (Sprite Spr = new Sprite(Gfx))
{
Spr.Begin(SpriteFlags.AlphaBlend);
int SprY = Gfx.PresentationParameters.BackBufferHeight/2;
int SprX = Gfx.PresentationParameters.BackBufferWidth/2;
Spr.Draw2D(Tex, new Point(0,0), 0.0f, new Point(SprX,SprY), Color.White);
Spr.End();
while (!Spr.Disposed)
Spr.Dispose();
}
It locating right in 128,128.
But I want to scale-down my image.
So i use 3rd overload of Sprite.Draw2D:
Spr.Draw2D(Tex, new Rectangle(0, 0, 1024, 1024), new Rectangle(0,0,256,256), new Point(SprX,SprY) , Color.White);
Then, it draws to weired position(but correct-sized).
I found-out that width of screen in case of 3rd overload = 1280.
And no matter of PresentationParameters or ViewPort sizes. Even on other machine it is 1280, and center will be 640.
I've tryed to debug Gfx(Device) object and see if any appereance of '1280' number, and it is appear in Gfx.DisplayMode. Unfortunatly, i cant set this parameter because "Device.SetDisplayMode is deprecated" as MSDN says. And DisplayMode.Width is differs between two computers i've test my 'game' on.
Probably i've missed something realy HUGE and stack on it.
By the way, im using DirectX libs from "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" if this matters.

XNA 3.1 DrawUserPrimitives with Anti Aliasing - MultiSampling doesn't work?

So this is a continuation of a question I asked earlier today. I've built myself some nice looking ribbon trails using XNA 3.1's DrawUserPrimitives method, essentially by expanding a polygon as motion occurs. It all looks super sleek and nice, except for one thing - anti-aliasing. I cannot for the life of me work out how to apply it.
I've set this in the game constructor:
graphics.PreferMultiSampling = true;
And I've also added this to test for the hardware:
graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>((sender, e) =>
{
PresentationParameters parameters = e.GraphicsDeviceInformation.PresentationParameters;
parameters.MultiSampleQuality = 0;
#if XBOX
pp.MultiSampleType = MultiSampleType.FourSamples;
return;
#else
int quality;
GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
SurfaceFormat format = adapter.CurrentDisplayMode.Format;
if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.FourSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.FourSamples;
}
else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.TwoSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.TwoSamples;
}
#endif
});
By adding some print lines, I know my hardware can support 4 sample AA, but this all seems to make no difference. I just can't seem to get this to work.
Here's a screenshot of one of my trails with all of that code applied:
I'd really appreciate some help. I looked at this a while ago for a solution to a different problem, and couldn't get it to work then, either.
Well, cheers.
Fixed this one, too!
The issue was that, while the back buffer was getting the right anti-alias settings, the render target wasn't. This meant that drawing to the render target was done without AA, but the texture that was then drawn to the back buffer was done with it. I've fixed it now.

CAD insert block with thumbnail under mouse

I need to insert an external DWG into an AutoCAD drawing via C# plugin.
I need to "ask" to the user the insertion point and rotation of the inserted block.
Until now I've always used a lisp function that calls the command "._-insert" which gives a thumbnail of the block under the mouse, allows the user to click into the drawing to set the insertion point and from that point allows the user to click one more time to set the rotation.
Now I want to avoid the use of Lisp or the use of low level API of AutoCAD because I need a solution that runs over various CAD environments.
What I found is something like this:
public static void InsertDwg(string dwgName)
{
CADAPI.ApplicationServices.Document doc = CADAPI.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
CADDB.Database db = doc.Database;
CADAPI.EditorInput.Editor ed = doc.Editor;
CADDB.ObjectId ObjId;
using (CADDB.Transaction trx = db.TransactionManager.StartTransaction())
{
CADDB.BlockTable bt = db.BlockTableId.GetObject(CADDB.OpenMode.ForRead) as CADDB.BlockTable;
CADDB.BlockTableRecord btrMs = bt[CADDB.BlockTableRecord.ModelSpace].GetObject(CADDB.OpenMode.ForWrite) as CADDB.BlockTableRecord;
using (CADDB.Database dbInsert = new CADDB.Database(false, true))
{
dbInsert.ReadDwgFile(dwgName, CADDB.FileOpenMode.OpenForReadAndAllShare, true, string.Empty);
ObjId = db.Insert(Path.GetFileNameWithoutExtension(dwgName), dbInsert, true);
}
CADAPI.EditorInput.PromptPointOptions ppo = new CADAPI.EditorInput.PromptPointOptions("\nInsertion Point");
CADAPI.EditorInput.PromptAngleOptions ppa = new CADAPI.EditorInput.PromptAngleOptions("\nInsert Rotation");
CADAPI.EditorInput.PromptPointResult ppr;
ppr = ed.GetPoint(ppo);
CADAPI.EditorInput.PromptDoubleResult ppd = ed.GetAngle(ppa);
if (ppr.Status == CADAPI.EditorInput.PromptStatus.OK)
{
CADGEOM.Point3d insertPt = ppr.Value;
CADDB.BlockReference bref = new CADDB.BlockReference(insertPt, ObjId);
btrMs.AppendEntity(bref);
trx.AddNewlyCreatedDBObject(bref, true);
trx.Commit();
}
}
}
But here I have two problems:
The main one is that there is no preview under the mouse.
The second is that the user needs to click 3 times instead of 2 to set both the insertion point and the rotation.
Is there any way that doesn't use some kind of SendCommand and does all of this stuff?
TIA
It seems Jigging is the way to go to allow the preview. I have three links for you.
Jigging multiple entities with the DrawJig
Using a jig to rotate an AutoCAD entity via .NET
Using transient graphics to simulate AutoCAD’s MOVE command using .NET
The first is an example of creating a simple jig with polylines - you could extend this to a block.
The second link is similar but applies rotation to the mix. This is applied to a rectangle but again could be modified to accomodate a block.
The third link describes a different method - AutoCADs transient graphics interface. You must be using AutoCAD 2009 or later to use this method.
The last two links are from the Through the Interface blog, where you may find some more examples and is a very good starting point if you have problems, especially for coding C#.
You will want to use the AcEdJig class. It provides the preview. You will have to write the code to collect the insert point and rotation and to transform the block accordingly.
Here is the first link from my google search for example usage code.

Using WPF and SlimDx (DirectX 10/11)

I am using SlimDX with WinForms for a while now, but want to make the switch to WPF now. However, I can't figure out how to get DX10/11 working with WPF. The February release of SlimDX provides a WPF example, which only works with DX 9 though.
I found the following solution: http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx
but can't get it to work with SlimDX. My main problem is the shared resource handle as I don't know how to retrieve the shared handle from a SlimDX texture. I can't find any information to this topic.
In C++ the code looks like this:
HRESULT D3DImageEx::GetSharedHandle(IUnknown *pUnknown, HANDLE * pHandle)
{
HRESULT hr = S_OK;
*pHandle = NULL;
IDXGIResource* pSurface;
if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))
return hr;
hr = pSurface->GetSharedHandle(pHandle);
pSurface->Release();
return hr;
}
Basically, what I want to do (because I think that this is the solution), is to share a texture between a Direct3d9DeviceEx (for rendering the WPF D3DImage) and a Direct3d10Device (a texture render target for my scene).
Any pointers in the right direction are greatly appreciated.
They posted some sample code on how to use slimdx/directx10 with WPF. Here's the link
There is a control called WindowsFormsHost, maybe you could integrate your current WinForm control that way?
Have a look at D3DImageEx. http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx
You provide a reference to your rendertarget, but it has to be created with the Shared flag. I was not able to use a swapchain in this way though.
let renderTargetDescription = Texture2DDescription( Width=width,
Height=height,
MipLevels=1,
ArraySize=1,
Format = Format.B8G8R8A8_UNorm,
SampleDescription = SampleDescription(Count = 1),
BindFlags = (BindFlags.RenderTarget ||| BindFlags.ShaderResource),
OptionFlags = ResourceOptionFlags.Shared)

Categories

Resources