Ejemplo n.º 1
0
void MyPositionController::NextMode(ScreenBase const & screen)
{
  string const kAlohalyticsClickEvent = "$onClick";

  // Skip switching to next mode while we are waiting for position.
  if (IsWaitingForLocation())
  {
    alohalytics::LogEvent(kAlohalyticsClickEvent,
                          LocationModeStatisticsName(location::PendingPosition));
    return;
  }

  alohalytics::LogEvent(kAlohalyticsClickEvent, LocationModeStatisticsName(m_mode));

  // Start looking for location.
  if (m_mode == location::NotFollowNoPosition)
  {
    m_pendingTimer.Reset();
    ChangeMode(location::PendingPosition);
    return;
  }

  // Calculate preferred zoom level.
  int const currentZoom = GetZoomLevel(screen);
  int preferredZoomLevel = kDoNotChangeZoom;
  if (currentZoom < kZoomThreshold)
    preferredZoomLevel = min(GetZoomLevel(screen, m_position, m_errorRadius), kMaxScaleZoomLevel);

  // In routing not-follow -> follow-and-rotate, otherwise not-follow -> follow.
  if (m_mode == location::NotFollow)
  {
    ChangeMode(m_isInRouting ? location::FollowAndRotate : location::Follow);
    UpdateViewport(preferredZoomLevel);
    return;
  }

  // From follow mode we transit to follow-and-rotate if compass is available or
  // routing is enabled.
  if (m_mode == location::Follow)
  {
    if (IsRotationAvailable() || m_isInRouting)
    {
      ChangeMode(location::FollowAndRotate);
      UpdateViewport(preferredZoomLevel);
    }
    return;
  }

  // From follow-and-rotate mode we can transit to follow mode if routing is disabled.
  if (m_mode == location::FollowAndRotate)
  {
    if (!m_isInRouting)
    {
      ChangeMode(location::Follow);
      ChangeModelView(m_position, 0.0, m_pixelRect.Center(), preferredZoomLevel);
    }
  }
}
Ejemplo n.º 2
0
void GLContainer::SetScrolls()
{
    horizontalScrollBar()->setVisible(true);
    verticalScrollBar()->setVisible(true);

    _prevZoomFactor = 1.0f;

    std::cout << "SetScrolls\n";

    // nasty code here...
    bool shouldZoom = true;
    do
    {
        //int _w = this->width();
        //int _h = this->height();
        QSize imgSize = _glWidget->GetCanvasSize();

        if(imgSize.width() == 0 || imgSize.height() == 0)
        {
            imgSize = QSize(100, 100);
        }

        std::cout << "image size " << imgSize.width() << " - " << imgSize.height() << "\n";
        double zoomFactor = _glWidget->GetZoomFactor();

        if((double)this->width()  < (double)imgSize.width() * zoomFactor ||  (double)this->height() < (double)imgSize.height() *zoomFactor)
        { _glWidget->ZoomOut(); }
        else
        { shouldZoom = false; }
    } while (shouldZoom);
    UpdateViewport(true);
}
Ejemplo n.º 3
0
void MyPositionController::SetTimeInBackground(double time)
{
  if (time >= kMaxTimeInBackgroundSec && m_mode == location::NotFollow)
  {
    ChangeMode(m_isInRouting ? location::FollowAndRotate : location::Follow);
    UpdateViewport(kDoNotChangeZoom);
  }
}
Ejemplo n.º 4
0
void DisplayManager::SetHeight (DISPLAY_INT h)
{
	if (Height() != h)
	{
		DisplayElement::SetHeight(h);
		UpdateViewport();
	}
}
Ejemplo n.º 5
0
void SceneManager::BeginScene(){
	if(mSizeChanged)
		UpdateViewport();

	OpenGL::mVertexCount = 0;
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	glEnable(GL_MULTISAMPLE_ARB);
}
Ejemplo n.º 6
0
void DisplayManager::SetWidth (DISPLAY_INT w)
{
	if (Width() != w)
	{
		DisplayElement::SetWidth(w);
		UpdateViewport();
	}
}
Ejemplo n.º 7
0
void DisplayManager::SizeTo (DISPLAY_INT w, DISPLAY_INT h)
{
	if (Height() != h || Width() != w)
	{
		DisplayElement::SizeTo(w, h);
		UpdateViewport();
	}
}
Ejemplo n.º 8
0
void MyPositionController::DragEnded(m2::PointD const & distance)
{
  float const kBindingDistance = 0.1;
  m_needBlockAnimation = false;
  if (distance.Length() > kBindingDistance * min(m_pixelRect.SizeX(), m_pixelRect.SizeY()))
    StopLocationFollow();

  UpdateViewport(kDoNotChangeZoom);
}
Ejemplo n.º 9
0
void
JXMesaCamera::InitMesa
	(
	JX3DWidget*		widget,
	J3DUniverse*	universe
	)
{
	assert( widget->GetColormap() == &(universe->GetColormap()) );

	itsWidget           = widget;
	itsDoubleBufferFlag = kJTrue;

	itsPerspectiveFlag  = kJTrue;
	itsFOVAngle         = 45.0;
	itsNearZ            = 0.1;
	itsFarZ             = 10.0;

	XVisualInfo xvi = (itsWidget->GetColormap())->GetXVisualInfo();
	itsXMVisual =
		XMesaCreateVisual(*(itsWidget->GetDisplay()),
						  &xvi,
						  kJTrue,				// RGB
						  GL_FALSE,				// alpha buffer
						  itsDoubleBufferFlag,	// double buffering
						  GL_FALSE,				// stereo visual
						  GL_FALSE,				// use Pixmap for back buffer
						  16,					// bits/depth
						  0,					// bits/stencil
						  0,0,0,0,				// bits/component (accum)
						  0,					// number of samples/pixel
						  0,					// visual level
						  GLX_NONE_EXT);		// GLX extension
	assert( itsXMVisual != NULL );

	itsXMContext = XMesaCreateContext(itsXMVisual, NULL);
	assert( itsXMContext != NULL );

	itsXMBuffer =
		XMesaCreateWindowBuffer(itsXMVisual, (itsWidget->GetWindow())->GetXWindow());
	assert( itsXMBuffer != NULL );

	const JBoolean ok = PrepareMesa();
	assert( ok );

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	if (!itsDoubleBufferFlag)
		{
		glEnable(GL_SCISSOR_TEST);
		}
	glEnable(GL_DITHER);
	glEnable(GL_LINE_SMOOTH);		// anti-aliasing
//	glEnable(GL_POLYGON_SMOOTH);	// anti-aliasing

	UpdateViewport();
}
Ejemplo n.º 10
0
void MyPositionController::Render(uint32_t renderMode, ScreenBase const & screen,
                                  ref_ptr<dp::GpuProgramManager> mng,
                                  dp::UniformValuesStorage const & commonUniforms)
{
  if (IsWaitingForLocation())
  {
    if (m_pendingTimer.ElapsedSeconds() >= kMaxPendingLocationTimeSec)
      ChangeMode(location::NotFollowNoPosition);
  }

  if (IsInRouting() && m_mode == location::NotFollow &&
      m_routingNotFollowTimer.ElapsedSeconds() >= kMaxNotFollowRoutingTimeSec)
  {
    ChangeMode(location::FollowAndRotate);
    UpdateViewport(kDoNotChangeZoom);
  }

  if (m_shape != nullptr && IsVisible() && IsModeHasPosition())
  {
    if (m_isDirtyViewport && !m_needBlockAnimation)
    {
      UpdateViewport(kDoNotChangeZoom);
      m_isDirtyViewport = false;
    }

    if (!IsModeChangeViewport())
      m_isPendingAnimation = false;

    m_shape->SetPosition(GetDrawablePosition());
    m_shape->SetAzimuth(GetDrawableAzimut());
    m_shape->SetIsValidAzimuth(IsRotationAvailable());
    m_shape->SetAccuracy(m_errorRadius);
    m_shape->SetRoutingMode(IsInRouting());

    double const updateInterval = m_updateLocationTimer.ElapsedSeconds();
    m_shape->SetPositionObsolete(updateInterval >= kMaxUpdateLocationInvervalSec);

    if ((renderMode & RenderAccuracy) != 0)
      m_shape->RenderAccuracy(screen, mng, commonUniforms);

    if ((renderMode & RenderMyPosition) != 0)
      m_shape->RenderMyPosition(screen, mng, commonUniforms);
  }
}
Ejemplo n.º 11
0
void CViewport::Render(void)
{
	if(m_rcViewPort.right <= m_rcViewPort.left + 1 || 
		m_rcViewPort.bottom <= m_rcViewPort.top + 1 )
		return;

	UpdateViewport();
	Clear();
	CRenderTarget::Render();
}
Ejemplo n.º 12
0
void MyPositionController::ScaleEnded()
{
  m_needBlockAnimation = false;
  if (m_wasRotationInScaling)
  {
    m_wasRotationInScaling = false;
    StopLocationFollow();
  }

  UpdateViewport(kDoNotChangeZoom);
}
Ejemplo n.º 13
0
void Display::RenderObjects()
{
	LayerContainerType::const_iterator i;
	ObjContainerType::const_iterator j;

	for (i = layers_.begin(); i != layers_.end(); ++i)
	{
		UpdateViewport((Viewport&)(i->second).viewport);
		for (j = (i->second).objects.begin(); j != (i->second).objects.end(); ++j)
		{
			(*j)->Render();
		}
	}
}
Ejemplo n.º 14
0
void TeapotRenderer::Init()
{
    //Settings
    glFrontFace( GL_CCW );

    //Load shader
    LoadShaders( &shader_param_, "Shaders/VS_ShaderPlain.vsh",
            "Shaders/ShaderPlain.fsh" );

    //Create Index buffer
    num_indices_ = sizeof(teapotIndices) / sizeof(teapotIndices[0]);
    glGenBuffers( 1, &ibo_ );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo_ );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(teapotIndices), teapotIndices,
            GL_STATIC_DRAW );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );

    //Create VBO
    num_vertices_ = sizeof(teapotPositions) / sizeof(teapotPositions[0]) / 3;
    int32_t iStride = sizeof(TEAPOT_VERTEX);
    int32_t iIndex = 0;
    TEAPOT_VERTEX* p = new TEAPOT_VERTEX[num_vertices_];
    for( int32_t i = 0; i < num_vertices_; ++i )
    {
        p[i].pos[0] = teapotPositions[iIndex];
        p[i].pos[1] = teapotPositions[iIndex + 1];
        p[i].pos[2] = teapotPositions[iIndex + 2];

        p[i].normal[0] = teapotNormals[iIndex];
        p[i].normal[1] = teapotNormals[iIndex + 1];
        p[i].normal[2] = teapotNormals[iIndex + 2];
        iIndex += 3;
    }
    glGenBuffers( 1, &vbo_ );
    glBindBuffer( GL_ARRAY_BUFFER, vbo_ );
    glBufferData( GL_ARRAY_BUFFER, iStride * num_vertices_, p, GL_STATIC_DRAW );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );

    delete[] p;

    UpdateViewport();
    mat_model_ = ndk_helper::Mat4::Translation( 0, 0, -15.f );

    ndk_helper::Mat4 mat = ndk_helper::Mat4::RotationX( M_PI / 3 );
    mat_model_ = mat * mat_model_;

    CreateFBO();
}
Ejemplo n.º 15
0
void GLContainer::wheelEvent(QWheelEvent* event)
{
    bool scrollDir = (event->delta() > 0) ? true : false;	// negative means scroll down, positive is otherwise
    _prevZoomFactor = _glWidget->GetZoomFactor();		// for anchor zoom

    //if(this->_ctrlPressed)
    //{
        if(scrollDir) _glWidget->ZoomOut();
        else _glWidget->ZoomIn();
    //}

    //float zoomFactor = _glWidget->GetZoomFactor() * 100.0;

    // update scrollbars
    UpdateViewport();
}
Ejemplo n.º 16
0
void GLContainer::paintEvent(QPaintEvent *event)
{
    if(this->_justInitialized)
    {
        UpdateViewport(true);
        this->_justInitialized = false;
    }

    // please fix me
    if(this->width() != _glWidget->width() || this->height() != _glWidget->height())
    {
        _glWidget->setFixedWidth(this->width());
        _glWidget->setFixedHeight(this->height());
    }

    QAbstractScrollArea::paintEvent(event);
    _glWidget->updateGL();
}
Ejemplo n.º 17
0
void CRenderTarget::Render(void)
{
	if(NULL == m_pRenderGroup)
		return;

	UpdateAspect();
	UpdateViewport();

	float inverseViewSize[2] = { 1.0f / m_rcViewPort.Width(), 1.0f / m_rcViewPort.Height() };
	CRenderPipeline::GetInst()->SetVertexShaderF(ACT_INVERSE_VIEW_SIZE, inverseViewSize, 1);
	m_pRenderGroup->GetCamera()->SetDeltaViewMatrix(m_matPreDeltaView);
	m_pRenderGroup->Render();


	if (NULL != m_pBloomTarget)
	{
		m_pBloomTarget->DoPostProcess();
		m_pRenderGroup->PostRender();
	}

	CRenderPipeline::GetInst()->ClearDepth();
	//Flip·Åµ½Õâ,·ÀÖ¹ÂǾµÓ°ÏìGUI
	Flip();

	for ( int i = 0; i < (int)m_lRenderSystems.size(); i++ )
	{
		SQR_TRY
		{	
			m_lRenderSystems[i]->Render();
		}
		SQR_CATCH(exp)
		{
			exp.AppendType("×ÓäÖȾϵͳ´íÎó");
			GfkLogExp(exp);
		}
		SQR_TRY_END;
	}
		
	m_pRenderGroup->Reset();
}
Ejemplo n.º 18
0
	bool SystemThink()
	{
		// if the window is not active, then block..
		if (! DSys::Window::Active())
			WaitMessage();

		// finish the message queue
		MSG msg;
		while( PeekMessage(&msg,DSys::Window::GetHWND(),0,0,PM_REMOVE))
		{
			if (msg.message != WM_QUIT)
			{
				TranslateMessage(&msg);	// Translate The Message
				DispatchMessage(&msg);	// Dispatch The Message
			}
			else
				return false;
		}		

		// do we have a fixed mouse?
		if( sv_bFixMousePosition )
			SetCursorPos(320,240);

		// update the audio system
		DAudio::Update();

		// update the opengl viewport
		UpdateViewport();

		// update and render the console
		static float tprev = Timer::Time();
		float dt = Timer::Time() - tprev;
		tprev = dt;
		Console::GFX_Render(dt);

		// swap the opengl buffers
		Window::SwapGLBuffers();
		return true;
	}
Ejemplo n.º 19
0
void Master::Init(char* filename) {

  // Local clipping planes
  float clipNear = 0.0;
  float clipFar = 0.0;

  // Local synchronization server port
  int synchronizationPort = 0;

  // Local user interface server port
  int userInterfacePort = 0;


#ifdef SAGE

  // Connect to SAGE

  // SAGE configuration
  _sageConfig.init("VRA.conf");
  _sageConfig.setAppName("VRA");
  _sageConfig.rank = 0;
  _sageConfig.nodeNum = (_communicator -> GetNumberOfNodes()) -1;
  _sageConfig.master = true;
  _sageConfig.rendering = false;

  // Initialize SAGE
  _sageInf.init(_sageConfig);

#endif


  // Read configuration file from disk

  // File pointer
  FILE* fptr = NULL;

  // Attempt to open file
  if ((fptr = fopen(filename, "r")) == NULL) {
    fprintf(stderr, 
            "Master: Can not read display configuration file %s\n.", 
            filename);
    return;
  }

  // Read user interface port
  fscanf(fptr, "%d", &userInterfacePort);

  // Read synchronization port
  fscanf(fptr, "%d", &synchronizationPort);

  // Read near and far clipping planes
  fscanf(fptr, "%f %f", &clipNear, &clipFar);

  // Assign all clipping planes
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    _clippingPlanes[i][0] = clipNear;
    _clippingPlanes[i][1] = clipFar;
  }

  // Read total display size
  fscanf(fptr, "%d %d", &_totalDisplayWidth, &_totalDisplayHeight);

  // Read vertical field of view
  fscanf(fptr, "%f", &_vFOV);

  // Read and assign viewport and normalize coordinates for each node
  for (int i = 0 ; i < _numberOfSlaves ; i++) {

    // Read viewport and normalized coordinates
    fscanf(fptr, "%d %d %d %d %f %f %f %f",
           &_viewport[i][0], &_viewport[i][1],
           &_viewport[i][2], &_viewport[i][3],
           &_displayPercentages[i][0], &_displayPercentages[i][1],
           &_displayPercentages[i][2], &_displayPercentages[i][3]);

    // Assign display size based on viewport
    _displaySize[i][0] = _viewport[i][2];
    _displaySize[i][1] = _viewport[i][3];

    // Read and interpret full screen flag
    int flag = 0;
    fscanf(fptr, "%d", &flag);
    if (flag == 0) {
      _fullScreenFlag[i] = false;
    }
    else {
      _fullScreenFlag[i] = true;
    }

  }

  // Read number of datasets in dataset list
  fscanf(fptr, "%d", &_numberOfDatasets);

  // Allocate memory for dataset list dataset file name
  _datasetListFile = new char*[_numberOfDatasets];
  for (int i = 0 ; i < _numberOfDatasets ; i++) {
    _datasetListFile[i] = new char[1024];
  }

  // Allocate memory for dataset list dataset name
  _datasetListName = new char*[_numberOfDatasets];
  for (int i = 0 ; i < _numberOfDatasets ; i++) {
    _datasetListName[i] = new char[1024];
  }

  // Allocate memory for dataset list dataset prefix
  _datasetListPrefix = new char*[_numberOfDatasets];
  for (int i = 0 ; i < _numberOfDatasets ; i++) {
    _datasetListPrefix[i] = new char[1024];
  }

  // Read dataset list
  for (int i = 0 ; i < _numberOfDatasets ; i++) {
    fscanf(fptr, 
           "%s %s %s", 
           _datasetListName[i], 
           _datasetListPrefix[i], 
           _datasetListFile[i]);
  }

  // Close file
  fclose(fptr);


  // Calculate frustums

  // Setup frustum calculator
  FrustumCalculator frustumCalculator;
  frustumCalculator.SetDisplayWidth(_totalDisplayWidth);
  frustumCalculator.SetDisplayHeight(_totalDisplayHeight);
  frustumCalculator.SetNearClippingPlane(clipNear);
  frustumCalculator.SetVerticalFieldOfView(_vFOV);

  // Calculate frustum for each node
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    frustumCalculator.SetPercentage(_displayPercentages[i]);
    frustumCalculator.CalculateFrustum();
    frustumCalculator.GetFrustum(_frustum[i]);
  }

  // Calculate full frustum for entire display
  frustumCalculator.GetFullFrustum(&_totalDisplayFrustum[0],
                                   &_totalDisplayFrustum[1],
                                   &_totalDisplayFrustum[2],
                                   &_totalDisplayFrustum[3]);
  _totalDisplayFrustum[4] = clipNear; 
  _totalDisplayFrustum[5] = clipFar;


  // Initialize and register observer with synchronizer server
  _progressObserver = new SynchronizerServerConcreteCommand(this);
  _synchronizationServer.SetProgressObserver(_progressObserver);
  if (_progressObserver == NULL) {
    fprintf(stderr, 
            "Master: Error creating SynchronizerServerConcreteCommand.\n");
  }

  // Initialize synchronization server
  _synchronizationServer.Init(synchronizationPort);


  // Initialize slaves

  // Get name of master node
  char hostname[128];
  _communicator -> GetMasterNodeName(hostname);

  // Send display size to slaves
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    UpdateDisplaySize(i+1, _displaySize[i][0], _displaySize[i][1],
                      _fullScreenFlag[i], hostname, synchronizationPort,
                      _displayPercentages[i][0], _displayPercentages[i][1],
                      _displayPercentages[i][2], _displayPercentages[i][3]);
    _communicator -> Barrier();
  }

  // Send clipping planes to slaves
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    UpdateClippingPlanes(i+1, _clippingPlanes[i][0], _clippingPlanes[i][1]);  
    _communicator -> Barrier();
  }

  // Send frustums to slaves
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    UpdateFrustum(i+1, _frustum[i][0], _frustum[i][1],
                  _frustum[i][2], _frustum[i][3]);
    _communicator -> Barrier();
  }

  // Send viewports to slaves
  for (int i = 0 ; i < _numberOfSlaves ; i++) {
    UpdateViewport(i+1, _viewport[i][0], _viewport[i][1],
                   _viewport[i][2], _viewport[i][3]);
    _communicator -> Barrier();
  }

  // Turn axis on
  UpdateAxisOn();
  _communicator -> Barrier();

  // Set axis position
  UpdateAxisPosition(_totalDisplayFrustum[0] + 0.5,
                     _totalDisplayFrustum[2] + 0.5,
                     0.0);
  _communicator -> Barrier();

  // Turn on bounding box
  UpdateBoundingBoxOn();
  _communicator -> Barrier();

  // Turn off brick box
  UpdateBrickBoxOff();
  _communicator -> Barrier();

  // Initialize user interface server
  _userInterfaceServer.Init(userInterfacePort);

}
Ejemplo n.º 20
0
void UpdateViewportWithCorrection()
{
	UpdateViewport(s_viewportCorrection);
}
Ejemplo n.º 21
0
void DisplayManager::Move (WebRect *pRect)
{
	DisplayElement::Move(pRect);
	UpdateViewport();
}
Ejemplo n.º 22
0
void DisplayManager::Draw(DISPLAY_INT x, DISPLAY_INT y, WebRect *pViewport, WebGraphics *pGC)
{
	if (mNoRefresh)
	{
		DisplayManager* parentDisplayManager = GetManager();

		if (parentDisplayManager)
		{
			// This handles the case where a DisplayManager that is NOT the root
			//  DisplayManager has a positive refresh lock, prohibiting its being
			//  drawn, but the parent DisplayManager does not (otherwise we would
			//  not even be in our Draw method); in this case:
			//
			// IF this element is within the collective invalid region being
			//    painted, THEN we want to re-invalidate the invalid part of (this),
			//    which will cause said region to re-paint when the refresh lock
			//    is removed from this element and this->Refresh is eventually called.

			WebRect clipRect;
			pGC->GetClip(&clipRect);

			WebRect screenRect(mRect);
			screenRect.MoveTo(x,y);

			if (clipRect.Overlaps(&screenRect))
			{
				SetManagerFlag(MANAGER_FLAG_TRIED_TO_DRAW);
				//screenRect.And(&clipRect);
				//screenRect.Shift(-pViewport->left, -pViewport->top);
				//parentDisplayManager->InvalidateViewportRegion(&screenRect);
			}
		}

		return;
	}

	FormatResult result;

	switch (GetScrollMode())
	{
		case SCROLL_MODE_NONE:
			if (mpVScroll || mpHScroll)
			{
				DetachVScroll();
				DetachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_HSCROLL:
			if (mpVScroll || !mpHScroll)
			{
				DetachVScroll();
				AttachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_VSCROLL:
			if (!mpVScroll || mpHScroll)
			{
				AttachVScroll();
				DetachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_BOTH:
			if (!mpVScroll || !mpHScroll)
			{
				AttachVScroll();
				AttachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_AUTO:
			break;
	}

	if (mRoot.Get())
	{
		int i = 0;

		do
		{
			result = mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));

			if (GetScrollMode() == SCROLL_MODE_AUTO)
			{
				if (result == DISPLAY_FORMAT_NEEDS_VSCROLL)
				{
					// create a vscroll bar
					if (mpVScroll)
					{
						// what the... we already have a vscroll bar!
						break;
					}
					AttachVScroll();

					// check for creation failure - may indicate low memory condition
					if (!mpVScroll)
					{
						// can't go on...
						break;
					}

					UpdateViewport();
				}
				else if (result == DISPLAY_FORMAT_NEEDS_HSCROLL)
				{
					// create a hscroll bar
					if (mpHScroll)
					{
						// what the... we already have a hscroll bar!
						break;
					}
					AttachHScroll();

					// check for creation failure - may indicate low memory condition
					if (!mpHScroll)
					{
						// can't go on...
						break;
					}

					UpdateViewport();
				}
			}
			else
			{
				break;
			}

			// put a hard upper bound on the number of times we try to re-format
			//  (4, since this means we've covered all combinations of horizontal
			//   and vertical scroll bars on the window)
			i++;
		}
		while (result != DISPLAY_FORMAT_SUCCESS && i < 5);

		if (GetScrollMode() == SCROLL_MODE_AUTO)
		{
			WebRect rootBounds;
			GetRootBounds(&rootBounds);

			if (rootBounds.Height() <= mViewRect.Height() && mpVScroll)
			{
				DetachVScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}

			if (rootBounds.Width() <= mViewRect.Width() && mpHScroll)
			{
				DetachHScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}

			if (rootBounds.Height() <= mViewRect.Height() && mpVScroll)
			{
				DetachVScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}
		}

		mViewportChanged = WEBC_FALSE;

		CorrectViewportPosition();

		if (mpFocus && (mpVScroll!=0) && (mpHScroll!=0))
		{
			WebRect focusRect;
			WebRect elemRect;
			WEBC_BOOL ensureFocusVisible = mpFocus->GetFocusRect (&focusRect);
			if (ensureFocusVisible)
			{
				GetElementRect(&elemRect, mpFocus);
				focusRect.Shift(elemRect.left, elemRect.top);

				// this will adjust the scroll bars so that the given rect is in view
				EnsureRectVisible(&focusRect);
			}
		}
	}

	DisplayElement::Draw(x, y, pViewport, pGC);
}
Ejemplo n.º 23
0
void MyPositionController::OnNewViewportRect()
{
  UpdateViewport(kDoNotChangeZoom);
}
Ejemplo n.º 24
0
void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool isNavigable,
                                            ScreenBase const & screen)
{
  m2::PointD const oldPos = GetDrawablePosition();
  double const oldAzimut = GetDrawableAzimut();

  m2::RectD const rect = MercatorBounds::MetresToXY(info.m_longitude, info.m_latitude,
                                                    info.m_horizontalAccuracy);
  // Use FromLatLon instead of rect.Center() since in case of large info.m_horizontalAccuracy
  // there is significant difference between the real location and the estimated one.
  m_position = MercatorBounds::FromLatLon(info.m_latitude, info.m_longitude);
  m_errorRadius = rect.SizeX() * 0.5;

  bool const hasBearing = info.HasBearing();
  if ((isNavigable && hasBearing) ||
      (!isNavigable && hasBearing && info.HasSpeed() && info.m_speed > kMinSpeedThresholdMps))
  {
    SetDirection(my::DegToRad(info.m_bearing));
    m_lastGPSBearing.Reset();
  }

  if (m_listener)
    m_listener->PositionChanged(Position());

  if (m_isPositionAssigned && (!AlmostCurrentPosition(oldPos) || !AlmostCurrentAzimut(oldAzimut)))
  {
    CreateAnim(oldPos, oldAzimut, screen);
    m_isDirtyViewport = true;
  }

  if (m_notFollowAfterPending && m_mode == location::PendingPosition)
  {
    ChangeMode(location::NotFollow);
    if (m_isInRouting)
      m_routingNotFollowTimer.Reset();
    m_notFollowAfterPending = false;
  }
  else if (!m_isPositionAssigned)
  {
    ChangeMode(m_isFirstLaunch ? location::Follow : m_desiredInitMode);
    if (!m_isFirstLaunch || !AnimationSystem::Instance().AnimationExists(Animation::MapPlane))
    {
      if (m_mode == location::Follow)
        ChangeModelView(m_position, kDoNotChangeZoom);
      else if (m_mode == location::FollowAndRotate)
        ChangeModelView(m_position, m_drawDirection,
                        m_isInRouting ? GetRoutingRotationPixelCenter() : m_pixelRect.Center(), kDoNotChangeZoom);
    }
  }
  else if (m_mode == location::PendingPosition || m_mode == location::NotFollowNoPosition)
  {
    if (m_isInRouting)
    {
      ChangeMode(location::FollowAndRotate);
      UpdateViewport(kMaxScaleZoomLevel);
    }
    else
    {
      ChangeMode(location::Follow);
      if (!m_isFirstLaunch)
      {
        if (GetZoomLevel(screen, m_position, m_errorRadius) <= kMaxScaleZoomLevel)
        {
          m2::PointD const size(m_errorRadius, m_errorRadius);
          ChangeModelView(m2::RectD(m_position - size, m_position + size));
        }
        else
        {
          ChangeModelView(m_position, kMaxScaleZoomLevel);
        }
      }
      else
      {
        if (!AnimationSystem::Instance().AnimationExists(Animation::MapPlane))
          ChangeModelView(m_position, kDoNotChangeZoom);
      }
    }
  }

  m_isPositionAssigned = true;
  SetIsVisible(true);

  double const kEps = 1e-5;
  if (fabs(m_lastLocationTimestamp - info.m_timestamp) > kEps)
  {
    m_lastLocationTimestamp = info.m_timestamp;
    m_updateLocationTimer.Reset();
  }
}