source: trunk/src/testing/app/JuxtaView/UI/Overview.cpp @ 4

Revision 4, 6.5 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

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