src/gldraw.cpp

changeset 262
56f8987f4c7c
parent 261
c4ad4e3c6839
child 263
d7b534057d61
equal deleted inserted replaced
261:c4ad4e3c6839 262:56f8987f4c7c
837 angle += 360.0; 837 angle += 360.0;
838 while (angle > 360.0) 838 while (angle > 360.0)
839 angle -= 360.0; 839 angle -= 360.0;
840 } 840 }
841 841
842 void GLRenderer::addDrawnVertex (vertex pos) {
843 // If we picked an already-existing vertex, stop drawing
844 for (vertex& vert : m_drawedVerts) {
845 if (vert == pos) {
846 endDraw (true);
847 return;
848 }
849 }
850
851 m_drawedVerts << pos;
852 }
853
842 // ============================================================================= 854 // =============================================================================
843 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 855 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
844 // ============================================================================= 856 // =============================================================================
845 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { 857 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) {
846 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton); 858 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton);
847 const bool wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton); 859 const bool wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton);
848 const bool wasMid = (m_lastButtons & Qt::MidButton) && !(ev->buttons() & Qt::MidButton); 860 const bool wasMid = (m_lastButtons & Qt::MidButton) && !(ev->buttons() & Qt::MidButton);
861 printf ("totalmove: %lu\n", m_totalmove);
849 862
850 if (wasLeft) { 863 if (wasLeft) {
851 // Check if we selected a camera icon 864 // Check if we selected a camera icon
852 if (!m_rangepick) { 865 if (!m_rangepick) {
853 for (CameraIcon& info : g_CameraIcons) { 866 for (CameraIcon& info : g_CameraIcons) {
873 return; 886 return;
874 } 887 }
875 888
876 if (m_drawedVerts.size () == 0 && ev->modifiers () & Qt::ShiftModifier) 889 if (m_drawedVerts.size () == 0 && ev->modifiers () & Qt::ShiftModifier)
877 m_rectdraw = true; 890 m_rectdraw = true;
878
879 // If we picked an already-existing vertex, stop drawing
880 for (vertex& vert : m_drawedVerts) {
881 if (vert == m_hoverpos) {
882 endDraw (true);
883 return;
884 }
885 }
886 } 891 }
887 892
888 m_drawedVerts << m_hoverpos; 893 addDrawnVertex (m_hoverpos);
889 update (); 894 update ();
890 break; 895 break;
891 896
892 case Select: 897 case Select:
893 if (!drawOnly ()) { 898 if (!drawOnly ()) {
899 } 904 }
900 break; 905 break;
901 } 906 }
902 907
903 m_rangepick = false; 908 m_rangepick = false;
904 m_totalmove = 0; 909 }
905 return; 910
906 } 911 if (wasMid && editMode () == Draw && m_drawedVerts.size () < 4 && m_totalmove < 10) {
907
908 if (wasMid && editMode () == Draw && m_drawedVerts.size () < 4) {
909 // Find the closest vertex to our cursor 912 // Find the closest vertex to our cursor
910 double mindist = 1024.0f; 913 double mindist = 1024.0f;
911 vertex closest; 914 vertex closest;
912 bool valid = false; 915 bool valid = false;
913 916
929 closest = pos3d; 932 closest = pos3d;
930 valid = true; 933 valid = true;
931 } 934 }
932 } 935 }
933 936
934 if (valid) { 937 if (valid)
935 m_drawedVerts << closest; 938 addDrawnVertex (closest);
936 update ();
937 }
938
939 return;
940 } 939 }
941 940
942 if (wasRight && m_drawedVerts.size () > 0) { 941 if (wasRight && m_drawedVerts.size () > 0) {
943 // Remove the last vertex 942 // Remove the last vertex
944 m_drawedVerts.erase (m_drawedVerts.size () - 1); 943 m_drawedVerts.erase (m_drawedVerts.size () - 1);
946 if (m_drawedVerts.size () == 0) 945 if (m_drawedVerts.size () == 0)
947 m_rectdraw = false; 946 m_rectdraw = false;
948 947
949 update (); 948 update ();
950 } 949 }
950
951 m_totalmove = 0;
951 } 952 }
952 953
953 // ============================================================================= 954 // =============================================================================
954 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 955 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
955 // ============================================================================= 956 // =============================================================================
956 void GLRenderer::mousePressEvent (QMouseEvent* ev) { 957 void GLRenderer::mousePressEvent (QMouseEvent* ev) {
957 if (ev->buttons () & Qt::LeftButton) 958 m_totalmove = 0;
958 m_totalmove = 0;
959 959
960 if (ev->modifiers () & Qt::ShiftModifier) { 960 if (ev->modifiers () & Qt::ShiftModifier) {
961 m_rangepick = true; 961 m_rangepick = true;
962 m_rangeStart.setX (ev->x ()); 962 m_rangeStart.setX (ev->x ());
963 m_rangeStart.setY (ev->y ()); 963 m_rangeStart.setY (ev->y ());

mercurial