Adding an interactive panel to a vessel

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
So, I thought I'd make a short tutorial covering panels in vessel modules. I'm currently adding a panel to EOP, so I'll use it as an example.

Part 1: Preparing the Panel

1. First, get a panel drawn. I'm using wehaveaproblem's panel that he drew specifically for EOP. I'd reccomend you make the dimensions 1024 x 768, as this is compatible with most resolutions.

2. Bring the panel to the bottom of the image, and leave the rest white:
IDBPANEL1.JPG



3. You can save the image either as an 8-bit (256 colours) or 24-bit bitmap (.bmp). 24-bit will let you use a higher quality image, but will be slower.

4. Save the panel in the vessel's project folder.

Part 2: Making a resource file

1. To make your panel loadable from orbiter, you need to make a resource (.rc) file for it. That means you need a resource editor. If you have the "full" version of visual studio, there's one included, otherwise you will have to use a free 3rd party editor. I strongly suggest ResEdit, which is what I will use in this tutorial. Download and install it.

2. Open ResEdit and make a new resource (File > New project). In the "Save As" dialog, navigate to your vessel's project folder and save it with a capitalised name (good practice).

3. Add a new bitmap (File > Add a resource... > Bitmap). Click "Create from an existing file" and click next. Browse for your panel bitmap and open it. In the dialog that appears, choose "Relative Path".

4. You will see your panel appear in right pane and a new resource will appear in the left pane. In the "Bitmap" folder, right click the resource and click "Rename". In "Ordinal Identifier", enter a new name. This is a Resource ID - choose something capitalised and relevant.

5. Save the resource.

Part 3: Coding

1. Open your vessel's project in visual studio. Click Project > Add Existing Item... and add these files (hold CTRL to select multiple items)

-Your panel's .bmp file
-The .rc file that ResEdit has generated
-"resource.h" that ResEdit has also generated

2. In your central header / cpp file, add this at the top:

Code:
#include "resource.h"

This allows access to the resource file (and it's contents)

3. Find your vessel's class declaration (where you declare member variables and functions), and add this callback function if you haven't already:

Code:
bool clbkLoadPanel(int id);

4. Create a new global variable HINSTANCE hDLL . Define the InitModule callback function somewhere, and inside it place this code:
Code:
hDLL = hModule;

Make sure you've defined ORBITER_MODULE somewhere or InitModule won't be called! #define it before you #include orbitersdk.h

5. In a cpp file, define the clbkLoadPanel method and add the code:

Code:
bool EOP::clbkLoadPanel(int id) {
//replace IDBPANEL1 with your resource ID (see resource.h if you can't remember)
HBITMAP hBmp = LoadBitmap (hDLL, MAKEINTRESOURCE(TIDBPANEL1));
oapiRegisterPanelBackground (hBmp,
PANEL_ATTACH_BOTTOM|PANEL_MOVEOUT_BOTTOM, 0xFFFFFF);
return true;
}

That should render the panel when you are in panel mode. Test it first before moving on.

If it doesn't work, check these:


- Is there something wrong with your bitmap? It must be 24-bit or 8-bit.

-Is there something wrong with the resource? Try making it again in ResEdit and follow my steps closely.

-Did you add the three files to your project?

-Are there any plugin modules activated? Some plugins (like mine xD) might cause Orbiter to crash anyway.

Experiment with oapiDebugString() until you find the problem.

If it did work, well done!
screen2.JPG

The reason mine looks really small is because I run Orbiter at a stupidly high resolution ( 1680 x 1050, it looks nice on a 22" monitor ;)) You should be able to move around the panel with the arrow keys.

More in another tutorial.
 
Top