~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxContribItems/wxchart/src/chartwindow.cpp

  • Committer: mortenmacfly
  • Date: 2012-02-22 14:40:26 UTC
  • Revision ID: svn-v4:98b59c6a-2706-0410-b7d6-d2fa1a1880c9:trunk:7835
* merged wxSmith branch into trunk
* this brings tons of new wxSmith items, including KWIC, wxImagePanel, wxGridBagSizer and more
* based on work of the community, mainly cryogen
* for more information, see changelog of wxSmith branch
* also, re-factoring of contributed wxWidgets items for wxSmith
* PLEASE DO A CLEAN CHECKOUT AND RE-BUILD EVERYTHING FROM SCRATCH!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        chartwindow.cpp
 
3
// Purpose:     wxChart
 
4
// Author:      Paolo Gava
 
5
// Modified by:
 
6
// Created:
 
7
// Copyright:   (C) 2006, Paolo Gava
 
8
// RCS-ID:      $Id: chartwindow.cpp 7551 2011-11-01 18:13:27Z jenslody $
 
9
// Licence:     wxWindows licence
 
10
/////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
//----------------------------------------------------------------------------
 
13
// Headers
 
14
//----------------------------------------------------------------------------
 
15
 
 
16
// wx
 
17
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
18
#pragma implementation "chartwindow.h"
 
19
#endif
 
20
 
 
21
// For compilers that support precompilation, includes "wx.h".
 
22
#include <wx/wxprec.h>
 
23
 
 
24
#ifdef __BORLANDC__
 
25
#pragma hdrstop
 
26
#endif
 
27
 
 
28
#ifndef WX_PRECOMP
 
29
    #include <wx/wx.h>
 
30
#endif
 
31
 
 
32
#include "wx/chartwindow.h"
 
33
#include "wx/chartsizes.h"
 
34
 
 
35
IMPLEMENT_DYNAMIC_CLASS(wxChartWindow, wxWindow)
 
36
 
 
37
BEGIN_EVENT_TABLE(wxChartWindow, wxWindow)
 
38
  EVT_PAINT(        wxChartWindow::OnPaint)
 
39
  EVT_LEFT_DOWN(    wxChartWindow::OnMouse)
 
40
  EVT_LEFT_DCLICK(  wxChartWindow::OnMouse)
 
41
END_EVENT_TABLE()
 
42
 
 
43
 
 
44
//+++-S-cf-------------------------------------------------------------------
 
45
//      NAME:           ctor
 
46
//      DESC:
 
47
//      PARAMETERS:     wxWindow* parent
 
48
//      RETURN:         None
 
49
//----------------------------------------------------------------------E-+++
 
50
wxChartWindow::wxChartWindow(
 
51
        wxScrolledWindow *parent,
 
52
    bool usegrid
 
53
):  wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize/*, wxSIMPLE_BORDER*/),
 
54
        m_WinParent(parent),
 
55
    m_UseGrid(usegrid)
 
56
{
 
57
        SetBackgroundColour( *wxWHITE );
 
58
}
 
59
 
 
60
//+++-S-cf-------------------------------------------------------------------
 
61
//      NAME:           Draw()
 
62
//      DESC:           Draw chart points
 
63
//      PARAMETERS:     CHART_HPAINT hp,
 
64
//                              int x,
 
65
//                              int y
 
66
//      RETURN:         None
 
67
//----------------------------------------------------------------------E-+++
 
68
void wxChartWindow::Draw(
 
69
        CHART_HPAINT hp,
 
70
        int x,
 
71
        int y
 
72
)
 
73
{
 
74
        //-----------------------------------------------------------------------
 
75
        // Get window information
 
76
        //-----------------------------------------------------------------------
 
77
        CHART_RECT r;
 
78
    r.x = x; r.y = y;
 
79
        r.xscroll = 0; r.yscroll = 0;
 
80
        GetClientSize( &r.w, &r.h );
 
81
 
 
82
    //-----------------------------------------------------------------------
 
83
    // Set Background
 
84
    //-----------------------------------------------------------------------
 
85
 
 
86
#if 0
 
87
    hp->SetBrush( wxBrush(0xecf1f1, wxSOLID) ); //fcfdd8, *wxLIGHT_GREY_BRUSH
 
88
    hp->SetPen( *wxTRANSPARENT_PEN );
 
89
    hp->DrawRectangle(
 
90
        r.x + 2,
 
91
        r.y + 5,
 
92
        static_cast<int>(GetVirtualWidth()),
 
93
        r.h - 5
 
94
    );
 
95
#endif
 
96
 
 
97
    //-----------------------------------------------------------------------
 
98
    // Draw horizontal lines
 
99
    //-----------------------------------------------------------------------
 
100
    if ( m_UseGrid )
 
101
        DrawHLines( hp, &r );
 
102
 
 
103
        //-----------------------------------------------------------------------
 
104
        // Draw all charts
 
105
        //-----------------------------------------------------------------------
 
106
        m_Chart.Draw( hp, &r );
 
107
}
 
108
 
 
109
//+++-S-cf-------------------------------------------------------------------
 
110
//  NAME:       DrawHLines()
 
111
//  DESC:       Draw horizontal lines
 
112
//  PARAMETERS: CHART_HPAINT hp,
 
113
//              CHART_HRECT hr
 
114
//  RETURN:     None
 
115
//----------------------------------------------------------------------E-+++
 
116
void wxChartWindow::DrawHLines(
 
117
    CHART_HPAINT hp,
 
118
    CHART_HRECT hr
 
119
)
 
120
{
 
121
    if ( GetVirtualMaxY() > 0 )
 
122
    {
 
123
        double range = GetVirtualMaxY();
 
124
        double start = 0;
 
125
        double end = range;
 
126
 
 
127
        int int_log_range = (int)floor( log10( range ) );
 
128
        double step = 1.0;
 
129
        if (int_log_range > 0)
 
130
        {
 
131
            for (int i = 0; i < int_log_range; i++)
 
132
                step *= 10;
 
133
        }
 
134
        if (int_log_range < 0)
 
135
        {
 
136
            for (int i = 0; i < -int_log_range; i++)
 
137
                step /= 10;
 
138
        }
 
139
        double lower = ceil(start / step) * step;
 
140
        double upper = floor(end / step) * step;
 
141
 
 
142
        // if too few values, shrink size
 
143
        if ((range/step) < 4)
 
144
        {
 
145
            step /= 2;
 
146
            if (lower-step > start) lower -= step;
 
147
            if (upper+step < end) upper += step;
 
148
        }
 
149
 
 
150
        // if still too few, again
 
151
        if ((range/step) < 4)
 
152
        {
 
153
            step /= 2;
 
154
            if (lower-step > start) lower -= step;
 
155
            if (upper+step < end) upper += step;
 
156
        }
 
157
 
 
158
        wxChartSizes *sizes = GetSizes();
 
159
/* C::B begin */
 
160
        // avoid crashes if style contains USE_GRID and no charts are added to chartctrl
 
161
        if (!sizes)
 
162
            return;
 
163
/* C::B end */
 
164
 
 
165
        hp->SetPen( *wxBLACK_DASHED_PEN );
 
166
 
 
167
        double current = lower;
 
168
        while (current < upper+(step/2))
 
169
        {
 
170
            int y = (int)( (GetVirtualMaxY()-current) /
 
171
                    range * ((double)hr->h - sizes->GetSizeHeight())) - 1;
 
172
            if ((y > 10) && (y < hr->h - 7 - sizes->GetSizeHeight()))
 
173
            {
 
174
                hp->DrawLine( hr->x,
 
175
                              y + sizes->GetSizeHeight() + hr->y,
 
176
                    hr->x + static_cast<int>(GetVirtualWidth()),
 
177
                    y + sizes->GetSizeHeight() + hr->y );
 
178
            }
 
179
 
 
180
            current += step;
 
181
        }
 
182
    }
 
183
}
 
184
 
 
185
//+++-S-cf-------------------------------------------------------------------
 
186
//  NAME:       GetVirtualWidth()
 
187
//  DESC:
 
188
//  PARAMETERS: NOne
 
189
//  RETURN:     None
 
190
//----------------------------------------------------------------------E-+++
 
191
ChartValue wxChartWindow::GetVirtualWidth() const
 
192
{
 
193
    int iNodes = static_cast<int>(ceil( GetVirtualMaxX() ));
 
194
    wxChartSizes *sizes = GetSizes();
 
195
 
 
196
/* C::B begin */
 
197
    // sizes may be NULL, in this case return a fixed value
 
198
    if (!sizes)
 
199
        return 1;
 
200
/* C::B end */
 
201
 
 
202
    ChartValue x = 0;
 
203
 
 
204
    for ( int iNode = 0; iNode <= iNodes; ++ iNode )
 
205
    {
 
206
        x +=  GetZoom() * ( sizes->GetWidthBar() * sizes->GetNumBar() +
 
207
                sizes->GetWidthBar3d() * sizes->GetNumBar3d() +
 
208
                sizes->GetGap() );
 
209
    }
 
210
 
 
211
    return ( x );
 
212
}
 
213
 
 
214
//+++-S-cf-------------------------------------------------------------------
 
215
//      NAME:           OnPaint()
 
216
//      DESC:
 
217
//      PARAMETERS:     wxPaintEvent &event
 
218
//      RETURN:         None
 
219
//----------------------------------------------------------------------E-+++
 
220
void wxChartWindow::OnPaint(
 
221
        wxPaintEvent &WXUNUSED(event)
 
222
)
 
223
{
 
224
    wxPaintDC dc( this );
 
225
    m_WinParent->PrepareDC( dc );
 
226
 
 
227
        //-----------------------------------------------------------------------
 
228
        // Draw all charts window
 
229
        //-----------------------------------------------------------------------
 
230
        Draw( &dc );
 
231
}
 
232
 
 
233
//+++-S-cf-------------------------------------------------------------------
 
234
//      NAME:           OnMouse()
 
235
//      DESC:
 
236
//      PARAMETERS:     wxMouseEvent &event
 
237
//      RETURN:         None
 
238
//----------------------------------------------------------------------E-+++
 
239
void wxChartWindow::OnMouse(
 
240
        wxMouseEvent &WXUNUSED(event)
 
241
)
 
242
{
 
243
}