Quelltext /~heha/ewa/Ofen/prozess.zip/msvc/prozess/xy.h

#pragma once
#include <windows.h>
#include <windowsx.h>
#include "vector.h"
#include <gdiplus.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{
 const wchar_t*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,int side=3,const wchar_t*name=0);
 ~Scale();
 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!)
 Gdiplus::Font*font[2];	// Schrift der Skaleneinteilung und der Achsenbezeichnung
 Gdiplus::Color color[2];// Farbe der Skaleneinteilung (Striche und Text) und der Achsenbezeichnung
 Gdiplus::Brush*brush[2];	// Pinsel für Schrift
 const wchar_t*name;	// Achsenbezeichnung
 const wchar_t*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(Gdiplus::Graphics&g);
 void onPaint(Gdiplus::Graphics&g);
 void onSize();
 void needSpace(Gdiplus::Graphics&g,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;
 Scale*xscale,*yscale;
 COLORREF color;
 TCHAR marker;
 float*pointlist;
 PLOTDATA*raw_data;
 struct stroke{
  Gdiplus::Pen*pen;
  Gdiplus::Point*points;
  int len;
  bool okay;
  bool check();
 }s;	// Cache für Kurvendaten
public:
 Plot(XY*_parent) {parent=_parent;}
 void onPaint(Gdiplus::Graphics&g);
};

class XY{
 XY(HWND);
 ~XY();
 HWND wnd;
 Rect rcPlot;
 Scale*xscale;
 std::vector<Scale*> yscales;
 std::vector<int> hdivs;
 std::vector<Plot*> plots;
 void onSize(int,int);
 void onPaint(Gdiplus::Graphics&g);
 LRESULT wndproc(UINT,WPARAM,LPARAM);
 static LRESULT CALLBACK wndproc(HWND,UINT,WPARAM,LPARAM);
 ULONG_PTR gdiplusToken;
public:
 static BOOL init();
};
Vorgefundene Kodierung: ANSI (CP1252)4
Umlaute falsch? - Datei sei ANSI-kodiert (CP1252)