Ejemplo n.º 1
0
void OpenGLComponent::updateContext()
{
    if (needToDeleteContext)
        deleteContext();

    if (context == nullptr)
    {
        const ScopedLock sl (contextLock);

        if (context == nullptr)
        {
            context = createContext();

            if (context != nullptr)
            {
               #if JUCE_LINUX
                if (! isUsingDedicatedThread())
               #endif
                    updateContextPosition();

                if (context->makeActive())
                {
                    newOpenGLContextCreated();
                    context->makeInactive();
                }
            }
        }
    }
}
Ejemplo n.º 2
0
void TguitarView::displayAt(const QPointF& scenePos) {
  m_fret = m_guitar->pointToFinger(QPoint(scenePos.x(), m_guitar->height() / 2)).fret();
  updateContextPosition();
  proxy()->setPos(m_fret ? m_guitar->fretPositionX(m_fret) + 9.0 : m_parent->width() - width(), m_parent->height() - height() - 4);
  proxy()->show();
  updateMarkPosition();
}
Ejemplo n.º 3
0
void OpenGLComponent::updateContext()
{
  //request to delete the context
  if (needToDeleteContext)
  {
    if (context.nativeContext!=nullptr)
    {
      context.nativeContext->shutdownOnRenderThread();
      delete context.nativeContext;
      context.nativeContext=nullptr;
    }
    needToDeleteContext = false;
  }

  //do not create the context if not visible!
  if (!this->isVisible()) 
    return;

  //recreate native context
  if (context.nativeContext==nullptr)
  {
    const ScopedLock sl(contextLock);
    if (context.nativeContext==nullptr)
    {
      context.nativeContext = new OpenGLContext::NativeContext (*this, preferredPixelFormat,
        contextToShareListsWith != nullptr ? contextToShareListsWith->nativeContext: nullptr);

      if (!context.nativeContext->createdOk())
      {
        delete context.nativeContext;
        context.nativeContext=nullptr;
      }

      if (context.nativeContext!=nullptr)
      {
        context.nativeContext->initialiseOnRenderThread();
        updateContextPosition();
        glViewport (0, 0, getWidth(), getHeight());
        
        if (context.makeActive())
        {
          context.extensions.initialise();
          newOpenGLContextCreated();
          makeCurrentContextInactive();
        }
      }
    }
  }
}
Ejemplo n.º 4
0
bool TguitarView::mapTouchEvent(QTouchEvent* te) {
#if defined (Q_OS_ANDROID)
  if (isPreview()) { // PREVIEW MODE
      if (!TtouchParams::i()->guitarWasTouched) { // display hint how to use fret preview
          tMessage->setMessage(TtouchProxy::touchGuitarHelp(), 0);
          TtouchParams::i()->guitarWasTouched = true;
      }
      switch (te->type()) {
        case QEvent::TouchBegin: {
          if (proxy()->isVisible()) // already displayed - can be scrolled or selected
            m_couldBeTouch = true;
          break;
        }
        case QEvent::TouchUpdate: {
          if (isVisible() && m_touchStartedHere &&
              QLineF(te->touchPoints().first().pos(), te->touchPoints().first().startPos()).length() > Tmtr::fingerPixels() / 2)
          { // scrolling - so not selected
              horizontalScrollBar()->setValue(horizontalScrollBar()->value() +
                                              (te->touchPoints()[0].pos().x() - te->touchPoints()[0].lastPos().x()));
              quint8 currFret = m_guitar->pointToFinger(QPoint(horizontalScrollBar()->value() / transform().m11(),
                                                               m_guitar->height() / 2)).fret();
              if ((m_fret == 1 && currFret > 1) || (m_fret != 1 && currFret != m_fret)) {
                m_fret = currFret;
                updateMarkPosition();
                proxy()->setPos(m_fret ? m_guitar->fretPositionX(m_fret) + 9.0 :
                                         m_parent->width() - width(), m_parent->height() - height() - 4);
              }
              m_couldBeTouch = false;
          }
          break;
        }
        case QEvent::TouchEnd: {
          if (isVisible()) {
            if (m_touchStartedHere) { // preview was touched so it might be scrolled or touched
              if (m_couldBeTouch) { // it was touched - fake press the guitar
                if (m_parent->itemAt(te->touchPoints().first().startPos().toPoint()) == proxy()) {
                  QPointF mtgv = proxy()->mapFromScene(te->touchPoints().first().pos()); // mapped from global scene to guitar view
                  m_guitar->fakePress(QPointF((mtgv.x() + horizontalScrollBar()->value()) / transform().m11(),
                                              mtgv.y() / transform().m11()).toPoint());
                }
              } else // touched but scrolled - update displayed fret
                  updateContextPosition();
            } else // guitar (parent widget) was touched, so hide the preview
                hide();
          } else // not visible -display it at touch position
              displayAt(te->touchPoints().first().pos());
          m_touchStartedHere = false;
          m_couldBeTouch = false;
          break;
        }
        default:
          break;
      }
  } else
#endif
  { // NO PREVIEW - only convert touch in guitar into mouse press
      if (te->type() == QEvent::TouchEnd)
          m_guitar->fakePress(QPoint(te->touchPoints().first().pos().x() - m_guitar->x(),
                                     te->touchPoints().first().pos().y() - m_guitar->y()));
  }
  return true;
}