-
Notifications
You must be signed in to change notification settings - Fork 0
/
clienzo.cpp
118 lines (98 loc) · 2.59 KB
/
clienzo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "clienzo.h"
#include <stdio.h>
#include <qcursor.h>
//#include <qpaintdevice.h>
#include <qpainter.h>
#include "cmundo3d.h"
CLienzo::CLienzo (int ancho, int alto, CFrameBuffer *framebuffer, CZBuffer *zbuffer, QWidget *padre, const char *nombre)
: QWidget (padre, nombre, Qt::WResizeNoErase | Qt::WRepaintNoErase)//Qt::WNoAutoErase)
{
setMinimumSize(ancho, alto);
//setMaximumSize(ancho, alto);
resize(ancho, alto);
setBackgroundMode(Qt::NoBackground);
setCursor(QCursor(Qt::CrossCursor));
centroX = ancho / 2;
centroY = alto / 2;
CLienzo::framebuffer = framebuffer;
CLienzo::zbuffer = zbuffer;
framebuffer->CambiarTamano(ancho, alto);
zbuffer->CambiarTamano(ancho, alto);
}
void CLienzo::mousePressEvent(QMouseEvent *e)
{
ButtonState b;
x = e->x();
y = e->y();
b = e->button();
if (b & Qt::LeftButton)
{
printf("raton Izquierdo presionado\n");
emit RatonPulsadoIzq(x - centroX, -y + centroY);
}
else
if (b & Qt::RightButton)
{
printf("raton Derecho presionado\n");
emit RatonPulsadoDer(x - centroX, -y + centroY);
}
printf("raton presionado\n");
grabMouse();
}
void CLienzo::mouseReleaseEvent(QMouseEvent *e)
{
x = e->x();
y = e->y();
releaseMouse();
}
void CLienzo::mouseMoveEvent(QMouseEvent *e)
{
ButtonState b;
xm = e->x() - x;
ym = y - e->y();
b = e->state();
if (b & Qt::LeftButton)
if (b & Qt::ControlButton)
emit RatonMovidoIzqCtrl(ym);
else
emit RatonMovidoIzq(xm, ym);
else
if (b & Qt::RightButton)
if (b & Qt::ControlButton)
emit RatonMovidoDerCtrl(ym);
else
emit RatonMovidoDer(xm, ym);
else
if (b & Qt::MidButton)
if (b & Qt::ControlButton)
emit RatonMovidoCenCtrl(ym);
else
emit RatonMovidoCen(xm, ym);
else
emit RatonMovido(e->x() - centroX, - e->y() + centroY);
x = e->x();
y = e->y();
}
void CLienzo::paintEvent(QPaintEvent *)
{
//QWidget::paintEvent(e);
//printf("pintado1: %d, %d\n", width(), height());
//framebuffer->TerminarPintar();
bitBlt(this, 0, 0, framebuffer, 0, 0, width(), height(), Qt::CopyROP);
// if (e->erased())
// printf("ERROR: Se hizo un BORRADO\n");
//printf("pintado2: %d, %d\n", e->rect().width(), e->rect().height());
}
void CLienzo::resizeEvent(QResizeEvent *)
{
//const QSize tamano = e->size();
//printf("resize1 %d x %d\n", tamano.width(), tamano.height());
centroX = width() / 2;
centroY = height() / 2;
framebuffer->CambiarTamano(width(), height());
zbuffer->CambiarTamano(width(), height());
((CMundo3d *)parentWidget())->DibujarMundo3d();
// repaint(0, 0, width(), height(), FALSE);
//update(0, 0, width(), height());
printf("Resize Event: %d, %d\n", width(), height());
}