Equivalent of CGRectInfinite & CGRectIsInfinite in MonoTouch/Xamarin - objective-c

I am trying to convert an open source flyout menu from Objective-C to Xamarin. The current issue I have is that the Obj-C code creates a frame using CGRectInfinite. This does not appear to be available under MonoTouch, via the usual RectangleF class. Is there an alternative?
Similarly, there does not appear to be a CGRectIsInfinite equivalent in RectangleF. What, if any, is the alternative?

Add this using statement first:
using MonoTouch.CoreGraphics;
Then you can test it with this:
public static RectangleF GetInfinite()
{
var image = CIImage.EmptyImage;
if (image.Extent.IsInfinite ())
{
return image.Extent;
}
throw new Exception ("Unable to create infinite rect");
}

Related

QObject::findChildren() for QML object finding

I have an QML form with QQuickApplicationWindow. I need to get QQuickItem pointers on BaseKey elements of QtVirtualKeyboard (it's implementation is placed in separate QML file and loads with Loader of layout when program executes), but it has dynamical (runtime) type like this BaseKey_QMLTYPE_XX, where "XX" is a changeable number.
I found QObject::findChildren() function http://doc.qt.io/qt-4.8/qobject.html#findChild, but i cant find out number "XX" in typename.
How can i find QQuickItem pointer on BaseKey from C++ code?
BaseKey_QMLTYPE_XX looks like what you'd get if you printed the object (print(myObject)). I think that comes from QMetaObject::className().
If the object doesn't have an objectName set, you won't be able to find it using findChild() (unless you have access to the C++ type and there's only one object of that type).
I have a hacky test helper function that does something similar to what you're after:
QObject *TestHelper::findPopupFromTypeName(const QString &typeName) const
{
QObject *popup = nullptr;
foreach (QQuickItem *child, overlay->childItems()) {
if (QString::fromLatin1(child->metaObject()->className()) == "QQuickPopupItem") {
if (QString::fromLatin1(child->parent()->metaObject()->className()).contains(typeName)) {
popup = child->parent();
break;
}
}
}
return popup;
}
You could adapt this to iterate over the children of an object that you pass in. There are a couple more changes than that to get it to work, but the general idea is there.

Eclipse Plugin Dev- Extracting IStackFrame object from selection in Debug View

So, I am developing an Eclipse plugin and trying to build a View similiar to the Variables View. Now, to get the selected StackFrame from the Debug View, I have registered an IDebugContextListener, which ultimately calls the method listed below in case of a selection.
The problem is that I ma unable to get a IStackFrame object from IStructuredSelection.getFirstElement().
I also tried to get an adapter for the IStackframe class. That too didn't work.
I would really appreciate if someone can point me the method of getting a IStackFrame object from a selection.
private void contextActivated(ISelection context) {
if (context instanceof StructuredSelection) {
System.out.println("a");
Object data = ((StructuredSelection) context).getFirstElement();
if (data instanceof IStackFrame) {
System.out.println("yes");
} else {
System.out.println("no" + data.getClass().getName());
}
}
}
The issue with this is that it always execute the else part (even when the selection is a StackFrame in the debug view). Also, the adapter approach didn't work.

NullReferenceException When Resolving SpriteBatch with Ninject

I have a very, very basic MonoGame game (almost just a new project, with just a single image drawn on screen).
In my Game class, I created an instance of StandardKernel. In LoadContent, I bind it to my SpriteBatch:
protected override void LoadContent ()
{
// Create a new SpriteBatch, which can be used to draw textures.
this.SpriteBatch = new SpriteBatch (GraphicsDevice);
// Setup DI bindings
this.Kernel.Bind<SpriteBatch>().ToConstant<SpriteBatch>(this.spriteBatch);
//TODO: use this.Content to load your game content here
}
(The debugger hits this line.) Later, I try to consume it:
protected void LoadSpritesLater() {
var spriteBatch = Game.Instance.Kernel.Get<SpriteBatch>();
}
For some reason, this line always throws a NullReferenceException. I've verified that Game.Instance.Kernel returns me a StandardKernel instance, that I expect.
Oddly, if I replace the Bind call with a setter (eg. this.SpriteBatch = spriteBatch), I can fetch it in LoadSpritesLater and use it without issue.
I checked the Ninject source code and docs to see if the instance is created through Ninject itself (it seems like it isn't). I don't see why this isn't working.

Monotouch derived class from a native class

I'm trying to derive a native class compiled from iCarousel native library ( used the LinkWith method described in this example ).
When using the generated binding everything works perfectly:
iCarousel carousel = new iCarousel( new RectangleF(0, 0, 300, 300) );
But when trying to create this derived class:
public class Carousel2 : iCarousel
{
public Carousel2( RectangleF rect ) : base(rect)
{
Console.WriteLine("do something");
}
}
and using it like this:
Carousel2 carousel = new Carousel2( new RectangleF(0, 0, 300, 300) );
It compiles but it just stops working, with no error. Is it something I'm missing?
UPDATE: I've put the objective-c header and the ApiDefinition.cs source code here:
http://dantes-andreea.blogspot.com/2012/02/icarousel-monotouch-binding-code.html
I think you need to pass -e to btouch when generating the bindings, otherwise they will not be subclassable.
By default btouch does not generate subclassable types because they're a little bit slower.
Update
I was wrong, the -e switch must not be passed to btouch to generate subclassable bindings. Unfortunately this switch is passed unconditionally. A bug report has been filed.
You can probably work around it by manually running the btouch command after MonoDevelop has built the project (you build the bindings project, c&p the btouch command line and remove the -e switch). Then you'll also have to run any subsequent steps manually too.

SetCompatibleTextRenderingDefault in .NET Class Library containing a form

I have a .net class library with a com class that calls a form.
I want to to SetCompatibleTextRenderingDefault(false) to ensure the form fonts look nice.
If I run the command in the class constructor I get the following error:
SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
Where can/should I run this? Surely there is no earlier place than sub New!
Thank in advance
Jon
Edit1: To clarify, I get this error when initiating the class from a .net test harness, if I call it from a VB6 app then I simply get "Automation Error"
Edit2: Is the answer that I cannot use SetCompatibleTextRenderingDefault in a com class when calling from a vb6 app?? Maybe it's the "parent" app that needs to call this method and as such a vb6 app cannot?
Edit3: Maybe I am asking this question in the wrong way! - Maybe the question is: how can I make the fonts look nice in a .net class library form called from a vb6 app?
A possible workaround would be to set the property manually on all buttons and labels in the form constructor:
public Form1()
{
InitializeComponent();
DisableCompatibleTextRendering(this);
}
private static void DisableCompatibleTextRendering(Control c)
{
var button = (c as ButtonBase);
var label = (c as Label);
if (button != null)
{
button.UseCompatibleTextRendering = false;
}
if (label != null)
{
label.UseCompatibleTextRendering = false;
}
foreach (var child in c.Controls.Cast<Control>())
{
DisableCompatibleTextRendering(child);
}
}
Place this inside the application startup code before the first window is created. Under C# this would be the main routine that then creates the initial window.