mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
reindent
This commit is contained in:
@@ -10,171 +10,171 @@
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h> // FIXME: ¿This work/necessary in Windows?
|
||||
//Not necessary, but if it was, it needs to be replaced by process.h AND io.h
|
||||
//Not necessary, but if it was, it needs to be replaced by process.h AND io.h
|
||||
#endif
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point(float x, float y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
float x;
|
||||
float y;
|
||||
public:
|
||||
Point(float x, float y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
class PolyLine
|
||||
{
|
||||
public:
|
||||
void addPoint(Point point);
|
||||
void draw();
|
||||
private:
|
||||
std::vector<Point> points;
|
||||
public:
|
||||
void addPoint(Point point);
|
||||
void draw();
|
||||
private:
|
||||
std::vector<Point> points;
|
||||
};
|
||||
|
||||
void PolyLine::addPoint(Point point)
|
||||
{
|
||||
points.push_back(point);
|
||||
points.push_back(point);
|
||||
}
|
||||
|
||||
void PolyLine::draw()
|
||||
{
|
||||
std::vector<Point>::const_iterator iter;
|
||||
std::vector<Point>::const_iterator iter;
|
||||
|
||||
glPushMatrix ();
|
||||
glDisable (GL_LIGHTING);
|
||||
glColor3f (1.0f, 0.8f, 0.2f);
|
||||
glPushMatrix ();
|
||||
glDisable (GL_LIGHTING);
|
||||
glColor3f (1.0f, 0.8f, 0.2f);
|
||||
|
||||
glBegin (GL_LINE_STRIP);
|
||||
glBegin (GL_LINE_STRIP);
|
||||
|
||||
for (iter = points.begin(); iter != points.end(); iter++)
|
||||
{
|
||||
printf("glVertex3f %f %f %f", (*iter).x, (*iter).y, 0.0f);
|
||||
glVertex3f ((*iter).x, (*iter).y, 0.0f);
|
||||
}
|
||||
for (iter = points.begin(); iter != points.end(); iter++)
|
||||
{
|
||||
printf("glVertex3f %f %f %f", (*iter).x, (*iter).y, 0.0f);
|
||||
glVertex3f ((*iter).x, (*iter).y, 0.0f);
|
||||
}
|
||||
|
||||
glEnd ();
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glPopMatrix ();
|
||||
glEnd ();
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glPopMatrix ();
|
||||
}
|
||||
|
||||
class wxGLCanvasSubClass: public wxGLCanvas
|
||||
{
|
||||
void Render();
|
||||
public:
|
||||
wxGLCanvasSubClass(wxFrame* parent);
|
||||
void Paintit(wxPaintEvent& event);
|
||||
protected:
|
||||
DECLARE_EVENT_TABLE()
|
||||
private:
|
||||
void OnMouseEvent (wxMouseEvent& event);
|
||||
void setup_polyline ();
|
||||
void drawAllLines ();
|
||||
std::vector<PolyLine> lines;
|
||||
void Render();
|
||||
public:
|
||||
wxGLCanvasSubClass(wxFrame* parent);
|
||||
void Paintit(wxPaintEvent& event);
|
||||
protected:
|
||||
DECLARE_EVENT_TABLE()
|
||||
private:
|
||||
void OnMouseEvent (wxMouseEvent& event);
|
||||
void setup_polyline ();
|
||||
void drawAllLines ();
|
||||
std::vector<PolyLine> lines;
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(wxGLCanvasSubClass, wxGLCanvas)
|
||||
EVT_PAINT (wxGLCanvasSubClass::Paintit)
|
||||
EVT_MOUSE_EVENTS(wxGLCanvasSubClass::OnMouseEvent)
|
||||
EVT_PAINT (wxGLCanvasSubClass::Paintit)
|
||||
EVT_MOUSE_EVENTS(wxGLCanvasSubClass::OnMouseEvent)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxGLCanvasSubClass::wxGLCanvasSubClass(wxFrame *parent)
|
||||
:wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas"))
|
||||
{
|
||||
int argc = 1;
|
||||
char* argv[1] = { wxString((wxTheApp->argv)[0]).char_str() };
|
||||
int argc = 1;
|
||||
char* argv[1] = { wxString((wxTheApp->argv)[0]).char_str() };
|
||||
}
|
||||
|
||||
void wxGLCanvasSubClass::Paintit(wxPaintEvent& WXUNUSED(event))
|
||||
{
|
||||
Render();
|
||||
Render();
|
||||
}
|
||||
|
||||
void wxGLCanvasSubClass::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
printf("x=%d y=%d LeftIsDown=%d\n", event.GetX(), event.GetY(), (int) event.LeftIsDown());
|
||||
printf("x=%d y=%d LeftIsDown=%d\n", event.GetX(), event.GetY(), (int) event.LeftIsDown());
|
||||
|
||||
if (event.LeftIsDown())
|
||||
{
|
||||
lines[0].addPoint(Point((float) event.GetX(), (float) event.GetY()));
|
||||
Render();
|
||||
}
|
||||
if (event.LeftIsDown())
|
||||
{
|
||||
lines[0].addPoint(Point((float) event.GetX(), (float) event.GetY()));
|
||||
Render();
|
||||
}
|
||||
}
|
||||
|
||||
void wxGLCanvasSubClass::drawAllLines()
|
||||
{
|
||||
std::vector<PolyLine>::iterator iter;
|
||||
std::vector<PolyLine>::iterator iter;
|
||||
|
||||
for (iter = lines.begin(); iter != lines.end(); iter++)
|
||||
{
|
||||
(*iter).draw();
|
||||
}
|
||||
for (iter = lines.begin(); iter != lines.end(); iter++)
|
||||
{
|
||||
(*iter).draw();
|
||||
}
|
||||
}
|
||||
|
||||
void wxGLCanvasSubClass::setup_polyline()
|
||||
{
|
||||
lines.push_back(PolyLine());
|
||||
// lines[0].addPoint(Point(30.0f, 30.0f));
|
||||
// lines[0].addPoint(Point(60.0f, 40.0f));
|
||||
// lines[0].addPoint(Point(90.0f, 20.0f));
|
||||
// lines[0].addPoint(Point(30.0f, 100.0f));
|
||||
lines.push_back(PolyLine());
|
||||
// lines[0].addPoint(Point(30.0f, 30.0f));
|
||||
// lines[0].addPoint(Point(60.0f, 40.0f));
|
||||
// lines[0].addPoint(Point(90.0f, 20.0f));
|
||||
// lines[0].addPoint(Point(30.0f, 100.0f));
|
||||
}
|
||||
|
||||
void wxGLCanvasSubClass::Render()
|
||||
{
|
||||
static bool polyline_is_set = false;
|
||||
static bool polyline_is_set = false;
|
||||
|
||||
SetCurrent();
|
||||
wxPaintDC(this);
|
||||
SetCurrent();
|
||||
wxPaintDC(this);
|
||||
|
||||
if (! polyline_is_set)
|
||||
{
|
||||
setup_polyline();
|
||||
polyline_is_set = true;
|
||||
}
|
||||
if (! polyline_is_set)
|
||||
{
|
||||
setup_polyline();
|
||||
polyline_is_set = true;
|
||||
}
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, (GLint) GetSize().x, (GLint) GetSize().y);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, (GLint) GetSize().x, (GLint) GetSize().y);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
glOrtho (
|
||||
0.0f, (float) GetSize().x, // left, right
|
||||
(float) GetSize().y, 0.0f, // bottom, top
|
||||
-1.0, 1.0f);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
glOrtho (
|
||||
0.0f, (float) GetSize().x, // left, right
|
||||
(float) GetSize().y, 0.0f, // bottom, top
|
||||
-1.0, 1.0f);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
glLoadIdentity ();
|
||||
glLoadIdentity ();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glLineWidth(2.0f);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glLineWidth(2.0f);
|
||||
|
||||
drawAllLines();
|
||||
drawAllLines();
|
||||
|
||||
glFlush();
|
||||
SwapBuffers();
|
||||
glFlush();
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
private:
|
||||
virtual bool OnInit();
|
||||
wxGLCanvasSubClass * MyGLCanvas;
|
||||
private:
|
||||
virtual bool OnInit();
|
||||
wxGLCanvasSubClass * MyGLCanvas;
|
||||
};
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, wxT("Hello GL World"), wxPoint(50, 50), wxSize(640, 480));
|
||||
//frame->SetWindowStyle(wxWANTS_CHARS);
|
||||
MyGLCanvas = new wxGLCanvasSubClass(frame);
|
||||
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, wxT("Hello GL World"), wxPoint(50, 50), wxSize(640, 480));
|
||||
//frame->SetWindowStyle(wxWANTS_CHARS);
|
||||
MyGLCanvas = new wxGLCanvasSubClass(frame);
|
||||
|
||||
frame->Show(TRUE);
|
||||
return TRUE;
|
||||
frame->Show(TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user