1 | /*============================================================================= |
---|
2 | |
---|
3 | Program: JuxtaView for SAGE |
---|
4 | Module: Overview.cpp - Part of JuxtaView's UI |
---|
5 | Authors: Arun Rao, arao@evl.uic.edu, |
---|
6 | Ratko Jagodic, rjagodic@evl.uic.edu, |
---|
7 | Nicholas Schwarz, schwarz@evl.uic.edu, |
---|
8 | Luc Renambot, luc@evl.uic.edu, |
---|
9 | et al. |
---|
10 | Date: 30 September 2004 |
---|
11 | Modified: 15 August 2005 |
---|
12 | |
---|
13 | Copyright (c) 2005 Electronic Visualization Laboratory, |
---|
14 | University of Illinois at Chicago |
---|
15 | |
---|
16 | All rights reserved. |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions are met: |
---|
20 | * |
---|
21 | * * Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * * Redistributions in binary form must reproduce the above |
---|
24 | * copyright notice, this list of conditions and the following disclaimer |
---|
25 | * in the documentation and/or other materials provided with the distribution. |
---|
26 | * * Neither the name of the University of Illinois at Chicago nor |
---|
27 | * the names of its contributors may be used to endorse or promote |
---|
28 | * products derived from this software without specific prior written permission. |
---|
29 | * |
---|
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
34 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
35 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
36 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
37 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
38 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
39 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
41 | |
---|
42 | Direct questions, comments, etc. to schwarz@evl.uic.edu or |
---|
43 | http://www.evl.uic.edu/cavern/forum/ |
---|
44 | |
---|
45 | =============================================================================*/ |
---|
46 | |
---|
47 | #include "JuxtaSCUI.h" |
---|
48 | |
---|
49 | |
---|
50 | JuxtaOverviewFrame::JuxtaOverviewFrame(wxWindow* parent, int id, const wxString& title, |
---|
51 | const wxPoint& pos, const wxSize& size, |
---|
52 | long style) |
---|
53 | :wxFrame(parent,id,title,pos,size,style) |
---|
54 | { |
---|
55 | data.imgArray = NULL; |
---|
56 | img = NULL; |
---|
57 | bmptodraw = NULL; |
---|
58 | penColor.Set(255,255,255); |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | BEGIN_EVENT_TABLE( JuxtaOverviewFrame, wxFrame ) |
---|
63 | EVT_PAINT( JuxtaOverviewFrame::OnPaint ) |
---|
64 | EVT_RIGHT_UP( JuxtaOverviewFrame::OnDropDownMenu ) |
---|
65 | EVT_MENU( ID_ChangePenColor, JuxtaOverviewFrame::OnMenuSelection ) |
---|
66 | EVT_MENU( ID_ZoomOutFromMouse, JuxtaOverviewFrame::OnMenuSelection ) |
---|
67 | EVT_MENU( ID_ZoomInFromMouse, JuxtaOverviewFrame::OnMenuSelection ) |
---|
68 | EVT_LEFT_UP( JuxtaOverviewFrame::OnLeftMouseUp ) |
---|
69 | END_EVENT_TABLE() |
---|
70 | |
---|
71 | JuxtaOverviewFrame::~JuxtaOverviewFrame() |
---|
72 | { |
---|
73 | |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | void JuxtaOverviewFrame::SetImage(int w, int h, unsigned char* pixels) |
---|
78 | { |
---|
79 | SetSize(w,h); |
---|
80 | |
---|
81 | //get the data |
---|
82 | data.w = w; |
---|
83 | data.h = h; |
---|
84 | if(data.imgArray) |
---|
85 | delete [] data.imgArray; |
---|
86 | data.imgArray = pixels; |
---|
87 | |
---|
88 | //make an image out of it |
---|
89 | if(img) |
---|
90 | delete img; |
---|
91 | |
---|
92 | img = new wxImage(data.w,data.h,data.imgArray,TRUE); |
---|
93 | |
---|
94 | if(bmptodraw) |
---|
95 | delete bmptodraw; |
---|
96 | |
---|
97 | bmptodraw = new wxBitmap(img); |
---|
98 | |
---|
99 | Refresh(); |
---|
100 | |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | void JuxtaOverviewFrame::SetExtentRectangle(float nx, float ny, float nw, float nh) |
---|
105 | { |
---|
106 | data.normX = nx; |
---|
107 | data.normY = ny; |
---|
108 | data.normW = nw; |
---|
109 | data.normH = nh; |
---|
110 | } |
---|
111 | |
---|
112 | void JuxtaOverviewFrame::OnPaint(wxPaintEvent& event) |
---|
113 | { |
---|
114 | pdc = new wxPaintDC(this); |
---|
115 | wxPen pen(penColor,5,wxDOT_DASH); |
---|
116 | pdc->SetPen(pen); |
---|
117 | pdc->BeginDrawing(); |
---|
118 | if(bmptodraw) |
---|
119 | { |
---|
120 | fprintf(stderr,"Bitmap valid! Drawing\n"); |
---|
121 | pdc->DrawBitmap((*bmptodraw),0,0,TRUE); |
---|
122 | //draw some lines with the extents |
---|
123 | // pdc->GetPen().SetJoin(wxJOIN_ROUND); |
---|
124 | // pdc->GetPen().SetWidth(10); |
---|
125 | // pdc->GetPen().SetCap(wxCAP_PROJECTING); |
---|
126 | // pdc->GetPen().SetColour(255,255,255); |
---|
127 | // pdc->GetPen().SetStyle(wxCROSSDIAG_HATCH); |
---|
128 | |
---|
129 | int x0,y0,x1,y1; |
---|
130 | x0 = (int)(data.normX * data.w); |
---|
131 | y0 = (int)(data.normY * data.h); |
---|
132 | x1 = (int)(x0 + (data.normW * data.w)); |
---|
133 | y1 = (int)(y0 + (data.normH * data.h)); |
---|
134 | |
---|
135 | pdc->DrawLine( x0,y0,x1,y0); |
---|
136 | pdc->DrawLine( x0,y0,x0,y1); |
---|
137 | pdc->DrawLine( x1,y0,x1,y1); |
---|
138 | pdc->DrawLine( x0,y1,x1,y1); |
---|
139 | |
---|
140 | } |
---|
141 | pdc->EndDrawing(); |
---|
142 | |
---|
143 | delete pdc; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | char OverviewMenuLabels[OVERVIEW_MENU_ITEM_COUNT][OVERVIEW_MENU_LABEL_LENGTH] = |
---|
148 | { "Change Border Color", "Zoom Out","Zoom In" }; |
---|
149 | |
---|
150 | void JuxtaOverviewFrame::OnDropDownMenu(wxMouseEvent& event) |
---|
151 | { |
---|
152 | //make the drop down menu |
---|
153 | wxMenu *menu = new wxMenu(); |
---|
154 | for ( int i = 0; i < OVERVIEW_MENU_ITEM_COUNT; i++) |
---|
155 | { |
---|
156 | menu->Append( i, wxString(OverviewMenuLabels[i])); |
---|
157 | } |
---|
158 | |
---|
159 | PopupMenu(menu,event.GetX(),event.GetY()); |
---|
160 | } |
---|
161 | |
---|
162 | void JuxtaOverviewFrame::OnMenuSelection(wxCommandEvent& event) |
---|
163 | { |
---|
164 | wxColourDialog *dlg; |
---|
165 | switch( event.GetId()) |
---|
166 | { |
---|
167 | case ID_ChangePenColor: |
---|
168 | fprintf(stderr,"Opening Color Dialog!\n"); |
---|
169 | //change the color of the pen |
---|
170 | dlg = new wxColourDialog(this); |
---|
171 | if( dlg->ShowModal() == wxID_OK) |
---|
172 | { |
---|
173 | unsigned char red, green, blue; |
---|
174 | red = dlg->GetColourData().GetColour().Red(); |
---|
175 | green = dlg->GetColourData().GetColour().Green(); |
---|
176 | blue = dlg->GetColourData().GetColour().Blue(); |
---|
177 | |
---|
178 | penColor.Set(red,green,blue); |
---|
179 | Refresh(); |
---|
180 | } |
---|
181 | |
---|
182 | dlg->Destroy(); |
---|
183 | break; |
---|
184 | case ID_ZoomOutFromMouse: |
---|
185 | if(gMainFrame) |
---|
186 | { |
---|
187 | gMainFrame->PassEvent(JVZOOM_OUT); |
---|
188 | gMainFrame->GetExtents(0); |
---|
189 | Refresh(); |
---|
190 | } |
---|
191 | break; |
---|
192 | case ID_ZoomInFromMouse: |
---|
193 | if(gMainFrame) |
---|
194 | { |
---|
195 | gMainFrame->PassEvent(JVZOOM_IN); |
---|
196 | gMainFrame->GetExtents(0); |
---|
197 | Refresh(); |
---|
198 | } |
---|
199 | break; |
---|
200 | default: |
---|
201 | break; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | void JuxtaOverviewFrame::OnLeftMouseUp(wxMouseEvent& event) |
---|
207 | { |
---|
208 | //figure out what normalized coordinates to send to the UI server... |
---|
209 | float coords[2] = { 0.0, 0.0 }; |
---|
210 | fprintf(stderr,"Left mouse up at %d, %d\n",event.GetX(),event.GetY()); |
---|
211 | coords[0] = ((float)event.GetX() / (float)data.w) - (data.normW / 2.0); |
---|
212 | coords[1] = ((float)event.GetY() / (float)data.h) - (data.normH / 2.0); |
---|
213 | |
---|
214 | if( coords[0] + data.normW > 1 ) |
---|
215 | { |
---|
216 | coords[0] += 1 - ( coords[0] + data.normW ); |
---|
217 | } |
---|
218 | else if( coords[0] < 0 ) |
---|
219 | { |
---|
220 | coords[0] = 0; |
---|
221 | } |
---|
222 | |
---|
223 | if( coords[1] + data.normH > 1 ) |
---|
224 | { |
---|
225 | coords[1] += 1 - ( coords[1] + data.normH ); |
---|
226 | } |
---|
227 | else if( coords[1] < 0 ) |
---|
228 | { |
---|
229 | coords[1] = 0; |
---|
230 | } |
---|
231 | |
---|
232 | fprintf(stderr,"Passing normalized coords %f, %f to server\n",coords[0],coords[1]); |
---|
233 | if( gMainFrame) |
---|
234 | { |
---|
235 | gMainFrame->PassEvent(JVTRANSLATE); |
---|
236 | gMainFrame->PassBuffer((void*)coords,sizeof(float) * 2); |
---|
237 | //gMainFrame->GetExtents(0); |
---|
238 | //gMainFrame->GetExtents(1); |
---|
239 | gMainFrame->BigRefresh(); |
---|
240 | } |
---|
241 | |
---|
242 | Refresh(); |
---|
243 | |
---|
244 | } |
---|
245 | |
---|