# HG changeset patch # User Santeri Piippo # Date 1387551966 -7200 # Node ID a86ae85a277ca309f59b2c874320966048148408 # Parent 17a88e2470c9cb64c5a8234778bc146a7f20459f - added visible line angles when drawing diff -r 17a88e2470c9 -r a86ae85a277c changelog.txt --- a/changelog.txt Fri Dec 20 13:35:08 2013 +0200 +++ b/changelog.txt Fri Dec 20 17:06:06 2013 +0200 @@ -24,6 +24,7 @@ - LDraw code parser no longer complains about scientific notation. - Changing to draw mode while in free camera now causes the camera to be changed to top. - When drawing polygons, line lengths are now displayed. Added a configuration option to toggle this behavior. +- Added an option for drawing line angles similarly. - Added config fields for default name/username/license. This data will be automatically filled into forms that require such information. - Upon first start the configuration prompt pops up on its own, defaulting on the profile tab. This diff -r 17a88e2470c9 -r a86ae85a277c ldforge.qrc --- a/ldforge.qrc Fri Dec 20 13:35:08 2013 +0200 +++ b/ldforge.qrc Fri Dec 20 17:06:06 2013 +0200 @@ -66,6 +66,7 @@ ./icons/line.png ./icons/mail.png ./icons/make-borders.png + ./icons/mode-angle.png ./icons/mode-circle.png ./icons/mode-draw.png ./icons/mode-select.png diff -r 17a88e2470c9 -r a86ae85a277c src/actions.h --- a/src/actions.h Fri Dec 20 13:35:08 2013 +0200 +++ b/src/actions.h Fri Dec 20 17:06:06 2013 +0200 @@ -109,5 +109,6 @@ act (AddHistoryLine) act (JumpTo) act (SubfileSelection) +act (DrawAngles) #undef act \ No newline at end of file diff -r 17a88e2470c9 -r a86ae85a277c src/gldraw.cc --- a/src/gldraw.cc Fri Dec 20 13:35:08 2013 +0200 +++ b/src/gldraw.cc Fri Dec 20 17:06:06 2013 +0200 @@ -68,6 +68,7 @@ cfg (Bool, gl_logostuds, false); cfg (Bool, gl_aa, true); cfg (Bool, gl_linelengths, true); +cfg (Bool, gl_drawangles, false); // argh const char* g_CameraNames[7] = @@ -582,43 +583,41 @@ linepen.setWidth (2); linepen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); - // If we're drawing, draw the vertices onto the screen. + // Mode-specific rendering if (getEditMode() == EDrawMode) - { int numverts = 4; + { QPoint poly[4]; + vertex poly3d[4]; + int numverts = 4; + + // Calculate polygon data + if (!m_rectdraw) + { numverts = m_drawedVerts.size() + 1; + int i = 0; + + for (vertex& vert : m_drawedVerts) + poly3d[i++] = vert; - if (!m_rectdraw) - numverts = m_drawedVerts.size() + 1; + // Draw the cursor vertex as the last one in the list. + if (numverts <= 4) + poly3d[i] = m_hoverpos; + else + numverts = 4; + } + else + { // Get vertex information from m_rectverts + if (m_drawedVerts.size() > 0) + for (int i = 0; i < numverts; ++i) + poly3d[i] = m_rectverts[i]; + else + poly3d[0] = m_hoverpos; + } + + // Convert to 2D + for (int i = 0; i < numverts; ++i) + poly[i] = coordconv3_2 (poly3d[i]); if (numverts > 0) - { QPoint poly[4]; - vertex poly3d[4]; - - if (!m_rectdraw) - { int i = 0; - - for (vertex& vert : m_drawedVerts) - poly3d[i++] = vert; - - // Draw the cursor vertex as the last one in the list. - if (numverts <= 4) - poly3d[i] = m_hoverpos; - else - numverts = 4; - } - else - { // Get vertex information from m_rectverts - if (m_drawedVerts.size() > 0) - for (int i = 0; i < numverts; ++i) - poly3d[i] = m_rectverts[i]; - else - poly3d[0] = m_hoverpos; - } - - // convert to 2d - for (int i = 0; i < numverts; ++i) - poly[i] = coordconv3_2 (poly3d[i]); - - // Draw the polygon-to-be + { // Draw the polygon-to-be paint.setPen (linepen); paint.setBrush (polybrush); paint.drawPolygon (poly, numverts); @@ -632,15 +631,30 @@ paint.drawText (blip.x(), blip.y() - 8, poly3d[i].stringRep (true)); } - // Draw line lengths - if (numverts >= 2 && gl_linelengths) + // Draw line lenghts and angle info if appropriate + if (numverts >= 2) { int numlines = (m_drawedVerts.size() == 1) ? 1 : m_drawedVerts.size() + 1; + paint.setPen (textpen); for (int i = 0; i < numlines; ++i) { const int j = (i + 1 < numverts) ? i + 1 : 0; - const str label = str::number (poly3d[i].distanceTo (poly3d[j])); - paint.setPen (textpen); - paint.drawText (QLineF (poly[i], poly[j]).pointAt (0.5), label); + const int h = (i - 1 >= 0) ? i - 1 : numverts - 1; + + if (gl_linelengths) + { const str label = str::number (poly3d[i].distanceTo (poly3d[j])); + QPoint origin = QLineF (poly[i], poly[j]).pointAt (0.5).toPoint(); + paint.drawText (origin, label); + } + + if (gl_drawangles) + { QLineF l0 (poly[h], poly[i]), + l1 (poly[i], poly[j]); + double angle = l0.angleTo (l1); + str label = str::number (angle) + str::fromUtf8 (QByteArray ("\302\260")); + QPoint pos = poly[i]; + pos.setY (pos.y() + metrics.height()); + paint.drawText (pos, label); + } } } } @@ -941,7 +955,7 @@ // ----------------------------------------------------------------------------- void GLRenderer::addDrawnVertex (vertex pos) { // If we picked an already-existing vertex, stop drawing - if (getEditMode() != ECircleMode) + if (getEditMode() == EDrawMode) { for (vertex& vert : m_drawedVerts) { if (vert == pos) { endDraw (true); @@ -1177,8 +1191,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::pick (int mouseX, int mouseY) -{ GLint viewport[4]; - makeCurrent(); +{ makeCurrent(); // Use particularly thick lines while picking ease up selecting lines. glLineWidth (max (gl_linethickness, 6.5f)); @@ -1197,11 +1210,8 @@ // Paint the picking scene glDisable (GL_DITHER); glClearColor (1.0f, 1.0f, 1.0f, 1.0f); - drawGLScene(); - glGetIntegerv (GL_VIEWPORT, viewport); - int x0 = mouseX, y0 = mouseY; int x1, y1; @@ -1229,7 +1239,6 @@ y0 = max (0, y0); x1 = min (x1, m_width); y1 = min (y1, m_height); - const int areawidth = (x1 - x0); const int areaheight = (y1 - y0); const qint32 numpixels = areawidth * areaheight; @@ -1238,10 +1247,8 @@ uchar* const pixeldata = new uchar[4 * numpixels]; uchar* pixelptr = &pixeldata[0]; - assert (viewport[3] == m_height); - // Read pixels from the color buffer. - glReadPixels (x0, viewport[3] - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); + glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); LDObject* removedObj = null; diff -r 17a88e2470c9 -r a86ae85a277c src/gldraw.h --- a/src/gldraw.h Fri Dec 20 13:35:08 2013 +0200 +++ b/src/gldraw.h Fri Dec 20 17:06:06 2013 +0200 @@ -98,7 +98,7 @@ PROPERTY (public, bool, DrawOnly, BOOL_OPS, STOCK_WRITE) PROPERTY (public, MessageManager*, MessageLog, NO_OPS, STOCK_WRITE) PROPERTY (private, bool, Picking, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, LDDocument*, File, NO_OPS, CUSTOM_WRITE) + PROPERTY (public, LDDocument*, File, NO_OPS, CUSTOM_WRITE) PROPERTY (public, EditMode, EditMode, NO_OPS, CUSTOM_WRITE) public methods: diff -r 17a88e2470c9 -r a86ae85a277c src/gui.cc --- a/src/gui.cc Fri Dec 20 13:35:08 2013 +0200 +++ b/src/gui.cc Fri Dec 20 17:06:06 2013 +0200 @@ -55,12 +55,13 @@ cfg (Bool, lv_colorize, true); cfg (String, gui_colortoolbar, "16:24:|:1:2:4:14:0:15:|:33:34:36:46"); cfg (Bool, gui_implicitfiles, false); -extern_cfg (List, io_recentfiles); -extern_cfg (Bool, gl_axes); -extern_cfg (String, gl_maincolor); -extern_cfg (Float, gl_maincolor_alpha); -extern_cfg (Bool, gl_wireframe); -extern_cfg (Bool, gl_colorbfc); +extern_cfg (List, io_recentfiles); +extern_cfg (Bool, gl_axes); +extern_cfg (String, gl_maincolor); +extern_cfg (Float, gl_maincolor_alpha); +extern_cfg (Bool, gl_wireframe); +extern_cfg (Bool, gl_colorbfc); +extern_cfg (Bool, gl_drawangles); #define act(N) extern_cfg (KeySequence, key_##N); #include "actions.h" @@ -929,6 +930,7 @@ ui->actionRedo->setEnabled (pos < (long) his->getSize() - 1); ui->actionAxes->setChecked (gl_axes); ui->actionBFCView->setChecked (gl_colorbfc); + ui->actionDrawAngles->setChecked (gl_drawangles); } QImage imageFromScreencap (uchar* data, int w, int h) diff -r 17a88e2470c9 -r a86ae85a277c src/gui_actions.cc --- a/src/gui_actions.cc Fri Dec 20 13:35:08 2013 +0200 +++ b/src/gui_actions.cc Fri Dec 20 17:06:06 2013 +0200 @@ -37,11 +37,12 @@ #include "widgets.h" #include "colors.h" -extern_cfg (Bool, gl_wireframe); -extern_cfg (Bool, gl_colorbfc); -extern_cfg (String, ld_defaultname); -extern_cfg (String, ld_defaultuser); -extern_cfg (Int, ld_defaultlicense); +extern_cfg (Bool, gl_wireframe); +extern_cfg (Bool, gl_colorbfc); +extern_cfg (String, ld_defaultname); +extern_cfg (String, ld_defaultuser); +extern_cfg (Int, ld_defaultlicense); +extern_cfg (Bool, gl_drawangles); // ============================================================================= // ----------------------------------------------------------------------------- @@ -483,7 +484,7 @@ DEFINE_ACTION (VisibilityHide, 0) { for (LDObject* obj : selection()) obj->setHidden (true); - + g_win->refresh(); } @@ -492,7 +493,6 @@ DEFINE_ACTION (VisibilityReveal, 0) { for (LDObject* obj : selection()) obj->setHidden (false); - g_win->refresh(); } @@ -541,6 +541,13 @@ // ============================================================================= // ----------------------------------------------------------------------------- +DEFINE_ACTION (DrawAngles, 0) +{ gl_drawangles = !gl_drawangles; + g_win->R()->refresh(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SetDrawDepth, 0) { if (g_win->R()->camera() == GL::EFreeCamera) return; diff -r 17a88e2470c9 -r a86ae85a277c ui/ldforge.ui --- a/ui/ldforge.ui Fri Dec 20 13:35:08 2013 +0200 +++ b/ui/ldforge.ui Fri Dec 20 17:06:06 2013 +0200 @@ -116,6 +116,7 @@ + @@ -365,6 +366,7 @@ + @@ -1345,6 +1347,21 @@ Subfile Selection + + + true + + + + :/icons/mode-angle.png:/icons/mode-angle.png + + + Draw Angles + + + Draw angle information when drawing lines + +