diff --git a/src/interface/main_window.ui b/src/interface/main_window.ui index 87db37ba9caa78aff95819c94bc9a17a53e3ee1b..9a5d6e7edbd138a2d59eba6d20c5faa14b101d3e 100644 --- a/src/interface/main_window.ui +++ b/src/interface/main_window.ui @@ -1,10 +1,11 @@ -<ui version="4.0" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> <class>main_window</class> - <widget class="QMainWindow" name="main_window" > - <property name="windowModality" > + <widget class="QMainWindow" name="main_window"> + <property name="windowModality"> <enum>Qt::NonModal</enum> </property> - <property name="geometry" > + <property name="geometry"> <rect> <x>0</x> <y>0</y> @@ -12,37 +13,29 @@ <height>628</height> </rect> </property> - <property name="sizePolicy" > - <sizepolicy vsizetype="Preferred" hsizetype="Preferred" > + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="windowTitle" > + <property name="windowTitle"> <string>ViTE</string> </property> - <property name="windowIcon" > - <iconset resource="vite.qrc" > + <property name="windowIcon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/vite.png</normaloff>:/icon/icon/vite.png</iconset> </property> - <widget class="QWidget" name="centralwidget" > - <property name="geometry" > - <rect> - <x>0</x> - <y>64</y> - <width>1060</width> - <height>564</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2" > + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2" > + <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> - <layout class="QVBoxLayout" name="render_area_layout" /> + <layout class="QVBoxLayout" name="render_area_layout"/> </item> <item> - <widget class="QScrollBar" name="y_scroll" > - <property name="orientation" > + <widget class="QScrollBar" name="y_scroll"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> </widget> @@ -50,450 +43,447 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_3" > + <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QLabel" name="label_3" > - <property name="text" > + <widget class="QLabel" name="label_3"> + <property name="text"> <string>Scale containers/states: </string> </property> - <property name="textFormat" > + <property name="textFormat"> <enum>Qt::PlainText</enum> </property> - <property name="scaledContents" > + <property name="scaledContents"> <bool>false</bool> </property> </widget> </item> <item> - <widget class="QSlider" name="scale_container_state" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <widget class="QSlider" name="scale_container_state"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="focusPolicy" > + <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> - <property name="value" > + <property name="value"> <number>20</number> </property> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> <item> - <widget class="Line" name="line" > - <property name="orientation" > + <widget class="Line" name="line"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> </widget> </item> <item> - <widget class="QLabel" name="label_2" > - <property name="text" > + <widget class="QLabel" name="label_2"> + <property name="text"> <string>Change position:</string> </property> </widget> </item> <item> - <widget class="QScrollBar" name="x_scroll" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Fixed" hsizetype="Expanding" > + <widget class="QScrollBar" name="x_scroll"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> <item> - <widget class="Line" name="line_2" > - <property name="orientation" > + <widget class="Line" name="line_2"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> </widget> </item> <item> - <widget class="QLabel" name="label_4" > - <property name="text" > + <widget class="QLabel" name="label_4"> + <property name="text"> <string>Zoom: </string> </property> </widget> </item> <item> - <widget class="QComboBox" name="zoom_box" > - <property name="font" > + <widget class="QComboBox" name="zoom_box"> + <property name="font"> <font> <italic>true</italic> </font> </property> - <property name="editable" > + <property name="editable"> <bool>true</bool> </property> - <property name="currentIndex" > + <property name="currentIndex"> <number>5</number> </property> - <property name="maxCount" > + <property name="maxCount"> <number>2147483640</number> </property> - <property name="insertPolicy" > + <property name="insertPolicy"> <enum>QComboBox::InsertAtBottom</enum> </property> - <property name="sizeAdjustPolicy" > + <property name="sizeAdjustPolicy"> <enum>QComboBox::AdjustToContents</enum> </property> <item> - <property name="text" > + <property name="text"> <string>1000%</string> </property> </item> <item> - <property name="text" > + <property name="text"> <string/> </property> </item> <item> - <property name="text" > + <property name="text"> <string>500%</string> </property> </item> <item> - <property name="text" > + <property name="text"> <string>200%</string> </property> </item> <item> - <property name="text" > + <property name="text"> <string>150%</string> </property> </item> <item> - <property name="text" > + <property name="text"> <string>100%</string> </property> </item> + <item> + <property name="text"> + <string>75%</string> + </property> + </item> </widget> </item> </layout> </item> </layout> </widget> - <widget class="QMenuBar" name="menubar" > - <property name="geometry" > + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1060</width> - <height>26</height> + <height>27</height> </rect> </property> - <widget class="QMenu" name="menuHelp" > - <property name="title" > + <widget class="QMenu" name="menuHelp"> + <property name="title"> <string>&Help</string> </property> - <addaction name="help" /> - <addaction name="separator" /> - <addaction name="about" /> + <addaction name="help"/> + <addaction name="separator"/> + <addaction name="about"/> </widget> - <widget class="QMenu" name="menuView" > - <property name="title" > + <widget class="QMenu" name="menuView"> + <property name="title"> <string>&View</string> </property> - <addaction name="show_info" /> - <addaction name="toolbar_menu" /> - <addaction name="separator" /> - <addaction name="zoom_in" /> - <addaction name="zoom_out" /> - <addaction name="show_all_trace" /> - <addaction name="goto_start" /> - <addaction name="goto_end" /> - <addaction name="separator" /> - <addaction name="fullscreen" /> - <addaction name="separator" /> - <addaction name="no_warning" /> - <addaction name="no_arrows" /> - <addaction name="no_events" /> + <addaction name="show_info"/> + <addaction name="toolbar_menu"/> + <addaction name="separator"/> + <addaction name="zoom_in"/> + <addaction name="zoom_out"/> + <addaction name="show_all_trace"/> + <addaction name="goto_start"/> + <addaction name="goto_end"/> + <addaction name="separator"/> + <addaction name="fullscreen"/> + <addaction name="separator"/> + <addaction name="no_warning"/> + <addaction name="no_arrows"/> + <addaction name="no_events"/> </widget> - <widget class="QMenu" name="menuFile" > - <property name="title" > + <widget class="QMenu" name="menuFile"> + <property name="title"> <string>&File</string> </property> - <addaction name="open" /> - <addaction name="export_file" /> - <addaction name="separator" /> - <addaction name="close" /> - <addaction name="separator" /> - <addaction name="quit" /> + <addaction name="open"/> + <addaction name="export_file"/> + <addaction name="separator"/> + <addaction name="close"/> + <addaction name="separator"/> + <addaction name="quit"/> </widget> - <widget class="QMenu" name="menuPreferences" > - <property name="title" > + <widget class="QMenu" name="menuPreferences"> + <property name="title"> <string>&Preferences</string> </property> - <addaction name="show_stats" /> - <addaction name="actionCommand" /> + <addaction name="show_stats"/> + <addaction name="actionCommand"/> </widget> - <addaction name="menuFile" /> - <addaction name="menuView" /> - <addaction name="menuPreferences" /> - <addaction name="menuHelp" /> + <addaction name="menuFile"/> + <addaction name="menuView"/> + <addaction name="menuPreferences"/> + <addaction name="menuHelp"/> </widget> - <widget class="QToolBar" name="toolBar" > - <property name="geometry" > - <rect> - <x>0</x> - <y>26</y> - <width>1060</width> - <height>38</height> - </rect> - </property> - <property name="windowTitle" > + <widget class="QToolBar" name="toolBar"> + <property name="windowTitle"> <string>toolBar</string> </property> - <property name="movable" > + <property name="movable"> <bool>true</bool> </property> - <property name="floatable" > + <property name="floatable"> <bool>true</bool> </property> - <attribute name="toolBarArea" > + <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> - <attribute name="toolBarBreak" > + <attribute name="toolBarBreak"> <bool>false</bool> </attribute> - <addaction name="open" /> - <addaction name="close" /> - <addaction name="export_file" /> - <addaction name="separator" /> - <addaction name="zoom_in" /> - <addaction name="zoom_out" /> - <addaction name="goto_start" /> - <addaction name="goto_end" /> - <addaction name="show_all_trace" /> - <addaction name="fullscreen" /> - <addaction name="separator" /> - <addaction name="help" /> - <addaction name="no_arrows" /> - <addaction name="no_events" /> + <addaction name="open"/> + <addaction name="close"/> + <addaction name="export_file"/> + <addaction name="separator"/> + <addaction name="zoom_in"/> + <addaction name="zoom_out"/> + <addaction name="goto_start"/> + <addaction name="goto_end"/> + <addaction name="show_all_trace"/> + <addaction name="fullscreen"/> + <addaction name="separator"/> + <addaction name="help"/> + <addaction name="no_arrows"/> + <addaction name="no_events"/> </widget> - <action name="open" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="open"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/folder_yellow_open.png</normaloff>:/icon/icon/folder_yellow_open.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Open</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Ctrl+O</string> </property> </action> - <action name="close" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="close"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/fileclose.png</normaloff>:/icon/icon/fileclose.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Close</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Ctrl+W</string> </property> </action> - <action name="quit" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="quit"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/quit.png</normaloff>:/icon/icon/quit.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Quit</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Ctrl+Q</string> </property> </action> - <action name="help" > - <property name="checkable" > + <action name="help"> + <property name="checkable"> <bool>false</bool> </property> - <property name="icon" > - <iconset resource="vite.qrc" > + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/help_index.png</normaloff>:/icon/icon/help_index.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Help</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>F1</string> </property> </action> - <action name="about" > - <property name="checkable" > + <action name="about"> + <property name="checkable"> <bool>false</bool> </property> - <property name="icon" > - <iconset resource="vite.qrc" > + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/about.png</normaloff>:/icon/icon/about.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&About ViTE</string> </property> </action> - <action name="fullscreen" > - <property name="checkable" > + <action name="fullscreen"> + <property name="checkable"> <bool>true</bool> </property> - <property name="icon" > - <iconset resource="vite.qrc" > + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/fullscreen_mode.png</normaloff>:/icon/icon/fullscreen_mode.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Fullscreen</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>F11</string> </property> </action> - <action name="show_info" > - <property name="checkable" > + <action name="show_info"> + <property name="checkable"> <bool>false</bool> </property> - <property name="checked" > + <property name="checked"> <bool>false</bool> </property> - <property name="text" > + <property name="text"> <string>Show infos window</string> </property> </action> - <action name="export_file" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="export_file"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/export_svg.png</normaloff>:/icon/icon/export_svg.png</iconset> </property> - <property name="text" > + <property name="text"> <string>&Export</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Ctrl+E</string> </property> </action> - <action name="zoom_in" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="zoom_in"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/zoom_in.png</normaloff>:/icon/icon/zoom_in.png</iconset> </property> - <property name="text" > + <property name="text"> <string>Zoom in</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>+</string> </property> </action> - <action name="zoom_out" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="zoom_out"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/zoom_out.png</normaloff>:/icon/icon/zoom_out.png</iconset> </property> - <property name="text" > + <property name="text"> <string>Zoom out</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>-</string> </property> </action> - <action name="toolbar_menu" > - <property name="checkable" > + <action name="toolbar_menu"> + <property name="checkable"> <bool>true</bool> </property> - <property name="checked" > + <property name="checked"> <bool>true</bool> </property> - <property name="text" > + <property name="text"> <string>Hide toolbar</string> </property> </action> - <action name="goto_end" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="goto_end"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/goto_end.png</normaloff>:/icon/icon/goto_end.png</iconset> </property> - <property name="text" > + <property name="text"> <string>Move to end</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>End</string> </property> </action> - <action name="goto_start" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="goto_start"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/goto_start.png</normaloff>:/icon/icon/goto_start.png</iconset> </property> - <property name="text" > + <property name="text"> <string>Move to start</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Home</string> </property> </action> - <action name="show_all_trace" > - <property name="icon" > - <iconset resource="vite.qrc" > + <action name="show_all_trace"> + <property name="icon"> + <iconset resource="vite.qrc"> <normaloff>:/icon/icon/print_all.png</normaloff>:/icon/icon/print_all.png</iconset> </property> - <property name="text" > + <property name="text"> <string>Show all</string> </property> - <property name="shortcut" > + <property name="shortcut"> <string>Ctrl+Shift+A</string> </property> </action> - <action name="no_warning" > - <property name="checkable" > + <action name="no_warning"> + <property name="checkable"> <bool>true</bool> </property> - <property name="text" > + <property name="text"> <string>No warning</string> </property> </action> - <action name="actionZoom_control" > - <property name="text" > + <action name="actionZoom_control"> + <property name="text"> <string>zoom_control</string> </property> </action> - <action name="no_arrows" > - <property name="checkable" > + <action name="no_arrows"> + <property name="checkable"> <bool>true</bool> </property> - <property name="text" > + <property name="text"> <string>No arrows</string> </property> </action> - <action name="no_events" > - <property name="checkable" > + <action name="no_events"> + <property name="checkable"> <bool>true</bool> </property> - <property name="text" > + <property name="text"> <string>No events</string> </property> </action> - <action name="show_stats" > - <property name="text" > + <action name="show_stats"> + <property name="text"> <string>Statistics</string> </property> </action> - <action name="actionCommand" > - <property name="text" > + <action name="actionCommand"> + <property name="text"> <string>Command</string> </property> </action> </widget> <resources> - <include location="vite.qrc" /> + <include location="vite.qrc"/> </resources> <connections/> </ui> diff --git a/src/render/Render_area.cpp b/src/render/Hook_event.cpp similarity index 58% rename from src/render/Render_area.cpp rename to src/render/Hook_event.cpp index 1829d29aeaef826fd7f476d5e45edbe97763c372..c7f9bea4b6c436f37939b082e8b23039469ccf25 100644 --- a/src/render/Render_area.cpp +++ b/src/render/Hook_event.cpp @@ -41,14 +41,14 @@ ** */ /*! - *\file Render_area.cpp + *\file Hook_event.cpp */ //#include "../core/Core.hpp" -#include "Render_area.hpp" +#include "Hook_event.hpp" -//#include "Render_area.hpp" +//#include "Hook_event.hpp" #include "Render_opengl.hpp" //#include "glew.h" @@ -60,11 +60,11 @@ using namespace std; #define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " -const int Render_area::DRAWING_STATE_WAITING = 1; -const int Render_area::DRAWING_STATE_DRAWING = 2; -const int Render_area::_ctrl_scroll_factor = 10; -const int Render_area::_ctrl_zoom_factor = 3; -const int Render_area::DRAWING_TIMER_DEFAULT = 10; +const int Hook_event::DRAWING_STATE_WAITING = 1; +const int Hook_event::DRAWING_STATE_DRAWING = 2; +const int Hook_event::_ctrl_scroll_factor = 10; +const int Hook_event::_ctrl_zoom_factor = 3; +const int Hook_event::DRAWING_TIMER_DEFAULT = 10; @@ -78,7 +78,7 @@ const int Render_area::DRAWING_TIMER_DEFAULT = 10; * **********************************/ -Render_area::Render_area(Render_opengl* render_instance, Core* core, QWidget *parent) +Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent) : QGLWidget(parent){ @@ -195,7 +195,7 @@ Render_area::Render_area(Render_opengl* render_instance, Core* core, QWidget *pa } -Render_area::~Render_area(){ +Hook_event::~Hook_event(){ /* Release the Rabbit and ruler lists */ if (glIsList(_wait_list) == GL_TRUE) @@ -226,7 +226,7 @@ Render_area::~Render_area(){ -void Render_area::mousePressEvent(QMouseEvent * event){ +void Hook_event::mousePressEvent(QMouseEvent * event){ /* If a right click was triggered, just restore the previous zoom */ if( Qt::RightButton == event->button() ){ @@ -272,7 +272,7 @@ void Render_area::mousePressEvent(QMouseEvent * event){ int buf; - buf = 100*((int)_x_state_scale); + buf = (int)(100*_x_state_scale); _core->launch_action(_core->_STATE_ZOOM_BOX_VALUE, &buf); /* Then, return */ @@ -289,35 +289,39 @@ void Render_area::mousePressEvent(QMouseEvent * event){ } -void Render_area::mouseDoubleClickEvent ( QMouseEvent * event ){ +void Hook_event::mouseDoubleClickEvent ( QMouseEvent * event ){ Element_pos x_click, y_click;/* Store the OpenGL scene point where user had clicked */ Element_pos x_result, y_result;/* The click coordinates for the Data Structure. */ - /* - * Now determine where the user had clicked - */ - x_click = _mouse_x * (Element_pos)_render_width/(Element_pos)_screen_width;/* x position of the click in the OpenGL scene */ - y_click = _mouse_y * (Element_pos)_render_height/(Element_pos)_screen_height;/* y position of the click in the OpenGL scene */ + + if( Qt::LeftButton == event->button() ){ + + + /* + * Now determine where the user had clicked + */ + x_click = _mouse_x * (Element_pos)_render_width/(Element_pos)_screen_width;/* x position of the click in the OpenGL scene */ + y_click = _mouse_y * (Element_pos)_render_height/(Element_pos)_screen_height;/* y position of the click in the OpenGL scene */ - /* - * First, check the y position if user clicks on the ruler or other - */ - if (y_click <= (_ruler_height+_ruler_y))/* user had clicked on the ruler */ - return; + /* + * First, check the y position if user clicks on the ruler or other + */ + if (y_click <= (_ruler_height+_ruler_y))/* user had clicked on the ruler */ + return; - /* Work out the y value in Data Structure coordinates */ - y_result = y_click-(_ruler_y+_ruler_height) + _y_state_translate; - y_result *= (_container_y_max-_container_y_min)/((_render_height-_ruler_height)*_y_state_scale); + /* Work out the y value in Data Structure coordinates */ + y_result = y_click-(_ruler_y+_ruler_height) + _y_state_translate; + y_result *= (_container_y_max-_container_y_min)/((_render_height-_ruler_height)*_y_state_scale); - /* - * Second, check the x position if user click on the container or other - */ - if (x_click <= (_x_scale_container_state*_render_width) ){/* user had clicked on the container */ - return; - } - else{ /* - * Determine the time corresponding to the x click position. + * Second, check the x position if user click on the container or other + */ + if (x_click <= (_x_scale_container_state*_render_width) ){/* user had clicked on the container */ + return; + } + else{ + /* + * Determine the time corresponding to the x click position. * It is equal to the x click position in the OpenGL render area minus the default translation of entities. * Also, near the container area time is 0 except if a translation had occured. * So add the state translate and the x_result will be obtained. @@ -339,11 +343,15 @@ void Render_area::mouseDoubleClickEvent ( QMouseEvent * event ){ _mouse_pressed = false; _render_instance->updateGL(); + + } + + return; } -void Render_area::mouseMoveEvent(QMouseEvent * event){ +void Hook_event::mouseMoveEvent(QMouseEvent * event){ if (!_mouse_pressed) return; _new_mouse_x = event->x(); @@ -353,7 +361,7 @@ void Render_area::mouseMoveEvent(QMouseEvent * event){ } -void Render_area::mouseReleaseEvent(QMouseEvent * event){ +void Hook_event::mouseReleaseEvent(QMouseEvent * event){ Element_pos invert_buf_x; Element_pos invert_buf_y; @@ -416,7 +424,7 @@ void Render_area::mouseReleaseEvent(QMouseEvent * event){ -void Render_area::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_pos y_min, Element_pos y_max){ +void Hook_event::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_pos y_min, Element_pos y_max){ Element_pos x_middle_selection; Element_pos y_middle_selection; @@ -483,7 +491,7 @@ void Render_area::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_p int buf; _x_state_scale *= _screen_width/(x_max - x_min); - buf = 100*((int)_x_state_scale); + buf = (int)(100*_x_state_scale); _core->launch_action(_core->_STATE_ZOOM_BOX_VALUE, &buf); @@ -495,7 +503,7 @@ void Render_area::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_p } -void Render_area::wheelEvent(QWheelEvent * event){ +void Hook_event::wheelEvent(QWheelEvent * event){ int num_degrees = event->delta() / 8; int num_steps = num_degrees / 15; Element_pos scale_coeff = num_steps; @@ -515,7 +523,7 @@ void Render_area::wheelEvent(QWheelEvent * event){ } -void Render_area::keyPressEvent(QKeyEvent * event) { +void Hook_event::keyPressEvent(QKeyEvent * event) { int ctrl_factor = 1; @@ -585,7 +593,7 @@ void Render_area::keyPressEvent(QKeyEvent * event) { } -void Render_area::keyReleaseEvent(QKeyEvent * event){ +void Hook_event::keyReleaseEvent(QKeyEvent * event){ if (event->key() == Qt::Key_Alt) { Info::Render::_key_alt = false; } @@ -597,7 +605,7 @@ void Render_area::keyReleaseEvent(QKeyEvent * event){ -void Render_area::change_scale(Element_pos scale_coeff){ +void Hook_event::change_scale(Element_pos scale_coeff){ Element_pos new_scale; new_scale = _x_state_scale*(1+scale_coeff*0.05);/* 5% scale */ @@ -608,7 +616,7 @@ void Render_area::change_scale(Element_pos scale_coeff){ replace_scale(new_scale); } -void Render_area::change_scale_y(Element_pos scale_coeff){ +void Hook_event::change_scale_y(Element_pos scale_coeff){ Element_pos new_scale; @@ -628,7 +636,7 @@ void Render_area::change_scale_y(Element_pos scale_coeff){ } -void Render_area::replace_scale(Element_pos new_scale){ +void Hook_event::replace_scale(Element_pos new_scale){ int buf; if(new_scale > 0.0){ @@ -644,7 +652,7 @@ void Render_area::replace_scale(Element_pos new_scale){ _x_state_translate += ( _x_state_translate - _default_entity_x_translate + (Element_pos)_render_width/2.0) * ((new_scale)/(_x_state_scale) - 1); _x_state_scale = new_scale; - buf = 100*(int)_x_state_scale; + buf = (int)(100*_x_state_scale); _core->launch_action(_core->_STATE_ZOOM_BOX_VALUE, &buf); @@ -654,17 +662,17 @@ void Render_area::replace_scale(Element_pos new_scale){ } -void Render_area::change_translate(int translate){ +void Hook_event::change_translate(int translate){ replace_translate(_x_state_translate + translate); } -void Render_area::change_translate_y(int translate){ +void Hook_event::change_translate_y(int translate){ replace_translate_y(_y_state_translate + translate); } -void Render_area::replace_translate(Element_pos new_translate){ +void Hook_event::replace_translate(Element_pos new_translate){ if ( new_translate < 0 ){ new_translate = 0; }else if ( new_translate > (100*_x_state_scale) ){ @@ -681,7 +689,7 @@ void Render_area::replace_translate(Element_pos new_translate){ } -void Render_area::replace_translate_y(Element_pos new_translate){ +void Hook_event::replace_translate_y(Element_pos new_translate){ if ( new_translate < 0 ){ new_translate = 0; }else if ( new_translate > (100*_y_state_scale) ){ @@ -698,7 +706,7 @@ void Render_area::replace_translate_y(Element_pos new_translate){ } -void Render_area::registered_translate(int id){ +void Hook_event::registered_translate(int id){ switch (id){ @@ -733,7 +741,7 @@ void Render_area::registered_translate(int id){ } -void Render_area::refresh_scroll_bars(bool LENGTH_CHANGED){ +void Hook_event::refresh_scroll_bars(bool LENGTH_CHANGED){ if (LENGTH_CHANGED){ Element_pos scroll_bar_length[2] = {_x_state_scale*100, _y_state_scale*100}; _core->launch_action(_core->_STATE_AJUST_SCROLL_BARS, scroll_bar_length); @@ -746,13 +754,13 @@ void Render_area::refresh_scroll_bars(bool LENGTH_CHANGED){ } -void Render_area::change_scale_container_state(int view_size){ +void Hook_event::change_scale_container_state(int view_size){ _x_scale_container_state = 0.01 * view_size; _render_instance->updateGL(); } -void Render_area::update_visible_interval_value(){ +void Hook_event::update_visible_interval_value(){ Info::Render::_x_min_visible = max(_state_x_min, (_x_state_translate - _default_entity_x_translate)/(_x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min)) )); Info::Render::_x_max_visible = min(_state_x_max, (_x_state_translate - _default_entity_x_translate + _render_width)/(_x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min)) )); } @@ -771,45 +779,45 @@ void Render_area::update_visible_interval_value(){ **********************************/ -Element_pos Render_area::screen_to_render_x(Element_pos e){ +Element_pos Hook_event::screen_to_render_x(Element_pos e){ return e * (Element_pos)_render_width / (Element_pos)_screen_width; } -Element_pos Render_area::screen_to_render_y(Element_pos e){ +Element_pos Hook_event::screen_to_render_y(Element_pos e){ return e * (Element_pos)_render_height / (Element_pos)_screen_height; } -Element_pos Render_area::render_to_trace_x(Element_pos e){ +Element_pos Hook_event::render_to_trace_x(Element_pos e){ return (e - _default_entity_x_translate + _x_state_translate) * (_state_x_max - _state_x_min) / ((_render_width - _default_entity_x_translate) * _x_state_scale); } -Element_pos Render_area::render_to_trace_y(Element_pos e){ +Element_pos Hook_event::render_to_trace_y(Element_pos e){ return (e-_ruler_y-_ruler_height + _y_state_translate) * (_container_y_max - _container_y_min) / ((_render_height - _ruler_height) * _y_state_scale); } -Element_pos Render_area::render_to_screen_x(Element_pos e){ +Element_pos Hook_event::render_to_screen_x(Element_pos e){ return e * (Element_pos)_screen_width / (Element_pos)_render_width; } -Element_pos Render_area::render_to_screen_y(Element_pos e){ +Element_pos Hook_event::render_to_screen_y(Element_pos e){ return e * (Element_pos)_screen_height / (Element_pos)_render_height; } -Element_pos Render_area::trace_to_render_x(Element_pos e){ +Element_pos Hook_event::trace_to_render_x(Element_pos e){ return e * ((_render_width-_default_entity_x_translate)*_x_state_scale) / (_state_x_max - _state_x_min) + _default_entity_x_translate - _x_state_translate; } -Element_pos Render_area::trace_to_render_y(Element_pos e){ +Element_pos Hook_event::trace_to_render_y(Element_pos e){ return e * ((_render_height-_ruler_height)*_y_state_scale) / (_container_y_max-_container_y_min) + _ruler_y + _ruler_height - _y_state_translate; @@ -817,485 +825,3 @@ Element_pos Render_area::trace_to_render_y(Element_pos e){ - -/*********************************** - * - * - * - * Building functions. - * - * - * - **********************************/ - - - -bool Render_area::build(){ - - _state = DRAWING_STATE_DRAWING;/* change the drawing state */ - - /* disable some OpenGL features to enhance the rendering */ - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - - replace_scale(1);/* for states scaling */ - _x_state_translate = 0;/* for states translation */ - _y_state_scale = 1;/* for states scaling */ - _y_state_translate = 0;/* for states translation */ - _x_scroll_pos = 0;/* horizontal bar placed on 0 */ - _y_scroll_pos = 0;/* vertical bar placed on 0 */ - - if (NULL == _render_instance) - return true; - - return _render_instance->display_build(); -} - - - -bool Render_area::unbuild(){ - - /********************** - * - * Init OpenGL features - * - **********************/ - - /* enable some OpenGL features*/ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glEnable(GL_TEXTURE_2D); - - glEnable(GL_BLEND);/* enable blending for the alpha color */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor3d(1.0, 1.0, 1.0);/* init color to white */ - - - /***************************** - * - * Init render area attributes - * - *****************************/ - - _state = DRAWING_STATE_WAITING;/* change the drawing state */ - - _wait_angle=0.0f;/* begin with 0 rad angle */ - _wait_angle_y=0.0f;/* begin with 0 rad angle */ - - /* init measurement attributes */ - _container_x_max = 0; - _container_y_max = 0; - _container_x_min = 0; - _container_y_min = 0; - - _state_x_max = 0; - _state_y_max = 0; - _state_x_min = 0; - _state_y_min = 0; - - _line_already_begun = false; - - /* empty the selection stack */ - while(false == _previous_selection.empty()) - _previous_selection.pop(); - - if (NULL == _render_instance) - return true; - - return _render_instance->display_unbuild(); -} - - - - - -/*********************************** - * - * - * - * Drawing function for the wait screen. - * - * - * - **********************************/ - - - -GLuint Render_area::draw_wait() { - GLuint object; - GLuint texture; - - object = glGenLists(1);/* create the list */ - - if (object == 0) - message << tr("Error when creating list").toStdString() << Message::endw; - - - glGenTextures(1, &texture);/* create the texture and link it with the list previously created */ - - QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png")); - - if (true == texture_file.exists())/* The texture exists */ - texture = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D); - else/* use the default picture */ - texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D); - - glNewList(object, GL_COMPILE);/* open the list */ - { - glBindTexture(GL_TEXTURE_2D, texture);/* load texture for drawing */ - - glBegin(GL_QUADS);/* draw a square */ - { - glTexCoord2d(0,0); glVertex2f(-1, -1); - glTexCoord2d(1,0); glVertex2f(1, -1); - glTexCoord2d(1,1); glVertex2f(1, 1); - glTexCoord2d(0,1); glVertex2f(-1, 1); - } - glEnd(); - - - } - glEndList();/* close the list */ - - /* apply some parameters on the texture */ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glEnable(GL_TEXTURE_2D); - - glEnable(GL_BLEND);/* enable blending for the alpha color */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - - /* Now, timer is set */ - if (_wait_timer == NULL){ - _wait_angle = 0.0f; - - _wait_timer = new QTimer(this); - connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL())); - _wait_timer->start(_wait_spf); - } - - return object; -} - - - - - -GLuint Render_area::draw_ruler() { - GLuint object; - unsigned int nb_graduation; - Element_pos graduation_distance_per_5; - double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/ - - /* light blue color */ - { - ruler_bg_r = 0.5; - ruler_bg_g = 0.5; - ruler_bg_b = 1.0; - } - - - /* - * NOTE: - * _ruler_distance is the desire distance between 2 graduations. - * There are ceil(_render_width/_ruler_distance) graduations. - * Between 2 consecutive graduations, there are 4 small graduations. - */ - - - /* - * Graduation number. - */ - nb_graduation = (unsigned int)ceil(_render_width/_ruler_distance); - - /* - * Distance between 2 small consecutive graduations. - */ - graduation_distance_per_5 = _ruler_distance/5.0; - - /* - * create the list - */ - object = glGenLists(1); - - if (object == 0) - message << tr("Error when creating list").toStdString() << Message::endw; - - - /* - * open the list - */ - glNewList(object, GL_COMPILE); - { - - for (unsigned int i = 0 ; i<=nb_graduation ; i++){ - - /* - * draw small graduations - */ - for (char k = 1 ; k < 5 ; k ++){ - glBegin(GL_LINES); - { - glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y); - glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0); - } - glEnd(); - }/* end for( k ) */ - - - /* - * Draw the graduation - */ - glBegin(GL_LINES); - { - glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y); - glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance, _ruler_y+_ruler_height); - } - glEnd(); - - }/* end for ( i ) */ - - /* Draw the background */ - glBegin(GL_QUADS); - { - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0, _ruler_y+_ruler_height); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0, _ruler_y); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y+_ruler_height); - } - glEnd(); - - - - } - glEndList();/* close the list */ - - return object; -} - - - - - -void Render_area::call_ruler(){ - - Element_pos nb_graduation; - Element_pos graduation_distance_per_5; - Element_pos buf_time; - Element_pos _info_degree_x; - Element_pos _info_degree_width; - ostringstream buf_txt; - - - Element_pos entire_part_d; - Element_pos degree_d; - Element_pos pow_10_degree_d; - Element_pos buf_min; - Element_pos buf_max; - Element_pos buf_d; - double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/ - - /* light blue color */ - { - ruler_bg_r = 0.5; - ruler_bg_g = 0.5; - ruler_bg_b = 1.0; - } - - /* Contains the degree scale to get a number from 0.01 to 100 */ - const Element_pos mul_scale_d = 4; - - /* Contains the scale to get a number from 0.01 to 100 (equals to 10^mul_scale_d) */ - const Element_pos mul_scale = 10000; - - /* The ruler accurate */ - const Element_pos limit_d = 0.00000000001; - - - /* Graduation number. */ - nb_graduation = ceil(_render_width/_ruler_distance); - - /* Distance between 2 small consecutive graduations. */ - graduation_distance_per_5 = _ruler_distance/5.0; - - /* Use to temporary store the graduation time value. */ - buf_time = 0; - - /* The info degree x beginning position. */ - _info_degree_x = 0; - - /* The info degree width: dynamically computed to fit its value. Default size: 1. */ - _info_degree_width = 0; - - /* Use to temporary store the graduation time value text. */ - buf_txt.str(""); - - - /* - * The following variables are used to work out each graduation value - * in a correct format. - * Need to work out the degree of ruler graduation time value. - * - * Try to distinct the common number part of each graduation and the distinct part - * from the left. - * For example, between 3.67834 and 3.67854, the common part is: 3.678 and - * the distinct part is 0.000xx (xx = {34,54}) - */ - - /* Update Info::Render::_x_min_visible and Info::Render::_x_max_visible values */ - update_visible_interval_value(); - - /* Contains the common left part of each graduate values */ - entire_part_d = 0; - - /* Contains the degree used to know how many we need to multiply to get - the uncommon right part of each graduate values more than 0.01 */ - degree_d = 0; - - /* Contains 10^degree_d */ - pow_10_degree_d = 1; - - /* Just a buffer for intermediate computations */ - buf_d = 0; - - - - - /* - * Draw ruler - */ - if (glIsList(_list_ruler) == GL_FALSE) { - message << tr("ERROR LIST not exist for the ruler.").toStdString() << Message::ende; - } - else{ - glPushMatrix(); - - /* - * Just translate for ruler follows the entity translate. - */ - glTranslated( - (int)_x_state_translate % (int)_ruler_distance, 0, _z_ruler); - glCallList(_list_ruler); - - glPopMatrix(); - } - - - /* - * Work out the graduation time value degree. - */ - - buf_max = Info::Render::_x_max_visible; - buf_min = Info::Render::_x_min_visible; - - if (buf_max>limit_d){ - while (buf_max>1){ - buf_max/=10.0; - buf_min/=10.0; - degree_d--; - pow_10_degree_d /= 10.0; - } - } - - buf_d = 0;/* to secure */ - - while ( (floor(buf_max) == floor(buf_min)) && (buf_d<10) ){/* buf<10 means that buf_max if greater than limit_d ! */ - buf_max *= 10; - buf_min *= 10; - pow_10_degree_d *= 10; - degree_d++; - buf_d++; - } - - /* ignore the last figure */ - // if (degree_d >= 0){ - pow_10_degree_d /= 10; - degree_d--; - //} - - entire_part_d = floor( Info::Render::_x_max_visible * pow_10_degree_d ); - - /* - * Draw the current ruler degree - */ - - /* Draw the text */ - glColor3d(1.0, 1.0, 1.0);/* text color */ - glRasterPos2f( 0, _ruler_y+_ruler_height); - - buf_txt << entire_part_d << "Xe-" << degree_d+mul_scale_d; - - for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){ - glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); - _info_degree_width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); - } - - _info_degree_width = screen_to_render_x(_info_degree_width); - - buf_txt.str("");/* flush the buffer */ - - /* Draw the foreground */ - glBegin(GL_QUADS); - { - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y+_ruler_height, _z_ruler_over); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y, _z_ruler_over); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y, _z_ruler_over); - glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y+_ruler_height, _z_ruler_over); - } - glEnd(); - - - - /* - * Draw coordinates - */ - glColor3d(1.0, 1.0, 1.0);/* text color */ - - for (unsigned int i = 0 ; i<=nb_graduation ; i++){ - - /* - * Work out the graduation time value. - */ - - buf_time = render_to_trace_x(i*_ruler_distance); - - if (buf_time < 0) continue;/* do not display negative time values */ - - - /* Now, convert (XXX,XXXXXXXXX) to (YYY * 10^ZZ and a common part WWWWWW * 10^TT) */ - - /* trunc the common part of each number */ - buf_d = buf_time*pow_10_degree_d; - buf_d = buf_d - floor( buf_d ); - - /* Mul buf_time to belongs to ]1000;0[ */ - buf_d *= mul_scale; - - /* Keep the entire part only */ - buf_d = floor(buf_d); - - /* Finally, fill the text buffer to display the graduate value */ - buf_txt << buf_d; - - /* - * Display the graduation time value. - */ - - glRasterPos2f( - (int)_x_state_translate % (int)_ruler_distance + i*_ruler_distance, _ruler_y+_ruler_height);/* set position */ - - if ( _info_degree_width < ( i*_ruler_distance - ((int)_x_state_translate % (int)_ruler_distance)) ){ - for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){ - glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); - } - }/* end for ( i ) */ - - buf_txt.str("");/* flush the buffer */ - - - }/* end for ( i ) */ - -} - diff --git a/src/render/Render_area.hpp b/src/render/Hook_event.hpp similarity index 93% rename from src/render/Render_area.hpp rename to src/render/Hook_event.hpp index 965776bc20afe02568d70bbdd4774f7e80b417f0..fa5f9301fcfa8e9c8d9d5b432e91081c5fcbb9d2 100644 --- a/src/render/Render_area.hpp +++ b/src/render/Hook_event.hpp @@ -41,17 +41,17 @@ ** */ /*! - *\file Render_area.hpp + *\file Hook_event.hpp */ -#ifndef RENDER_AREA_HPP -#define RENDER_AREA_HPP +#ifndef HOOK_EVENT_HPP +#define HOOK_EVENT_HPP -class Render_area; +class Hook_event; class Core; class Render_opengl; @@ -140,7 +140,7 @@ struct Selection_{ /*! * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace. */ -class Render_area : public QGLWidget/*, public Render*/ +class Hook_event : public QGLWidget/*, public Render*/ { Q_OBJECT @@ -554,29 +554,6 @@ protected: - /*********************************** - * - * Render OpenGL drawing functions. - * - **********************************/ - - /*! - * \brief Display a wait on the screen if there is no file opened. - * \return Asset value of the wait. - */ - GLuint draw_wait(); - - /*! - * \brief Create the ruler display list. - * \return Asset value of the ruler. - */ - GLuint draw_ruler(); - - /*! - * \brief Draw the ruler display list. - */ - void call_ruler(); - /*********************************** * @@ -587,9 +564,9 @@ protected: /*! * \brief The default constructor. * - * Default constructor has a private scope to avoid any direct instantiation of Render_area. + * Default constructor has a private scope to avoid any direct instantiation of Hook_event. */ - Render_area(); + Hook_event(); public: @@ -599,12 +576,12 @@ public: * \brief The constructor. * \param render_instance The instance of a drawing class. */ - Render_area(Render_opengl* render_instance, Core* core, QWidget *parent); + Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent); /*! * \brief The destructor */ - virtual ~Render_area(); + virtual ~Hook_event(); @@ -753,22 +730,6 @@ public: */ Element_pos trace_to_render_y(Element_pos e); - - /*********************************** - * - * Building functions. - * - **********************************/ - - /*! - * \brief This function draws the trace. - */ - bool build(); - - /*! - * \brief This function releases the trace. - */ - bool unbuild(); }; diff --git a/src/render/Render_opengl.cpp b/src/render/Render_opengl.cpp index f09d7400281128b12a6975168ae221a6c426f47d..9adb82b8a181e33f2e9dc60a3e8d00da2729b35f 100644 --- a/src/render/Render_opengl.cpp +++ b/src/render/Render_opengl.cpp @@ -48,7 +48,7 @@ #include "Render_opengl.hpp" -#include "Render_area.hpp" +#include "Hook_event.hpp" @@ -70,7 +70,7 @@ using namespace std; **********************************/ Render_opengl::Render_opengl(Render_opengl* render, Core* core, QWidget *parent) - : Render_area(render, core, parent){ + : Hook_event(render, core, parent){ setAutoFillBackground(false); @@ -257,3 +257,489 @@ void Render_opengl::paintGL(){ if(glerror != GL_NO_ERROR) message << tr("Render area : the following OpengGL error occured: ").toStdString() << (char *)gluErrorString(glerror) << Message::endw; } + + + + + +/*********************************** + * + * + * + * Building functions. + * + * + * + **********************************/ + + + +bool Render_opengl::build(){ + + _state = DRAWING_STATE_DRAWING;/* change the drawing state */ + + /* disable some OpenGL features to enhance the rendering */ + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + replace_scale(1);/* for states scaling */ + _x_state_translate = 0;/* for states translation */ + _y_state_scale = 1;/* for states scaling */ + _y_state_translate = 0;/* for states translation */ + _x_scroll_pos = 0;/* horizontal bar placed on 0 */ + _y_scroll_pos = 0;/* vertical bar placed on 0 */ + + if (NULL == _render_instance) + return true; + + return _render_instance->display_build(); +} + + + +bool Render_opengl::unbuild(){ + + /********************** + * + * Init OpenGL features + * + **********************/ + + /* enable some OpenGL features*/ + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glEnable(GL_TEXTURE_2D); + + glEnable(GL_BLEND);/* enable blending for the alpha color */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor3d(1.0, 1.0, 1.0);/* init color to white */ + + + /***************************** + * + * Init render area attributes + * + *****************************/ + + _state = DRAWING_STATE_WAITING;/* change the drawing state */ + + _wait_angle=0.0f;/* begin with 0 rad angle */ + _wait_angle_y=0.0f;/* begin with 0 rad angle */ + + /* init measurement attributes */ + _container_x_max = 0; + _container_y_max = 0; + _container_x_min = 0; + _container_y_min = 0; + + _state_x_max = 0; + _state_y_max = 0; + _state_x_min = 0; + _state_y_min = 0; + + _line_already_begun = false; + + /* empty the selection stack */ + while(false == _previous_selection.empty()) + _previous_selection.pop(); + + if (NULL == _render_instance) + return true; + + return _render_instance->display_unbuild(); +} + + + + + +/*********************************** + * + * + * + * Drawing function for the wait screen. + * + * + * + **********************************/ + + + +GLuint Render_opengl::draw_wait() { + GLuint object; + GLuint texture; + + object = glGenLists(1);/* create the list */ + + if (object == 0) + message << tr("Error when creating list").toStdString() << Message::endw; + + + glGenTextures(1, &texture);/* create the texture and link it with the list previously created */ + + QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png")); + + if (true == texture_file.exists())/* The texture exists */ + texture = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D); + else/* use the default picture */ + texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D); + + glNewList(object, GL_COMPILE);/* open the list */ + { + glBindTexture(GL_TEXTURE_2D, texture);/* load texture for drawing */ + + glBegin(GL_QUADS);/* draw a square */ + { + glTexCoord2d(0,0); glVertex2f(-1, -1); + glTexCoord2d(1,0); glVertex2f(1, -1); + glTexCoord2d(1,1); glVertex2f(1, 1); + glTexCoord2d(0,1); glVertex2f(-1, 1); + } + glEnd(); + + + } + glEndList();/* close the list */ + + /* apply some parameters on the texture */ + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glEnable(GL_TEXTURE_2D); + + glEnable(GL_BLEND);/* enable blending for the alpha color */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + /* Now, timer is set */ + if (_wait_timer == NULL){ + _wait_angle = 0.0f; + + _wait_timer = new QTimer(this); + connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL())); + _wait_timer->start(_wait_spf); + } + + return object; +} + + + + + +GLuint Render_opengl::draw_ruler() { + GLuint object; + unsigned int nb_graduation; + Element_pos graduation_distance_per_5; + double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/ + + /* light blue color */ + { + ruler_bg_r = 0.5; + ruler_bg_g = 0.5; + ruler_bg_b = 1.0; + } + + + /* + * NOTE: + * _ruler_distance is the desire distance between 2 graduations. + * There are ceil(_render_width/_ruler_distance) graduations. + * Between 2 consecutive graduations, there are 4 small graduations. + */ + + + /* + * Graduation number. + */ + nb_graduation = (unsigned int)ceil(_render_width/_ruler_distance); + + /* + * Distance between 2 small consecutive graduations. + */ + graduation_distance_per_5 = _ruler_distance/5.0; + + /* + * create the list + */ + object = glGenLists(1); + + if (object == 0) + message << tr("Error when creating list").toStdString() << Message::endw; + + + /* + * open the list + */ + glNewList(object, GL_COMPILE); + { + + for (unsigned int i = 0 ; i<=nb_graduation ; i++){ + + /* + * draw small graduations + */ + for (char k = 1 ; k < 5 ; k ++){ + glBegin(GL_LINES); + { + glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y); + glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0); + } + glEnd(); + }/* end for( k ) */ + + + /* + * Draw the graduation + */ + glBegin(GL_LINES); + { + glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y); + glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance, _ruler_y+_ruler_height); + } + glEnd(); + + }/* end for ( i ) */ + + /* Draw the background */ + glBegin(GL_QUADS); + { + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0, _ruler_y+_ruler_height); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0, _ruler_y); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y+_ruler_height); + } + glEnd(); + + + + } + glEndList();/* close the list */ + + return object; +} + + + + + +void Render_opengl::call_ruler(){ + + Element_pos nb_graduation; + Element_pos graduation_distance_per_5; + Element_pos buf_time; + Element_pos _info_degree_x; + Element_pos _info_degree_width; + ostringstream buf_txt; + + + Element_pos entire_part_d; + Element_pos degree_d; + Element_pos pow_10_degree_d; + Element_pos buf_min; + Element_pos buf_max; + Element_pos buf_d; + double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/ + + /* light blue color */ + { + ruler_bg_r = 0.5; + ruler_bg_g = 0.5; + ruler_bg_b = 1.0; + } + + /* Contains the degree scale to get a number from 0.01 to 100 */ + const Element_pos mul_scale_d = 4; + + /* Contains the scale to get a number from 0.01 to 100 (equals to 10^mul_scale_d) */ + const Element_pos mul_scale = 10000; + + /* The ruler accurate */ + const Element_pos limit_d = 0.00000000001; + + + /* Graduation number. */ + nb_graduation = ceil(_render_width/_ruler_distance); + + /* Distance between 2 small consecutive graduations. */ + graduation_distance_per_5 = _ruler_distance/5.0; + + /* Use to temporary store the graduation time value. */ + buf_time = 0; + + /* The info degree x beginning position. */ + _info_degree_x = 0; + + /* The info degree width: dynamically computed to fit its value. Default size: 1. */ + _info_degree_width = 0; + + /* Use to temporary store the graduation time value text. */ + buf_txt.str(""); + + + /* + * The following variables are used to work out each graduation value + * in a correct format. + * Need to work out the degree of ruler graduation time value. + * + * Try to distinct the common number part of each graduation and the distinct part + * from the left. + * For example, between 3.67834 and 3.67854, the common part is: 3.678 and + * the distinct part is 0.000xx (xx = {34,54}) + */ + + /* Update Info::Render::_x_min_visible and Info::Render::_x_max_visible values */ + update_visible_interval_value(); + + /* Contains the common left part of each graduate values */ + entire_part_d = 0; + + /* Contains the degree used to know how many we need to multiply to get + the uncommon right part of each graduate values more than 0.01 */ + degree_d = 0; + + /* Contains 10^degree_d */ + pow_10_degree_d = 1; + + /* Just a buffer for intermediate computations */ + buf_d = 0; + + + + + /* + * Draw ruler + */ + if (glIsList(_list_ruler) == GL_FALSE) { + message << tr("ERROR LIST not exist for the ruler.").toStdString() << Message::ende; + } + else{ + glPushMatrix(); + + /* + * Just translate for ruler follows the entity translate. + */ + glTranslated( - (int)_x_state_translate % (int)_ruler_distance, 0, _z_ruler); + glCallList(_list_ruler); + + glPopMatrix(); + } + + + /* + * Work out the graduation time value degree. + */ + + buf_max = Info::Render::_x_max_visible; + buf_min = Info::Render::_x_min_visible; + + if (buf_max>limit_d){ + while (buf_max>1){ + buf_max/=10.0; + buf_min/=10.0; + degree_d--; + pow_10_degree_d /= 10.0; + } + } + + buf_d = 0;/* to secure */ + + while ( (floor(buf_max) == floor(buf_min)) && (buf_d<10) ){/* buf<10 means that buf_max if greater than limit_d ! */ + buf_max *= 10; + buf_min *= 10; + pow_10_degree_d *= 10; + degree_d++; + buf_d++; + } + + /* ignore the last figure */ + // if (degree_d >= 0){ + pow_10_degree_d /= 10; + degree_d--; + //} + + entire_part_d = floor( Info::Render::_x_max_visible * pow_10_degree_d ); + + /* + * Draw the current ruler degree + */ + + /* Draw the text */ + glColor3d(1.0, 1.0, 1.0);/* text color */ + glRasterPos2f( 0, _ruler_y+_ruler_height); + + buf_txt << entire_part_d << "Xe-" << degree_d+mul_scale_d; + + for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){ + glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); + _info_degree_width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); + } + + _info_degree_width = screen_to_render_x(_info_degree_width); + + buf_txt.str("");/* flush the buffer */ + + /* Draw the foreground */ + glBegin(GL_QUADS); + { + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y+_ruler_height, _z_ruler_over); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y, _z_ruler_over); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y, _z_ruler_over); + glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y+_ruler_height, _z_ruler_over); + } + glEnd(); + + + + /* + * Draw coordinates + */ + glColor3d(1.0, 1.0, 1.0);/* text color */ + + for (unsigned int i = 0 ; i<=nb_graduation ; i++){ + + /* + * Work out the graduation time value. + */ + + buf_time = render_to_trace_x(i*_ruler_distance); + + if (buf_time < 0) continue;/* do not display negative time values */ + + + /* Now, convert (XXX,XXXXXXXXX) to (YYY * 10^ZZ and a common part WWWWWW * 10^TT) */ + + /* trunc the common part of each number */ + buf_d = buf_time*pow_10_degree_d; + buf_d = buf_d - floor( buf_d ); + + /* Mul buf_time to belongs to ]1000;0[ */ + buf_d *= mul_scale; + + /* Keep the entire part only */ + buf_d = floor(buf_d); + + /* Finally, fill the text buffer to display the graduate value */ + buf_txt << buf_d; + + /* + * Display the graduation time value. + */ + + glRasterPos2f( - (int)_x_state_translate % (int)_ruler_distance + i*_ruler_distance, _ruler_y+_ruler_height);/* set position */ + + if ( _info_degree_width < ( i*_ruler_distance - ((int)_x_state_translate % (int)_ruler_distance)) ){ + for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){ + glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); + } + }/* end for ( i ) */ + + buf_txt.str("");/* flush the buffer */ + + + }/* end for ( i ) */ + +} + diff --git a/src/render/Render_opengl.hpp b/src/render/Render_opengl.hpp index c6f47cd3a2cf22f4ec8e3bd9e46b3d8ed169d01b..61849edb0c0d113dc4517362c749270e6c410e60 100644 --- a/src/render/Render_opengl.hpp +++ b/src/render/Render_opengl.hpp @@ -51,13 +51,13 @@ class Core; #include "render.hpp" -#include "Render_area.hpp" +#include "Hook_event.hpp" /*! * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace. */ -class Render_opengl : /*public QGLWidget,*/ public Render_area, public Render +class Render_opengl : /*public QGLWidget,*/ public Hook_event, public Render { Q_OBJECT @@ -301,6 +301,47 @@ public: + /*********************************** + * + * Render OpenGL drawing functions. + * + **********************************/ + + /*! + * \brief Display a wait on the screen if there is no file opened. + * \return Asset value of the wait. + */ + GLuint draw_wait(); + + /*! + * \brief Create the ruler display list. + * \return Asset value of the ruler. + */ + GLuint draw_ruler(); + + /*! + * \brief Draw the ruler display list. + */ + void call_ruler(); + + + + /*********************************** + * + * Building functions. + * + **********************************/ + + /*! + * \brief This function draws the trace. + */ + bool build(); + + /*! + * \brief This function releases the trace. + */ + bool unbuild(); + /*********************************** * * Displaying functions. diff --git a/src/render/Render_opengl_dl.hpp b/src/render/Render_opengl_dl.hpp index d0b01bd6854c248695e6748a94dc05bb177732b8..c544bb65e333879f9821f52788ff7e8c570732d2 100644 --- a/src/render/Render_opengl_dl.hpp +++ b/src/render/Render_opengl_dl.hpp @@ -49,7 +49,7 @@ class Render_opengl_dl; -#include "Render_area.hpp" +#include "Hook_event.hpp" #include "../core/Core.hpp" #include "Render_opengl.hpp" diff --git a/src/render/render.hpp b/src/render/render.hpp index f47e61f02c7a5636a76044d258ba612f06b370aa..4a83e6db5b9cb03c4fe7df9a7e09ebbee01e410c 100644 --- a/src/render/render.hpp +++ b/src/render/render.hpp @@ -78,16 +78,9 @@ public: * \param y the y position of the container * \param w the width of the container * \param h the height of the container - */ - virtual void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) = 0; - - /*! - * \brief Draw the text of a container. - * \param x the x position of the text. - * \param y the y position of the text. * \param value the string value of the text. */ - virtual void draw_container_text(const Element_pos x, const Element_pos y, const std::string value) = 0; + void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const std::string value); /*! * \brief Called when all container draws are finished. @@ -166,21 +159,6 @@ public: * \brief Called when all draws are finished. */ virtual void end_draw() = 0; - - - /*! - * \brief Set Statistics and Informations about input trace - */ - virtual void set_total_width(Element_pos w) = 0; - - /*! - * \brief Set Statistics and Informations about input trace - */ - virtual void set_total_time(Times t) = 0; - /*! - * \brief display the scale - */ - virtual void display_time_scale() = 0; }; diff --git a/src/src.pro b/src/src.pro index fd0197645072e6703124ea25dfd29ad3cd342e80..82f2d7242892229d5ba32c03b4e110975dfd27a6 100644 --- a/src/src.pro +++ b/src/src.pro @@ -84,7 +84,7 @@ HEADERS += message/Message.hpp \ interface/resource.hpp \ # Render headers render/render.hpp \ - render/Render_area.hpp \ + render/Hook_event.hpp \ render/Render_opengl_dl.hpp \ render/Render_opengl.hpp \ render/render_svg.hpp \ @@ -159,7 +159,7 @@ SOURCES += message/Message.cpp \ interface/Interface_graphic.cpp \ interface/parsing_thread.cpp \ # Render code files - render/Render_area.cpp \ + render/Hook_event.cpp \ render/Render_opengl.cpp \ render/render_svg.cpp \ render/render_stats_opengl.cpp \