246 glLoadIdentity (); |
246 glLoadIdentity (); |
247 glMatrixMode (GL_PROJECTION); |
247 glMatrixMode (GL_PROJECTION); |
248 gluPerspective (45.0f, (double)w / (double)h, 0.1f, 100.0f); |
248 gluPerspective (45.0f, (double)w / (double)h, 0.1f, 100.0f); |
249 } |
249 } |
250 |
250 |
251 template<class T> using initlist = std::initializer_list<T>; |
|
252 |
|
253 // ============================================================================= |
251 // ============================================================================= |
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
255 // ============================================================================= |
253 // ============================================================================= |
256 void GLRenderer::paintGL () { |
254 void GLRenderer::paintGL () { |
257 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
255 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
285 |
283 |
286 glPushMatrix (); |
284 glPushMatrix (); |
287 glLoadIdentity (); |
285 glLoadIdentity (); |
288 glOrtho (.0, width, height, .0, -1.0, 1.0); |
286 glOrtho (.0, width, height, .0, -1.0, 1.0); |
289 |
287 |
290 for (int x : vector<int> ({GL_QUADS, GL_LINE_LOOP})) { |
288 for (int x : {GL_QUADS, GL_LINE_LOOP}) { |
291 if (x == GL_QUADS) |
289 if (x == GL_QUADS) |
292 glColor4f (.0, .8, 1.0, .6); |
290 glColor4f (.0, .8, 1.0, .6); |
293 else |
291 else |
294 glColor4f (1.0, 1.0, 1.0, 1.0); |
292 glColor4f (1.0, 1.0, 1.0, 1.0); |
295 |
293 |
543 |
541 |
544 // ============================================================================= |
542 // ============================================================================= |
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
543 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
546 // ============================================================================= |
544 // ============================================================================= |
547 void GLRenderer::updateSelFlash () { |
545 void GLRenderer::updateSelFlash () { |
548 if (gl_selflash && g_ForgeWindow->paSelection.size() > 0) { |
546 if (gl_selflash && g_ForgeWindow->sel.size() > 0) { |
549 qPulseTimer->start (g_dPulseInterval); |
547 qPulseTimer->start (g_dPulseInterval); |
550 g_dPulseTick = 0; |
548 g_dPulseTick = 0; |
551 } else |
549 } else |
552 qPulseTimer->stop (); |
550 qPulseTimer->stop (); |
553 } |
551 } |
558 void GLRenderer::pick (uint mx, uint my, bool add) { |
556 void GLRenderer::pick (uint mx, uint my, bool add) { |
559 GLint viewport[4]; |
557 GLint viewport[4]; |
560 |
558 |
561 // Clear the selection if we do not wish to add to it. |
559 // Clear the selection if we do not wish to add to it. |
562 if (add == false) { |
560 if (add == false) { |
563 std::vector<LDObject*> paOldSelection = g_ForgeWindow->paSelection; |
561 std::vector<LDObject*> paOldSelection = g_ForgeWindow->sel; |
564 g_ForgeWindow->paSelection.clear (); |
562 g_ForgeWindow->sel.clear (); |
565 |
563 |
566 // Recompile the prior selection to remove the highlight color |
564 // Recompile the prior selection to remove the highlight color |
567 for (LDObject* obj : paOldSelection) |
565 for (LDObject* obj : paOldSelection) |
568 recompileObject (obj); |
566 recompileObject (obj); |
569 } |
567 } |
627 |
625 |
628 if (idx == 0xFFFFFF) |
626 if (idx == 0xFFFFFF) |
629 continue; // White is background; skip |
627 continue; // White is background; skip |
630 |
628 |
631 LDObject* obj = g_CurrentFile->object (idx); |
629 LDObject* obj = g_CurrentFile->object (idx); |
632 g_ForgeWindow->paSelection.push_back (obj); |
630 g_ForgeWindow->sel.push_back (obj); |
633 } |
631 } |
634 |
632 |
635 delete[] pixeldata; |
633 delete[] pixeldata; |
636 |
634 |
637 // Remove duplicate entries. For this to be effective, the vector must be |
635 // Remove duplicate entries. For this to be effective, the vector must be |
638 // sorted first. |
636 // sorted first. |
639 std::vector<LDObject*>& sel = g_ForgeWindow->paSelection; |
637 std::vector<LDObject*>& sel = g_ForgeWindow->sel; |
640 std::sort (sel.begin(), sel.end ()); |
638 std::sort (sel.begin(), sel.end ()); |
641 std::vector<LDObject*>::iterator pos = std::unique (sel.begin (), sel.end ()); |
639 std::vector<LDObject*>::iterator pos = std::unique (sel.begin (), sel.end ()); |
642 sel.resize (std::distance (sel.begin (), pos)); |
640 sel.resize (std::distance (sel.begin (), pos)); |
643 |
641 |
644 // Update everything now. |
642 // Update everything now. |
679 |
677 |
680 // ============================================================================= |
678 // ============================================================================= |
681 void GLRenderer::slot_timerUpdate () { |
679 void GLRenderer::slot_timerUpdate () { |
682 ++g_dPulseTick %= g_dNumPulseTicks; |
680 ++g_dPulseTick %= g_dNumPulseTicks; |
683 |
681 |
684 for (LDObject* obj : g_ForgeWindow->selection ()) |
682 for (LDObject* obj : g_ForgeWindow->sel) |
685 recompileObject (obj); |
683 recompileObject (obj); |
686 |
684 |
687 paintGL (); |
685 paintGL (); |
688 swapBuffers (); |
686 swapBuffers (); |
689 } |
687 } |