I'm trying to port a XNA game to MonoGame. I only want to target Windows platform.
I want to display the game in a borderless window. I do that, this way, in my XNA game:
private void SetForm()
{
Form myForm = (Form)Form.FromHandle(this.Window.Handle);
myForm.Name = "WIPForm";
int width = 1024;
int height = 768;
IntPtr auxptr = (this.Window.Handle);
SafeNativeMethods.MoveWindow(
(int)auxptr,
0,
0,
Properties.Settings.Default.width,
Properties.Settings.Default.height,
1);
myForm.FormBorderStyle = FormBorderStyle.None;
myForm.SetBounds(0, 0, width, height);
}
When I test this code in the monogame version myForm = null.
Is there any way to draw a borderless window in the monogame version?
In the constructor of your MonoGame game class:
set:
Window.IsBorderless = true;
As per:
https://monogame.codeplex.com/discussions/432292
Related
I am trying to open the Control Center using appium and the following code:
int halfWidth = driver.manage().window().getSize().width / 2;
int screenHeight = driver.manage().window().getSize().height;
driver.swipe(halfWidth, screenHeight-5, halfWidth, screenHeight-300, 500); // driver is instance of IOSDriver
Instead of opening control centre the app simply draws on the screen upwards from the bottom (using coordinates input). Anyone know how to open Control Center using appium and swipe (or any other way)?
Thanks, Charlie
We can do this. I tried in Appium 1.4.13 and I am able to change settings.
I used below code to change the settings in my iPadAir2.
int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
driver.swipe(width-100, height, width-100, height-200, 500);
driver.findElementByAccessibilityId("Wi-Fi").click();
Appium 1.6.5, You can use swipe method, bellow my Python code:
window_size = self.driver.get_window_size() # this returns dictionary
el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
action = TouchAction(self.driver)
start_x = window_size["width"] * 0.5
start_y = window_size["height"]
end_x = window_size["width"] * 0.5
end_y = window_size["height"] * 0.5
action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform()
I am able to toggle the Wifi OFF or turn Airplane mode ON using Appium 1.6.4-beta for iOS
Swipe up from the bottom of the screen
Click continue link
Click the Wifi or Airplane button
Swipe down from middle of screen
But this doesn't appear to be doing anything in the simulator. I have to actually turn off my computers internet connection to disable the internet on the simulator.
#iOSFindBy(xpath = "//XCUIElementTypeSwitch[#name='Wi-Fi']")
private MobileElement WIFI_MODE_BUTTON;
public void disableWifi() {
openToolBarMenu();
//if wifi is on/true then turn it off
if (WIFI_MODE_BUTTON.getAttribute("value") == "true" ) {
Autoscope.tap(WIFI_MODE_BUTTON);
}
closeToolBarMenu();
}
#iOSFindBy(xpath = "//XCUIElementTypeButton[#name='Continue']")
private MobileElement CONTINUE_BUTTON; //continue button on control center
public void openToolBarMenu() {
Autoscope.scrollFromBottomOfScreen();
if (Autoscope.isElementDisplayed(CONTINUE_BUTTON)) {
Autoscope.tap(CONTINUE_BUTTON);
}
}
static public void scrollFromBottomOfScreen() {
TouchAction touchAction = new TouchAction(autoscopeDriver);
int xStartPoint = Math.round(pixelWidth() / 2);
int yStartPoint = pixelHeight();
int yEndPoint = 0 - yStartPoint;
touchAction.press(xStartPoint, yStartPoint).moveTo(0, yEndPoint).release().perform();
}
This code will help in bringing up the Control center, while you are in your app, you can perform all the operations which are available in the Control Center
new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
.perform();
C#: iOS 13.x
//Opening control center
var size = Driver.Manage().Window.Size;
var height = size.Height;
var width = size.Width;
var touchAction = new TouchAction(Driver);
touchAction.Press(width - 100, height).Wait(1000).MoveTo(width - 100, height - 200).Release().Perform();
//Clicking the WiFi button
Driver.FindElementByAccessibilityId("wifi-button").Click();
//Checking if WiFi enabled or not
var myElement = Driver.FindElementByAccessibilityId("wifi-button");
var result = myElement.GetAttribute("label");
if(!result.Contains("Wi-Fi, Not Connected") && !result.Equals("Wi-Fi"))
{
// WiFi connected
}
else
{
// WiFi Not connected
}
The idea is to simulate the swipe action you use to open Control Center on the corresponding iOS device. My device is iPhone 11 so it is swipe from the top right(to the right of the notch) down. My code is to swipe from position(x,y) (80% width, 0) to (80% width, 50% height)
Dimension size = getScreenSize();
int x = (size.getWidth() / 5) * 4;
int startY = 0;
int endY = size.getHeight() / 2;
new TouchAction(driver).press(PointOption.point(x, startY))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
.moveTo(PointOption.point(x, endY))
.release().perform();
Ok so after a fair amount of investigation it seems to me that this is not possible. If you really need this functionality then I think a tool like eggplant might be appropriate.
I'm working in a cross test project for display ecg graph in realtime. it's work fine on windows and android using Xamarin, BUT in IOS i have slow and slow performarces.
I think the problem is due to my lack of expertise in ios..
I've done two tests both failed, someone have a solutions to speed up ?
TEST A
I call Plot and then assign the UIImage wBitmap as MyView Backgroud every < 10ms
public void Plot(PointF pPrec, PointF pNext)
{
SizeF bitmapSize = new SizeF(wBitmap.Size);
using (CGBitmapContext context2 = new CGBitmapContext(IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst))
{
context2.DrawImage(new RectangleF(0, 0, wBitmap.Size.Width, wBitmap.Size.Height), wBitmap.CGImage);
context2.SetLineWidth(1);
context2.AddLineToPoint(pNext.X, pNext.Y);
context2.DrawPath(CGPathDrawingMode.Stroke);
// output the drawing to the view
wBitmap = UIImage.FromImage(context2.ToImage());
}
}
TEST B
I call Plot and then assign the UIImage wBitmap as MyView Backgroud every < 10ms
public void Plot2(PointF pPrec, PointF pNext) { UIGraphics.BeginImageContext(wBitmap.Size); context = UIGraphics.GetCurrentContext();
using (context)
{
if (wBitmap != null)
{
context.TranslateCTM(0f, wBitmap.Size.Height);
context.ScaleCTM(1.0f, -1.0f);
context.DrawImage(new RectangleF(0f, 0f, wBitmap.Size.Width, wBitmap.Size.Height), wBitmap.CGImage);
context.ScaleCTM(1.0f, -1.0f);
context.TranslateCTM(0f, -wBitmap.Size.Height);
}
context.SetLineWidth(1);
context.MoveTo(pPrec.X, pPrec.Y);
context.AddLineToPoint(pNext.X, pNext.Y);
context.DrawPath(CGPathDrawingMode.Stroke);
wBitmap = UIGraphics.GetImageFromCurrentImageContext();
}//end using cont
UIGraphics.EndImageContext();
}
You don't need to draw into a bitmap first and then use that bitmap in a view. The correct approach to this is to subclass UIView and then override the Draw() method and paint your stuff in there.
You can then call SetNeedsDisplay() on the view to schedule a redraw.
The example below draw an arrow shaped background:
class YourView: UIView
{
public override void Draw(RectangleF rect)
{
const float inset = 15f;
UIColor.Blue.SetFill();
var path = new UIBezierPath();
path.MoveTo(new PointF(0, 0));
path.AddLineTo(new PointF(rect.Width - inset, 0));
path.AddLineTo(new PointF(rect.Width, rect.Height * 0.5f));
path.AddLineTo(new PointF(rect.Width - inset, rect.Bottom));
path.AddLineTo(new PointF(0, rect.Bottom));
path.AddLineTo(new PointF(0, 0));
path.Fill();
}
}
}
Alternatively you might want to look at existing components, like CorePlot or TeeChart available in the Xamarin Components store. TeeChart would even be cross platform, so you wouldn't have to worry about Android vs. iOS.
is there a way to draw on the screen using my finger
i'm creating a Blackberry-10 application like draw something as a school assignment
If you have Qt Quick 2.0 available, you can make use the Canvas object in QML. The following sample shows how to draw a red line whenever there is a onPressed / onPositionChanged event:
import QtQuick 2.0
Rectangle {
property int startX;
property int startY;
property int finishX;
property int finishY;
Canvas {
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
ctx.fillStyle = "black";
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = "red";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(finishX, finishY);
ctx.stroke();
ctx.closePath();
}
MouseArea {
anchors.fill: parent
onPressed: {
startX = mouseX;
startY = mouseY;
}
onPositionChanged: {
finishX = mouseX;
finishY = mouseY;
parent.requestPaint();
}
}
}
}
Sorry but you are planning to use what a BB10 because I didn't understood the question.
Try this solution from the SDK documentation.
I am trying to use DirectX to create and paint into a bitmap, and then later use that bitmap to paint to the screen. I have the following test code which I have pieced together from a number of sources. I seem to be able to create the bitmap without errors, and I try and fill it with red. However, when I use the bitmap to paint to the screen I just get a black rectangle. Can anyone tell me what I might be doing wrong? Note that this is running as a Windows 8 Metro app, if that makes a difference.
Note that the formatter seems to be removing my angle brackets and I don't how stop it from doing that. The 'device' variable is of class ID3D11Device, the 'context' variable is ID3D11DeviceContext, the d2dContext variable is ID2D1DeviceContext, the dgixDevice variable is IDXGIDevice, and the 'd2dDevice' is ID2D1Device.
void PaintTestBitmap(GRectF& rect)
{
HRESULT hr;
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
ComPtr<ID2D1DeviceContext> d2dContext;
hr = D3D11CreateDevice( NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
creationFlags,
featureLevels,
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION,
&device,
NULL,
&context);
if (SUCCEEDED(hr))
{
ComPtr<IDXGIDevice> dxgiDevice;
device.As(&dxgiDevice);
// create D2D device context
ComPtr<ID2D1Device> d2dDevice;
hr = D2D1CreateDevice(dxgiDevice.Get(), NULL, &d2dDevice);
if (SUCCEEDED(hr))
{
hr = d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dContext);
if (SUCCEEDED(hr))
{
ID2D1Bitmap1 *pBitmap;
D2D1_SIZE_U size = { rect.m_width, rect.m_height };
D2D1_BITMAP_PROPERTIES1 properties = {{ DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED }, 96, 96, D2D1_BITMAP_OPTIONS_TARGET, 0 };
hr = d2dContext->CreateBitmap(size, (const void *) 0, 0, &properties, &pBitmap);
if (SUCCEEDED(hr))
{
d2dContext->SetTarget(pBitmap);
d2dContext->BeginDraw();
d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Red)); // Clear the bitmap to Red
d2dContext->EndDraw();
// If I now use pBitmap to paint to the screen, I get a black rectange
// rather than the red one I was expecting
}
}
}
}
}
Note that I am fairly new to both DirectX and Metro style apps.
Thanks
what you're probably forgetting is that you dont draw your bitmap on your context.
what you can try is
hr = d2dContext->CreateBitmap(size, (const void *) 0, 0, &properties, &pBitmap);
if (SUCCEEDED(hr))
{
ID2D1Image *pImage = nullptr;
d2dContext->GetTarget(&image);
d2dContext->SetTarget(pBitmap);
d2dContext->BeginDraw();
d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Red)); // Clear the bitmap to Red
d2dContext->SetTarget(pImage);
d2dContext->DrawBitmap(pBitmap);
d2dContext->EndDraw();
}
what you do is store your rendertarget and then draw your bitmap and at the end you set your context to the right render target and let it draw your bitmap on it
How can I adjust the size of the window in XNA.
Default it starts in a 800x600 resolution.
As of XNA 4.0 this property is now found on the GraphicsDeviceManager.
Ie. this code would go in your Game's constructor.
graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = false;
graphics.PreferredBackBufferHeight = 340;
graphics.PreferredBackBufferWidth = 480;
// if changing GraphicsDeviceManager properties outside
// your game constructor also call:
// graphics.ApplyChanges();
I found out that you need to set the
GraphicDevice.PreferredBackBufferHeight = height;
GraphicDevice.PreferredBackBufferWidth = width;
When you do this in the constructor of the game class it works, but when you try do to this outside the constructor you also need to call
GraphicsDevice.ApplyChanges();
Furthermore to have fullscreen (which is not really working correctly while debugging) you can use
if (!GraphicsDevice.IsFullScreen)
GraphicsDevice.ToggleFullScreen();
You should look at this, http://forums.xna.com/forums/p/1031/107718.aspx.
This solution works in XNA 3.0. Just put it in your game object's constructor:
// Resize the screen to 1024 x 768.
IntPtr ptr = this.Window.Handle;
System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(ptr);
form.Size = new System.Drawing.Size(1024, 768);
graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;
graphics.ApplyChanges();