NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetContentDisposition(nsAString& aCD)
{
    nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetDefaultView();
    if (NS_WARN_IF(!window)) {
        aCD.SetIsVoid(true);
        return NS_OK;
    }
    nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
    if (NS_WARN_IF(!utils)) {
        aCD.SetIsVoid(true);
        return NS_OK;
    }
    nsresult rv = utils->GetDocumentMetadata(
        NS_LITERAL_STRING("content-disposition"), aCD);
    if (NS_WARN_IF(NS_FAILED(rv))) {
        aCD.SetIsVoid(true);
    }
    return NS_OK;
}
already_AddRefed<nsISHEntry>
WebBrowserPersistLocalDocument::GetHistory()
{
    nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetDefaultView();
    if (NS_WARN_IF(!window)) {
        return nullptr;
    }
    nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
    if (NS_WARN_IF(!webNav)) {
        return nullptr;
    }
    nsCOMPtr<nsIWebPageDescriptor> desc = do_QueryInterface(webNav);
    if (NS_WARN_IF(!desc)) {
        return nullptr;
    }
    nsCOMPtr<nsISupports> curDesc;
    nsresult rv = desc->GetCurrentDescriptor(getter_AddRefs(curDesc));
    // This can fail if, e.g., the document is a Print Preview.
    if (NS_FAILED(rv) || NS_WARN_IF(!curDesc)) {
        return nullptr;
    }
    nsCOMPtr<nsISHEntry> history = do_QueryInterface(curDesc);
    return history.forget();
}
Ejemplo n.º 3
0
int main( int argc, const char *argv[] )
{
  // reads model into global glb_model;
  ON::Begin();

  ON_TextLog error_log;

  ON_BOOL32 bOK;
  int window_width  = 500;
  int window_height = 500;
  //double port_aspect = ((double)window_width)/((double)window_height);

  // read the file into model
  if ( argc != 2 ) {
    printf("Syntax: %s filename.3dm\n",argv[0] );
    return 0;
  }
  const char* sFileName = argv[1];
  printf("\nFile:  %s\n", sFileName );

  // read the file
  CModel model;
  if ( !model.Read( sFileName, &error_log ) )
  {
    // read failed
    error_log.Print("Unable to read file %s\n",sFileName);
    return 1;
  }

  glb_model = &model;

  // set bbox = world bounding box of all the objects
  model.m_bbox = model.BoundingBox();
  if ( !model.m_bbox.IsValid() )
  {
    // nothing to look at in this model
    return 2;
  }

  // set model.m_view
  if ( model.m_settings.m_views.Count() > 0 )
  {
    // use first viewport projection in file
    double angle;
    model.m_view.m_vp = model.m_settings.m_views[0].m_vp;
    model.m_view.m_target = model.m_settings.m_views[0].m_target;
    model.m_view.m_vp.GetCameraAngle( &angle );
    model.m_view.m_vp.Extents( angle, model.m_bbox );
  }
  else 
  {
    GetDefaultView( model.m_bbox, model.m_view );
  }

  // If needed, enlarge frustum so its aspect matches the window's aspect.
  // Since the Rhino file does not store the far frustum distance in the
  // file, viewports read from a Rhil file need to have the frustum's far
  // value set by inspecting the bounding box of the geometry to be
  // displayed.

  
  ///////////////////////////////////////////////////////////////////
  //
  // GL stuff starts here
  //
  for(;;) {  
    
#if defined(ON_EXAMPLE_GL_USE_GLAUX)
    wchar_t sWindowTitleString[256];
#endif
#if defined(ON_EXAMPLE_GL_USE_GLUT)
    char sWindowTitleString[256];
#endif
    sWindowTitleString[255] = 0;
    if ( argv[0] && argv[0][0] )
    {
      int i;
      for ( i = 0; i < 254 && argv[0][i]; i++ )
        sWindowTitleString[i] = argv[0][i];
      sWindowTitleString[i] = 0;
    }

#if defined(ON_EXAMPLE_GL_USE_GLAUX)
    auxInitPosition( 0, 0, window_width, window_height );
    auxInitDisplayMode( AUX_SINGLE | AUX_RGB | AUX_DEPTH );
    auxInitWindow( sWindowTitleString );

    // register event handler functions
    auxIdleFunc( 0 );
    auxReshapeFunc( myGLAUX_Reshape );
    auxMouseFunc( AUX_LEFTBUTTON,   AUX_MOUSEDOWN, myGLAUX_MouseLeftEvent );
    auxMouseFunc( AUX_LEFTBUTTON,   AUX_MOUSEUP,   myGLAUX_MouseLeftEvent );
    auxMouseFunc( AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, myGLAUX_MouseMiddleEvent );
    auxMouseFunc( AUX_MIDDLEBUTTON, AUX_MOUSEUP,   myGLAUX_MouseMiddleEvent );
    auxMouseFunc( AUX_RIGHTBUTTON,  AUX_MOUSEDOWN, myGLAUX_MouseRightEvent );
    auxMouseFunc( AUX_RIGHTBUTTON,  AUX_MOUSEUP,   myGLAUX_MouseRightEvent );
    auxKeyFunc( AUX_LEFT,  myKeyLeftArrowEvent );
    auxKeyFunc( AUX_RIGHT, myKeyRightArrowEvent );
    auxKeyFunc( AUX_UP,    myKeyUpArrowEvent );
    auxKeyFunc( AUX_DOWN,  myKeyDownArrowEvent );
    auxKeyFunc( AUX_E,  myKeyViewExtents );
    auxKeyFunc( AUX_e,  myKeyViewExtents );
    auxKeyFunc( AUX_Z,  myKeyViewExtents );
    auxKeyFunc( AUX_z,  myKeyViewExtents );
#endif

#if defined(ON_EXAMPLE_GL_USE_GLUT)
    glutInit(&argc,(char**)argv);
    glutInitWindowPosition( 0, 0);
    glutInitWindowSize( window_width, window_height );
    glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( sWindowTitleString );

    // register event handler functions
    glutIdleFunc( 0 );
    glutReshapeFunc( myGLUT_Reshape );
    glutMouseFunc( myGLUT_MouseEvent );
    glutKeyboardFunc( myGLUT_KeyboardEvent );
    glutSpecialFunc( myGLUT_SpecialKeyEvent );
    glutDisplayFunc( myDisplay );
#endif

    // setup model view matrix, GL defaults, and the GL NURBS renderer
    GLUnurbsObj* pTheGLNURBSRender = NULL; // OpenGL NURBS rendering context
    bOK = myInitGL( model.m_view.m_vp, pTheGLNURBSRender );

    if ( bOK ) {
      // build display list
      myBuildDisplayList( glb_display_list_number,
                          pTheGLNURBSRender,
                          model );

      // look at it
#if defined(ON_EXAMPLE_GL_USE_GLAUX)
      auxMainLoop( myDisplay );
#endif

#if defined(ON_EXAMPLE_GL_USE_GLUT)
      glutMainLoop(  );
#endif

    }

    gluDeleteNurbsRenderer( pTheGLNURBSRender );

    break;
  }

  //
  // GL stuff ends here
  //
  ///////////////////////////////////////////////////////////////////

  ON::End();

  return 0;
}
Ejemplo n.º 4
0
    void BacteroidsState::Render()
    {
        Renderer &renderer = GetRenderer();
        renderer.SetTime(m_time.GetTimeMicros());

        renderer.SetView(m_playView);

        renderer.BindColorShader();
        renderer.SetColor(Color(0.05f, 0.13f, 0.15f));
        renderer.DrawFilledRectangle(PLAY_AREA_LEFT, PLAY_AREA_BOTTOM, PLAY_AREA_RIGHT, PLAY_AREA_TOP);

        for (size_t_32 i = 0; i < m_objects.Size(); i++)
        {
            GameObject *obj = m_objects[i];

            vec2f p = obj->GetPosition();
            float r = obj->GetRadius() * 1.1f;

            if ((p.x > PLAY_AREA_LEFT - r && p.x < PLAY_AREA_RIGHT + r &&
                 p.y > PLAY_AREA_BOTTOM - r && p.y < PLAY_AREA_TOP + r) == false)
            {
                continue;
            }

            renderer.BindShader(obj->GetShader());

            const vec2f vel2 = obj->GetVelocity();
            const vec4f velocity(vel2.x, vel2.y, 0.0f, 0.0f);
            renderer.GetGraphics()->SetUniform(m_uniforms.m_velocity, velocity);
            obj->Render(&renderer, m_uniforms);
        }

        renderer.BindColorShader();
        m_damageFade.Render(&renderer);
        m_pauseFade.Render(&renderer);


        renderer.SetView(GetDefaultView());

        if (m_time.IsPaused())
        {
            RenderPause();
        }
        else if (m_player.IsDead())
        {
            RenderGameOver();
        }

        {
            TextLayout layout(renderer, 0.0f, 0.0f);

            renderer.BindFontShader();
            renderer.SetColor(Color(1.0f, 1.0f, 1.0f));
            renderer.SetFontScale(1.0f);

            char buf[64];
            StringPrintF(buf, "Score: %i", m_score);
            layout.AddText(buf, 0.0f);
            layout.AddLine();

            StringPrintF(buf, "Kills: %i", m_kills);
            layout.AddText(buf, 0.0f);
            layout.AddLine();

            const float ptPerKill = (m_kills) ? (m_score / float(m_kills)) : 0;
            StringPrintF(buf, "pt per kill: %.1f", ptPerKill);
            layout.AddText(buf, 0.0f);
            layout.AddLine();

            const float hx = 10.0f;
            const float hy = layout.m_cursor.y + 10.0f;

            renderer.BindColorShader();
            renderer.SetColor(Color(0.5f, 0.5f, 0.5f));
            renderer.DrawFilledRectangle(hx, hy, hx + 100.0f, hy + 10.0f);
            renderer.SetColor(Color(0.85f, 0.05f, 0.05f));
            renderer.DrawFilledRectangle(hx, hy, hx + m_player.GetHealth(), hy + 10.0f);
        }

        {
            const Viewport vp = renderer.GetView().m_viewport;

            TextLayout layout(renderer, 0.0f, vp.h);

            renderer.BindFontShader();
            renderer.SetColor(Color(1.0f, 1.0f, 1.0f));
            renderer.SetFontScale(1.0f);

            char buf[64];
            StringPrintF(buf, "[M] - Muted: %s", GetAudio().IsMuted() ? "yes" : "no");
            layout.AddLines(-1);
            layout.AddText(buf, 0.0f);
        }
    }