psSlotManager::psSlotManager()
{
    isDragging = false;
    isPlacing = false;
    isRotating = false;
    draggingSlot.stackCount = 0;
    last_count = -1;

    // Initialize event shortcuts
    MouseMove = csevMouseMove (psengine->GetEventNameRegistry(), 0);
    MouseDown = csevMouseDown (psengine->GetEventNameRegistry(), 0);
    MouseUp = csevMouseUp (psengine->GetEventNameRegistry(), 0);
    KeyDown = csevKeyboardDown (psengine->GetEventNameRegistry());
    KeyUp = csevKeyboardUp (psengine->GetEventNameRegistry());
}
Esempio n. 2
0
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
PawsManager::PawsManager(iObjectRegistry* object, const char* skin, const char* skinBase,
                         const char* pawsConfigFile) : render2texture(false)
{
    objectReg = object;
    pawsConfig = pawsConfigFile;

    graphics2D = csQueryRegistry<iGraphics2D > ( objectReg );
    graphics3D = csQueryRegistry<iGraphics3D > ( objectReg );
    soundloader =  csQueryRegistry<iSndSysLoader > ( objectReg);
    soundrenderer =  csQueryRegistry<iSndSysRenderer > ( objectReg);
    nameRegistry = csEventNameRegistry::GetRegistry (objectReg);

    // Initialize event shortcuts
    MouseMove = csevMouseMove (nameRegistry, 0);
    MouseDown = csevMouseDown (nameRegistry, 0);
    MouseDoubleClick = csevMouseDoubleClick (nameRegistry, 0);
    MouseUp = csevMouseUp (nameRegistry, 0);
    KeyboardDown = csevKeyboardDown (objectReg);
    KeyboardUp = csevKeyboardUp (objectReg);

    vfs =  csQueryRegistry<iVFS > ( objectReg);
    xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem);
    csRef<iConfigManager> cfg =  csQueryRegistry<iConfigManager> (objectReg);

    float screenWidth = cfg->GetFloat( "Video.ScreenWidth", 800.0f );
    float screenHeight = cfg->GetFloat( "Video.ScreenHeight", 600.0f );
    fontFactor = min(( screenWidth  / 800.0f ), ( screenHeight /  600.0f ));

    RegisterFactories();

    mainWidget = new pawsMainWidget();

    textureManager = new pawsTextureManager( objectReg );

    prefs = new pawsPrefManager();

    csString prefsFile = cfg->GetStr("PlaneShift.GUI.PrefsFile", "/this/data/prefs.xml");
    csString borderFile = cfg->GetStr("PlaneShift.GUI.BorderFile", "/this/data/gui/borderlist.xml");

    styles = new pawsStyles( objectReg );

    if(!LoadSkinDefinition(skin))
    {
        Error2("Failed to load skin %s!", skin);
        exit(1);
    }

    // now load standard styles for anything else
    if (!styles->LoadStyles("/this/data/gui/styles.xml"))
    {
        Error1("Failed to load PAWS styles, all style application attempts will be ignored");
        delete styles;
        styles = NULL;
    }

    // Mount base skin to satisfy unskinned elements
    if(skinBase)
    {
        if(!LoadSkinDefinition(skinBase))
        {
            Error2("Couldn't load base skin '%s'!\n", skinBase);
        }
    }

    if ( !prefs->LoadPrefFile( prefsFile ) )
        Error2("Failed to load prefsFile '%s'", prefsFile.GetData());
    if ( !prefs->LoadBorderFile( borderFile ) )
        Error2("Failed to load borderFile '%s'", borderFile.GetData());


    mouse = new pawsMouse();
    mouse->ChangeImage("Standard Mouse Pointer");

    resizeImg = textureManager->GetPawsImage("ResizeBox");

    graphics2D->SetMouseCursor( csmcNone );

    currentFocusedWidget = mainWidget;
    movingWidget         = 0;
    focusOverridesControls = false;

    resizingWidget       = 0;
    resizingFlags        = 0;

    modalWidget = 0;
    mouseoverWidget = 0;
    lastfadeWidget = 0;

    assert(cfg);
    csString lang = cfg->GetStr("PlaneShift.GUI.Language", "");
    localization = new psLocalization();
    localization->Initialize(objectReg);
    localization->SetLanguage(lang);

    tipDelay = cfg->GetInt("PlaneShift.GUI.ToolTipDelay", 250);

    hadKeyDown = false;
    dragDropWidget = NULL;
    useSounds = true;
    volume = 1.0;

    soundStatus = false;
    timeOver = 0;

    // Init render texture.
    csRef<iTextureManager> texman = graphics3D->GetTextureManager();
    guiTexture = texman->CreateTexture(graphics3D->GetWidth(), graphics3D->GetHeight(),
      csimg2D, "rgba8", 0x9);
    if(guiTexture.IsValid())
        guiTexture->SetAlphaType (csAlphaMode::alphaBinary);
    else
	render2texture = false;
}
Esempio n. 3
0
int main (int argc, char *argv[])
{
  G2DTestSystemDriver System (argc, argv);
  Sys = &System;
  iObjectRegistry* object_reg = System.object_reg;

  if (!csInitializer::SetupEventHandler (object_reg, G2DEventHandler))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.g2dtest",
        "Unable to init app!");
    return false;
  }

  // Check for commandline help.
  if (csCommandLineHelper::CheckHelp (object_reg))
  {
    csCommandLineHelper::Help (object_reg);
    exit (0);
  }

  csRef<iPluginManager> plugin_mgr (
  	csQueryRegistry<iPluginManager> (object_reg));
  csRef<iCommandLineParser> cmdline (
  	csQueryRegistry<iCommandLineParser> (object_reg));

  System.myG3D = csQueryRegistry<iGraphics3D> (object_reg);
  // Now load the renderer plugin
  if (!System.myG3D)
  {
    csString canvas = cmdline->GetOption ("video");
    if (!canvas || !*canvas)
      canvas = "crystalspace.graphics3d.opengl";
    else if (strncmp ("crystalspace.", canvas, 13))
    {
      canvas = "crystalspace.graphics3d." + canvas;
    }
    System.myG3D = csLoadPlugin<iGraphics3D> (plugin_mgr, canvas);
    if (!object_reg->Register (System.myG3D, "iGraphics3D"))
    {
      csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	  "crystalspace.application.g2dtest",
	  "Unable to register renderer!");
      return -1;
    }
  }

  if (!System.myG3D)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.g2dtest",
	"Unable to load canvas driver!");
    return -1;
  }
  System.myG2D = System.myG3D->GetDriver2D ();
    
  System.SystemOpen = csevSystemOpen (object_reg);
  System.KeyboardDown = csevKeyboardDown (object_reg);
  System.Frame = csevFrame (object_reg);
  System.CanvasResize = csevCanvasResize (object_reg, System.myG2D);

  System.framePrinter.AttachNew (new FramePrinter (object_reg));

  if (!csInitializer::OpenApplication (object_reg))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.g2dtest",
        "Unable to open drivers!");
    return -1;
  }
  
  System.cursorPlugin = csQueryRegistry<iCursor> (object_reg);
  if (System.cursorPlugin)
  {
    csRef<iConfigManager> cfg (csQueryRegistry<iConfigManager> (object_reg));
    if (System.cursorPlugin->Setup (System.myG3D))
    {
      System.cursorPlugin->ParseConfigFile ((iConfigManager*)cfg);
    }
    else
      System.cursorPlugin = 0;
  }

  iNativeWindow* nw = System.myG2D->GetNativeWindow ();
  if (nw) nw->SetTitle (APP_TITLE);

  csDefaultRunLoop(object_reg);

  System.myG2D = 0;
  System.myG3D->Close();
  System.myG3D = 0;
  plugin_mgr = 0;
  cmdline = 0;

  return 0;
}
Esempio n. 4
0
bool csWaterDemo::Initialize ()
{
  if (!csInitializer::SetupConfigManager (object_reg, 
    "/config/waterdemo.cfg"))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, 
      "crystalspace.application.waterdemo",
      "Failed to initialize config!");
    return false;
  }

  if (!csInitializer::RequestPlugins (object_reg,
  	CS_REQUEST_VFS,
        CS_REQUEST_PLUGIN ("crystalspace.graphics3d.opengl", iGraphics3D),
        CS_REQUEST_ENGINE,
	CS_REQUEST_IMAGELOADER,
	CS_REQUEST_FONTSERVER,
	CS_REQUEST_REPORTER,
	CS_REQUEST_REPORTERLISTENER,
        CS_REQUEST_CONSOLEOUT,
        CS_REQUEST_LEVELLOADER,
 	CS_REQUEST_END))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
	"Can't initialize plugins!");
    return false;
  }

  FocusGained = csevFocusGained (object_reg);
  FocusLost = csevFocusLost (object_reg);
  Frame = csevFrame (object_reg);
  KeyboardDown = csevKeyboardDown (object_reg);

  if (!csInitializer::SetupEventHandler (object_reg, SimpleEventHandler))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
	"Can't initialize event handler!");
    return false;
  }

  // Check for commandline help.
  if (csCommandLineHelper::CheckHelp (object_reg))
  {
    csCommandLineHelper::Help (object_reg);
    return false;
  }

  vc = csQueryRegistry<iVirtualClock> (object_reg);
  if (vc == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iVirtualClock plugin!");
    return false;
  }

  vfs = csQueryRegistry<iVFS> (object_reg);
  if (vfs == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iVFS plugin!");
    return false;
  }

  r3d = csQueryRegistry<iGraphics3D> (object_reg);
  if (r3d == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iGraphics3D plugin!");
    return false;
  }

  font = r3d->GetDriver2D ()->GetFontServer()->LoadFont(CSFONT_LARGE);

  engine = csQueryRegistry<iEngine> (object_reg);
  if (engine == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iEngine plugin!");
    return false;
  }

  kbd = csQueryRegistry<iKeyboardDriver> (object_reg);
  if (kbd == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iKeyboardDriver plugin!");
    return false;
  }

  mouse = csQueryRegistry<iMouseDriver> (object_reg);
  if (mouse == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iMouseDriver plugin!");
    return false;
  }

  csRef<iLoader> loader = csQueryRegistry<iLoader> (object_reg);
  if (loader == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"No iLoader plugin!");
    return false;
  }

  vfs->ChDir ("/tmp");
  
  console = csQueryRegistry<iConsoleOutput> (object_reg);

  // Open the main system. This will open all the previously loaded plug-ins.
  if (!csInitializer::OpenApplication (object_reg))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.waterdemo",
    	"Error opening system!");
    return false;
  }

  csRef<iSector> room = engine->CreateSector ("room");

  view = csPtr<iView> (new csView (engine, r3d));
  view->GetCamera ()->SetSector (room);
  view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 5, 0));
  view->GetCamera ()->GetTransform ().LookAt (csVector3(5,-5,20), csVector3(0,1,0));
  csRef<iGraphics2D> g2d = r3d->GetDriver2D ();
  view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());

  bool hasAccel;
  if (g2d->PerformExtension ("hardware_accelerated", &hasAccel))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY,
      "crystalspace.application.waterdemo",
      "Hardware acceleration %s.\n",
      hasAccel ? "present" : "not present");
  }
  else
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY,
      "crystalspace.application.waterdemo",
      "Hardware acceleration check not available.\n");
  }

  r3d->GetDriver2D ()->SetMouseCursor( csmcNone );

  csRef<iPluginManager> plugin_mgr (
    csQueryRegistry<iPluginManager> (object_reg));

  csRef<iStringSet> strings = 
    csQueryRegistryTagInterface<iStringSet> 
    (object_reg, "crystalspace.shared.stringset");

  csRef<iShaderVarStringSet> stringsSvName = 
    csQueryRegistryTagInterface<iShaderVarStringSet> 
    (object_reg, "crystalspace.shader.variablenameset");

  //get a custom renderloop
  csRef<iRenderLoop> rl = engine->GetRenderLoopManager ()->Create ();
  
  csRef<iRenderStepType> genType = csLoadPlugin<iRenderStepType> (
    plugin_mgr, "crystalspace.renderloop.step.generic.type");

  csRef<iRenderStepFactory> genFact = genType->NewFactory ();

  csRef<iRenderStep> step;
  csRef<iGenericRenderStep> genStep;

  step = genFact->Create ();
  rl->AddStep (step);
  genStep = scfQueryInterface<iGenericRenderStep> (step);

  genStep->SetShaderType ("general");
  genStep->SetZBufMode (CS_ZBUF_USE);
  genStep->SetZOffset (false);

  engine->GetRenderLoopManager ()->Register ("waterdemoRL", rl);
  engine->SetCurrentDefaultRenderloop (rl);

  // Load in lighting shaders
  csRef<iVFS> vfs (csQueryRegistry<iVFS> (object_reg));
  csRef<iFile> shaderFile = vfs->Open ("/shader/water.xml", VFS_FILE_READ);

  csRef<iDocumentSystem> docsys (
    csQueryRegistry<iDocumentSystem> (object_reg));
  csRef<iDocument> shaderDoc = docsys->CreateDocument ();
  shaderDoc->Parse (shaderFile, true);

  csRef<iShader> shader;
  csRef<iShaderManager> shmgr (csQueryRegistry<iShaderManager> (object_reg));
  csRef<iShaderCompiler> shcom (shmgr->GetCompiler ("XMLShader"));
  csRef<iLoaderContext> ldr_context = engine->CreateLoaderContext ();
  shader = shcom->CompileShader (ldr_context,
      shaderDoc->GetRoot ()->GetNode ("shader"));

  // setup the mesh 
  csRef<iMeshObjectType> gType = csLoadPluginCheck<iMeshObjectType> (
  	plugin_mgr, "crystalspace.mesh.object.genmesh");
  
  if (!gType)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.waterdemo",
        "Error loading genmesh baseobject!");
    return false;
  }

  
  gFact = gType->NewFactory ();
  csRef<iMeshFactoryWrapper> fw = engine->CreateMeshFactory (gFact, "waterFactory");
  gFactState = scfQueryInterface<iGeneralFactoryState> (gFact);

  gMesh = gFact->NewInstance ();
  gMeshState = scfQueryInterface<iGeneralMeshState> (gMesh);
  gMeshState->SetShadowCasting (false);
  gMeshState->SetShadowReceiving (false);

  //setup a wrapper too
  gMeshW = engine->CreateMeshWrapper (gMesh, "water", room);
  csMatrix3 m;
  m.Identity ();
  gMeshW->GetMovable ()->SetTransform (m);
  gMeshW->GetMovable ()->SetPosition (csVector3(0,-5,0));
  gMeshW->GetMovable ()->UpdateMove ();
  
  //setup a material
  csRef<iMaterial> mat = engine->CreateBaseMaterial (0);

  mat->SetShader (strings->Request ("general"), shader);

  csRef<iMaterialWrapper> matW = engine->GetMaterialList ()->NewMaterial (mat,
  	"waterMaterial");


  csRef<csImageCubeMapMaker> cubeMaker;
  cubeMaker.AttachNew (new csImageCubeMapMaker ());

  csRef<iImage> img = loader->LoadImage ("/lib/cubemap/cubemap_rt.jpg");
  cubeMaker->SetSubImage (0, img);
  img = loader->LoadImage ("/lib/cubemap/cubemap_lf.jpg");
  cubeMaker->SetSubImage (1, img);

  img = loader->LoadImage ("/lib/cubemap/cubemap_up.jpg");
  cubeMaker->SetSubImage (2, img);
  img = loader->LoadImage ("/lib/cubemap/cubemap_dn.jpg");
  cubeMaker->SetSubImage (3, img);

  img = loader->LoadImage ("/lib/cubemap/cubemap_fr.jpg");
  cubeMaker->SetSubImage (4, img);
  img = loader->LoadImage ("/lib/cubemap/cubemap_bk.jpg");
  cubeMaker->SetSubImage (5, img);


  csRef<iTextureHandle> tex = r3d->GetTextureManager ()->RegisterTexture (
    cubeMaker, CS_TEXTURE_3D | CS_TEXTURE_CLAMP | CS_TEXTURE_NOMIPMAPS);

  csRef<csShaderVariable> attvar (csPtr<csShaderVariable> (
    new csShaderVariable (stringsSvName->Request ("tex diffuse"))));
  attvar->SetValue (tex);
  mat->AddVariable (attvar);  


  gMesh->SetMaterialWrapper (matW);
  
  Width = Height = 64;

  water = new float[Width*Height];
  water1 = new float[Width*Height];
  water2 = new float[Width*Height];

  memset(water,0,Width*Height*sizeof(float));
  memset(water1,0,Width*Height*sizeof(float));
  memset(water2,0,Width*Height*sizeof(float));

  WaveSpeed = 0.3f;
  WaveLife = 0.1f;
  GridSize = 0.25f;
  TimeDelta = 0.12f;


  //setup the mesh
  gFactState->SetVertexCount (Width*Height);
  gFactState->SetTriangleCount (2*((Width-1)*(Height-1)));

  //setup ibuf
  int x, z, cnt=0,idx;
  csTriangle *ibuf=gFactState->GetTriangles ();
  for(x=0;x<(Height-1);x++)
  {
    for(z=0;z<(Width-1);z++)
    {
      idx = 2*(x*(Width-1)+z);
      ibuf[idx].a = x*Width+z;
      ibuf[idx].b = x*Width+z+1;
      ibuf[idx].c = (x+1)*Width+z;
      idx++;
      ibuf[idx].a = x*Width+z+1;
      ibuf[idx].b = (x+1)*Width+(z+1);
      ibuf[idx].c = (x+1)*Width+z;
    }
  }

  //setup our vbuf
  csVector3 *vbuf = gFactState->GetVertices ();
  cnt=0;
  for(x=0;x<Height;x++)
  {
    for(z=0;z<Width;z++)
    {
      idx = x*Width+z;
      vbuf[idx].x = x*GridSize;
      vbuf[idx].y = water[idx];
      vbuf[idx].z = z*GridSize;
    }
  }

  //setup texture
  csVector2 *tbuf = gFactState->GetTexels ();
  for(x=0;x<Height;x++)
  {
    for(z=0;z<Width;z++)
    {
      idx = x*Width+z;
      tbuf[idx].x = (float)x/(float)Height;
      tbuf[idx].y = (float)z/(float)Width;
    }
  }

  lastSimTime = nextSimTime = 0.0f;

  gFactState->Invalidate ();

  engine->Prepare ();

  console->SetVisible (false);
  hasfocus = true;
  int w = r3d->GetDriver2D ()->GetWidth()/2;
  int h = r3d->GetDriver2D ()->GetHeight()/2;
  r3d->GetDriver2D ()->SetMousePosition (w, h);

  printer.AttachNew (new FramePrinter (object_reg));

  return true;
}