Example #1
0
void IrrlichtWidget::buildIrrlichtScene(){
    scene::ISceneManager* manager = mDevice->getSceneManager();
    mDevice->setWindowCaption(L"Hello World!");

    scene::IAnimatedMesh* mesh = manager->getMesh("./media/sydney.md2");
    if(mesh == NULL){
        return;
    }
    scene::IAnimatedMeshSceneNode* node = manager->addAnimatedMeshSceneNode(mesh);
    if(node !=NULL){
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture(0, mDriver->getTexture("./media/sydney.bmp"));
    }
    manager->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

    IGUIEnvironment* guienv = mDevice->getGUIEnvironment();
    gui::IGUIListBox* box = guienv->addListBox(core::rect<int>(10,10,220,120));
    box->addItem(L"OpenGL 1.5");
    box->addItem(L"Direct3D 8.1");
    box->addItem(L"Direct3D 9.0c");
    box->addItem(L"Burning's Video 0.47");
    box->addItem(L"Irrlicht Software Renderer 1.0");
    box->setSelected(true);


    m_pTimer = new QTimer(this);
    connect(m_pTimer, SIGNAL(timeout()), this, SLOT(drawIrrlichtScene()));
    m_pTimer->start(5);

}
Example #2
0
TextureDialog::TextureDialog(EditorState *pstate, Node *pnode, CubeSide pface):
    Dialog(pstate),
    node(pnode),
    face(pface),
    lb(NULL),
    the_image(NULL),
    context(NULL)
{
    IVideoDriver *driver = state->device->getVideoDriver();
    IGUIEnvironment *guienv = state->device->getGUIEnvironment();

    // Window and basic items
    win = guienv->addWindow(rect<s32>(340, 50, 340 + 74 * 3 + 10, 50 + 74 * 3 + 10), true,
                            narrow_to_wide(std::string(getCubeSideName(face)) + " texture").c_str());
    guienv->addButton(rect<s32>(155, 30, 74*3, 55), win, ETD_GUI_ID_APPLY,   L"Apply",  L"Apply this texture selection to the node face");
    guienv->addButton(rect<s32>(155, 60, 74*3, 85), win, ETD_GUI_ID_IMPORT,  L"Import", L"Import images from files");
    guienv->addButton(rect<s32>(84,  60, 150,  85), win, ETD_GUI_ID_ACTIONS, L"Actions");

    // Fill out listbox
    lb = guienv->addListBox(rect<s32>(10, 104, 74 * 3, 74 * 3), win, 502);
    Media *media = &state->project->media;
    std::map<std::string, Media::Image*>& images = media->getList();
    int count = 1;
    lb->addItem(L"");
    lb->setSelected(0);
    for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
            it != images.end();
            ++it) {
        if (!it->second) {
            continue;
        }
        if (it->second->name == "default") {
            lb->addItem(L"");
        } else {
            lb->addItem(narrow_to_wide(it->second->name + " [used " +
                                       num_to_str(it->second->getHolders()) + " times]").c_str());
        }
        if (it->second == node->getTexture(face))
            lb->setSelected(count);
        count++;
    }

    Media::Image *image = node->getTexture(face);
    if (image) {
        the_image = driver->addTexture("tmpicon.png", image->get());
    }

    // Context menu
    context = guienv->addContextMenu(rect<s32>(84, 85, 150, 180), win, ETD_GUI_ID_ACTIONS_CM);
    context->addItem(L"Export", ETD_GUI_ID_EXPORT);
    context->setCloseHandling(ECMC_HIDE);
    context->setVisible(false);
    context->setEventParent(win);
}
void NBEditor::load()
{
	IGUIStaticText* sidebar = state->menu->sidebar;
	IGUIEnvironment* guienv = state->device->getGUIEnvironment();

	if (sidebar) {
		sidebar->setText(L"Node Box Tool");
		IGUIStaticText* t = guienv->addStaticText(L"No node selected",
				rect<s32>(20, 30, 140, 100),
				false, true, sidebar, ENB_GUI_MAIN_MSG);
		
		IGUIListBox* lb = guienv->addListBox(rect<s32>(20, 30, 230, 128),
				sidebar, ENB_GUI_MAIN_LISTBOX, true);

		if (lb) {
			lb->setVisible(false);
			IGUIButton* b1 = guienv->addButton(rect<s32>(0, 100, 50, 125),
					lb, GUI_PROJ_NEW_BOX, L"+", L"Add a node box");
			IGUIButton* b2 = guienv->addButton(rect<s32>(60, 100, 110,125),
					lb, GUI_PROJ_DELETE_BOX, L"-", L"Delete node box");
			b1->setNotClipped(true);
			b2->setNotClipped(true);
		}

		// Create nodebox properties
		t = guienv->addStaticText(L"Properties",
				rect<s32>(0, 170, 120, 190),
				false, true, sidebar, ENB_GUI_PROP);
		t->setVisible(false);

		// Add name properties box
		guienv->addStaticText(L"Name:", rect<s32>(10, 30, 50, 50), false,
				true, t)->setNotClipped(true);
		guienv->addEditBox(L"", rect<s32>(60, 30, 210, 50), true,
				t, ENB_GUI_PROP_NAME)->setNotClipped(true);

		// Add positioning
		addXYZ(t, guienv, vector2di(10, 60),  ENB_GUI_PROP_X1);
		addXYZ(t, guienv, vector2di(10, 160), ENB_GUI_PROP_X2); // 60

		// Add buttons
		guienv->addButton(rect<s32>(30, 250, 100, 280), t, ENB_GUI_PROP_UPDATE,
				L"Update", L"")->setNotClipped(true);
		guienv->addButton(rect<s32>(110, 250, 180, 280), t, ENB_GUI_PROP_REVERT,
				L"Revert", L"")->setNotClipped(true);
	}
	load_ui();
}
Example #4
0
void NBEditor::load(){
	IGUIStaticText* sidebar = GetState()->Menu()->GetSideBar();
	IGUIEnvironment* guienv = GetState()->GetDevice()->getGUIEnvironment();
	sidebar->setText(L"Node boxes");
	IGUIStaticText* t = guienv->addStaticText(L"No node selected",rect<s32>(20,30,140,100),false,true,sidebar,GUI_SIDEBAR_LABEL);
	
	if (t)
		t->setVisible(false);
	
	IGUIListBox* lb = guienv->addListBox(rect<s32>(20,30,230,128),sidebar,GUI_SIDEBAR_LISTBOX,true);

	if (lb){
		lb->setVisible(false);
		IGUIButton* b = guienv->addButton(rect<s32>(20-20,130-30,70-20,155-30),lb,GUI_PROJ_NEW_BOX,L"+",L"Add a node box");
		IGUIButton* c = guienv->addButton(rect<s32>(80-20,130-30,130-20,155-30),lb,GUI_PROJ_DELETE_BOX,L"-",L"Delete node box");
		b->setNotClipped(true);
		c->setNotClipped(true);
	}

	load_ui();
}
Example #5
0
/*
OK, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example.
*/
int main()
{


	// create device and exit if creation failed
	IrrlichtDevice * device = createDevice(EDT_OPENGL,core::dimension2d<u32>(640, 480));

	if (device == 0)
		return 1; // could not create selected driver.

	/* The creation was successful, now we set the event receiver and
		store pointers to the driver and to the gui environment. */

	device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
	device->setResizable(true);

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	const io::path mediaPath = getExampleMediaPath();

	/*
	To make the font a little bit nicer, we load an external font
	and set it as the new default font in the skin.
	To keep the standard font for tool tip text, we set it to
	the built-in font.
	*/

	IGUISkin* skin = env->getSkin();
	IGUIFont* font = env->getFont(mediaPath + "fonthaettenschweiler.bmp");
	if (font)
		skin->setFont(font);

	skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);

	/*
	We add three buttons. The first one closes the engine. The second
	creates a window and the third opens a file open dialog. The third
	parameter is the id of the button, with which we can easily identify
	the button in the event receiver.
	*/

	env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
			L"Quit", L"Exits Program");
	env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
			L"New Window", L"Launches a new Window");
	env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
			L"File Open", L"Opens a file");

	/*
	Now, we add a static text and a scrollbar, which modifies the
	transparency of all gui elements. We set the maximum value of
	the scrollbar to 255, because that's the maximal value for
	a color value.
	Then we create an other static text and a list box.
	*/

	env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
	IGUIScrollBar* scrollbar = env->addScrollBar(true,
			rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
	scrollbar->setMax(255);
	scrollbar->setPos(255);
	setSkinTransparency( scrollbar->getPos(), env->getSkin());

	// set scrollbar position to alpha value of an arbitrary element
	scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha());

	env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true);
	IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210));
	env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));

	// Store the appropriate data in a context structure.
	SAppContext context;
	context.device = device;
	context.counter = 0;
	context.listbox = listbox;

	// Then create the event receiver, giving it that context structure.
	MyEventReceiver receiver(context);

	// And tell the device to use our custom event receiver.
	device->setEventReceiver(&receiver);


	/*
	And at last, we create a nice Irrlicht Engine logo in the top left corner.
	*/
	env->addImage(driver->getTexture(mediaPath + "irrlichtlogo2.png"),
			position2d<int>(10,10));


	/*
	That's all, we only have to draw everything.
	*/
  fluid_settings_t* settings;
//  int arg1 = 1;
  char buf[512];
//  int c, i;
  int interactive = 1;
  int midi_in = 1;
  fluid_player_t* player = NULL;
  fluid_midi_router_t* router = NULL;
  //fluid_sequencer_t* sequencer = NULL;
  fluid_midi_driver_t* mdriver = NULL;
  fluid_audio_driver_t* adriver = NULL;
  fluid_synth_t* synth = NULL;
#ifdef NETWORK_SUPPORT
  fluid_server_t* server = NULL;
  int with_server = 0;
#endif
  char* config_file = NULL;
  int audio_groups = 0;
  int audio_channels = 0;
  int dump = 0;
  int fast_render = 0;
  static const char optchars[] = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:R:r:sT:Vvz:";
#ifdef LASH_ENABLED
  int connect_lash = 1;
  int enabled_lash = 0;		/* set to TRUE if lash gets enabled */
  fluid_lash_args_t *lash_args;

  lash_args = fluid_lash_extract_args (&argc, &argv);
#endif



  settings = new_fluid_settings();


 /* The 'groups' setting is relevant for LADSPA operation and channel mapping
   * in rvoice_mixer.
   * If not given, set number groups to number of audio channels, because
   * they are the same (there is nothing between synth output and 'sound card')
   */
  if ((audio_groups == 0) && (audio_channels != 0)) {
      audio_groups = audio_channels;
  }
  if (audio_groups != 0)
  {
      fluid_settings_setint(settings, "synth.audio-groups", audio_groups);
  }

  if (fast_render) {
    midi_in = 0;
    interactive = 0;
#ifdef NETWORK_SUPPORT
    with_server = 0;
#endif
    fluid_settings_setstr(settings, "player.timing-source", "sample");
    fluid_settings_setint(settings, "synth.lock-memory", 0);
  }

  /* create the synthesizer */
  synth = new_fluid_synth(settings);
  if (synth == NULL) {
    fprintf(stderr, "Failed to create the synthesizer\n");
    exit(-1);
  }


  /* load the soundfonts (check that all non options are SoundFont or MIDI files) */
//  for (i = arg1; i < argc; i++) {
    if (fluid_is_soundfont(psoundfont))
    {
      if (fluid_synth_sfload(synth, psoundfont, 1) == -1)
	fprintf(stderr, "Failed to load the SoundFont %s\n", psoundfont);
    }
    else if (!fluid_is_midifile(psoundfont))
      fprintf (stderr, "Parameter '%s' not a SoundFont or MIDI file or error occurred identifying it.\n",
	       psoundfont);


  /* start the synthesis thread */
  if (!fast_render) {
		fluid_settings_setstr(settings, "audio.driver", "alsa");
    adriver = new_fluid_audio_driver(settings, synth);
    if (adriver == NULL) {
      fprintf(stderr, "Failed to create the audio driver\n");
//      goto cleanup;
    }
  }


  /* start the midi router and link it to the synth */
#if WITH_MIDI
  if (midi_in) {
    /* In dump mode, text output is generated for events going into and out of the router.
     * The example dump functions are put into the chain before and after the router..
     */
    //sequencer = new_fluid_sequencer2(0);

    router = new_fluid_midi_router(
      settings,
      dump ? fluid_midi_dump_postrouter : fluid_synth_handle_midi_event,
      (void*)synth);

    if (router == NULL) {
      fprintf(stderr, "Failed to create the MIDI input router; no MIDI input\n"
	      "will be available. You can access the synthesizer \n"
	      "through the console.\n");
    } else {
      mdriver = new_fluid_midi_driver(
	settings,
	dump ? fluid_midi_dump_prerouter : fluid_midi_router_handle_midi_event,
	(void*) router);
      if (mdriver == NULL) {
	fprintf(stderr, "Failed to create the MIDI thread; no MIDI input\n"
		"will be available. You can access the synthesizer \n"
		"through the console.\n");
      }
    }
  }
#endif


  /* play the midi fildes, if any */
//  for (i = arg1; i < argc; i++) {
    if  (fluid_is_midifile(psong)) {

      if (player == NULL) {
	player = new_fluid_player(synth);
	if (player == NULL) {
	  fprintf(stderr, "Failed to create the midifile player.\n"
		  "Continuing without a player.\n");
	//  break;
	}
      }

      fluid_player_add(player, psong);
    }
 // }

  if (player != NULL) {

    if (fluid_synth_get_sfont(synth, 0) == NULL) {
      /* Try to load the default soundfont if no soundfont specified */
      char *s;
      if (fluid_settings_dupstr(settings, "synth.default-soundfont", &s) != FLUID_OK)
        s = NULL;
      if ((s != NULL) && (s[0] != '\0'))
        fluid_synth_sfload(synth, s, 1);

      FLUID_FREE(s);
    }

    fluid_player_play(player);
  }

  cmd_handler = new_fluid_cmd_handler(synth, router);
  if (cmd_handler == NULL) {
    fprintf(stderr, "Failed to create the command handler\n");
 //   goto cleanup;
  }

  /* try to load the user or system configuration */
  if (config_file != NULL) {
    fluid_source(cmd_handler, config_file);
  } else if (fluid_get_userconf(buf, sizeof(buf)) != NULL) {
    fluid_source(cmd_handler, buf);
  } else if (fluid_get_sysconf(buf, sizeof(buf)) != NULL) {
    fluid_source(cmd_handler, buf);
  }

  /* run the server, if requested */
#ifdef NETWORK_SUPPORT
  if (with_server) {
    server = new_fluid_server(settings, synth, router);
    if (server == NULL) {
      fprintf(stderr, "Failed to create the server.\n"
	     "Continuing without it.\n");
    }
  }
#endif

#ifdef LASH_ENABLED
  if (enabled_lash)
    fluid_lash_create_thread (synth);
#endif




	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200));

		env->drawAll();

//fast_render;

// if (fast_render) {
//    char *filename;
//    if (player == NULL) {
//      fprintf(stderr, "No midi file specified!\n");
//   //   fluid_player_play(player);
////      goto cleanup;
//    }
//
//    fluid_settings_dupstr (settings, "audio.file.name", &filename);
//    printf ("Rendering audio to file '%s'..\n", filename);
//    if (filename) FLUID_FREE (filename);
//
//    fast_render_loop(settings, synth, player);
//  }

        /* Play a note */
  //      fluid_synth_noteon(synth, 0, 60, 100);

//        printf("Press \"Enter\" to stop: ");
//        fgetc(stdin);
//        printf("done\n");



		device->sleep(129);

		driver->endScene();
	}

        if (adriver) {
                delete_fluid_audio_driver(adriver);
        }
        if (synth) {
                delete_fluid_synth(synth);
        }
        if (settings) {
                delete_fluid_settings(settings);
        }

	device->drop();

	return 0;
}
Example #6
0
/*
Ok, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example:
*/
int main()
{
	// ask user for driver
	video::E_DRIVER_TYPE driverType=driverChoiceConsole();
	if (driverType==video::EDT_COUNT)
		return 1;

	// create device and exit if creation failed

	IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));

	if (device == 0)
		return 1; // could not create selected driver.

	/* The creation was successful, now we set the event receiver and
		store pointers to the driver and to the gui environment. */

	device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
	device->setResizable(true);

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	/*
	To make the font a little bit nicer, we load an external font
	and set it as the new default font in the skin.
	To keep the standard font for tool tip text, we set it to
	the built-in font.
	*/

	IGUISkin* skin = env->getSkin();
	IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
	if (font)
		skin->setFont(font);

	skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);

	/*
	We add three buttons. The first one closes the engine. The second
	creates a window and the third opens a file open dialog. The third
	parameter is the id of the button, with which we can easily identify
	the button in the event receiver.
	*/

	env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
			L"Quit", L"Exits Program");
	env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
			L"New Window", L"Launches a new Window");
	env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
			L"File Open", L"Opens a file");

	/*
	Now, we add a static text and a scrollbar, which modifies the
	transparency of all gui elements. We set the maximum value of
	the scrollbar to 255, because that's the maximal value for
	a color value.
	Then we create an other static text and a list box.
	*/

	env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
	IGUIScrollBar* scrollbar = env->addScrollBar(true,
			rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
	scrollbar->setMax(255);
	scrollbar->setPos(255);
	setSkinTransparency( scrollbar->getPos(), env->getSkin());

	// set scrollbar position to alpha value of an arbitrary element
	scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha());

	env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true);
	IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210));
	env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));

	// Store the appropriate data in a context structure.
	SAppContext context;
	context.device = device;
	context.counter = 0;
	context.listbox = listbox;

	// Then create the event receiver, giving it that context structure.
	MyEventReceiver receiver(context);

	// And tell the device to use our custom event receiver.
	device->setEventReceiver(&receiver);


	/*
	And at last, we create a nice Irrlicht Engine logo in the top left corner.
	*/
	env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
			position2d<int>(10,10));


	/*
	That's all, we only have to draw everything.
	*/

	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, SColor(0,200,200,200));

		env->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
int main()
{
    // ask user for driver
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        return 1;

    // create device and exit if creation failed

    Device = createDevice(driverType, core::dimension2d<u32>(640, 480));
    if(Device == NULL)
        return 1;

    IVideoDriver *Driver = Device->getVideoDriver();
    IGUIEnvironment* env = Device->getGUIEnvironment();
    ISceneManager *Scene = Device->getSceneManager();

    Scene->addCameraSceneNode(0, vector3df(0,10,-40), vector3df(0,0,0));

    MyEventReceiver receiver;
    Device->setEventReceiver(&receiver);

    // Load fonts
    fonts[0] = env->getFont(FONTPATH1, SIZE_FONT_NORMAL);
    fonts[1] = env->getFont(FONTPATH1, SIZE_FONT_BIG);
    fonts[2] = env->getFont(FONTPATH2, SIZE_FONT_NORMAL);
    fonts[3] = env->getFont(FONTPATH2, SIZE_FONT_BIG);
    fonts[4] = env->getFont(FONTPATH3, SIZE_FONT_NORMAL);
    fonts[5] = env->getFont(FONTPATH3, SIZE_FONT_BIG);

    for( int i = 0; i < 6; ++i ) {
        fonts[i]->setBatchLoadSize(1);
        fonts[i]->setMaxPageTextureSize( dimension2du(512, 512) );
    }

    font = fonts[0];
    font2 = fonts[1];

    skin = env->getSkin();
    skin->setFont(font);

    txtTrans = env->addStaticText(L"Transparency:", rect<s32>(50,20,250,40), true);
    IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32>(50, 45, 250, 60), 0, 104);
    scrollbar->setMax(255);
    SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)0);
    scrollbar->setPos(col.getAlpha());

    txtLog = env->addStaticText(L"Logging ListBox:", rect<s32>(50,80,250,100), true);
    listbox = env->addListBox(rect<s32>(50, 110, 250, 180));

    btnQuit = env->addButton(rect<s32>(10,210,100,240), 0, 101, L"Quit");
    btnNew = env->addButton(rect<s32>(10,250,100,290), 0, 102, L"New Window");
    btnFile = env->addButton(rect<s32>(10,300,100,340), 0, 103, L"Open File");

    edtName = env->addEditBox(L"",rect<s32>(300,60,580,80));
    edtName->setMax(40);
    edtMemo = env->addEditBox(L"",rect<s32>(300,100,580,450));
    edtMemo->setMultiLine(true);
    edtMemo->setTextAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);

    lstLang = env->addListBox(rect<s32>(10, 400, 250, 470),0,120);
    lstLang->addItem(L"Arial");
    lstLang->addItem(L"Times Roman");
    lstLang->addItem(L"MS-Gothic(Japanese)");
    lstLang->setSelected(0);

    int lastFPS = -1;

    while(Device->run())
    {
        Driver->beginScene(true, true, SColor(0,64,64,128));

        Scene->drawAll();
        env->drawAll();

        if (!lang){
            font2->draw(L"Hello TrueType",rect<s32>(250,20,640,100),SColor(255,255,64,64),true);
        } else {
            //font2->draw(jtxtHello,rect<s32>(250,20,640,100),SColor(255,255,64,64),true);
            font2->draw(zhtwHello,rect<s32>(100,100,640,100),SColor(255,255,64,64),false);
        }

        Driver->endScene();

        int fps = Driver->getFPS();
        if (lastFPS != fps)
        {
            wchar_t tmp[1024];
            swprintf(tmp, L"Irrlicht TrueType Demo (fps:%d)", fps);
            Device->setWindowCaption(tmp);
            lastFPS = fps;
        }

    }

    Device->drop();
    return 0;
}
Example #8
0
int main()
{
	video::E_DRIVER_TYPE driverType = driverChoiceConsole();
	if (driverType==video::EDT_COUNT)
		return 1;

	IrrlichtDevice * device = createDevice(driverType, dimension2d<u32>(640, 480));
	if (device == 0)
		return 1; // could not create selected driver.

	// It's sometimes of interest to know how the mouse behaves after a resize
	device->setResizable(true);

	device->setWindowCaption(L"Cursor control - Irrlicht engine tutorial");
	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	gui::IGUISpriteBank * SpriteBankIcons;

	SAppContext context;
	context.Device = device;

	rect< s32 > rectInfoStatic(10,10, 200, 200);
	env->addStaticText (L"Cursor state information", rectInfoStatic, true, true);
	rectInfoStatic.UpperLeftCorner += dimension2di(0, 15);
	context.InfoStatic = env->addStaticText (L"", rectInfoStatic, true, true);
	rect< s32 > rectEventBox(10,210, 200, 400);
	env->addStaticText (L"click events (new on top)", rectEventBox, true, true);
	rectEventBox.UpperLeftCorner += dimension2di(0, 15);
	context.EventBox = env->addListBox(rectEventBox);
	rect< s32 > rectCursorBox(210,10, 400, 250);
	env->addStaticText (L"cursors, click to set the active one", rectCursorBox, true, true);
	rectCursorBox.UpperLeftCorner += dimension2di(0, 15);
	context.CursorBox = env->addListBox(rectCursorBox);
	rect< s32 > rectSpriteBox(210,260, 400, 400);
	env->addStaticText (L"sprites", rectSpriteBox, true, true);
	rectSpriteBox.UpperLeftCorner += dimension2di(0, 15);
	context.SpriteBox = env->addListBox(rectSpriteBox);

	context.ButtonSetVisible = env->addButton( rect<s32>( 410, 20, 560, 40 ), 0, -1, L"set visible (delayed)" );
	context.ButtonSetInvisible = env->addButton( rect<s32>( 410, 50, 560, 70 ), 0, -1, L"set invisible (delayed)" );
	context.ButtonSimulateBadFps = env->addButton( rect<s32>( 410, 80, 560, 100 ), 0, -1, L"simulate bad FPS" );
	context.ButtonSimulateBadFps->setIsPushButton(true);
	context.ButtonChangeIcon = env->addButton( rect<s32>( 410, 140, 560, 160 ), 0, -1, L"replace cursor icon\n(cursor+sprite must be selected)" );

	// set the names for all the system cursors
	for ( int i=0; i < (int)gui::ECI_COUNT; ++i )
	{
		context.CursorBox->addItem(stringw( GUICursorIconNames[i] ).c_str());
	}

	/*
		Create sprites which then can be used as cursor icons.
	 */
	SpriteBankIcons = env->addEmptySpriteBank(io::path("cursor_icons"));
	context.SpriteBox->setSpriteBank(SpriteBankIcons);

	// create one animated icon from several files
	array< io::path > files;
	files.push_back( io::path("../media/icon_crosshairs16x16bw1.png") );
	files.push_back( io::path("../media/icon_crosshairs16x16bw2.png") );
	files.push_back( io::path("../media/icon_crosshairs16x16bw3.png") );
	files.push_back( io::path("../media/icon_crosshairs16x16bw3.png") );
	files.push_back( io::path("../media/icon_crosshairs16x16bw2.png") );
	SCursorSprite spriteBw;	// the sprite + some additional information needed for cursors
	spriteBw.SpriteId = AddAnimatedIconToSpriteBank( SpriteBankIcons, driver, files, 200 );
	spriteBw.SpriteBank = SpriteBankIcons;
	spriteBw.HotSpot = position2d<s32>(7,7);
	context.addIcon(L"crosshair_bw", spriteBw);

	// create one animated icon from one file
	array< rect<s32> > iconRects;
	iconRects.push_back( rect<s32>(0,0, 16, 16) );
	iconRects.push_back( rect<s32>(16,0, 32, 16) );
	iconRects.push_back( rect<s32>(0,16, 16, 32) );
	iconRects.push_back( rect<s32>(0,16, 16, 32) );
	iconRects.push_back( rect<s32>(16,0, 32, 16) );
	SCursorSprite spriteCol;	// the sprite + some additional information needed for cursors
	spriteCol.SpriteId = AddAnimatedIconToSpriteBank( SpriteBankIcons, driver, io::path("../media/icon_crosshairs16x16col.png"), iconRects, 200 );
	spriteCol.HotSpot = position2d<s32>(7,7);
	spriteCol.SpriteBank = SpriteBankIcons;
	context.addIcon(L"crosshair_colored", spriteCol);

	// Create some non-animated icons
	rect<s32> rectIcon;
	SCursorSprite spriteNonAnimated(SpriteBankIcons, 0, position2d<s32>(7,7));

	rectIcon = rect<s32>(0,0, 16, 16);
	spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, io::path("../media/icon_crosshairs16x16col.png"), rectIcon );
	context.addIcon(L"crosshair_col1", spriteNonAnimated, false);

	rectIcon = rect<s32>(16,0, 32, 16);
	spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, io::path("../media/icon_crosshairs16x16col.png"), rectIcon );
	context.addIcon(L"crosshair_col2", spriteNonAnimated, false);

	rectIcon = rect<s32>(0,16, 16, 32);
	spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, io::path("../media/icon_crosshairs16x16col.png"), rectIcon );
	context.addIcon(L"crosshair_col3", spriteNonAnimated, false);


	MyEventReceiver receiver(context);
	device->setEventReceiver(&receiver);

	while(device->run() && driver)
	{
		// if (device->isWindowActive())
		{
			u32 realTimeNow = device->getTimer()->getRealTime();

			context.update();

			driver->beginScene(true, true, SColor(0,200,200,200));

			env->drawAll();

			// draw custom sprite with Irrlicht functions for comparison. It should usually look the same as the cursors.
			if ( context.SpriteBox )
			{
				s32 selectedSprite = context.SpriteBox->getSelected();
				if ( selectedSprite >= 0 && context.Sprites[selectedSprite].SpriteId >= 0 )
				{
					SpriteBankIcons->draw2DSprite(u32(context.Sprites[selectedSprite].SpriteId), position2di(580, 140), 0, video::SColor(255, 255, 255, 255), 0, realTimeNow);
				}
			}

			driver->endScene();
		}

		// By simulating bad fps we can find out if hardware-support for cursors works or not. If it works the cursor will move as usual,while it otherwise will just update with 2 fps now.
		if ( context.SimulateBadFps )
		{
			device->sleep(500);	// 2 fps
		}
		else
		{
			device->sleep(10);
		}
	}

	device->drop();

	return 0;
}
void MultiBouncerGame::initGUI()
{	
	//TODO: Filesystem tools
	//Clear file names
	m_MapFiles.clear();
	
	if( !filesystem::exists( "maps" ) )
	{
		std::cout << "Directory maps does not exist!" << std::endl;
		exit( EXIT_FAILURE );
	}
	
	//Read bouncer and map file names
	filesystem::directory_iterator end;
	for( filesystem::directory_iterator x( "maps" ); x != end; x++ )
		m_MapFiles.push_back( x->path() );
	
	for( unsigned int x = 0; x < m_MapFiles.size(); x++ )
	{
		ConfigStorage *conf = new ConfigStorage();
		conf->parseXMLFile( m_MapFiles.at( x ).string().c_str(), "Data" );
		m_MapData.push_back( conf );
	}
	
	//Get gui environment
	//TODO: Add a better method for gui management
	IGUIEnvironment *gui = m_Engine->getIrrlichtDevice()->getGUIEnvironment();
	
	//some defines for easier size definitions
	#define W mWinWidth
	#define H mWindHeight
	#define W2 (W/2)
	#define H2 (H/2)
	#define W4 (W/4)
	#define H4 (H/4)
	
	//Add main menu window
	m_MainMenu = gui->addWindow( 
		recti( 20, 20, W - 20, H - 20 ),
		false, L"MainMenu" );
	m_MainMenu->getCloseButton()->setVisible( false );
	m_MainMenu->setDraggable( false );
	m_MainMenu->setDrawTitlebar( false );

	//Add the reconnect button
	mReconnectButton = gui->addButton( recti( 10, 10, 410, 60 ),
		m_MainMenu, -1, L"(Re)connect wiimotes" );
	mReconnectButton->setVisible( m_Engine->getConfig()->get<bool>( "UseWiimotes", false ) );
	
	//Add the bouncer list
	m_MapList = gui->addListBox( recti( W4, H4, 3 * W4, 3 * H4 ), 
		m_MainMenu, -1, true );
	for( unsigned int x = 0; x < m_MapFiles.size(); x++ )
		m_MapList->addItem( stringw( 
		m_MapData.at( x )->get<String>( "MapName", "No Name!" ) ).c_str() );
	
	m_OkButton = gui->addButton( recti( W4, 3 * H4 + 10, W2 - 5, 3 * H4 + 60 ), 
		m_MainMenu, -1, L"Start" );
	
	m_PlayerCounter = gui->addSpinBox( L"Spieleranzahl:", 
		recti( W2 + 4, 3 * H4 + 10, 3 * W4, 3 * H4 + 60 ), true, m_MainMenu );
	m_PlayerCounter->getEditBox()->setTextAlignment( irr::gui::EGUIA_CENTER, 
		irr::gui::EGUIA_CENTER );
	m_PlayerCounter->setDecimalPlaces( 0 );
	m_PlayerCounter->setRange( 1.f, 32.f );
	m_PlayerCounter->setValue( 2.f );
	
	//Create ingame gui
	
	//Upper window for scores etc.
	mScoreWindow = gui->addWindow( recti( 0, 0, W, 50 ) );
	mScoreWindow->setDraggable( false );
	mScoreWindow->setDrawTitlebar( false );
	mScoreWindow->getCloseButton()->setVisible( false );
	
	mScoreCounter = gui->addStaticText( TEXT_SCORE_ZERO, 
		recti( W4, 0, 3 * W4, 50 ), false, false, mScoreWindow );
	mScoreCounter->setTextAlignment( irr::gui::EGUIA_CENTER, 
		irr::gui::EGUIA_CENTER );
	mScoreCounter->setOverrideColor( SColor( 255, 255, 255, 255 ) );
	
	//undefine sizes
	#undef W
	#undef H
	#undef W2
	#undef H2
	#undef W4
	#undef H4
	
	//hide all windows
	m_MainMenu->setVisible( false );
	mScoreWindow->setVisible( false );
}
Example #10
0
/*
OK, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example.
*/
int main()
{


	// create device and exit if creation failed
	IrrlichtDevice * device = createDevice(EDT_OPENGL,core::dimension2d<u32>(640, 480));

	if (device == 0)
		return 1; // could not create selected driver.

	/* The creation was successful, now we set the event receiver and
		store pointers to the driver and to the gui environment. */

	device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
	device->setResizable(true);

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	const io::path mediaPath = getExampleMediaPath();

	/*
	To make the font a little bit nicer, we load an external font
	and set it as the new default font in the skin.
	To keep the standard font for tool tip text, we set it to
	the built-in font.
	*/

	IGUISkin* skin = env->getSkin();
	IGUIFont* font = env->getFont(mediaPath + "fonthaettenschweiler.bmp");
	if (font)
		skin->setFont(font);

	skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);

	/*
	We add three buttons. The first one closes the engine. The second
	creates a window and the third opens a file open dialog. The third
	parameter is the id of the button, with which we can easily identify
	the button in the event receiver.
	*/

	env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
			L"Quit", L"Exits Program");
	env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
			L"New Window", L"Launches a new Window");
	env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
			L"File Open", L"Opens a file");

	/*
	Now, we add a static text and a scrollbar, which modifies the
	transparency of all gui elements. We set the maximum value of
	the scrollbar to 255, because that's the maximal value for
	a color value.
	Then we create an other static text and a list box.
	*/

	env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
	IGUIScrollBar* scrollbar = env->addScrollBar(true,
			rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
	scrollbar->setMax(255);
	scrollbar->setPos(255);
	setSkinTransparency( scrollbar->getPos(), env->getSkin());

	// set scrollbar position to alpha value of an arbitrary element
	scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha());

	env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true);
	IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210));
	env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));

	// Store the appropriate data in a context structure.
	SAppContext context;
	context.device = device;
	context.counter = 0;
	context.listbox = listbox;

	// Then create the event receiver, giving it that context structure.
	MyEventReceiver receiver(context);

	// And tell the device to use our custom event receiver.
	device->setEventReceiver(&receiver);


	/*
	And at last, we create a nice Irrlicht Engine logo in the top left corner.
	*/
	env->addImage(driver->getTexture(mediaPath + "irrlichtlogo2.png"),
			position2d<int>(10,10));


	/*
	That's all, we only have to draw everything.
	*/
	        fluid_settings_t* settings;
        fluid_synth_t* synth = NULL;
        fluid_audio_driver_t* adriver = NULL;
        int err = 0;
        struct fx_data_t fx_data;
//
//        if (argc != 3) {
//                fprintf(stderr, "Usage: fluidsynth_simple [soundfont] [gain]\n");
//                return 1;
//        }
//
        /* Create the settings object. This example uses the default
         * values for the settings. */
        settings = new_fluid_settings();
        if (settings == NULL) {
                fprintf(stderr, "Failed to create the settings\n");
                err = 2;
                goto cleanup;
        }

        /* Create the synthesizer */
        synth = new_fluid_synth(settings);
        if (synth == NULL) {
                fprintf(stderr, "Failed to create the synthesizer\n");
                err = 3;
                goto cleanup;
        }

        /* Load the soundfont */
//        if (fluid_synth_sfload(synth, "soundfonts/example.sf2", 1) == -1) {
        if (fluid_synth_sfload(synth, "soundfonts/VintageDreamsWaves-v2.sf2", 1) == -1) {
//        if (fluid_synth_sfload(synth, "soundfonts/VintageDreamsWaves-v2.sf3", 1) == -1) {
 //       if (fluid_synth_sfload(synth, "soundfonts/philharmonia_violin_short.gig", 1) == -1) { //was to check and see if it had gig support but no.

                fprintf(stderr, "Failed to load the SoundFont\n");
                err = 4;
                goto cleanup;
        }

        /* Fill in the data of the effects unit */
        fx_data.synth = synth;
        fx_data.gain = 10; //atof(argv[2]);

        /* Create the audio driver. As soon as the audio driver is
         * created, the synthesizer can be played. */
fluid_settings_setstr(settings, "audio.driver", "alsa");
        adriver = new_fluid_audio_driver2(settings, fx_function, (void*) &fx_data);
        if (adriver == NULL) {
                fprintf(stderr, "Failed to create the audio driver\n");
                err = 5;
                goto cleanup;
        }



	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200));

		env->drawAll();




        /* Play a note */
        fluid_synth_noteon(synth, 0, 60, 100);

//        printf("Press \"Enter\" to stop: ");
//        fgetc(stdin);
//        printf("done\n");





		driver->endScene();
	}
 cleanup:

        if (adriver) {
                delete_fluid_audio_driver(adriver);
        }
        if (synth) {
                delete_fluid_synth(synth);
        }
        if (settings) {
                delete_fluid_settings(settings);
        }

	device->drop();

	return 0;
}