OpenCPN Partial API docs
thumbwin.cpp
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Chart Thumbnail Object
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2010 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  ***************************************************************************
25  *
26  *
27  */
28 
29 #include <wx/wxprec.h>
30 
31 #ifndef WX_PRECOMP
32 #include <wx/wx.h>
33 #endif // precompiled headers
34 
35 #include <stdlib.h>
36 #include <math.h>
37 #include <time.h>
38 
39 #include "dychart.h"
40 
41 #include "thumbwin.h"
42 #include "chartdb.h"
43 #include "model/wx28compat.h"
44 #include "color_handler.h"
45 //------------------------------------------------------------------------------
46 // Thumbwin Implementation
47 //------------------------------------------------------------------------------
48 BEGIN_EVENT_TABLE(ThumbWin, wxWindow)
49 EVT_PAINT(ThumbWin::OnPaint)
50 END_EVENT_TABLE()
51 
52 // Define a constructor
53 
54 ThumbWin::ThumbWin(wxWindow *parent)
55  : wxWindow(parent, wxID_ANY, wxPoint(20, 20), wxSize(5, 5),
56  wxSIMPLE_BORDER) {
57  pThumbChart = NULL;
58  m_max_size.x = m_max_size.y = 100;
59  Show(false);
60 }
61 
62 ThumbWin::~ThumbWin() {}
63 
64 void ThumbWin::Resize(void) {
65  if (pThumbChart) {
66  if (pThumbChart->GetThumbData()->pDIBThumb) {
67  int newheight = std::min(
68  m_max_size.y, pThumbChart->GetThumbData()->pDIBThumb->GetHeight());
69  int newwidth = std::min(
70  m_max_size.x, pThumbChart->GetThumbData()->pDIBThumb->GetWidth());
71  SetSize(0, 0, newwidth, newheight);
72  }
73  }
74 }
75 
76 void ThumbWin::SetMaxSize(wxSize const &max_size) { m_max_size = max_size; }
77 
78 void ThumbWin::OnPaint(wxPaintEvent &event) {
79  wxPaintDC dc(this);
80 
81  if (pThumbChart) {
82  if (pThumbChart->GetThumbData()) {
83  if (pThumbChart->GetThumbData()->pDIBThumb)
84  dc.DrawBitmap(*(pThumbChart->GetThumbData()->pDIBThumb), 0, 0, false);
85 
86  wxPen ppPen(GetGlobalColor(_T("CHBLK")), 1, wxPENSTYLE_SOLID);
87  dc.SetPen(ppPen);
88  wxBrush yBrush(GetGlobalColor(_T("CHYLW")), wxBRUSHSTYLE_SOLID);
89  dc.SetBrush(yBrush);
90  dc.DrawCircle(pThumbChart->GetThumbData()->ShipX,
91  pThumbChart->GetThumbData()->ShipY, 6);
92  }
93  }
94 }
95 
96 const wxBitmap &ThumbWin::GetBitmap(void) {
97  if (pThumbChart) {
98  if (pThumbChart->GetThumbData()) {
99  if (pThumbChart->GetThumbData()->pDIBThumb)
100  m_bitmap = *(pThumbChart->GetThumbData()->pDIBThumb);
101  }
102  }
103 
104  return m_bitmap;
105 }