~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: KX_BlenderCanvas.cpp 15662 2008-07-20 23:03:01Z zaghaghi $
 
2
 * $Id: KX_BlenderCanvas.cpp 32387 2010-10-09 13:46:34Z dfelinto $
3
3
 * ***** BEGIN GPL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software Foundation,
17
 
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
 *
19
19
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20
20
 * All rights reserved.
26
26
 * ***** END GPL LICENSE BLOCK *****
27
27
 */
28
28
 
29
 
#include "BIF_scrarea.h"
30
29
#include "KX_BlenderCanvas.h"
31
 
 
32
 
#ifdef HAVE_CONFIG_H
33
 
#include <config.h>
34
 
#endif
35
 
 
36
 
KX_BlenderCanvas::KX_BlenderCanvas(struct ScrArea *area) :
37
 
m_area(area)
 
30
#include "DNA_screen_types.h"
 
31
#include "stdio.h"
 
32
 
 
33
 
 
34
KX_BlenderCanvas::KX_BlenderCanvas(struct wmWindow *win, RAS_Rect &rect, struct ARegion *ar) :
 
35
m_win(win),
 
36
m_frame_rect(rect)
38
37
{
 
38
        // area boundaries needed for mouse coordinates in Letterbox framing mode
 
39
        m_area_left = ar->winrct.xmin;
 
40
        m_area_top = ar->winrct.ymax;
39
41
}
40
42
 
41
43
KX_BlenderCanvas::~KX_BlenderCanvas()
50
52
 
51
53
void KX_BlenderCanvas::SwapBuffers()
52
54
{
53
 
        BL_SwapBuffers();
 
55
        BL_SwapBuffers(m_win);
54
56
}
55
57
 
56
58
void KX_BlenderCanvas::BeginFrame()
93
95
 
94
96
int KX_BlenderCanvas::GetWidth(
95
97
) const {
96
 
        return scrarea_get_win_width(m_area);
 
98
        return m_frame_rect.GetWidth();
97
99
}
98
100
 
99
101
int KX_BlenderCanvas::GetHeight(
100
102
) const {
101
 
        return scrarea_get_win_height(m_area);
 
103
        return m_frame_rect.GetHeight();
 
104
}
 
105
 
 
106
int KX_BlenderCanvas::GetMouseX(int x)
 
107
{
 
108
        float left = GetWindowArea().GetLeft();
 
109
        return float(x - (left - m_area_left));
 
110
}
 
111
 
 
112
int KX_BlenderCanvas::GetMouseY(int y)
 
113
{
 
114
        float top = GetWindowArea().GetTop();
 
115
        return float(y - (m_area_top - top));
 
116
}
 
117
 
 
118
float KX_BlenderCanvas::GetMouseNormalizedX(int x)
 
119
{
 
120
        int can_x = GetMouseX(x);
 
121
        return float(can_x)/this->GetWidth();
 
122
}
 
123
 
 
124
float KX_BlenderCanvas::GetMouseNormalizedY(int y)
 
125
{
 
126
        int can_y = GetMouseY(y);
 
127
        return float(can_y)/this->GetHeight();
102
128
}
103
129
 
104
130
RAS_Rect &
114
140
        int x1, int y1,
115
141
        int x2, int y2
116
142
){
 
143
        /*      x1 and y1 are the min pixel coordinate (e.g. 0)
 
144
                x2 and y2 are the max pixel coordinate
 
145
                the width,height is calculated including both pixels
 
146
                therefore: max - min + 1
 
147
        */
117
148
        int vp_width = (x2 - x1) + 1;
118
149
        int vp_height = (y2 - y1) + 1;
119
 
        int minx = scrarea_get_win_x(m_area);
120
 
        int miny = scrarea_get_win_y(m_area);
 
150
        int minx = m_frame_rect.GetLeft();
 
151
        int miny = m_frame_rect.GetBottom();
121
152
 
122
153
        m_area_rect.SetLeft(minx + x1);
123
154
        m_area_rect.SetBottom(miny + y1);
131
162
 
132
163
void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate)
133
164
{
 
165
        m_mousestate = mousestate;
 
166
 
134
167
        switch (mousestate)
135
168
        {
136
169
        case MOUSE_INVISIBLE:
137
170
                {
138
 
                        BL_HideMouse();
 
171
                        BL_HideMouse(m_win);
139
172
                        break;
140
173
                }
141
174
        case MOUSE_WAIT:
142
175
                {
143
 
                        BL_WaitMouse();
 
176
                        BL_WaitMouse(m_win);
144
177
                        break;
145
178
                }
146
179
        case MOUSE_NORMAL:
147
180
                {
148
 
                        BL_NormalMouse();
 
181
                        BL_NormalMouse(m_win);
149
182
                        break;
150
183
                }
151
184
        default:
159
192
//      (0,0) is top left, (width,height) is bottom right
160
193
void KX_BlenderCanvas::SetMousePosition(int x,int y)
161
194
{
162
 
        int winX = scrarea_get_win_x(m_area);
163
 
        int winY = scrarea_get_win_y(m_area);
164
 
        int winH = scrarea_get_win_height(m_area);
 
195
        int winX = m_frame_rect.GetLeft();
 
196
        int winY = m_frame_rect.GetBottom();
 
197
        int winH = m_frame_rect.GetHeight();
165
198
        
166
 
        BL_warp_pointer(winX + x, winY + (winH-y-1));
 
199
        BL_warp_pointer(m_win, winX + x, winY + (winH-y));
167
200
}
168
201
 
169
202
 
170
203
 
171
204
void KX_BlenderCanvas::MakeScreenShot(const char* filename)
172
205
{
173
 
        BL_MakeScreenShot(m_area, filename);
 
206
        ScrArea area_dummy= {0};
 
207
        area_dummy.totrct.xmin = m_frame_rect.GetLeft();
 
208
        area_dummy.totrct.xmax = m_frame_rect.GetRight();
 
209
        area_dummy.totrct.ymin = m_frame_rect.GetBottom();
 
210
        area_dummy.totrct.ymax = m_frame_rect.GetTop();
 
211
 
 
212
        BL_MakeScreenShot(&area_dummy, filename);
174
213
}