#ifndef __INCLUDED_VITAL #define __INCLUDED_VITAL #include #include #include #include #pragma warning (disable:4305) class string; const double Degrees = 3.1415926535897932384626433832795 / 180.0; const int FONT_NORMAL = 0, FONT_BOLD = 1, FONT_ITALIC = 2, FONT_UNDERLINE = 4, FONT_STRIKEOUT = 8, FONT_ROMAN = 16, FONT_SERIF = 16, FONT_SANS = 32, FONT_SANS_SERIF = 32, FONT_FIXED = 64, FONT_NAMED = 256, REDRAW_MODE = 1, OFFSCREEN_MODE = 2, AUTOMATIC_MODE = 3, NORMAL_MODE = 0, DIRECT_MODE = 4; const char * const hversion="graphics 1.02.010 of 10th June 2002"; int CheckSameVersions(void); extern int qwqwqwignorethis; class Image { protected: int width, height; int **pix; public: void GetSize(int &w, int &h); int **GetPixels(void); Image(int w, int h); ~Image(void); }; class string { protected: char *data; int max, len; public: string(void); string(int mx); string(const char *s); string(const string &s); ~string(void); char *getcstr(void) const; char *c_str(void) const; string &operator=(const string &s); string &operator=(const char *s); bool operator==(const string &s) const; bool operator!=(const string &s) const; bool operator<(const string &s) const; bool operator>(const string &s) const; bool operator<=(const string &s) const; bool operator>=(const string &s) const; int length(void) const; int maximum(void) const; string &append(const char *s, int len); string &append(const string &s); string &append(const char *s); string &append(char c); string operator+(const string &s); string operator+(const char *s); string operator+(char c); string substring(int begin, int end); int to_int(int &ok=qwqwqwignorethis); static string from_int(int n); char &character(int n) const; char &operator[](int n) const; }; class Xframe; void MakeWindow(int w, int h, int xtl=-999888, int ytl=-999888); void GetSize(int &w, int &h); int EncodeColor(double r, double g, double b); int EncodeColor0255(int r, int g, int b); void DecodeColor(int c, double &r, double &g, double &b); void DecodeColor0255(int c, int &r, int &g, int &b); void PenWidthColor0255(int w, int r, int g, int b); void PenColor0255(int rr, int gg, int bb); void PenWidthColor(int w, double rr, double gg, double bb); void PenWidthColor(int w, int c); void PenColor(double rr, double gg, double bb); void PenColor(int c); void PenWidth(int w); void MoveTo(double x, double y); void MoveBy(double dx, double dy); void MoveByLength(double s); void DrawPointAt(double x, double y); int GetPixelColor(int x, int y); void GetPixelColor0255(int x, int y, int &r, int &g, int &b); void GetPixelColor(int x, int y, float &r, float &g, float &b); void GetPixelColor(int x, int y, double &r, double &g, double &b); void DrawPointHere(void); void ColorPixel(int x, int y, double R, double G, double B); void ColorPixel(int x, int y, int c); void ColorPixel0255(int x, int y, int R, int G, int B); void DrawLineTo(double x, double y); void DrawLineLength(double s); void DrawLineBy(double dx, double dy); void DrawRectangleXYXY(double x0, double y0, double x1, double y1); void DrawRectangleXYWH(double x0, double y0, double w, double h); void FillRectangleXYXY(double x0, double y0, double x1, double y1); void FillRectangleXYWH(double x0, double y0, double w, double h); void TurnLeftBy(double radians); void TurnRightBy(double radians); void TurnToHeading(double radians); void TurnLeftByDegrees(double degrees); void TurnRightByDegrees(double degrees); void TurnToHeadingDegrees(double degrees); double DirectionTo(double x, double y); double DirectionToDegrees(double x, double y); double DistanceTo(double x, double y); double DirectionFromTo(double x0, double y0, double x1, double y1); double DirectionFromToDegrees(double x0, double y0, double x1, double y1); double DistanceFromTo(double x0, double y0, double x1, double y1); void GetPosition(int &x, int &y); void GetPosition(float &x, float &y); void GetPosition(double &x, double &y); double GetHeading(void); double GetHeadingDegrees(void); void Clear(void); void Show(void); void SetFontFace(int ff, char *fn=""); void SetFontFace(char *fn); void SetFontFace(string fn); void SetFontAttributes(int fa); void SetFontSize(int fs); void SetFontFaceAttributesSize(string fn, int fa, int fs); void SetFontFaceAttributesSize(char *fn, int fa, int fs); void SetFontFaceAttributesSize(int ff, char *fn, int fa, int fs); void SetFontFaceAttributesSize(int ff, int fa, int fs); void UseDefaultFont(void); int GetNumberOfFonts(void); string GetFontName(int i); void WriteText(char *s); void WriteTextf(char *s, ...); void WriteText(string s); void MeasureText(string s, int &w, int &h); void MeasureText(char *s, int &w, int &h); void Clear(void); void Show(void); void Pause(double seconds); void log(char *patt, ...); void HLStoRGB(double H, double L, double S, double &R, double &G, double &B); void RGBtoHLS(double R, double G, double B, double &H, double &L, double &S); void WaitForMouse(int &x0, int &y0, int &x1, int &y1, int &b); void WaitForMouseEventOrKeyPress(int &x0, int &y0, int &b); void WaitForMouseOrInput(int &x0, int &y0, int &x1, int &y1, int &b); void WaitForMouseOrKeyPress(int &x0, int &y0, int &x1, int &y1, int &b); void StartMonitoringMouse(void); int CheckMouseAction(void); void GetMouseAction(int &x0, int &y0, int &x1, int &y1, int &b); void GetMouseEvent(int &x0, int &y0, int &b); void PrintStats(void); void SaveAsBMP(FILE *f); void SaveAsBMP(FILE *f, int x, int y, int w, int h); Image *ImageFromFile(char *fn); Image *ImageFromFile(string fn); string GetReasonForFailure(void); int SaveAsBMP(string fn); int SaveAsBMP(string fn, int x, int y, int w, int h); string GetWorkingDirectory(void); void DrawImage(Image *); void DrawImage(Image *, double x, double y); string SaveAsFileDialog(string suggestedfilename="", string initdirectory="", string defaultextension="", string title="Save As"); string OpenFileDialog(string suggestedfilename="", string initdirectory="", string title="Open File"); int ErrorDialog(string message, string title="Error"); void TerminalErrorDialog(string message, string title="Program Terminating"); void InformationDialog(string message, string title="Information"); int YesNoDialog(string message, string title="Query"); Xframe *GetMainWindow(void); Xframe *GetConsoleWindow(void); class TextOutput { protected: char **textbuffer; char *currentline; int textbufferlines, currentlinenum, currentcharpos, textlinewidth, changed; Xframe *container; public: TextOutput(int ht, int wd); void SetCaption(char *s); void setcontainer(Xframe *f); void print_flush(void); void print_char(char c); void print_int(int n); void print_hex(int n); int cursor_position(void); void print_string(const char *s); int printf(char *patt, ...); int vaprintf(char *patt, va_list &a); void get(int &ht, int &wd, char ** &data); void savein(FILE *f); int sized; }; typedef void (* XFunction)(Xframe *fr, int msg, int param1, int param2); int AddHandler(XFunction f); typedef void (*paintproc)(Xframe *); class Xframe { protected: HWND hwnd; HDC hdc, bitmapdc; HBITMAP bitmap; HPEN currentpen; HBRUSH currentbrush; HFONT currentfont; TEXTMETRIC currentmetric; int gotmetrics, mode; char *title; int xpos, ypos, width, height; static int nxtnum, numframes; TextOutput *tout; double penx, peny, heading; int penw, brushrgb, penrgb, textpenrgb, headingminutes; void setHeading(double dx, double dy); int fontface, fontattr, fontsize, fontchanged; char fontname[100]; public: short int tag, closable; paintproc painter; HDC getDC(void); void setDC(HDC h); HWND getHWND(void); Xframe(char *tt=NULL, int xp=-1, int yp=-1, int wp=-1, int hp=-1); Xframe(TextOutput *tout, char *tt=NULL, int xp=-1, int yp=-1, int wp=-1, int hp=-1); int istext(void); void close(void); void dispose(void); void repaint(void); void autopaint(void); TextOutput *gettext(void); Xframe *setclosable(int b=1); Xframe *setsize(int w, int h); Xframe *setpos(int x, int y); Xframe *create(paintproc pr=NULL); void getpos(int &x, int &y); void getsize(int &w, int &h); void threadedcreate(void); Xframe *appear(void); void PenWidthColor0255(int w, int r, int g, int b); void PenColor0255(int r, int g, int b); void PenWidthColor(int w, double rr, double gg, double bb); void PenWidthColor(int w, int c); void PenColor(double rr, double gg, double bb); void PenColor(int c); void PenWidth(int w); void MoveTo(double x, double y); void MoveBy(double dx, double dy); void MoveByLength(double s); void DrawPointAt(double x, double y); int GetPixelColor(int x, int y); void GetPixelColor0255(int x, int y, int &r, int &g, int &b); void GetPixelColor(int x, int y, float &r, float &g, float &b); void GetPixelColor(int x, int y, double &r, double &g, double &b); void DrawPointHere(void); void ColorPixel(int x, int y, double R, double G, double B); void ColorPixel(int x, int y, int c); void ColorPixel0255(int x, int y, int R, int G, int B); void DrawLineTo(double x, double y); void DrawLineLength(double s); void DrawLineBy(double dx, double dy); void DrawRectangleXYXY(double x0, double y0, double x1, double y1); void DrawRectangleXYWH(double x0, double y0, double w, double h); void FillRectangleXYXY(double x0, double y0, double x1, double y1); void FillRectangleXYWH(double x0, double y0, double w, double h); void TurnLeftBy(double rads); void TurnRightBy(double rads); void TurnToHeading(double rads); void TurnLeftByDegrees(double degs); void TurnRightByDegrees(double degs); void TurnToHeadingDegrees(double degs); double DirectionTo(double x, double y); double DirectionToDegrees(double x, double y); double DistanceTo(double x, double y); void GetPosition(int &x, int &y); void GetPosition(float &x, float &y); void GetPosition(double &x, double &y); double GetHeading(void); double GetHeadingDegrees(void); void SetFontFace(int ff, char *fn=""); void SetFontFace(char *fn=""); void SetFontFace(string fn); void SetFontAttributes(int fa); void SetFontSize(int fs); void SetFontFaceAttributesSize(string fn, int fa, int fs); void SetFontFaceAttributesSize(char *fn, int fa, int fs); void SetFontFaceAttributesSize(int ff, char *fn, int fa, int fs); void SetFontFaceAttributesSize(int ff, int fa, int fs); void UseDefaultFont(void); void SetFont(void); TEXTMETRIC &GetFontMetrics(void); void SetFont(HFONT f); HFONT GetFont(void); int GetNumberOfFonts(void); string GetFontName(int i); void WriteText(char *s); void WriteTextf(char *s, ...); void WriteText(string s); void MeasureText(string s, int &w, int &h); void MeasureText(char *s, int &w, int &h); void Clear(void); void Show(void); void SetCaption(char *s); void SaveAsBMP(FILE *f, int x, int y, int w, int h); void SaveAsBMP(FILE *f); int SaveAsBMP(string fn); int SaveAsBMP(string fn, int x, int y, int w, int h); void DrawImage(Image *); void DrawImage(Image *, double x, double y); }; bool operator==(const char *x, const string &s); bool operator!=(const char *x, const string &s); bool operator<(const char *x, const string &s); bool operator>(const char *x, const string &s); bool operator<=(const char *x, const string &s); bool operator>=(const char *x, const string &s); typedef void (*threadfunctionv)(void); typedef void (*threadfunctioni)(int); typedef void (*threadfunctionvs)(void *); class Semaphore { protected: static int numsems; int num; string name; int val; public: Semaphore(string name=""); void SetName(string n); string GetName(void); void Clear(void); void Set(void); int IsClear(void); int IsSet(void); void WaitUntilClearThenSet(void); void Wait(void); }; class Thread { protected: HANDLE thread; static int numthreads; int num; string name; int type, param, running; unsigned long threadid; void *threadfn; friend DWORD WINAPI startthreadfn(LPVOID pp); public: Thread(void); Thread(threadfunctionv); Thread(threadfunctioni, int p=0); Thread(threadfunctionvs, void *p=NULL); void SetName(string s); string GetName(void); int IsRunning(void); virtual void Run(void); void Start(void); void Start(int p); void Start(void *p); }; class output_object { protected: FILE *ofile; public: output_object(void); void print_char(char c); void print(int n); void print(double f); void print(float f); void print(const char *s); void print(const string &s); void newline(void); void flush(void); void close(void); }; class screen_object: public output_object { public: screen_object(void); void close(void); }; class output_file: public output_object { public: output_file(void); output_file(char *filename); output_file(string &filename); }; class input_object { protected: FILE *ifile; char line[260]; char *t; void get(void); char *read_charstar(void); public: input_object(void); bool ok; void rewind(void); void read(char &c); void read_char(char &c); void read(int &i); void read(float &f); void read(double &f); void read(string &s); char read_char(void); char *read_line(void); int read_int(void); float read_float(void); double read_double(void); string read_string(void); void read(void); void close(void); }; class keyboard_object: public input_object { public: keyboard_object(void); void close(void); }; class input_file: public input_object { public: input_file(void); input_file(char *filename); input_file(string &filename); }; class string_scanner: public input_object { public: string_scanner(void); string_scanner(string s); void rewind(void); void read(char &c); void read(int &i); void read(float &f); void read(double &f); void read(string &s); char read_char(void); char *read_line(void); void read_char(char &c); int read_int(void); int read_digit(void); float read_float(void); double read_double(void); string read_string(void); void read(void); void close(void); protected: char *read_charstar(void); int pos, len; }; class timer_object { protected: int thedate, thetime, themilliseconds, theseconds; public: timer_object(void); void look_at_the_clock(); int integer_date(void); int integer_time(void); int integer_ms(void); double double_time(void); }; extern screen_object screen; extern keyboard_object keyboard; extern timer_object timer; void look_at_the_clock(void); int integer_date(void); int integer_time(void); int integer_ms(void); double double_time(void); void print_char(char c); void printf(char *patt, ...); void print(int n); void print(float f); void print(double f); void print(const char *s); void print(const string &s); void newline(void); int get_text_cursor_position(void); void flush(void); int CheckKeyPressed(void); int CheckInputReady(void); void SetKeyboardMode(int m); void read(char &c); void read_char(char &c); void read_char_no_echo(char &c); void read(int &n); void read(float &f); void read(double &f); void read(string &s); void read(void); char read_char(void); char read_char_no_echo(void); char read_char_no_wait(void); char read_char_no_wait_no_echo(void); int read_int(void); float read_float(void); double read_double(void); char read_char(void); string read_string(void); string read_line(void); void Delay(double t); void randomise(void); void randomize(void); void do_not_randomise(void); void do_not_randomize(void); int random_in_range(int a, int b); float random_in_range(float a, float b); double random_in_range(double a, double b); #endif