3
* $Id: wchroma.cpp 3535 2011-03-18 17:57:05Z carlos $
6
* Copyright 2008-10 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
14
//#define _GINKGO_TRACE
18
#include <wx/xml/xml.h>
20
#include <api/globals.h>
22
#include <api/ievento.h>
23
#include <api/iwidgetsrenderer.h>
24
#include <api/iwidgetsmanager.h>
25
#include <api/icontexto.h>
26
#include <api/westilo.h>
28
#include <eventos/eventosginkgo.h>
30
#include <main/managers/widgetsmanager.h>
36
#define WRADIO_CRUZ 12.0f
37
#define WLONGITUD_LINEA 15.0f
39
//region "Implementacion de WSemillasBuilder"
41
GNC::GCS::Widgets::WChromaBuilder::WChromaBuilder(GNC::GCS::IWidgetsManager* pManager, long gid, GNC::GCS::Widgets::Observadores::IObservadorChroma* pObservador) : GNC::GCS::Widgets::IWidgetBuilder(pManager, gid), GNC::GCS::Widgets::Notificadores::INotificadorChroma(pObservador)
45
m_Estado = WBS_Ninguno;
48
GNC::GCS::Widgets::WChromaBuilder::~WChromaBuilder()
53
void GNC::GCS::Widgets::WChromaBuilder::OnMouseEvents(GNC::GCS::Eventos::EventoRaton& evento)
58
GTRACE("GNC::GCS::Widgets::WSemillasBuilder::OnMouseEvents(wxMouseEvent&)");
59
if (m_MouseDown && evento.ButtonUp(GNC::GCS::Eventos::EventoRaton::EB_IZQUIERDO)) {
70
GNC::GCS::Widgets::WChroma* semilla = new GNC::GCS::Widgets::WChroma(m_pManager, evento.c->GetRenderer()->GetVID(), m_Nodo, "chroma", m_GID);
72
if (m_NumMaxSemillas > 0) {
73
for (GNC::GCS::ListaWidgets::iterator it = m_pManager->GetListaWidgets().begin(); it != m_pManager->GetListaWidgets().end(); it++) {
74
if ( (*it)->GetGID() == m_GID) {
76
if (numSemillas >= m_NumMaxSemillas) {
77
m_pManager->EliminarWidget(it);
83
m_pManager->InsertarWidget(semilla);
84
m_pManager->LanzarEventoCreacion(semilla);
85
m_pManager->Modificado();
89
case WBS_Seleccionando:
94
m_Estado = WBS_Ninguno;
96
} else if (evento.ButtonDown(GNC::GCS::Eventos::EventoRaton::EB_IZQUIERDO)) {
97
if (m_Estado != WBS_Ninguno) {
102
if (m_NumMaxSemillas > 0) {
103
for (GNC::GCS::ListaWidgets::iterator it = m_pManager->GetListaWidgets().begin(); it != m_pManager->GetListaWidgets().end(); it++) {
104
if ( (*it)->GetGID() == m_GID) {
106
if (numSemillas >= m_NumMaxSemillas) {
107
m_pManager->EliminarWidget(it);
116
m_Estado = WBS_Creando;
117
m_pManager->Modificado();
120
} else if (evento.Dragging() && m_MouseDown) {
121
if (m_Estado == WBS_Creando) {
123
m_pManager->Modificado();
129
void GNC::GCS::Widgets::WChromaBuilder::OnKeyEvents(GNC::GCS::Eventos::EventoTeclado& evt)
131
NotificarKeyEvent(evt);
134
void GNC::GCS::Widgets::WChromaBuilder::Render(GNC::GCS::Contexto3D* c)
136
if (m_Estado != WBS_Creando) {
140
GNC::GCS::Vector escala = c->RelacionImagenPantalla();
142
float radioCruz = WRADIO_CRUZ * escala.x;
143
float longitudLinea = WLONGITUD_LINEA * escala.x;
146
float fsombrax, fsombray;
149
fsombrax = WIDGET_OFFSET_X_SOMBRA_SELECCIONADO * escala.x;
150
fsombray = WIDGET_OFFSET_Y_SOMBRA_SELECCIONADO * escala.y;
154
fsombrax = WIDGET_OFFSET_X_SOMBRA * escala.x;
155
fsombray = WIDGET_OFFSET_Y_SOMBRA * escala.y;
159
wColorSombra.Aplicar();
161
glLineWidth(WIDGET_GROSOR_LINEA);
163
glEnable(GL_LINE_STIPPLE);
164
glLineStipple(3, 0xAAAA);
165
glBegin(GL_LINE_STRIP);
166
glVertex3f(m_Nodo.x - radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
167
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
169
glBegin(GL_LINE_STRIP);
170
glVertex3f(m_Nodo.x + radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
171
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
174
glBegin(GL_LINE_STRIP);
175
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - radioCruz - fsombray, 0.0f);
176
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
178
glBegin(GL_LINE_STRIP);
179
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y + radioCruz - fsombray, 0.0f);
180
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
182
glDisable(GL_LINE_STIPPLE);
184
//linea de la cruz 45 grados xa abajo
186
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
187
glVertex3f(m_Nodo.x + longitudLinea + fsombrax, m_Nodo.y - longitudLinea - fsombray, 0.0f);
192
glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
193
wAplicarColor(m_Nodo.m_Iluminado, m_MouseDown, m_Nodo.m_Seleccionado);
196
glEnable(GL_LINE_STIPPLE);
197
glLineStipple(3, 0xAAAA);
198
glBegin(GL_LINE_STRIP);
199
glVertex3f(m_Nodo.x - radioCruz, m_Nodo.y, 0.0f);
200
glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
202
glBegin(GL_LINE_STRIP);
203
glVertex3f(m_Nodo.x + radioCruz, m_Nodo.y, 0.0f);
204
glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
207
glBegin(GL_LINE_STRIP);
208
glVertex3f(m_Nodo.x, m_Nodo.y - radioCruz, 0.0f);
209
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
211
glBegin(GL_LINE_STRIP);
212
glVertex3f(m_Nodo.x, m_Nodo.y + radioCruz, 0.0f);
213
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
215
glDisable(GL_LINE_STIPPLE);
217
//linea de la cruz 45 grados xa abajo
221
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
222
glVertex3f(m_Nodo.x + longitudLinea, m_Nodo.y - longitudLinea, 0.0f);
226
GNC::GCS::Widgets::TipoCursor GNC::GCS::Widgets::WChromaBuilder::GetCursor()
228
return GNC::GCS::Widgets::CUR_CREAR_PUNTO;
234
//region "Constructor y destructor"
236
GNC::GCS::Widgets::WChroma::WChroma(IWidgetsManager* pManager, long vid, GNC::GCS::Nodo nodo, const char* nombre, long gid, bool oculto) : GNC::GCS::Widgets::IWidget(pManager, vid, nombre, gid)
239
m_Nodo.m_Size = WRADIO_CRUZ;
244
/*GNC::GCS::Eventos::EventoModificacionImagen evt1(m_pManager->GetVista());
245
m_pManager->GetControladorEventos()->Registrar(this, evt1);*/
248
GNC::GCS::Widgets::WChroma::~WChroma()
250
LanzarEventoDestruccion();
255
void GNC::GCS::Widgets::WChroma::OnMouseEvents(GNC::GCS::Eventos::EventoRaton& evento)
260
//------------------------------------------------------
262
else if (evento.Leaving() ) {
265
//------------------------------------------------------
267
else if (evento.Entering() ) {
272
//------------------------------------------------------
274
if (evento.Dragging() && m_MouseDown) {
275
if (m_Nodo.m_Seleccionado) {
276
Vector delta = evento.iP - m_PosCursor;
277
m_PosCursor = evento.iP;
281
NotificarCambios(true);
283
LanzarEventoModificacion();
287
//------------------------------------------------------
289
else if (evento.LeftDown()) {
291
if (EventoConsumido() && !evento.m_controlDown) {
292
if (EstaSeleccionado()) {
293
NotificarCambios(true);
299
const GNC::GCS::Vector::TComponente& factor = evento.c->RelacionImagenPantalla().NormaInfinito();
303
m_PosCursor = evento.iP;
305
if (m_Nodo.Hits(evento.iP, factor)) { // click sobre el nodo
307
if (evento.m_controlDown) { // Inversion de seleccion
314
else { // Click fuera del nodo
315
if (!evento.m_controlDown) {
320
if (EstaSeleccionado()) {
327
m_PosAntigua = m_Nodo;
332
//------------------------------------------------------
334
else if (evento.LeftUp()) {
340
//------------------------------------------------------
342
else if (evento.Moving()) {
343
if (EventoConsumido()) {
346
const GNC::GCS::Vector::TComponente& factor = evento.c->RelacionImagenPantalla().NormaInfinito();
350
m_PosCursor = evento.iP;
352
if (m_Nodo.Hits(evento.iP, factor)) {
366
void GNC::GCS::Widgets::WChroma::OnKeyEvents(GNC::GCS::Eventos::EventoTeclado& evento)
368
if (evento.GetKeyCode() == WXK_ESCAPE) {
373
bool GNC::GCS::Widgets::WChroma::HitTest(float /*x*/, float /*y*/, float /*umbralCuadrado*/)
378
bool GNC::GCS::Widgets::WChroma::HitTest(GNC::GCS::Vector* vertices, int numVertices)
380
return m_Nodo.DentroDePoligono2(vertices,numVertices);
383
void GNC::GCS::Widgets::WChroma::Render(GNC::GCS::Contexto3D* c)
389
GNC::GCS::Vector escala = c->RelacionImagenPantalla();
391
float radioCruz = WRADIO_CRUZ * escala.x;
392
float longitudLinea = WLONGITUD_LINEA * escala.x;
395
float fsombrax, fsombray;
398
fsombrax = WIDGET_OFFSET_X_SOMBRA_SELECCIONADO * escala.x;
399
fsombray = WIDGET_OFFSET_Y_SOMBRA_SELECCIONADO * escala.y;
403
fsombrax = WIDGET_OFFSET_X_SOMBRA * escala.x;
404
fsombray = WIDGET_OFFSET_Y_SOMBRA * escala.y;
408
wColorSombra.Aplicar();
411
glEnable(GL_LINE_STIPPLE);
412
glLineStipple(3, 0xAAAA);
413
glBegin(GL_LINE_STRIP);
414
glVertex3f(m_Nodo.x - radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
415
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
417
glBegin(GL_LINE_STRIP);
418
glVertex3f(m_Nodo.x + radioCruz + fsombrax, m_Nodo.y - fsombray, 0.0f);
419
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
422
glBegin(GL_LINE_STRIP);
423
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - radioCruz - fsombray, 0.0f);
424
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
426
glBegin(GL_LINE_STRIP);
427
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y + radioCruz - fsombray, 0.0f);
428
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
430
glDisable(GL_LINE_STIPPLE);
432
//linea de la cruz 45 grados xa abajo
434
glVertex3f(m_Nodo.x + fsombrax, m_Nodo.y - fsombray, 0.0f);
435
glVertex3f(m_Nodo.x + longitudLinea + fsombrax, m_Nodo.y - longitudLinea - fsombray, 0.0f);
440
glEnable(GL_LINE_STIPPLE);
441
wColorLineaArrastre.Aplicar();
442
glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
443
glLineStipple(3, 0xAAAA);
445
glBegin(GL_LINE_STRIP);
446
glVertex2d(m_PosAntigua.x, m_PosAntigua.y);
447
glVertex2d(m_Nodo.x, m_Nodo.y);
450
glDisable(GL_LINE_STIPPLE);
454
glLineWidth(WIDGET_GROSOR_LINEA_ARRASTRE);
455
wAplicarColor(m_Nodo.m_Iluminado, m_MouseDown, m_Nodo.m_Seleccionado);
458
glEnable(GL_LINE_STIPPLE);
459
glLineStipple(3, 0xAAAA);
460
glBegin(GL_LINE_STRIP);
461
glVertex3f(m_Nodo.x - radioCruz, m_Nodo.y, 0.0f);
462
glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
464
glBegin(GL_LINE_STRIP);
465
glVertex3f(m_Nodo.x + radioCruz, m_Nodo.y, 0.0f);
466
glVertex3f(m_Nodo.x , m_Nodo.y, 0.0f);
469
glBegin(GL_LINE_STRIP);
470
glVertex3f(m_Nodo.x, m_Nodo.y - radioCruz, 0.0f);
471
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
473
glBegin(GL_LINE_STRIP);
474
glVertex3f(m_Nodo.x, m_Nodo.y + radioCruz, 0.0f);
475
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
477
glDisable(GL_LINE_STIPPLE);
479
//linea de la cruz 45 grados xa abajo
481
glLineWidth(WIDGET_GROSOR_LINEA);
483
glVertex3f(m_Nodo.x, m_Nodo.y, 0.0f);
484
glVertex3f(m_Nodo.x + longitudLinea, m_Nodo.y - longitudLinea, 0.0f);