This code should divide a screen in a certain number of parts, and then compute the size of various drawings knowing how much "parts" each drawing needs.
#include <iostream>
using namespace std;
// number of divisions per element
#define AREA_MarginSX 1
#define AREA_SpaceSX 1
#define AREA_Drawing 4
#define AREA_SpaceCN 1
#define AREA_Chart 4
#define AREA_SpaceDX 1
#define AREA_Total_DIV AREA_MarginSX + AREA_SpaceSX + AREA_Drawing + AREA_SpaceCN + AREA_Chart + AREA_SpaceDX
// L'area ORIZZONTALE totale viene divisa in questo modo:
// margine sx (etichette asse y), Aree x NumSensori, margine dx
#define DRAW_Margin_SX 3
#define DRAW_Margin_DX 1
// l'area verticale viene divisa in Margine inferiore, area del grafico, e margine superiore
#define DRAW_Margin_Bottom 2
#define DRAW_AreaHeight 13
#define DRAW_Margin_Top 1
int main() {
int NumAreas = 3;
int ScreenWidth = 480;
int ScreenHeight = 270;
int NumDivsX = DRAW_Margin_SX + AREA_Total_DIV*NumAreas + DRAW_Margin_DX;
int NumDivsY = DRAW_Margin_Bottom + DRAW_AreaHeight + DRAW_Margin_Top;
double ChartDivX = (double)ScreenWidth / (double)NumDivsX;
double ChartDivY = (double)ScreenHeight / (double)NumDivsY;
cout << "ChartArea Width (px) =" << ChartDivX << " * " << AREA_Total_DIV << " = " << ChartDivX*AREA_Total_DIV << endl;
cout << "ChartArea Height (px) =" << ChartDivY << " * " << DRAW_AreaHeight << " = " << ChartDivY*DRAW_AreaHeight << endl;
cout << "TEST 1: " << ChartDivX << " * " << 12 << " = " << ChartDivX*12 << endl;
cout << "TEST 2: " << ChartDivX << " * " << "12.0" << " = " << ChartDivX*12.0 << endl;
}
The output is:
ChartArea Width (px) =26.6667 * 12 = 37.6667 <=== WHY?
ChartArea Height (px) =16.875 * 13 = 219.375
TEST 1: 26.6667 * 12 = 320
TEST 2: 26.6667 * 12.0 = 320
I don't understand why i get that 37.6667, but the right result on the second multiply.