158 CLineGraphViewCtrl(
void) : m_isReverseIndexMode(false), m_viewHorizontalPos(0), m_markerWidth(6), m_scrollOneStep(1)
159 , m_viewTopValue(
EDGE_VALUE), m_viewbottomValue(-
EDGE_VALUE), m_scrollBarHeight(::GetSystemMetrics(SM_CYHSCROLL))
160 , m_backColor(RGB(0, 0, 0)), m_isGraphImageDcLeading(false), m_isOndemandRemakeViewImage(false), m_horzIndexPixel(1)
161 , m_isMouseButtonPressed(false), m_isScrollBarUsed(true)
163 m_viewHeight = m_viewTopValue - m_viewbottomValue + 0.0;
181 CSize sz = rc.Size();
182 m_backColor = backgroundColor;
183 if ( graphWidth == 0 )
187 if ( sz.cx == 0 || sz.cy == 0 )
191 m_Resize(sz, graphWidth);
221 m_horzIndexPixel = pixel;
222 if ( m_horzIndexPixel <= 0 )
224 m_horzIndexPixel = 1;
226 m_isReverseIndexMode = isReverseIndexMode;
240 return m_horzIndexPixel;
251 size_t r = m_markerWidth;
252 m_markerWidth = width;
263 _topValue = m_viewTopValue;
264 _bottomValue = m_viewbottomValue;
281 if ( topValue < bottomValue )
283 Swap(topValue, bottomValue);
285 if ( m_viewTopValue == topValue && m_viewbottomValue == bottomValue )
289 m_viewTopValue = topValue;
290 m_viewbottomValue = bottomValue;
291 m_viewHeight = m_viewTopValue - m_viewbottomValue + 0.0;
293 const SIZE& sz = m_graphImage.
GetSize();
294 if ( m_graphImageDc.GetSafeHdc() != NULL )
315 m_scrollBarHeight = height;
318 m_scrollBarHeight = ::GetSystemMetrics(SM_CYHSCROLL);
320 m_isScrollBarUsed = (height >= 0);
335 m_scrollOneStep = os;
346 m_scaleLine.Set(style, color, 0.0);
361 if ( number >= 1 && number <= 3 )
363 TScaleLineInfo& I = m_subScaleLines[number - 1];
368 I.Set(style, color, step);
385 bool SetOverlayText(INDEX pos, COLORREF color = RGB(0, 0, 0), LPCTSTR lpsz = NULL, HFONT hFont = NULL)
387 if ( pos > 0 && pos < 10 )
389 TTextInfo& t = m_testInfo[pos];
406 return m_isReverseIndexMode;
417 return !! ::IsWindow(m_scrollBar);
430 if ( m_isGraphImageDcLeading || m_graphImageDc.GetSafeHdc() == NULL )
434 m_isGraphImageDcLeading =
true;
435 return &m_graphImageDc;
444 if ( m_isGraphImageDcLeading )
446 m_isGraphImageDcLeading =
false;
468 int xx =
ToInt(horizontalIndex * m_horzIndexPixel + m_horzIndexPixel / 2);
469 if ( m_isReverseIndexMode )
471 xx = (m_graphImage.
GetSize().cx - 1) - xx;
485 if ( m_graphImageDc.GetSafeHdc() != NULL )
487 const SIZE& sz = m_graphImage.
GetSize();
488 count *= m_horzIndexPixel;
489 if ( m_isReverseIndexMode )
493 m_graphImageDc.ScrollDC(count, 0, NULL, NULL, NULL, NULL);
498 else if ( count < 0 )
500 m_graphImageDc.FillSolidRect(sz.cx + count, 0, -count, sz.cy,
INTERNALLY_COLOR);
502 loop ( i, m_pointMap )
504 m_pointMap.
Ref(i).
second->point.x += count;
517 return m_graphImage.
GetSize().cx / m_horzIndexPixel;
526 if ( m_graphImageDc.GetSafeHdc() != NULL )
528 const SIZE& sz = m_graphImage.
GetSize();
544 void SetPoint(COLORREF color,
double value, INDEX horizontalIndex = 0,
bool withContinuousLine =
true)
546 if ( m_graphImageDc.GetSafeHdc() != NULL )
549 m_SetMaker(m_graphImageDc, xx, value, color, withContinuousLine);
563 if ( m_graphImageDc.GetSafeHdc() != NULL )
566 CPen pen((length != -2) ? PS_SOLID : PS_DASH, 1, color);
567 CPen* pOldPen = m_graphImageDc.SelectObject(&pen);
570 m_graphImageDc.MoveTo(xx, 0);
571 m_graphImageDc.LineTo(xx, m_clientSize.cy);
575 int yy = m_CalcDrawY(0.0);
576 m_graphImageDc.MoveTo(xx, yy - length);
577 m_graphImageDc.LineTo(xx, yy + length);
579 m_graphImageDc.SelectObject(pOldPen);
609 return m_scrollBar.GetScrollLimit();
618 return m_viewHorizontalPos / m_horzIndexPixel;
628 if ( ::IsWindow(m_scrollBar) )
631 if ( m_isReverseIndexMode )
633 xx = m_scrollBar.GetScrollLimit() - xx;
635 m_scrollBar.SetScrollPos(
ToInt(xx));
636 xx = m_scrollBar.GetScrollPos();
637 if ( m_isReverseIndexMode )
639 xx = m_scrollBar.GetScrollLimit() - xx;
641 m_viewHorizontalPos = xx * m_horzIndexPixel;
654 m_isOndemandRemakeViewImage =
true;
675 _super::PreSubclassWindow();
678 m_clientSize = rc.Size();
679 const SIZE& sz = m_clientSize;
680 m_viewImage.
Set(sz.cx, sz.cy, m_backColor);
683 m_graphImageDc.
Attach(&m_graphImage);
695 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
702 if ( m_isOndemandRemakeViewImage )
704 m_isOndemandRemakeViewImage =
false;
707 m_viewImage.
Draw(
reinterpret_cast<HDC
>(wParam));
710 if ( m_isOndemandRemakeViewImage )
712 m_isOndemandRemakeViewImage =
false;
715 m_viewImage.
Draw(CPaintDC(
this));
721 CSize sz(LOWORD(lParam), HIWORD(lParam));
722 if ( sz != m_clientSize )
724 CSize gsz = m_graphImage.
GetSize();
725 m_Resize(sz, gsz.cx);
731 if (
reinterpret_cast<HWND
>(lParam) == m_scrollBar )
733 int sbCode = LOWORD(wParam);
734 int nPos = HIWORD(wParam);
737 case SB_THUMBPOSITION:
741 if ( m_scrollBar.GetScrollInfo(&si, SIF_TRACKPOS) )
748 m_OnScrollBar(sbCode, nPos);
752 if ( ::IsWindow(m_scrollBar) )
754 m_isMouseButtonPressed =
true;
756 m_pressedPos = CPoint(lParam);
759 return _super::DefWindowProc(message, wParam, lParam);
763 if ( m_isMouseButtonPressed )
765 m_isMouseButtonPressed =
false;
770 if ( m_isMouseButtonPressed )
772 if ( GetCapture() !=
this )
774 m_isMouseButtonPressed =
false;
779 int d = (pos.x - m_pressedPos.x) / m_horzIndexPixel;
782 m_OnScrollBar(SB_THUMBPOSITION, m_scrollBar.GetScrollPos() - d);
791 return _super::WindowProc(message, wParam, lParam);
802 TTextInfo(
void) : hFont(NULL)
818 if ( colorPen.GetSafeHandle() != NULL )
820 colorPen.DeleteObject();
827 pPen =
new CPen(PS_SOLID, 1, color);
830 pPen =
new CPen(PS_SOLID, 3, color);
833 pPen =
new CPen(PS_DOT, 1, color);
838 colorPen.Attach(pPen->Detach());
844 struct TScaleLineInfo : TLineInfo
847 void Set(
ELineStyle ls, COLORREF color,
double sp)
850 TLineInfo::Set(ls, color);
854 class CMyScrollBar :
public CScrollBar
856 DEFSUPER(CScrollBar);
858 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
860 if ( message == WM_LBUTTONDOWN )
862 return _super::DefWindowProc(message, wParam, lParam);
864 return _super::WindowProc(message, wParam, lParam);
868 int m_CalcDrawY(
double y)
const
870 double yy = (m_viewTopValue - y);
871 yy *= (m_clientSize.cy - 1);
873 return down_cast<int>(yy);
877 void m_OnScrollBar(
int sbCode,
int nPos)
880 INT_PTR maxPos = m_scrollBar.GetScrollLimit();
881 INT_PTR p = m_scrollBar.GetScrollPos();
890 p -= m_scrollOneStep;
893 p += m_scrollOneStep;
896 p -= m_clientSize.cx / m_horzIndexPixel;
899 p += m_clientSize.cx / m_horzIndexPixel;
904 case SB_THUMBPOSITION:
912 m_scrollBar.SetScrollPos(
ToInt(p));
913 p = m_scrollBar.GetScrollPos();
914 if ( m_isReverseIndexMode )
916 p = m_scrollBar.GetScrollLimit() - p;
921 CWnd* pParent = GetParent();
922 if ( pParent != NULL )
924 pParent->SendMessage(WM_HSCROLL, MAKELONG(SB_THUMBPOSITION, p),
reinterpret_cast<LPARAM
>(
GetSafeHwnd()));
933 void m_Resize(
const SIZE& sz,
size_t graphWidth)
935 if ( sz.cx < 0 || sz.cx > 0x7FFF || sz.cy < 0 || sz.cy > 0x7FFF )
941 if ( ::IsWindow(m_scrollBar) )
943 m_scrollBar.DestroyWindow();
945 if (
ToInt(graphWidth) > m_clientSize.cx )
948 DWORD style = SBS_HORZ | WS_CHILD;
949 if ( m_isScrollBarUsed )
951 m_clientSize.cy -=
ToInt(m_scrollBarHeight);
954 m_scrollBar.Create(style, CRect(0, m_clientSize.cy, m_clientSize.cx,
ToInt(m_clientSize.cy + m_scrollBarHeight)),
this, 1000);
956 m_scrollBar.GetScrollInfo(&si);
957 si.nPage = m_clientSize.cx / m_horzIndexPixel;
959 si.nMax =
ToInt(graphWidth / m_horzIndexPixel);
960 if ( m_isReverseIndexMode )
964 m_scrollBar.SetScrollInfo(&si);
966 m_viewImage.
Set(sz.cx, sz.cy, m_backColor);
968 if ( sz.cx > 0 && sz.cy > 0 && m_clientSize.cy > 0 )
971 m_graphImageDc.
Attach(&m_graphImage);
977 const CSize& gsz = m_graphImage.
GetSize();
980 m_Resize(rc.Size(), gsz.cx);
990 void m_SetMaker(CDC& dc,
int xx,
double y, COLORREF color,
bool withContinuousLine)
992 if ( ! IS_RGBVALUE(color) )
996 if ( ! ::_finite(y) )
1000 int yy = m_CalcDrawY(y);
1001 bool hasColorKey = m_pointMap.
HasKey(color);
1003 if ( ! hasColorKey )
1005 m_pointMap[color] =
new TPointInfo(color);
1007 TPointInfo* P = m_pointMap[color];
1008 ASSERT( P != NULL );
1009 CPen* pOldPen = dc.SelectObject(&P->pen);
1012 if ( withContinuousLine && hasColorKey )
1014 dc.MoveTo(P->point);
1018 if ( m_markerWidth <= 1 )
1020 dc.SetPixel(xx, yy, color);
1022 else if ( m_markerWidth <= 3 )
1024 int mw =
ToInt(m_markerWidth);
1026 dc.FillSolidRect(xx - d1, yy - d1, mw, mw, color);
1030 CBrush* pOldBrush = dc.SelectObject(&P->brush);
1031 int d1 =
ToInt(m_markerWidth / 2);
1032 int d2 =
ToInt(m_markerWidth - d1);
1033 dc.Ellipse(xx - d1, yy - d1, xx + d2, yy + d2);
1034 dc.SelectObject(pOldBrush);
1037 dc.SelectObject(pOldPen);
1047 DWORD m_ToDtStyle(INDEX idx)
const
1052 case 1: r = DT_LEFT | DT_BOTTOM;
break;
1053 case 2: r = DT_CENTER | DT_BOTTOM;
break;
1054 case 3: r = DT_RIGHT | DT_BOTTOM;
break;
1055 case 4: r = DT_LEFT | DT_VCENTER;
break;
1056 case 5: r = DT_CENTER | DT_VCENTER;
break;
1057 case 6: r = DT_RIGHT | DT_VCENTER;
break;
1058 case 7: r = DT_LEFT | DT_TOP;
break;
1059 case 8: r = DT_CENTER | DT_TOP;
break;
1060 case 9: r = DT_RIGHT | DT_TOP;
break;
1065 void m_MakeViewImage(
void)
1067 const SIZE& sz = m_clientSize;
1069 dc.FillSolidRect(0, 0, sz.cx, sz.cy, m_backColor);
1071 m_DrawScaleLine(dc, m_subScaleLines[2],
false);
1072 m_DrawScaleLine(dc, m_subScaleLines[1],
false);
1073 m_DrawScaleLine(dc, m_subScaleLines[0],
false);
1074 m_DrawScaleLine(dc, m_scaleLine,
true);
1076 if ( ! m_graphImage.
IsEmpty() )
1078 const SIZE& sz = m_graphImage.
GetSize();
1079 INT_PTR x = -down_cast<INT_PTR>(m_viewHorizontalPos);
1080 if ( m_isReverseIndexMode )
1082 x = m_clientSize.cx - sz.cx + m_viewHorizontalPos;
1084 ::TransparentBlt(dc,
ToInt(x), 0, sz.cx, sz.cy, m_graphImageDc, 0, 0, sz.cx, sz.cy,
INTERNALLY_COLOR);
1088 CRect rc(2, 2, sz.cx - 2, sz.cy - 2);
1089 CWnd* pParent = GetParent();
1090 CFont* pParentFont = GetFont();
1091 if ( pParent != NULL )
1093 pParentFont = pParent->GetFont();
1095 CFont* pOldFont = dc.SelectObject(GetFont());
1096 dc.SetBkMode(TRANSPARENT);
1100 const TTextInfo& t = m_testInfo[idx];
1101 if ( ! t.text.IsEmpty() )
1103 if ( t.hFont == NULL )
1105 dc.SelectObject(pParentFont);
1109 ::SelectObject(dc, t.hFont);
1114 dc.SelectObject(pOldFont);
1122 void m_DrawStyleHorzLine(CDC& dc,
bool isEdgeDotMode,
int yy)
1125 if ( ! isEdgeDotMode )
1128 dc.LineTo(m_clientSize.cx, yy);
1134 dc.MoveTo(m_clientSize.cx, yy);
1135 dc.LineTo(m_clientSize.cx - 4, yy);
1139 void m_DrawScaleLine(CDC& dc, TScaleLineInfo& sli,
bool isMaster)
1141 if ( sli.colorPen.GetSafeHandle() == NULL )
1146 dc.SetBkColor(m_backColor);
1147 CPen* pOldPen = dc.SelectObject(&sli.colorPen);
1150 m_DrawStyleHorzLine(dc, isEdgeDotMode, m_CalcDrawY(0));
1154 double ss = sli.step;
1155 double hh = max(::fabs(m_viewTopValue), ::fabs(m_viewbottomValue));
1158 m_DrawStyleHorzLine(dc, isEdgeDotMode, m_CalcDrawY(ss));
1159 m_DrawStyleHorzLine(dc, isEdgeDotMode, m_CalcDrawY(-ss));
1163 dc.SelectObject(pOldPen);
1171 TPointInfo(COLORREF c) : brush(c), pen(PS_SOLID, 1, c)
1178 bool m_isScrollBarUsed;
1179 CMyScrollBar m_scrollBar;
1180 size_t m_scrollBarHeight;
1181 size_t m_scrollOneStep;
1182 TTextInfo m_testInfo[10];
1183 CMyPointMap m_pointMap;
1184 TScaleLineInfo m_scaleLine;
1185 TScaleLineInfo m_subScaleLines[3];
1186 COLORREF m_backColor;
1187 size_t m_markerWidth;
1188 double m_viewTopValue;
1189 double m_viewbottomValue;
1190 double m_viewHeight;
1191 bool m_isReverseIndexMode;
1196 bool m_isGraphImageDcLeading;
1197 INDEX m_viewHorizontalPos;
1198 bool m_isOndemandRemakeViewImage;
1199 int m_horzIndexPixel;
1200 bool m_isMouseButtonPressed;
1201 CPoint m_pressedPos;
#define loop(VAR, CNT)
loop構文.
HWND GetSafeHwnd(void) const
[取得] ウィンドウハンドル取得.
bool IsEmpty(void) const
[確認] Empty状態確認.
const SIZE & GetSize(void) const
[取得] イメージサイズ取得.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
virtual CPair & Ref(INDEX index)
[取得] 要素の参照取得.
virtual bool RemoveAll(void)
[削除] すべてのキーと値を削除
bool HasKey(INK key) const
[確認] キー有無
static bool DrawTextRect(RECT &_rect, HDC dc, DWORD drawStyle, const POINT &offset, COLORREF color1, COLORREF color2, LPCTSTR str)
[表示] 範囲文字表示.
CBitmapImage * Detach(void)
[設定] デタッチ.
bool Attach(CBitmapImage *pBI)
[設定] アタッチ
void Settle(bool isForce=false)
[設定] 確定.
INDEX GetHorizontalIndexLimit(void) const
[取得] 横軸最大インデックス取得.
void ClearPoint(void)
[設定] ポイントクリア.
void SetScaleLine(COLORREF color, ELineStyle style=LineStyle_Solid)
[設定] スケール線設定.
bool IsReverseHorizontalIndexMode(void) const
[確認] 逆インデックスモード?.
void Shift(int count=1)
[移動] シフト.
size_t SetPointMakertSize(size_t width)
[設定] ポイントマーカーサイズ設定.
INDEX GetViewHorizontalPos(void) const
[取得] 水平表示位置取得.
bool SetBackgroundWidth(COLORREF backgroundColor, size_t graphWidth=0)
[設定] グラフ背景幅設定.
void OndemandRemakeViewImage(void)
[通知] 再構築要求通知.
const SIZE & GetImageSize(void) const
[取得] グラフイメージサイズ取得.
void SetPoint(COLORREF color, double value, INDEX horizontalIndex=0, bool withContinuousLine=true)
[設定] ポイント設定.
bool SetViewValueRange(double topValue, double bottomValue)
[設定] 垂直表示範囲設定.
void GetViewValueRange(double &_topValue, double &_bottomValue) const
[取得] 垂直表示範囲取得.
void SetVerticalLine(COLORREF color, INDEX horizontalIndex, int length=-1)
[設定] 縦スケール設定.
bool SetScrollBarHeight(int height=0)
[設定] スクロールバー高さ.
CDC * GetImageDC(void)
[取得] グラフイメージ DC 取得.
CLineGraphViewCtrl(void)
コンストラクタ.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
void SetScrollOneStep(size_t os=1)
[設定] スクロールバー1ステップ幅.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
bool SetHorizontalIndexPixel(int pixel=1, bool isReverseIndexMode=false)
[設定] インデックスピクセル設定.
void SetViewHorizontalPos(INDEX pos)
[設定] 水平表示位置設定.
bool SetSubScaleLine(INDEX number, ELineStyle style=LineStyle_Non, COLORREF color=0, double step=0.0)
[設定] サブスケール線設定.
bool SetOverlayText(INDEX pos, COLORREF color=RGB(0, 0, 0), LPCTSTR lpsz=NULL, HFONT hFont=NULL)
[設定] 文字列設定.
void ReleaseImageDC(void)
[設定] グラフイメージ DC 返却.
bool HasScrollBar(void) const
[確認] スクロールバーあり?.
size_t GetViewHorizontalPosLimit(void)
[取得] 水平表示最大位置取得.
virtual void OnMadeViewImage(CDC *pDC, const SIZE &sz)
[通知] 表示用イメージ作成通知.
int HorizontalIndexToX(INDEX horizontalIndex)
[取得] 横軸インデックス to X座標.
@ EDGE_VALUE
デフォルトの上下端のポイント値
@ INTERNALLY_COLOR
内部処理用カラー
int GetHorizontalIndexPixel(void) const
[取得] インデックスピクセル取得.
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void Swap(T &t1, T &t2)
[変換] スワッパー.