#pragma once
#include <windows.h>
#include <windowsx.h>
#include "vector.h"
//#define T(x) TEXT(x)
#define elemof(x) (sizeof(x)/sizeof(*(x)))
#define nobreak
struct Rect:public RECT{
int width() const {return right-left;}
int height() const {return bottom-top;}
const int&operator[](int x) const {return (const int&)(&left)[x];}
};
struct Label{
PTSTR string;
float position;
int priority; // bspw. 99 für kalkulierte Labels, 0 für Anwender-Labels, 1 für Achsenenden
};
class XY;
class Plot;
class Scale:public Rect{
public:
Scale(XY*_parent):a(0),e(10),F(1),O(0),name(0),format(TEXT("%.2f")),parent(_parent) {};
int side; // left+topdown/top+leftright/right+topdown/bottom+leftright/left+downup/top+rightleft/right+downup/bottom+rightleft
// Bit 0: X- oder Y-Ausrichtung
// Bit 1: links/oben (0) oder rechts/unten (1)
// Bit 2: nach rechts/unten wachsend (0) oder umgekehrt (1)
// Bit 3: logarithmisch
// Bit 4: Partiell linear/logarithmisch
float a,e; // Anfang, Ende (darf nie gleich sein, sonst ÷0-Fehler!)
HFONT font[2]; // Schrift der Skaleneinteilung und der Achsenbezeichnung
COLORREF color[2];// Farbe der Skaleneinteilung (Striche und Text) und der Achsenbezeichnung
const TCHAR*name; // Achsenbezeichnung
const TCHAR*format; // Formatstring für automatische Achsenbeschriftung, Standard: "%.2f"
std::vector<Label> labels; // Feste und kalkulierte Labels (= Skaleneinteilung)
std::vector<Plot*> plots; // Zugeordnete Plots (für Autoskalierung)
XY*parent;
private:
float F,O; // Faktor, Offset (Großbuchstaben = Pixelbereich, Kleinbuchstaben = Anwenderbereich)
float Length() const {float ret=float(side&1?height():width())-1;if (side&4) ret=-ret; return ret;} // Länge der Skale in Pixel; negativ wenn rückwärts laufend
float length() const {return e-a;}
float start() const {return a;}
float Start() const {return float(side&4?operator[](side&1|2)-1:operator[](side&1));} // Koordinate des Skalenanfangs (zu "a" gehörig)
public:
void calcFO() {F=Length()/length(); O=Start()/F-start();} // Faktor + Offset neu berechnen (Bereichsänderung oder Größenänderung)
float scale(float x) const {return x*F+O;}
float unscale(float X) const {return (X-O)/F;}
void setRange(float _a, float _e) {a=_a; e=_e; calcFO();}
void distributeTicks(HDC dc);
// virtual void onPaint(PAINTSTRUCT&) = 0;
// virtual int needLat(HDC) const = 0;
};
class XScale:public Scale{
public:
XScale(XY*_parent,int Side=3):Scale(_parent) {side=Side;} // Standardmäßig unten und von links nach rechts
void onPaint(PAINTSTRUCT&ps);
void needSpace(HDC,SIZE&) const;
};
class YScale:public Scale{
public:
YScale(XY*_parent,int Side=4):Scale(_parent) {side=Side;} // Standardmäßig links und von unten nach oben
void onPaint(PAINTSTRUCT&ps);
void needSpace(HDC,SIZE&) const;
};
union DATA{
const float*cf;
const bool*ca;
const BYTE*cb;
const WORD*ch;
const DWORD*cw;
const char*cc;
const short*cs;
const long*cl;
const double*cd;
const void*cv;
};
struct PLOTDATA{
const TCHAR*name;
int options; // Art der Daten und der Verschachtelung; TODO: Delta-T, Attribute, Einheit, Skalenzuordnung
DATA data;
};
// Für die Anwendung im Dialog (wenig ++)
enum{
PM_DELETEPLOT=0x401, // Plot Nr. <wParam> löschen; wParam=-1: Alle Plots löschen
PM_SETPLOT=0x402, // Plot Nr. <wParam> ersetzen, wParam=-1: Plot an Plotliste anhängen
PM_ADDSAMPLE=0x0403, // Sample <lParam> an Plot <wParam> anhängen; wParam=-1: Sample-Liste an Plots anhängen
PM_SETSCALE=0x404, // Skale <wParam> ersetzen oder hinzufügen
PM_SAVE=0x405, // Speichern des Plots in Registry-Key <wParam>, Name <lParam> oder in Puffer <lParam> Länge <wParam>
PM_RESTORE=0x406, // Laden des Plots aus Registry-Key <wParam>, Name <lParam> oder aus Puffer <lParam> Länge <wParam>
};
class Plot{
XY*parent;
XScale*xscale;
YScale*yscale;
COLORREF color;
TCHAR marker;
float*pointlist;
PLOTDATA*raw_data;
public:
Plot(XY*_parent) {parent=_parent;}
// int index() const {return std::find(parent.plots.
};
class XY{
XY(HWND);
HWND wnd;
Rect rcPlot;
XScale*xscale;
std::vector<YScale*> yscales;
std::vector<int> hdivs;
std::vector<Plot*> plots;
void onSize(int,int);
void onPaint(PAINTSTRUCT&ps);
LRESULT wndproc(UINT,WPARAM,LPARAM);
static LRESULT CALLBACK wndproc(HWND,UINT,WPARAM,LPARAM);
public:
static BOOL init();
};
Detected encoding: ANSI (CP1252) | 4
|
|