Esempio n. 1
0
 	public int Attach ( TTFace face, uint size )
 	{
 		return (int)TTFont_Attach( _raw, face.Raw, size);
 	}
Esempio n. 2
0
        static void Main(string[] args)
        {
            //We choosed OpenGL because it is cross-platform and GUI does not need
            //Amazing performances...
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL,
                                                    new Dimension2D(640, 480),
                                                    16, false, false, false, false);
            //Delegate that will catch our events
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            //Does not seem to work on Linux but well...
            device.Resizeable = false;

            //We set a basic caption
            device.WindowCaption = "Irrlicht .NET CP General User Interface Example";

            //We set our handlers
            driver = device.VideoDriver;
            guienv = device.GUIEnvironment;

            //We set the skin as a metallic windows skin
            guienv.Skin = guienv.CreateSkin(GUISkinTypes.WindowsMetallic);
            guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White);

            TTFont font = new TTFont(device.VideoDriver);
            font.Antialias = true;
            TTFace face = new TTFace();
            face.Load("../../medias/FreeSans.ttf");
            font.Attach(face, 14);
            guienv.Skin.Font = font;

            //Our fader. We set it as first because we don't want him to hide our buttons.
            guienv.AddInOutFader(null, (int)GUIItems.Fader);
            //We add several buttons with the IDs we defined downwards
            guienv.AddButton(new Rect(new Position2D(250, 0), new Dimension2D(140, 100)),
                             null, (int)GUIItems.ClickMe, "Click me !");
            guienv.AddButton(new Rect(new Position2D(250, 380), new Dimension2D(140, 100)),
                             null, (int)GUIItems.DontClickMe, "Don't click me !");
            guienv.AddButton(new Rect(new Position2D(0, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FadeMe, "Fade me !");
            guienv.AddButton(new Rect(new Position2D(500, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FunnyEffect, "Funny effect !");

            guienv.AddStaticText ("Move this scrollbar and you'll see the miracle !", new Rect(new Position2D(220, 240), new Dimension2D(240, 30)),
                                  false, true, null, -1, false);

            guienv.AddSpinBox ("", new Rect(new Position2D (220, 270), new Dimension2D (120, 30)), null, -1);
            guienv.AddEditBox ("", new Rect(new Position2D (220, 300), new Dimension2D (120, 30)), true, null, -1);

            listbox = guienv.AddListBox(new Rect(new Position2D(400, 20), new Dimension2D(220, 150)), null, -1, true);
            //Our logo
            guienv.AddImage(driver.GetTexture("../../medias/NETCPlogo.png"), new Position2D(0, 0), true, null, -1, "");

            //And now the scrollbar
            GUIScrollBar scroll = guienv.AddScrollBar(true, new Rect(new Position2D(220, 220), new Dimension2D(240, 20)), null,
                                (int)GUIItems.ScrollBar);

            el = new CustomElement(guienv, null, -1, new Rect(new Position2D(220, 120), new Dimension2D(160, 100)));

            //Var for the funny effects
            int toAdd = 1;
            //While the device is running and we don't want him to exit
            while (device.Run() && !Exit)
            {
                //If our funny effect is enabled, we just scroll the scrollbar
                //It may seems strange but the "ScrollBarChanged" event is NOT fired
                //When we manually change the position... It's a gift and a cursed, depending on the situation.
                if (FunnyEffectEnabled)
                {
                    scroll.Pos += toAdd;
                    if(scroll.Pos >= 100 || scroll.Pos <= 0)
                        toAdd = -toAdd;
                    BackColor = Color.From(255, 255-scroll.Pos * 5 / 2, 255 - (scroll.Pos * 5 / 2), scroll.Pos * 5 / 2);
                }
                //Here we are, we begin the scene
                //Notice that we DO NOT use the ZBuffer because we have only two dimensions
                driver.BeginScene(true, false, BackColor);
                //We draw all the GUI
                guienv.DrawAll();
                //And we end
                driver.EndScene();
            }
            //As in the first example, we need to release main resources
            device.DumpElements();
            device.Close();
        }
Esempio n. 3
0
        private void StartupGUI(object target)
        {
            // Enforce the underlying Irrlicht engine to load a local D3DX9_40.dll
            // (Note: Environment.CurrentDirectory is visible to other plug-ins)
            Environment.CurrentDirectory = Util.ApplicationDataDirectory;

            SetupAddins();
            SetupLog();

            f = new RenderForm(this);
            f.Width = width;
            f.Height = height;
            f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            f.ImeMode = System.Windows.Forms.ImeMode.Inherit;
            try
            {
                SetParent(f.Handle, (IntPtr)target);

            #if MANAGED_D3D
                Microsoft.DirectX.Direct3D.PresentParameters pp = new Microsoft.DirectX.Direct3D.PresentParameters();
                pp.Windowed = true;
                pp.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;

                try
                {
                    d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                        0,
                        Microsoft.DirectX.Direct3D.DeviceType.Hardware,
                        f,
                        Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                        pp
                        );
                }
                catch
                {
                    try
                    {
                        d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                            0,
                            Microsoft.DirectX.Direct3D.DeviceType.Reference,
                            f,
                            Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                            pp
                            );
                    }
                    catch
                    {
                    }
                }

                CreateVideoObject();
            #endif
            }
            catch (System.Exception)
            {

            }
            f.Location = new System.Drawing.Point(0, 0);
            //f.FormClosed += new System.Windows.Forms.FormClosedEventHandler(f_FormClosed);
            f.Show();
            renderTarget = f.Handle;

            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string cacheFlag = m_config.Source.Configs["Startup"].Get("cache_delete", "false");
                if (cacheFlag == "true")
                {
                    CleanChache();
                }

            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            try
            {
                device = new IrrlichtDevice(DriverType.Direct3D9, new Dimension2D(width, height), 32, false, true, false, false, renderTarget);
                if (device == null)
                {
                    m_log.Error("can't create irrlicht device.");
                    System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);
                }
            }
            catch (Exception e)
            {
                m_log.Error("can't create irrlicht device.", e);
                System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);

                device = null;
            }

            if (device == null)
            {
                // release all.

                // exit application.

                return;
            }
            else
            {
                m_log.InfoFormat("AdapterVendorID: 0x{0:x8}", device.VideoDriver.AdapterVendorId);
                m_log.InfoFormat("AdapterDeviceId: 0x{0:x8}", device.VideoDriver.AdapterDeviceId);
                m_log.InfoFormat("AdapterSubSysId: 0x{0:x8}", device.VideoDriver.AdapterSubSysId);
                m_log.InfoFormat("AdapterRevision: 0x{0:x8}", device.VideoDriver.AdapterRevision);
                m_log.InfoFormat("AdapterMaxTextureHeight: {0}", device.VideoDriver.AdapterMaxTextureHeight);
                m_log.InfoFormat("AdapterMaxTextureWidth: {0}", device.VideoDriver.AdapterMaxTextureWidth);
                m_log.InfoFormat("AdapterMaxActiveLights: {0}", device.VideoDriver.AdapterMaxActiveLights);
                m_log.InfoFormat("AdapterVertexShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterVertexShaderVersion);
                m_log.InfoFormat("AdapterPixelShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterPixelShaderVersion);

                // AdapterVendorId
                // 0x1002 : ATI Technologies Inc.
                // 0x10DE : NVIDIA Corporation
                // 0x102B : Matrox Electronic Systems Ltd.
                // 0x121A : 3dfx Interactive Inc
                // 0x5333 : S3 Graphics Co., Ltd.
                // 0x8086 : Intel Corporation
                //
                if (device.VideoDriver.AdapterVendorId == 0x1002)
                {
                    string warningMessage = DialogText.WarningGraphicCardMessage;
                    string warningCaption = DialogText.WarningGraphicCardCaption;

                    System.Windows.Forms.DialogResult yesno = System.Windows.Forms.MessageBox.Show(warningMessage, warningCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
                    if (System.Windows.Forms.DialogResult.Yes != yesno)
                    {
                        return;
                    }
                }
            }

            reference = new RefController(this);

            device.OnEvent += new OnEventDelegate(device_OnEvent);

            // If enabled is true, videotexture is not correctly render.
            device.VideoDriver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            #if DEBUG
            device.Logger.LogLevel = LogLevel.Information;
            #endif
            // Create video Textrue
            videoTexture = device.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"\media\textures\videoTexture.tga");

            IrrlichtNETCP.Extensions.TTFont font = new TTFont(Device.VideoDriver);
            IrrlichtNETCP.Extensions.TTFace face = new TTFace();
            bool font_loaded = false;
            uint fontsize = 16;
            string fontface = Config.Source.Configs["Startup"].GetString("guifont_face");

            if (!string.IsNullOrEmpty(Config.Source.Configs["Startup"].GetString("guifont_size")))
            {
                fontsize = (uint)Config.Source.Configs["Startup"].GetInt("guifont_size");
            }

            if (!string.IsNullOrEmpty(fontface))
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface);
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                    font_loaded = true;
                }
                else
                {
                    m_log.Warn("[FONT]: The specified font (" + fontface + ") was not available on this system. Reverting to default.");
                }
            }
            if (!font_loaded)
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc"))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc");
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                }
                else
                {
                    JapaneseEnabled = false;
                    Locale = "en";
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                    if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf"))
                    {
                        face.Load(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf");
                        font.Attach(face, fontsize);
                        font.Antialias = true;
                        Reference.GUIEnvironment.Skin.Font = font;
                    }
                    else
                    {
                        // Use built in font--- this looks horrible and should be avoided if possible
                        Reference.GUIEnvironment.Skin.Font = Reference.GUIEnvironment.BuiltInFont;
                    }
                }
            }
            font.Drop();
            face.Drop();
            // if font and face are being used, at this point face and font should both have reference counts of 1.
            // if font and face are not being used (last else branch above, using built-in font), font and face should both be deleted at this point.

            // Zaki: Adding Japanese support end

            Reference.VideoDriver.SetFog(new Color(0, 255, 255, 255), false, 9999, 9999, 0, false, false);

            //Reference.Device.FileSystem.WorkingDirectory = Util.UserCacheDirectory;
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ApplicationDataDirectory);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ModelFolder);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.TextureFolder);

            camera = new Camera(this);

            // Create managers.
            cacheManager = new CacheManager(this, -1);
            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string s_cacheMB = m_config.Source.Configs["Startup"].Get("cache_size", DEFAULT_CACHE_MB_SIZE.ToString());

                long cacheMB = DEFAULT_CACHE_MB_SIZE;
                if (long.TryParse(s_cacheMB, out cacheMB))
                {
                    cacheMB = cacheMB * 1000 * 1000;

                    cacheManager.CacheMaxSize = cacheMB;
                    cacheManager.Clean();
                }
            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            // Locale can be used from this point on
            if (Locale == "en")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("en-US");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            }
            if (Locale == "jp")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("ja-JP");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja-JP");
            }

            stateManager = new Managers.StateManager(this);
            protocolManager = new Managers.ProtocolManager(this);
            guiManager = new GuiManager(this);
            menuManager = new MenuManager(this);
            shaderManager = new ShaderManager(this);
            entityManager = new EntityManager(this);
            irrManager = new IrrManager(this, -1);
            textureManager = new TextureManager(this);
            textureManager.OnTextureLoaded += OnTextureComplete;
            terrainManager = new Managers.TerrainManager(this);
            avatarManager = new Managers.AvatarManager(this);
            effectManager = new Managers.EffectManager(this);
            chatManager = new Managers.ChatManager(this);
            soundManager = new Managers.SoundManager(this);
            debugManager = new DebugManager(this, -1);

            // Experimental manager plugin loader
            LoadPlugins();

            // Initialize.
            Initialize();

            // Event
            stateManager.OnChanged += StateChanged;

            clearColor = Color.FromBCL(Util.FromString(BackgroundColor));
            progressBarColor = Color.FromBCL(Util.FromString(ProgressColor, System.Drawing.Color.FromArgb(63, 0, 0, 0)));

            guiManager.LoadBackgrounds();

            soundManager.InitWindowBackgroundMusicURL = InitBackgroundMusicURL;
            soundManager.LoadBackgroundMusic();

            // After all managers all initialized
            stateManager.State = State.INITIALIZED;

            adapter.Initialize(this.reference);

            adapter.CallSetWorldAmbientColor(WorldAmbientColor);
            adapter.CallSetFixDirectional(FixDirectional);
            adapter.CallSetFixDirectionalRotation(FixDirectionalRotation);
            adapter.CallSetFixDirectionalDiffuseColor(FixDirectionalDiffuseColor);
            adapter.CallSetFixDirectionalAmbientColor(FixDirectionalAmbientColor);

            SetLogFilter();

            guiManager.ShowLoginWindow(new LoginInfo(ServerURI, FirstName, LastName, Password, LoginMode, true, true));

            // Hide mouse cursor.
            ShowCursor(false);

            #if _SECOND_SURFACE_ON
            pip = Reference.VideoDriver.CreateRenderTargetTexture(new Dimension2D(256, 256));
            pipImage = Reference.GUIEnvironment.AddImage(pip, new Position2D(Width - pip.OriginalSize.Width - 10, 40), false, Reference.GUIEnvironment.RootElement, -1, "");

            CameraSceneNode oldCam = Reference.SceneManager.ActiveCamera;
            pipCamera = Reference.SceneManager.AddCameraSceneNode(Reference.SceneManager.RootSceneNode);
            material.Lighting = false;
            if (Reference.SceneManager.ActiveCamera.Raw != oldCam.Raw)
                Reference.SceneManager.ActiveCamera = oldCam;
            #endif

            System.Windows.Forms.DialogResult dialogRes = System.Windows.Forms.DialogResult.Retry;
            while (dialogRes == System.Windows.Forms.DialogResult.Retry)
            {
                dialogRes = RenderLoop();
            }

            #if MANAGED_D3D
            try
            {
                if (video != null)
                {
                    lock (video)
                    {
                        video.Stop();
                        video.Dispose();
                    }
                }

                if (d3ddevice != null)
                {
                    lock (d3ddevice)
                    {
                        d3ddevice.Dispose();
                        d3ddevice = null;
                    }
                }
            }
            catch
            {
            }
            #endif

            if (device != null)
            {
                device.Dispose();
                device = null;
            }
        }