/** * Copyright Mikael Högdahl - triyana@users.sourceforge.com * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef Fl_DC_h #define Fl_DC_h #include "MHDayChart.h" #include "MHDC.h" #include "MHPrice.h" #include "MHUtil.h" #include #include #include #include #include #include /** * Fl_DC is the device context for MHChart to be used with the fltk toolkit. */ class Fl_DC : public MHDC, public Fl_Box { public: enum { SCROLL_SIZE = 20, SCROLL_HEIGHT = 16, SPACE = 2, }; Fl_DC (int x, int y, int w, int h, char *label = 0, Fl_Slider* slider = 0); virtual ~Fl_DC (); virtual void draw (); int handle (int event); void resize (int x1, int y1, int x2, int y2); void slidercb_ (); static void slidercb (Fl_Slider* slider, void* d) {Fl_DC* dc = (Fl_DC*)d; dc->slidercb_();} void AddChart (MHDayChart* chart); void BeginClip (); void Color (int color); void DrawLine (int x1, int y1, int x2, int y2); void DrawRect (int x1, int y1, int x2, int y2); void DrawText (const char* p, int x1, int y1, bool center = false); void EndClip (); int GetHeight (); int GetWidth (); int GetCharHeight (); Fl_Scrollbar* GetScrollbar (); int GetStringWidth (const char* pString); void SetBrushColor (int Color); void SetPenColor (int Color); MHPrice aLeft; MHPrice aRight; MHDayChart* aChart; Fl_Box* aCanvas; Fl_Scrollbar* aScrollbar; Fl_Slider* aSlider; }; /** * Create a clip rectangle */ inline void Fl_DC::BeginClip () { fl_push_clip (x(), y(), w(), h()); } /** * Set new background color * @param int - Color */ inline void Fl_DC::Color (int color) { if (color > 0 && color < 255) aCanvas->color (Fl_Color(color)); else aCanvas->color (FL_WHITE); } /** * Delete a clip rectangle */ inline void Fl_DC::EndClip () { fl_pop_clip(); } /** * Get height of drawing canvas * @return int - Height of window in pixels */ inline int Fl_DC::GetHeight () { return h(); } /** * Get width of drawing canvas * @return int - Width of window in pixels */ inline int Fl_DC::GetWidth () { return w(); } /** * Get height of current font * @return int - Height of char in pixels */ inline int Fl_DC::GetCharHeight() { return GetFontSize(); } /** * Get width in pixels of supplied string * @param char* - String to draw * @return int - String width in pixels */ inline int Fl_DC::GetStringWidth(const char* pString) { fl_font (FL_COURIER, GetFontSize()); return int(fl_width(pString)); } #endif