MPV: Get window position and size? Or window-moved/resized event? - mpv

Is there a way to get the current position and size of the MPV media player's window (or an event that fires when they are changed)?
I'm trying to make a script that automatically saves the last position of the window, and then loads it when the player starts. Settings the position on startup can be done with geometry, but reading can't.
In the log it is logged when the windows is moved:
[ 34.308][d][vo/gpu/win32] move window: 1953:48
And resized:
[ 37.990][v][vo/gpu] Resize: 1810x1004
[ 37.990][v][vo/gpu] Window size: 1810x1004
Is there a way to get these values or callbacks in a (javascript) script? I couldn't find the event in the documentation sadly, or did I just miss it?
Only thing I could find were dwidth and dheight, but these represent only the size of the video, not the entire window nor the position of it.
Thanks!
Note: I also asked this on mpv's github, but no reply yet. I'll update the other when I get a reply in either.

I figured out a way using mp.utils.subprocess to run some powershell script, as mpv doesn't have any API's to get the position directly. It's a bit slow, but it does work:
(The ps1 script:)
Add-Type #"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
}
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
"#
$Handle = (Get-Process -Id $Args[0]).MainWindowHandle
$WindowRect = New-Object RECT
$GotWindowRect = [Window]::GetWindowRect($Handle, [ref]$WindowRect)
ConvertTo-Json($WindowRect)
This then gives you a json object that has the position and size of the window. You can then use SetWindowRect in a similar way to set the position again. Note that this rect doesn't correspond to the thing you would set with geometry in mpv itself, as this rect also includes the title bar and such.
Edit:
I made a better version.
The powershell script now gets the client-rect which can be used with geometry, and thus opening mpv is now much smoother.
So the new powershell script:
Add-Type #"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint);
}
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public struct POINT
{
public int x;
public int y;
}
"#
$Handle = (Get-Process -Id $Args[0]).MainWindowHandle
$WindowRect = New-Object RECT
$ClientRect = New-Object RECT
$TopLeft = New-Object POINT
$BottomRight = New-Object POINT
[Window]::GetClientRect($Handle, [ref]$ClientRect) | out-null
$TopLeft.x = $ClientRect.Left
$TopLeft.y = $ClientRect.Top
$BottomRight.x = $ClientRect.Right
$BottomRight.y = $ClientRect.Bottom
[Window]::ClientToScreen($Handle, [ref]$TopLeft) | out-null
[Window]::ClientToScreen($Handle, [ref]$BottomRight) | out-null
$WindowRect.Left = $TopLeft.x
$WindowRect.Top = $TopLeft.y
$WindowRect.Right = $BottomRight.x
$WindowRect.Bottom = $BottomRight.y
ConvertTo-Json($WindowRect)
Then I have a javascript plugin that calls this ps1 in a simple javascript plugin:
// Some setup used by both reading and writing
var dir = mp.utils.split_path(mp.get_script_file())[0]
var rect_path = mp.utils.join_path(dir, "last_window_rect.txt")
// Read last window rect if present
try {
var rect_json = mp.utils.read_file(rect_path)
var rect = JSON.parse(rect_json)
var width = rect.Right - rect.Left
var height = rect.Bottom - rect.Top
mp.set_property("screen", 0)
mp.set_property("geometry", width + "x" + height + "+" + rect.Left + "+" + rect.Top)
}
catch (e) {
dump(e)
}
// Save the rect at shutdown
function save_rect() {
var ps1_script = mp.utils.join_path(dir, "Get-Client-Rect.ps1")
var rect_json = mp.utils.subprocess({ args: ["powershell", "&(\"" + ps1_script + "\")", mp.utils.getpid()], cancellable: false }).stdout
mp.utils.write_file("file://" + rect_path, rect_json)
}
mp.register_event("shutdown", save_rect)
You can also find these scripts on my github: https://github.com/TheOddler/mpv-config/tree/master/scripts but I can't promise these will stay the same forever.

Related

Parent & Child Node with different images & Clickable Event - Treeview Blackberry

I am using tree view in app to show the client server data in blackberry. Same thing i achieved in android app by using expandable listview items. But here i'm facing two issues
One is:
I want to add parent node icon like a folder icon & Child node must have different icon. For example if Parent item is images then child nodes must have Images icon, if parent item is video Then child have video icons.
Second:
When i click on any child node (Like image child node), this node opens in new screen & shows the clickable item whether i click on image or video.
Here is my code that i used to Get the desired result:
class CustomTreeFieldCallback implements TreeFieldCallback {
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y,
int width, int indent) {
// FontFamily
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 18);
g.setFont(font);
String text = (String) _tree.getCookie(node);
Bitmap b = Bitmap.getBitmapResource("images.png");
g.drawText(text, indent + b.getWidth(), y);
g.drawBitmap(indent, y - 15, b.getWidth(), b.getHeight(), b, 0, 0);
}
}
and
public class FilesManager extends MainScreen {
public FilesManager() {
// Set the linear background.
Bitmap background = Bitmap.getBitmapResource("background.png");
Background bg = BackgroundFactory.createBitmapBackground(background);
this.getMainManager().setBackground(bg);
String parentNode = new String("Images");
String firstChild = new String("first child");
String secondChild = new String("second child");
String thirdChild = new String("third child");
CustomTreeFieldCallback myCallback = new CustomTreeFieldCallback();
myTree = new TreeField(myCallback, Field.FOCUSABLE);
int node2 = myTree.addChildNode(0, parentNode);
myTree.addChildNode(node2, firstChild);
myTree.addChildNode(node2, secondChild);
myTree.addChildNode(node2, thirdChild);
add(myTree);
}
}
I also attached the screenShot that i made in android. Any one give me guideline to achieve this thing in BB?
You are off to a good start.
To get the right icons, you just need to detect which tree "nodes" are folders, movies, songs, images, etc. Do that either with TreeField#getFirstChild() or by checking the cookie/text, for each node, inside drawTreeItem().
To handle clicks on the movie, image, or song rows, override navigationClick().
For example, starting with the TreeFieldDemo from BlackBerry:
class TreeFieldDemoScreen extends MainScreen
{
private final Bitmap openIcon = Bitmap.getBitmapResource("folder-open.png");
private final Bitmap closedIcon = Bitmap.getBitmapResource("folder-closed.png");
private final Bitmap movieIcon = Bitmap.getBitmapResource("movie.png");
private final Bitmap songIcon = Bitmap.getBitmapResource("song.png");
private final Bitmap playIcon = Bitmap.getBitmapResource("play.png");
public TreeFieldDemoScreen()
{
setTitle("Tree Field Demo");
TreeCallback myCallback = new TreeCallback();
TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
// We'll only override unvarnished navigation click behavior
if ((status & KeypadListener.STATUS_ALT) == 0 &&
(status & KeypadListener.STATUS_SHIFT) == 0)
{
final int node = getCurrentNode();
if (getFirstChild(node) == -1) {
// Click is on a leaf node. Do some default action or else fall through.
// Note: this will also detect empty folders, which might or
// might not be something your app has to handle
Dialog.alert("clicked " + getCookie(node));
// TODO: open player screen, etc.
return true;
}
}
return super.navigationClick(status, time);
}
};
myTree.setDefaultExpanded(false);
myTree.setRowHeight(openIcon.getHeight());
String nodeOne = new String("Video"); // folder
String nodeTwo = new String("Music"); // folder
String nodeThree = new String("Images"); // folder
String nodeFour = new String("song.mp3");
String nodeFive = new String("movie.m4v");
int node1 = myTree.addChildNode(0, nodeOne);
int node2 = myTree.addChildNode(0, nodeTwo);
int node3 = myTree.addChildNode(0, nodeThree);
int node4 = myTree.addChildNode(node2, nodeFour);
int node5 = myTree.addChildNode(node1, nodeFive);
add(myTree);
}
private class TreeCallback implements TreeFieldCallback
{
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent)
{
final int PAD = 8;
String text = (String)_tree.getCookie(node);
Bitmap icon = closedIcon;
if (text.endsWith(".mp3")) {
icon = songIcon;
} else if (text.endsWith(".m4v")) {
icon = movieIcon;
} else if (_tree.getExpanded(node)) {
icon = openIcon;
}
g.drawBitmap(indent, y, icon.getWidth(), icon.getHeight(), icon, 0, 0);
// This assumes filenames all contain '.' character!
if (text.indexOf(".") > 0) {
// Leaf node, so this is a playable item (movie or song)
g.drawBitmap(_tree.getWidth() - playIcon.getWidth() - PAD, y + PAD,
playIcon.getWidth(), playIcon.getHeight(), playIcon, 0, 0);
}
int fontHeight = getFont().getHeight();
g.drawText(text, indent + icon.getWidth() + PAD, y + (_tree.getRowHeight() - fontHeight)/2);
}
}
}
My navigation click handler is coded to accept clicks on the entire movie or song row, not just the "play" button itself. I think this is easier on touch devices, since the user's finger doesn't have to hit a small touch target. You can change this if you like, though.
Results
Note: I didn't bother to hook up an icon for image files ... you should be able to do that now.

C# + Windows CE + Multiline & Align label

I need to make a multiline label with vertical and horizontal alignment and I don't know how I can do it !
I have found a way to make any control multiline with this function :
private const int BS_MULTILINE = 0x00002000;
private const int BS_CENTER = 0x00000300;
private const int BS_VCENTER = 0x00000C00;
private const int GWL_STYLE = -16;
[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
public static void MakeControlMultiline(Control control) {
IntPtr hwnd = control.Handle;
int currentStyle = GetWindowLong(hwnd, GWL_STYLE);
int newStyle = SetWindowLong(hwnd, GWL_STYLE, currentStyle | /*BS_CENTER | BS_VCENTER | */BS_MULTILINE);
}
The "BS_CENTER | BS_VCENTER" is in comment since it doesn't work !
So I try to make a customControl where I realise both alignments, like this :
public partial class ImproveLabel : Control {
...
protected override void OnPaint(PaintEventArgs pe) {
Graphics g = pe.Graphics;
// text
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
drawFormat.LineAlignment = StringAlignment.Center;
g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new Rectangle(0, 0, this.Width, this.Height), drawFormat);
// Calling the base class OnPaint
base.OnPaint(pe);
}
The strange thing here is that if I put both alignements to "Center", the multiline doesn't work anymore but if there is only the vertical alignment to "Center" and the horizontal alignment to "near", the multiline works.
I don't understand why it works this way but I need help to figure how I can get the 3 attributes working at the same time !
The code below is straight out of the P/Invoke SetWindowLong example.
private const int GWL_STYLE = -16;
private const int BS_CENTER = 0x00000300;
private const int BS_VCENTER = 0x00000C00;
private const int BS_MULTILINE = 0x00002000;
public static void SetButtonStyle(Button ctrl)
{
IntPtr hWnd;
int style;
// ctrl.Capture = true;
// hWnd = GetCapture();
// ctrl.Capture = false;
// Comment below and uncomment above if using Visual Studio 2003
hWnd = ctrl.Handle;
style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, (style | BS_CENTER | BS_VCENTER | BS_MULTILINE));
ctrl.Refresh();
}
It looks about exactly like yours, but I have not tested it personally.

Print Canvas from Processing

I am trying to make something along the lines of this: http://instaprint.me/, however I don't have a dedicated Linux machine, ink-less paper and WiFi. I do, on the other hand, have a desktop connected to the internet and a color photo-printer.
So what I had in mind was this -
Set up an Instagram API App that gets all the information of the most recent photo
A PHP script and a server that can produce a static URL for the most recent photo with a header("Content-Type: image/jpeg"), so that every time I take a new photo, the contents of the image on that static page changes to be the most recent photo.
Other pages, like the one mentioned above, that change to reflect the new location and caption of each photo I take, hosted on a static URL.
Some basic knowledge of Processing.
So here's how for I've got so far - I can download the most recent photo ID, and if it has changed since the last time it checked (15 seconds ago), then it proceeds to download the most recent image, caption and location.
I can then arrange these on the canvas to look like an old-fashioned polaroid. Now the only thing I have to do is print the canvas, at 150dpi, on a piece of 6x4in photo paper.
Anyone got any idea how I could do this?
Focusing on the part about bringing up large images in Processing, I did a Google search and came up with this thread. Quoting their problem and results:
The goal is to print a 180 pdi image with a shape depending on the
original canvas. So can be diffrent but it will end up being a
1500x1000mm picture approximately. So a big image. I'm not trying to
display it just to dump it into a file.
Then I setup a 64bits JVM. The latest one from Oracle website. Then I
created different size of picture and push the memory up to 1024MB. 5000x7500 test OK and 6000x9000 test OK
I tried to setup the memory up to 1500MB, but the JVM was not able to start.
So I tried 1200MB 8000x12000 test OK
So it doesn't do the image-printing part but it brings up key information on getting large images in memory via a Java Virtual Machine (JVM).
Lastly, this thread describes a TileSaver class for viewing/printing a large number of pixels using OpenGL. I pasted a large code block below. (This may be unrelated to your question but makes the answer more complete for other uses.)
import processing.opengl.*;
import toxi.geom.*;
Tiler tiler;
void setup() {
size(640,480,OPENGL);
tiler=new Tiler((PGraphics3D)g,NUM_TILES);
}
void draw() {
// see thread
}
/**
* Implements a screen tile exporter with support for FOV,
* clip planes and flexible file formats.
*
* Re-engineered from an older version by Marius Watz:
* http://workshop.evolutionzone.com/unlekkerlib/
*
* #author toxi <info at postspectacular dot com>
*/
class Tiler {
protected PGraphics3D gfx;
protected PImage buffer;
protected Vec2D[] tileOffsets;
protected double top;
protected double bottom;
protected double left;
protected double right;
protected Vec2D tileSize;
protected int numTiles;
protected int tileID;
protected float subTileID;
protected boolean isTiling;
protected String fileName;
protected String format;
protected double cameraFOV;
protected double cameraFar;
protected double cameraNear;
public Tiler(PGraphics3D g, int n) {
gfx = g;
numTiles = n;
}
public void chooseTile(int id) {
Vec2D o = tileOffsets[id];
gfx.frustum(o.x, o.x + tileSize.x, o.y, o.y + tileSize.y,
(float) cameraNear, (float) cameraFar);
}
public void initTiles(float fov, float near, float far) {
tileOffsets = new Vec2D[numTiles * numTiles];
double aspect = (double) gfx.width / gfx.height;
cameraFOV = fov;
cameraNear = near;
cameraFar = far;
top = Math.tan(cameraFOV * 0.5) * cameraNear;
bottom = -top;
left = aspect * bottom;
right = aspect * top;
int idx = 0;
tileSize = new Vec2D((float) (2 * right / numTiles), (float) (2 * top / numTiles));
double y = top - tileSize.y;
while (idx < tileOffsets.length) {
double x = left;
for (int xi = 0; xi < numTiles; xi++) {
tileOffsets[idx++] = new Vec2D((float) x, (float) y);
x += tileSize.x;
}
y -= tileSize.y;
}
}
public void post() {
if (isTiling) {
subTileID += 0.5;
if (subTileID > 1) {
int x = tileID % numTiles;
int y = tileID / numTiles;
gfx.loadPixels();
buffer.set(x * gfx.width, y * gfx.height, gfx);
if (tileID == tileOffsets.length - 1) {
buffer.save(fileName + "_" + buffer.width + "x"
+ buffer.height + "." + format);
buffer = null;
}
subTileID = 0;
isTiling = (++tileID < tileOffsets.length);
}
}
}
public void pre() {
if (isTiling) {
chooseTile(tileID);
}
}
public void save(String path, String baseName, String format) {
(new File(path)).mkdirs();
this.fileName = path + "/" + baseName;
this.format = format;
buffer = new PImage(gfx.width * numTiles, gfx.height * numTiles);
tileID = 0;
subTileID = 0;
isTiling = true;
}
public boolean isTiling() {
return isTiling;
}
}

Away3D 4.0 Loading dynamic textures for primitives from arrays

I have several arrays storing the attributes needed to build primitives. One array stores the widths, another stores the heights, another the depths, x, y, z etc. I have one more that stores the remote filename for the texture to be applied. After I get my response from the server I attempt to apply the textures to the primitives. When I move the camera to look at the primitive, I am not able to see it. My view seems to freeze up (the view will not update). Once the camera has moved past the primitive, it can see again. Any ideas?
private var loadedBuildingTextures:Object = new Object();
private var map_building_count:Number = 0;
private var loadedBuildings:Number = 0;
public var map_building_widths:Array;
public var map_building_heights:Array;
public var map_building_depths:Array;
public var map_building_xs:Array;
public var map_building_ys:Array;
public var map_building_zs:Array;
public var map_building_textures:Array;
// I POPULATE THE ARRAYS BUT LEFT THAT CODE OUT FOR SIMPLICITY
public function placeBuildings():void {
trace('FUNCTION: placeBuildings() fired');
var buildingsPlaced:Number = 0;
for (var a:Number = 0; a < map_building_count; a++ ) {
loadedBuildingTextures['texture_' + a.toString()] = new BitmapFileMaterial(map_building_textures[a]); // ASSIGNS THE BitmapFileMaterials TO AN OBJECT FOR REFERENCING LATER
loadedBuildingTextures['texture_' + a.toString()].loader.contentLoaderInfo.addEventListener(Event.COMPLETE, postBuildingLoad);
buildingsPlaced++;
}
trace('placed ' + buildingsPlaced.toString() + ' of ' + map_building_count.toString() + ' buildings.'); // OUTPUT = "placed 4 of 4 buildings."
trace('FUNCTION: placeBuildings() completed');
}
public function postBuildingLoad(event : Event):void {
loadedBuildings++;
if (int(loadedBuildings) == int(map_building_count)) {
placeBuildingsStep2();
}
}
public function placeBuildingsStep2():void {
trace('RECEIVED ALL RESPONSES FROM SERVER FOR TEXTURES');
for (var a:Number = 0; a < map_building_count; a++ ) {
cube = new Cube(
loadedBuildingTextures['texture_' + a], // <----- THIS SEEMS TO BE THE PROBLEM
map_building_widths[a], // WIDTH
map_building_heights[a], // HEIGHT
map_building_depths[a], // DEPTH
1, // WIDTH UNITS
1, // HEIGHT UNITS
1, // DEPTH UNITS
true);
cube.x = map_building_xs[a];
cube.y = map_building_ys[a];
cube.z = map_building_zs[a];
view.scene.addChild(cube);
}
}
Although this post is old, it does highlight an important issue. BitmapFileMaterial is more a shortcut to test than a production ready scheme.
I would highly recommend using a loading queue for external assets (like LoaderMax or the new AssetLibrary in 4.0) and then instantiate materials as needed.

Custom XNA Game loop in Windows

I'm trying to figure out how to manage the whole game loop manually in a Windows game, without using the regular Game Microsoft.Xna.Framework.Game class.
The reason for this is using the regular Game class causes some stuttering in my game. Not much, but because of the specific nature of the game it is still quite visible.
After trying a bunch of different settings (vsync, fixedtimestep, various framerates etc.) I decided to try write my own Game class to have full control of the timing. I am not sure that will fix it, but at least this way I have full control.
Basically I need to:
Set up the game window
In a loop: Do all rendering as usual, and then flush the result to the screen, manage backbuffers etc.
Anyone knows how to do this? It sounds quite easy in fact, but could not find any documentation on how to do it.
Not sure what I am doing wrong, but I have the following code (just for testing, timing will be handled differently), and the loop will run for a little while then stop. Once I pass my mousepointer over the window the loop will run for a little while again.
private void Application_Idle(object pSender, EventArgs pEventArgs)
{
Thread.Sleep(500);
//Message message;
//while (!PeekMessage(out message, IntPtr.Zero, 0, 0, 0))
{
gametime.update();
Update(gametime);
Draw(gametime);
GraphicsDevice.Present();
}
}
If enabling the "while PeekMessage", the loop will run continuously, but ignoring the sleep and also stopping when the mouse is moving over the window. Not sure what is going on here...
I think optimally I would just want to do something simple like this in the main render loop:
while (alive)
{
Thread.Sleep(100);
gametime.update();
Update(gametime);
Draw(gametime);
GraphicsDevice.Present();
}
But in this case the window remains blank, as it seems the window is not actually being redrawn with the new content. I tried a form.Refresh(), but still no go... Any ideas?
(added xbox information)
for windows you Basically need to create a Form and Show it, then store its handle and the form itself.
Using this handle you can create a GraphicsDevice.
Then you hook Application.Idle to your own function that calls your update and render.
For example
public class MyGame
{
public Form form;
public GraphicsDevice GraphicsDevice;
public MyGame()
{
form = new Form();
form.ClientSize = new Size(1280, 1024);
form.MainMenuStrip = null;
form.Show();
}
public void Run()
{
PresentationParameters pp = new PresentationParameters();
pp.DeviceWindowHandle = form.Handle;
pp.BackBufferFormat = SurfaceFormat.Color;
pp.BackBufferWidth = 1280;
pp.BackBufferHeight = 1024;
pp.RenderTargetUsage = RenderTargetUsage.DiscardContents;
pp.IsFullScreen = false;
pp.MultiSampleCount = 16;
pp.DepthStencilFormat = DepthFormat.Depth24Stencil8;
GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
GraphicsProfile.HiDef,
pp);
Application.Idle += new EventHandler(Application_Idle);
Application.Run(form);
}
private void Application_Idle(object pSender, EventArgs pEventArgs)
{
Message message;
while (!PeekMessage(out message, IntPtr.Zero, 0, 0, 0))
{
/* Your logic goes here
Custom timing and so on
Update();
Render();
*/
}
}
void Render()
{
GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1, 0);
//Your logic here.
GraphicsDevice.Present();
}
[StructLayout(LayoutKind.Sequential)]
private struct Message
{
public IntPtr hWnd;
public int msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public Point p;
}
[return: MarshalAs(UnmanagedType.Bool)]
[SuppressUnmanagedCodeSecurity, DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint
messageFilterMin, uint messageFilterMax, uint flags);
}
EDIT 1
For xbox you may just be able to place your own custom run function with your game loop in a throttled while true loop. Inside that run outside the top of the while true you will probably have to do the graphics device initialization and verification with IntPtr.Zero as your handle
EDIT 2
i use something like this ( got from http://www.koonsolo.com/news/dewitters-gameloop/ )
private long nextGameTick;
private Stopwatch stopwatch;
const int ticksPerSecond = 60;
const int skipTicks = 1000 / ticksPerSecond;
private const int maxSkip = 10;
`constructor
stopwatch = Stopwatch.StartNew();
nextGameTick = stopwatch.ElapsedMilliseconds;
`loop
int loops = 0;
long currentTick = stopwatch.ElapsedMilliseconds;
while ( (ulong)(currentTick - nextGameTick) > skipTicks && loops < maxSkip)
{
Update(16.667f);
nextGameTick += skipTicks;
loops++;
}
PreRender();
Render();
PostRender();
EDIT 3
Creating a content manager was a little more work, but still managable. You need to create a class that implements IServiceProvider. This class takes a GraphicsDevice in its constructor in order to create the next class the implements IGraphicsDeviceProvider. in addition I implement GetService like this
//in implementer of IServiceProvider
public object GetService ( Type serviceType )
{
if ( serviceType == typeof ( IGraphicsDeviceService ) )
{
return myGraphicsService;
}
return null;
}
For convenience i also add a method to the class to create and return managers
//in implementer of IServiceProvider
public ContentManager CreateContentManager( string sPath )
{
ContentManager content = new ContentManager(this);
content.RootDirectory = sPath;
return content;
}
In addition i create a class that implements IGraphicsDeviceService and takes a reference to my GraphicsDevice. then I create a property and field in it like so
//in implementer of IGraphicsDeviceService
private GraphicsDevice graphicsDevice;
public GraphicsDevice GraphicsDevice
{
get
{
return graphicsDevice;
}
}
So the call ends up being somehting like
MyServiceProvider m = new MyServiceProvider(graphicsDevice);
ContentManager content = m.CreateContentManager("Content");
where
MyServiceProvider(GraphicsDevice graphicsDevice)
{
myGraphicsService = new MyGraphicsDeviceService(graphicsDevice);
}
MyGraphicsDeviceService(GraphicsDevice gfxDevice)
{
graphicsDevice = gfxDevice;
}
-Sorry for fragmenting the code around but its not something i wrote too recently so im having difficulty remembering parts.
EDIT 4
i had an odd case with my custom game i just remembered when i new the Form for it i
had to bind
private void IgnoreAlt(object pSender, KeyEventArgs pEventArgs)
{
if (pEventArgs.Alt && pEventArgs.KeyCode != Keys.F4)
pEventArgs.Handled = true;
}
to
form.KeyUp += IgnoreAlt;
form.KeyDown += IgnoreAlt;
otherwise i got some horrible stalls.

Resources