Sign in to follow this  
Guest iholrf

My gauge coding style recommendation

Recommended Posts

Please read my suggestions open-minded and criticize it.I would like to see clearly before jumping into biggergauge programming projects (well, I am in already...)I am a newbie in gauge programing, but I have quite a lotC programming experience. Recently I had to touch a gaugecode and I was shocked about the logic it was designed.Later I learned that - at least partially - it was comingfrom the RECOMMENDED structure of gauge programming.The main problem is the "including-everything-together"method. It has the following disadvantages:- everything is global, you are forced to figure out funny variable and function names to avoid conflicts;- it is rather difficult to manage which gauge can see and use which variables;- difficult to test, what happens if I remove/replace a module;- compilation time is long (everything is compiled)I played a bit around and I created a programming stylethat is very closed to the traditional, but allows youto do structured programming.Traditional structure starts like this:=======================================================MAIN GAUGE PACK FILE (TRADITIONAL)//-----------------------------------------------------#define GAUGE_NAME "COM_Radio"#define GAUGEHDR_VAR_NAME ComHdr#define GAUGE_W 100#include "my_gauge_1.c"//-----------------------------------------------------#define GAUGE_NAME "Gyro"#define GAUGEHDR_VAR_NAME GyroHdr#define GAUGE_W 200#include "my_gauge_2.c"...=======================================================I modified the code structure as follows:- removed includes and defined gauge header vars extern- reorganized module code to allow macros work- used all macros to define static vars/structures- only gauge hdr macro is let to global- defined all callbacks as staticThe additional advantage is that I could use constant names for general components:- bacground (static element name)- pbackground (pointer to above)- rect (mouse rectangle)- callBack (gauge call back function)Here is my suggested structure (please be aware of that- for historical reasons - I had to play with an olderversion FS code, but I hope it does not matter):=======================================================My versionextern GAUGEHDR comhdr; // com radioextern GAUGEHDR gyrohdr; // gyroscope...// The gauge table is the same in both versionsGAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&ComHdr) GAUGE_TABLE_ENTRY(&GyroHdr)GAUGE_TABLE_END()==============================================================================================================INDIVIDUAL GAUGE FILE FOR COM RADIO#include "gauges_2k2.h" // or newer//--- Mouse function ---------------------------------static BOOL FSAPI mouse_cb_1( ... ){ ...}// name of mouse rectangle can be same in each modulestatic MOUSE_BEGIN( rect, HELP_NONE, 0, 0 ) MOUSE_CHILD_FUNCT( ... )MOUSE_END//--- Element callbacks ------------------------------FLOAT64 FSAPI element_1_cb( ... ){ ...}//--- Gauge Callback Function ------------------------// name of function can be same in each modulestatic void FSAPI callBack ( ... ){ ...}//--- Gauge header -----------------------------------// Only gauge var name and gauge name should be set// Notice: GAUGE_HEADER_FS700 is the only macro not static!#define GAUGEHDR_VAR_NAME ComHdrstatic PELEMENT_HEADER pbackground;GAUGE_HEADER_FS700(153, "COM_Radio", &pbackground, rect, callBack, 0, 0, 0);//--- Gauge elements ---------------------------------#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMAL... all gauge element macros defined as static ...static MAKE_STATIC( background, // this can be the same in each module BMP_COM_BG, &pswitch, NULL, IMAGE_USE_TRANSPARENCY|IMAGE_USE_ERASE, 0, 0,0)// this can be the same in each modulestatic PELEMENT_HEADER pbackground = &background.header;=======================================================That's all by now, but I have some other ideas as well ;)Gabor

Share this post

Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this