- Messages
- 36
- Country
Hello,
I stumbled over a little problem with my first trial standing on my own feet with GDI+ in FS9 - the gauge stays empty - no ERROR, no fault, it simply doesn't draw anything (although I added some draw code)...
Some general information:
I use Dai's latest gauge.h from sd2gau29 (fsxgauges_sp2.h) with some modifications of mine. The IDE and compiler setup (MS VS 2008) worked with other FS projects (normal gauges, modules w/ and w/o FSUIPC useage) so far. I also have received and compiled the GDI+ template from Bill (thank you very much again!) and it works in FS too. Now I have started my own GDI project with inspiration from Bill's - and I can not see any obvious reason why it should not work, thats why I have to ask here if you could point out to me whats fishy.
Setup is easy:
It all compiles well (beside the 3 warnings not to use the deprecated fopen and fprintf but rather the mem safe versions _s...), loads in FS and gives me the output in my hand made debug file dump - the only thing it doesn't do is show anything...
Here you can see from my debug dump that the loading, initialization and closing works (compare to the code blocks from where these prompts are written). The pelement data seems to be correct too. As you can see from this dump: PANEL_SERVICE_DISCONNECT is never triggered, thats why I moved the close_gdiplus() method call to PANEL_SERVICE_PRE_KILL
Attached are the contents of the 3 files I think you might want to see.
I hope someone can help me, as it would be nice if I could use GDI+ in my gauges as well (reminds me sooo much of PostScript I once could write by hand...)
Thank you in advance,
Jakob
(GDIPlusTest.cpp)
(GDIPlusTest.h)
and the suspected heart of the problem: the Hello subgauge:
(GDIPlusTest.Hello.cpp)
I stumbled over a little problem with my first trial standing on my own feet with GDI+ in FS9 - the gauge stays empty - no ERROR, no fault, it simply doesn't draw anything (although I added some draw code)...
Some general information:
I use Dai's latest gauge.h from sd2gau29 (fsxgauges_sp2.h) with some modifications of mine. The IDE and compiler setup (MS VS 2008) worked with other FS projects (normal gauges, modules w/ and w/o FSUIPC useage) so far. I also have received and compiled the GDI+ template from Bill (thank you very much again!) and it works in FS too. Now I have started my own GDI project with inspiration from Bill's - and I can not see any obvious reason why it should not work, thats why I have to ask here if you could point out to me whats fishy.
Setup is easy:
- One "master" .cpp #including the subgauges in classic multigauge cluster style with one .h (GDIPlusTest.cpp and GDIPlusTest.h).
- There is only one subgauge .cpp for my "Hello GDI+ World" gauge (GDIPlusTest.Hello.cpp).
- Resources are 2 bitmaps (24bpp, 100x100) one for the Background STATIC_IMAGE (all 0x010101), one for the canvas - the STATIC on which I try to draw on (pure black) and of course the resource file script.
- In the build targets (both debug & release) under Linker Options there is gdiplus.lib added.
It all compiles well (beside the 3 warnings not to use the deprecated fopen and fprintf but rather the mem safe versions _s...), loads in FS and gives me the output in my hand made debug file dump - the only thing it doesn't do is show anything...
Here you can see from my debug dump that the loading, initialization and closing works (compare to the code blocks from where these prompts are written). The pelement data seems to be correct too. As you can see from this dump: PANEL_SERVICE_DISCONNECT is never triggered, thats why I moved the close_gdiplus() method call to PANEL_SERVICE_PRE_KILL
Code:
####################
New Session
####################
Gauge: Hello
2010-08-01T20:20:59.718Z Service ID: PANEL_SERVICE_CONNECT_TO_WINDOW
2010-08-01T20:20:59.718Z Gauge: Hello opened, gdiplusUsers 1
2010-08-01T20:20:59.718Z Service ID: PANEL_SERVICE_PRE_QUERY
2010-08-01T20:20:59.718Z Service ID: PANEL_SERVICE_POST_QUERY
2010-08-01T20:21:00.093Z Service ID: PANEL_SERVICE_PRE_INSTALL
2010-08-01T20:21:00.093Z Service ID: PANEL_SERVICE_POST_INSTALL
2010-08-01T20:21:00.109Z Service ID: PANEL_SERVICE_PRE_INITIALIZE
2010-08-01T20:21:00.109Z Service ID: PANEL_SERVICE_POST_INITIALIZE
2010-08-01T20:21:00.109Z Service ID: PANEL_SERVICE_PANEL_OPEN
2010-08-01T20:21:00.687Z Service ID: PANEL_SERVICE_PRE_INITIALIZE
2010-08-01T20:21:00.687Z Service ID: PANEL_SERVICE_POST_INITIALIZE
2010-08-01T20:21:00.687Z Service ID: PANEL_SERVICE_PRE_UPDATE
2010-08-01T20:21:00.687Z Service ID: PANEL_SERVICE_POST_UPDATE
2010-08-01T20:21:02.468Z Service ID: PANEL_SERVICE_PRE_GENERATE
2010-08-01T20:21:02.468Z Service ID: PANEL_SERVICE_POST_GENERATE
2010-08-01T20:21:02.468Z Service ID: PANEL_SERVICE_PRE_DRAW
2010-08-01T20:21:02.468Z pelement final dim.x 83, final dim.y 83
2010-08-01T20:21:02.468Z pelement source dim.x 83, source dim.y 83
2010-08-01T20:21:02.468Z pelement element_type 0 (ELEMENT_TYPE_STATIC_IMAGE)
2010-08-01T20:21:02.468Z pelement position.x 166, position.y 0
2010-08-01T20:21:02.468Z pelement hdc (so 4) 3001449a
2010-08-01T20:21:02.468Z Service ID: PANEL_SERVICE_POST_DRAW
2010-08-01T20:21:05.828Z Service ID: PANEL_SERVICE_PRE_DRAW
2010-08-01T20:21:05.828Z Service ID: PANEL_SERVICE_POST_DRAW
[....]
2010-08-01T20:21:31.250Z Service ID: PANEL_SERVICE_PRE_UPDATE
2010-08-01T20:21:31.250Z Service ID: PANEL_SERVICE_POST_UPDATE
2010-08-01T20:21:31.250Z Service ID: PANEL_SERVICE_PRE_DRAW
2010-08-01T20:21:31.250Z Service ID: PANEL_SERVICE_POST_DRAW
2010-08-01T20:21:31.281Z Service ID: PANEL_SERVICE_PRE_UPDATE
2010-08-01T20:21:31.281Z Service ID: PANEL_SERVICE_POST_UPDATE
2010-08-01T20:21:31.296Z Service ID: PANEL_SERVICE_PRE_DRAW
2010-08-01T20:21:31.296Z Service ID: PANEL_SERVICE_POST_DRAW
[....]
2010-08-01T20:21:40.015Z Service ID: PANEL_SERVICE_PRE_DRAW
2010-08-01T20:21:40.015Z Service ID: PANEL_SERVICE_POST_DRAW
2010-08-01T20:21:40.031Z Service ID: PANEL_SERVICE_PRE_UPDATE
2010-08-01T20:21:40.031Z Service ID: PANEL_SERVICE_POST_UPDATE
2010-08-01T20:21:45.875Z Service ID: PANEL_SERVICE_PANEL_CLOSE
2010-08-01T20:21:45.875Z Service ID: PANEL_SERVICE_PRE_KILL
2010-08-01T20:21:45.875Z Gdiplus Shutdown
2010-08-01T20:21:45.875Z gdiplusUsers 0
Attached are the contents of the 3 files I think you might want to see.
I hope someone can help me, as it would be nice if I could use GDI+ in my gauges as well (reminds me sooo much of PostScript I once could write by hand...)
Thank you in advance,
Jakob
(GDIPlusTest.cpp)
Code:
// GDIPlusTest.cpp
// Copyright (c) 2010 Jakob Klein, Project Open Sky. All Rights Reserved.
#include "..\inc\fsxgauges_sp2_jk.h"
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <windows.h>
#include <Gdiplus.h>
using namespace Gdiplus;
#include "GDIPlusTest.h"
/////////////////////////////////////////////////////////////////////////////
// Global GDI+ Variables
/////////////////////////////////////////////////////////////////////////////
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
int gdiplusUsers = 0;
bool gdiplus_initialized = false;
/////////////////////////////////////////////////////////////////////////////
// Hello GDI+ World
/////////////////////////////////////////////////////////////////////////////
#define GAUGE_NAME "Hello"
#define GAUGEHDR_VAR_NAME gaugehdr_hello
#define GAUGE_W 100
#include "GDIPlusTest.Hello.cpp"
/////////////////////////////////////////////////////////////////////////////
// Gauge table entries
/////////////////////////////////////////////////////////////////////////////
GAUGE_TABLE_BEGIN_JK(MODULE_INIT_NONE, MODULE_DEINIT_NONE)
GAUGE_TABLE_ENTRY(&gaugehdr_hello)
GAUGE_TABLE_END()
(GDIPlusTest.h)
Code:
// GDIPlusTest.h
// Copyright (c) 2010 Jakob Klein, Project Open Sky. All rights reserved.
//
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_BUILD 0
// magic to get the preprocessor to do what we want
#define lita(arg) #arg
#define xlita(arg) lita(arg)
#define cat3(w,x,z) w##.##x##.##z##\000
#define xcat3(w,x,z) cat3(w,x,z)
#define VERSION_STRING xlita(xcat3(VERSION_MAJOR,VERSION_MINOR,VERSION_BUILD))
#ifndef VS_VERSION_INFO
#define VS_VERSION_INFO 0x0001
#endif
////////////////////////////////////
//
// Common Defines
//
#define ULONG_PTR DWORD
#define GAUGE_CHARSET DEFAULT_CHARSET
#define GAUGE_FONT_DEFAULT "Courier New"
#define GAUGE_WEIGHT_DEFAULT FW_NORMAL
/////////////////////////////////////////////////////////////////////////////
//
// Hello Bitmaps
//
#define BMP_HELLO_SMALL_BACKGROUND 0x0100
#define BMP_HELLO_SMALL_CANVAS 0x0104
and the suspected heart of the problem: the Hello subgauge:
(GDIPlusTest.Hello.cpp)
Code:
// GDIPlusTest.Hello.cpp
// Copyright (c) 2010 Jakob Klein, Project Open Sky. All rights reserved.
// Set up gauge header
char hello_gauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER hello_list;
extern MOUSERECT hello_mouse_rect[];
/////////////////////////////////////////////////////////////////////////////
// Gauge Specific Declarations
//
GAUGE_CALLBACK hello_callback;
float hello_width = 100.0f;
float hello_height = 100.0f;
FILE* debug_file;
bool debug_output_done = false;
/////////////////////////////////////////////////////////////////////////////
// GDI+ Defines
//
Color black (0x01, 0x01, 0x01);
Color transBlack (0, 0, 0);
Color white (0xFF, 0xFF, 0xFF);
Color red (0xFF, 0, 0);
Color green (0, 0xFF, 0);
Color blue (0, 0, 0xFF);
Color cyan (0, 0xFF, 0xFF);
Color magenta (0xFF, 0, 0xFF);
Pen whitePen (white, 1);
SolidBrush whiteBrush (white);
/////////////////////////////////////////////////////////////////////////////
// Mouse Rectangle Macro
//
MOUSE_BEGIN( hello_mouse_rect, NULL, 0, 0 )
MOUSE_END
/////////////////////////////////////////////////////////////////////////////
// Gauge Header Macro
//
GAUGE_HEADER_FS700(GAUGE_W, hello_gauge_name, &hello_list, \
hello_mouse_rect, hello_callback, 0, 0, 0);
/////////////////////////////////////////////////////////////////////////////
// GDI+ Canvas Static
//
MAKE_STATIC (
hello_canvas,
BMP_HELLO_SMALL_CANVAS,
NULL,
NULL,
IMAGE_USE_TRANSPARENCY | IMAGE_USE_BRIGHT | IMAGE_CREATE_DIBSECTION,
0,
0,0
)
PELEMENT_HEADER hello_canvas_plist[] =
{
&hello_canvas.header,
NULL
};
/////////////////////////////////////////////////////////////////////////////
// Background Static
//
MAKE_STATIC (
hello_background,
BMP_HELLO_SMALL_BACKGROUND,
&hello_canvas_plist,
NULL,
IMAGE_USE_TRANSPARENCY,
0,
0,0
)
PELEMENT_HEADER hello_list = &hello_background.header;
/////////////////////////////////////////////////////////////////////////////
// Set Render Quality Routine
//
void set_render_quality(Graphics& graphics)
{
graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
}
/////////////////////////////////////////////////////////////////////////////
// Custom Debug Printer
// useage analouge to printf (fprintf(debug_file, format, ...))
// outputs timestamped text to debug file.
//
void dprintf( const char* format, ... )
{
if (debug_file)
{
va_list args;
SYSTEMTIME now;
GetSystemTime(&now);
fprintf(debug_file, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ ", now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond, now.wMilliseconds );
va_start(args, format);
vfprintf(debug_file, format, args);
va_end(args);
fprintf(debug_file, "\n");
}
}
/////////////////////////////////////////////////////////////////////////////
// GDI Plus Startup Method and User Registration
//
bool start_gdiplus()
{
gdiplusUsers ++;
if (!gdiplus_initialized)
{
if (GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) == 0)
{
gdiplus_initialized = true;
dprintf("Gauge: %s opened, gdiplusUsers %d", GAUGE_NAME, gdiplusUsers);
}
}
return gdiplus_initialized;
}
/////////////////////////////////////////////////////////////////////////////
// GDI Plus Closedown Method with user unlisting
bool close_gdiplus()
{
if (gdiplus_initialized)
gdiplusUsers--;
if (gdiplus_initialized && gdiplusUsers <= 0)
{
GdiplusShutdown(gdiplusToken);
gdiplus_initialized = false;
dprintf("Gdiplus Shutdown");
}
dprintf("gdiplusUsers %d", gdiplusUsers);
return !gdiplus_initialized;
}
/////////////////////////////////////////////////////////////////////////////
// Main Gauge Callback Routine
// Switches service dependent actions.
//
void FSAPI hello_callback( PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data )
{
if (!debug_file)
{
debug_file = fopen("G:\\Eigene Dokumente\\Aircraft Modeling\\Programming\\POSKY Gauges\\debug.txt", "a");
fprintf(debug_file, "####################\nNew Session\n####################\nGauge: %s\n", GAUGE_NAME);
}
switch (service_id)
{
case PANEL_SERVICE_PRE_DRAW:
dprintf("Service ID: PANEL_SERVICE_PRE_DRAW");
if (!gdiplus_initialized)
start_gdiplus();
if (gdiplus_initialized)
{
PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list[0]->next_element[0]);
if (pelement)
{
HDC hdc = pelement->hdc;
PIXPOINT dim = pelement->image_data.final->dim;
if (hdc)
{
//Beep(1000,200);
Graphics graphics(hdc);
FLOAT64 dx = dim.x / hello_width;
FLOAT64 dy = dim.y / hello_height;
set_render_quality(graphics);
if (!debug_output_done)
{
dprintf("pelement final dim.x %d, final dim.y %d", dim.x, dim.y);
dprintf("pelement source dim.x %d, source dim.y %d", pelement->image_data.source->dim.x, pelement->image_data.source->dim.y);
dprintf("pelement element_type %d", pgauge->elements_list[0]->next_element[0]->element_type);
dprintf("pelement position.x %d, position.y %d", pelement->position.x, pelement->position.y );
dprintf("pelement hdc (so %d) %x", sizeof(hdc), hdc);
debug_output_done = true;
}
graphics.ScaleTransform(dx, dy);
// Do Drawing
graphics.Clear(black);
// Draw white X
graphics.DrawLine(&whitePen,0,0,100,100);
graphics.DrawLine(&whitePen,0,100,100,0);
// Draw Inset Filled Box
Point box[5] = { Point(10,10), Point(10,90), Point(90,90), Point(90,10), Point(10,10) };
graphics.FillPolygon(&whiteBrush, box, 5);
}
// Set region "offscreen" to trigger redraw in FS.
SET_OFF_SCREEN(pelement);
}
}
break;
case PANEL_SERVICE_PRE_KILL:
dprintf("Service ID: PANEL_SERVICE_PRE_KILL");
close_gdiplus();
fclose(debug_file);
debug_file = NULL;
break;
case PANEL_SERVICE_CONNECT_TO_WINDOW:
dprintf("Service ID: PANEL_SERVICE_CONNECT_TO_WINDOW");
start_gdiplus();
break;
case PANEL_SERVICE_DISCONNECT:
dprintf("Service ID: PANEL_SERVICE_DISCONNECT");
break;
}
}
/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
Last edited: