diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..586b6b1 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,26 @@ + +CP := cp +TARGET := jcad +MODULES := main gui engine +export GTKMM_VERSION := 2.4 +export GTKGLEXTMM_VERSION := 1.2 +CXXFLAGS := -O2 +LDFLAGS := `pkg-config --libs gtkmm-$(GTKMM_VERSION)` \ + `pkg-config --libs gtkglextmm-$(GTKGLEXTMM_VERSION)` +ARCHIVES := $(foreach module,$(MODULES),$(module)/$(module).a) + +all: $(MODULES) $(TARGET) + +$(TARGET): $(ARCHIVES) + $(CXX) -o $@ $(ARCHIVES) $(LDFLAGS) + +%.o: %.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $< + +.PHONY: $(MODULES) +$(MODULES): + $(MAKE) -C $@ + +clean: + $(RM) -f *.o *.a *~ $(TARGET) + for m in $(MODULES); do (cd $$m; $(MAKE) clean ); done diff --git a/src/engine/Makefile b/src/engine/Makefile new file mode 100644 index 0000000..544f762 --- /dev/null +++ b/src/engine/Makefile @@ -0,0 +1,30 @@ + +SRCS := Profile.cpp +MODULES := Profile.o +TARGET := engine.a +GTKMM_VERSION := 2.4 +GTKGLEXTMM_VERSION := 1.2 +CPPFLAGS = -I.. +CXXFLAGS = -O2 $(CPPFLAGS) \ + `pkg-config --cflags gtkmm-$(GTKMM_VERSION)` \ + `pkg-config --cflags gtkglextmm-$(GTKGLEXTMM_VERSION)` +DEPS := $(SRCS:.cpp=.d) + +all: $(TARGET) + +$(TARGET): $(MODULES) + $(AR) rcv $@ $? + +%.o: %.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $< + +.PHONY: clean +clean: + $(RM) -f *.o *.d *~ $(TARGET) + +%.d: %.cpp + @set -e; rm -f $@; \ + $(CXX) -MM $(CPPFLAGS) $< | \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@ + +include $(DEPS) diff --git a/src/engine/Profile.cpp b/src/engine/Profile.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/engine/Profile.h b/src/engine/Profile.h new file mode 100644 index 0000000..fda59bc --- /dev/null +++ b/src/engine/Profile.h @@ -0,0 +1,12 @@ + +#ifndef PROFILE_H +#define PROFILE_H + +class Profile +{ + public: + protected: +}; + +#endif + diff --git a/src/gui/Displayer.cpp b/src/gui/Displayer.cpp new file mode 100644 index 0000000..7e54c0e --- /dev/null +++ b/src/gui/Displayer.cpp @@ -0,0 +1,81 @@ + +#include +#include +#include +#include "ProfileDisplayer.h" +#include "PartDisplayer.h" +#include "Displayer.h" + +Displayer::Displayer(const Glib::RefPtr & config) + : Gtk::GL::DrawingArea(config) +{ + set_gl_capability(config); + set_events(Gdk::POINTER_MOTION_MASK + | Gdk::BUTTON_PRESS_MASK + | Gdk::BUTTON_RELEASE_MASK + | Gdk::SCROLL_MASK); +} + +Displayer::~Displayer() +{ +} + +bool Displayer::draw() +{ + return false; +} + +bool Displayer::on_motion_notify_event(GdkEventMotion * event) +{ + get_pointer(m_x, m_y); + return true; +} + +bool Displayer::on_button_press_event(GdkEventButton * event) +{ +} + +bool Displayer::on_button_release_event(GdkEventButton * event) +{ +} + +bool Displayer::on_scroll_event(GdkEventScroll * event) +{ +} + +void Displayer::on_realize() +{ + Gtk::GL::DrawingArea::on_realize(); + + Glib::RefPtr glwindow = get_gl_window(); + glwindow->get_window()->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR)); + + if (!glwindow->gl_begin(get_gl_context())) + return; + + glViewport(0, 0, get_width(), get_height()); + + glwindow->gl_end(); +} + +/* + * called on widget resizes + */ +bool Displayer::on_configure_event(GdkEventConfigure * event) +{ + Glib::RefPtr glwindow = get_gl_window(); + + if (!glwindow->gl_begin(get_gl_context())) + return false; + + glViewport(0, 0, get_width(), get_height()); + + glwindow->gl_end(); + + return true; +} + +bool Displayer::on_expose_event(GdkEventExpose * event) +{ + return draw(); +} diff --git a/src/gui/Displayer.h b/src/gui/Displayer.h new file mode 100644 index 0000000..2460cf0 --- /dev/null +++ b/src/gui/Displayer.h @@ -0,0 +1,29 @@ + +#ifndef GLWIDGET_H +#define GLWIDGET_H + +#include + +class Displayer : public Gtk::GL::DrawingArea +{ + public: + Displayer(const Glib::RefPtr & config); + ~Displayer(); + + protected: + int m_x, m_y; + + virtual bool draw(); + virtual void on_realize(); + virtual bool on_configure_event(GdkEventConfigure * event); + virtual bool on_expose_event(GdkEventExpose * event); + + /* signal handlers */ + virtual bool on_motion_notify_event(GdkEventMotion * event); + virtual bool on_button_press_event(GdkEventButton * event); + virtual bool on_button_release_event(GdkEventButton * event); + virtual bool on_scroll_event(GdkEventScroll * event); +}; + +#endif + diff --git a/src/gui/GUI.cpp b/src/gui/GUI.cpp new file mode 100644 index 0000000..6fffa9c --- /dev/null +++ b/src/gui/GUI.cpp @@ -0,0 +1,35 @@ + +#include "GUI.h" +#include "MainWindow.h" +#include +#include +#include + +int GUI::start(int argc, char * argv[]) +{ + Gtk::Main gtkmain(argc, argv); + Gtk::GL::init(argc, argv); + + Glib::RefPtr glconfig; + glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | + Gdk::GL::MODE_DEPTH | + Gdk::GL::MODE_DOUBLE); + + if (!glconfig) + { + std::cerr << "Could not create double-buffered GL visual" + << "Trying single-buffered visual." << std::endl; + + glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | + Gdk::GL::MODE_DEPTH); + + if (!glconfig) + { + std::cerr << "Cannot create OpenGL context!" << std::endl; + return -1; + } + } + + MainWindow mw(glconfig); + Gtk::Main::run(mw); +} diff --git a/src/gui/GUI.h b/src/gui/GUI.h new file mode 100644 index 0000000..a0d95aa --- /dev/null +++ b/src/gui/GUI.h @@ -0,0 +1,12 @@ + +#ifndef GUI_H +#define GUI_H + +class GUI +{ + public: + int start(int argc, char * argv[]); +}; + +#endif + diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp new file mode 100644 index 0000000..c995ab5 --- /dev/null +++ b/src/gui/MainWindow.cpp @@ -0,0 +1,54 @@ + +#include "MainWindow.h" +#include +#include +#include +#include "PartDisplayer.h" + +MainWindow::MainWindow(const Glib::RefPtr & config) + : m_displayer(new PartDisplayer(config)) +{ + set_default_size(500, 500); + + m_refActionGroup = Gtk::ActionGroup::create(); + m_refActionGroup->add(Gtk::Action::create("FileMenu", "_File")); + m_refActionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), + sigc::mem_fun(*this, &MainWindow::on_action_new)); + m_refActionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), + sigc::mem_fun(*this, &MainWindow::on_action_quit)); + Glib::RefPtr m_refUIManager = Gtk::UIManager::create(); + m_refUIManager->insert_action_group(m_refActionGroup); + add_accel_group(m_refUIManager->get_accel_group()); + Glib::ustring ui_info = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + m_refUIManager->add_ui_from_string(ui_info); + + m_VBox.pack_start(*m_refUIManager->get_widget("/MenuBar"), + Gtk::PACK_SHRINK); + m_VBox.pack_start(*m_refUIManager->get_widget("/ToolBar"), + Gtk::PACK_SHRINK); + m_VBox.pack_start(*m_displayer); + m_VBox.pack_start(m_statusBar, Gtk::PACK_SHRINK); + add(m_VBox); + show_all(); +} + +void MainWindow::on_action_new() +{ +} + +void MainWindow::on_action_quit() +{ + Gtk::Main::quit(); +} diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h new file mode 100644 index 0000000..a6502e3 --- /dev/null +++ b/src/gui/MainWindow.h @@ -0,0 +1,29 @@ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include "Displayer.h" + +class MainWindow : public Gtk::Window +{ + public: + MainWindow(const Glib::RefPtr & config); + + protected: + Glib::RefPtr m_refUIManager; + Glib::RefPtr m_refActionGroup; + Displayer * m_displayer; + Gtk::VBox m_VBox; + Gtk::Statusbar m_statusBar; + + void on_action_new(); + void on_action_quit(); +}; + +#endif diff --git a/src/gui/Makefile b/src/gui/Makefile new file mode 100644 index 0000000..ccf3227 --- /dev/null +++ b/src/gui/Makefile @@ -0,0 +1,30 @@ + +SRCS := MainWindow.cpp GUI.cpp Displayer.cpp ProfileDisplayer.cpp PartDisplayer.cpp +MODULES := MainWindow.o GUI.o Displayer.o ProfileDisplayer.o PartDisplayer.o +TARGET := gui.a +GTKMM_VERSION := 2.4 +GTKGLEXTMM_VERSION := 1.2 +CPPFLAGS = -I.. +CXXFLAGS = -O2 $(CPPFLAGS) \ + `pkg-config --cflags gtkmm-$(GTKMM_VERSION)` \ + `pkg-config --cflags gtkglextmm-$(GTKGLEXTMM_VERSION)` +DEPS := $(SRCS:.cpp=.d) + +all: $(TARGET) + +$(TARGET): $(MODULES) + $(AR) rcv $@ $? + +%.o: %.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $< + +.PHONY: clean +clean: + $(RM) -f *.o *.d *~ $(TARGET) + +%.d: %.cpp + @set -e; rm -f $@; \ + $(CXX) -MM $(CPPFLAGS) $< | \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@ + +include $(DEPS) diff --git a/src/gui/PartDisplayer.cpp b/src/gui/PartDisplayer.cpp new file mode 100644 index 0000000..ab77a77 --- /dev/null +++ b/src/gui/PartDisplayer.cpp @@ -0,0 +1,73 @@ + +#include "PartDisplayer.h" +#include +#include + +PartDisplayer::PartDisplayer(const Glib::RefPtr & config) + : Displayer(config) +{ +} + +PartDisplayer::~PartDisplayer() +{ +} + +bool PartDisplayer::draw() +{ + Glib::RefPtr glwindow = get_gl_window(); + if (!glwindow->gl_begin(get_gl_context())) + return false; + + glClearColor(0.1, 0.6, 1.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-3, 3, -3, 3, 0.0001, 100000); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(10, -10, 10, + 0, 0, 0, + 0, 0, 1); + drawPlane(); + glPushMatrix(); + glRotatef(90, 1, 0, 0); + drawPlane(); + glPopMatrix(); + glRotatef(90, 0, 0, 1); + glRotatef(90, 1, 0, 0); + drawPlane(); + + if (glwindow->is_double_buffered()) + glwindow->swap_buffers(); + else + glFlush(); + return true; +} + +void PartDisplayer::drawPlane() +{ + glColor4f(0.1, 0.8, 1.0, 0.3); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glBegin(GL_QUADS); + glVertex2f(1, 1); + glVertex2f(-1, 1); + glVertex2f(-1, -1); + glVertex2f(1, -1); + glEnd(); + glEnable(GL_LINE_SMOOTH); + glColor4f(0.0, 0.15, 0.3, 1.0); + glBegin(GL_LINE_LOOP); + glVertex2f(1, 1); + glVertex2f(-1, 1); + glVertex2f(-1, -1); + glVertex2f(1, -1); + glEnd(); + glBegin(GL_LINE_STRIP); + glVertex2f(0.6, -1.0); + glVertex2f(0.6, -0.9); + glVertex2f(1.0, -0.9); + glEnd(); + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); +} diff --git a/src/gui/PartDisplayer.h b/src/gui/PartDisplayer.h new file mode 100644 index 0000000..13ac77a --- /dev/null +++ b/src/gui/PartDisplayer.h @@ -0,0 +1,19 @@ + +#ifndef PARTDISPLAYER_H +#define PARTDISPLAYER_H + +#include "Displayer.h" + +class PartDisplayer : public Displayer +{ + public: + PartDisplayer(const Glib::RefPtr & config); + ~PartDisplayer(); + bool draw(); + + protected: + void drawPlane(); +}; + +#endif + diff --git a/src/gui/ProfileDisplayer.cpp b/src/gui/ProfileDisplayer.cpp new file mode 100644 index 0000000..f7c2cb9 --- /dev/null +++ b/src/gui/ProfileDisplayer.cpp @@ -0,0 +1,30 @@ + +#include "ProfileDisplayer.h" +#include +#include + +ProfileDisplayer::ProfileDisplayer(const Glib::RefPtr & config) + : Displayer(config) +{ +} + +ProfileDisplayer::~ProfileDisplayer() +{ +} + +bool ProfileDisplayer::draw() +{ + Glib::RefPtr glwindow = get_gl_window(); + if (!glwindow->gl_begin(get_gl_context())) + return false; + + glClearColor(0.1, 0.6, 1.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (glwindow->is_double_buffered()) + glwindow->swap_buffers(); + else + glFlush(); + return true; +} + diff --git a/src/gui/ProfileDisplayer.h b/src/gui/ProfileDisplayer.h new file mode 100644 index 0000000..5367e95 --- /dev/null +++ b/src/gui/ProfileDisplayer.h @@ -0,0 +1,18 @@ + +#ifndef PROFILEDISPLAYER_H +#define PROFILEDISPLAYER_H + +#include "Displayer.h" + +class ProfileDisplayer : public Displayer +{ + public: + ProfileDisplayer(const Glib::RefPtr & config); + ~ProfileDisplayer(); + bool draw(); + + protected: +}; + +#endif + diff --git a/src/main/Makefile b/src/main/Makefile new file mode 100644 index 0000000..2a3d888 --- /dev/null +++ b/src/main/Makefile @@ -0,0 +1,26 @@ + +SRCS := main.cpp +MODULES := main.o +TARGET := main.a +DEPS := $(SRCS:.cpp=.d) +CPPFLAGS := -I.. +CXXFLAGS := -O2 $(CPPFLAGS) + +all: $(TARGET) + +$(TARGET): $(MODULES) + $(AR) rcv $@ $? + +%.o: %.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $< + +.PHONY: clean +clean: + $(RM) -f *.o *.d *~ $(TARGET) + +%.d: %.cpp + @set -e; rm -f $@; \ + $(CXX) -MM $(CPPFLAGS) $< | \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@ + +include $(DEPS) diff --git a/src/main/main.cpp b/src/main/main.cpp new file mode 100644 index 0000000..1333406 --- /dev/null +++ b/src/main/main.cpp @@ -0,0 +1,9 @@ + +#include "gui/GUI.h" + +int main(int argc, char * argv[]) +{ + GUI theGUI; + theGUI.start(argc, argv); + return 0; +}