Esempio n. 1
0
 public static void AddSprite(string key, SampleSprite sprite)
 {
     if (spriteDict.ContainsKey(key) == false)
     {
         spriteDict.Add(key, sprite);
     }
 }
Esempio n. 2
0
 public override void Dispose()
 {
     if (textSprite != null)
     {
         textSprite.Dispose();
         textSprite = null;
     }
 }
Esempio n. 3
0
            public SoundButton(int id, int pixelX, int pixelY)
            {
                textSprite   = new SampleSprite("SE " + id, 0xffffffff, SampleDraw.CurrentFont, pixelX - 64, pixelY + 12);
                playButton   = new SampleButton(pixelX, pixelY, 96, 48);
                stopButton   = new SampleButton(pixelX + 112, pixelY, 96, 48);
                volumeSlider = new SampleSlider(pixelX + 224, pixelY, 256, 48);

                playButton.SetText("Play");
                stopButton.SetText("Stop");

                sound       = new Sound(soundName[id]);
                soundPlayer = sound.CreatePlayer();
            }
Esempio n. 4
0
        /// Terminate
        public static void Term()
        {
            if (httpText != null)
            {
                httpText.Dispose();
                httpText = null;
            }

            connectButton.Dispose();

            SampleDraw.Term();
            graphics.Dispose();
        }
Esempio n. 5
0
            public Ball()
            {
                Random rand = new System.Random();

                var positionX = rand.Next(0, SampleDraw.Width - ballTexture.Width);
                var positionY = rand.Next(0, SampleDraw.Height - ballTexture.Height);

                sprite = new SampleSprite(ballTexture, positionX, positionY, 0.0f, 1.0f);

                dirX = rand.Next(2) > 0 ? 1 : -1;
                dirY = rand.Next(2) > 0 ? 1 : -1;

                addPosition = 0.5f + (float)rand.NextDouble() * 5.0f;
                addRotation = 0.1f + (float)rand.NextDouble() * 5.0f;
            }
Esempio n. 6
0
        public static void DrawSprite(SampleSprite sprite)
        {
            var modelMatrix   = sprite.CreateModelMatrix();
            var worldViewProj = projectionMatrix * viewMatrix * modelMatrix;

            textureShaderProgram.SetUniformValue(0, ref worldViewProj);

            graphics.SetShaderProgram(textureShaderProgram);
            graphics.SetVertexBuffer(0, sprite.Vertices);
            graphics.SetTexture(0, sprite.Texture);

            graphics.Enable(EnableMode.Blend);
            graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha);

            graphics.DrawArrays(DrawMode.TriangleFan, 0, 4);
        }
Esempio n. 7
0
        public static bool Update()
        {
            List <TouchData> touchDataList = Touch.GetData(0);

            switch (connectState)
            {
            case ConnectState.None:
                if (connectButton.TouchDown(touchDataList))
                {
                    connectState = ConnectState.Ready;
                    if (httpText != null)
                    {
                        httpText.Dispose();
                    }
                    connectButton.ButtonColor = 0xff7f7f7f;
                }
                break;

            case ConnectState.Ready:
                connectHttpTest("http://www.scei.co.jp/index_e.html");
                break;

            case ConnectState.Success:
                connectButton.ButtonColor = 0xffffffff;

                if (readStream != null)
                {
                    httpText = createTextSprite(readStream.ToArray(), statusCode, contentLength);

                    readStream.Dispose();
                    readStream = null;
                    readBuffer = null;
                }

                connectState = ConnectState.None;
                break;

            case ConnectState.Failed:
                httpText     = createTextSprite(null, statusCode, contentLength);
                connectState = ConnectState.None;
                break;
            }

            return(true);
        }
Esempio n. 8
0
        public static Texture2D __DrawSprite(SampleSprite sprite, Matrix4 worldViewProj, bool notdraw)
        {
            if (!notdraw)
            {
                textureShaderProgram.SetUniformValue(0, ref worldViewProj);

                graphics.SetShaderProgram(textureShaderProgram);
                graphics.SetVertexBuffer(0, sprite.Vertices);
                graphics.SetTexture(0, sprite.Texture);

                graphics.Enable(EnableMode.Blend);
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha);

                graphics.DrawArrays(DrawMode.TriangleFan, 0, 4);
            }

            return(sprite.Texture);
        }
Esempio n. 9
0
        /// Create a sprite from a string buffer
        private static SampleSprite createTextSprite(byte[] buffer, string statusCode, long contentLength)
        {
            int width      = SampleDraw.Width;
            int height     = SampleDraw.Height - 128;
            int positionX  = 0;
            int positionY  = 0;
            int fontHeight = SampleDraw.CurrentFont.Metrics.Height;

            var image = new Image(ImageMode.Rgba,
                                  new ImageSize(width, height),
                                  new ImageColor(0, 0, 0, 0));

            image.DrawText("ResponseCode : " + statusCode, new ImageColor(0xff, 0xff, 0xff, 0xff), SampleDraw.CurrentFont, new ImagePosition(positionX, positionY));
            positionY += fontHeight;
            image.DrawText("ContentLength : " + contentLength, new ImageColor(0xff, 0xff, 0xff, 0xff), SampleDraw.CurrentFont, new ImagePosition(positionX, positionY));
            positionY += fontHeight;
            positionY += fontHeight;

            if (buffer != null)
            {
                var stream = new MemoryStream(buffer);
                var reader = new StreamReader(stream);

                while (!reader.EndOfStream && positionY < height)
                {
                    string text = reader.ReadLine();
                    image.DrawText(text, new ImageColor(0xff, 0xff, 0xff, 0xff), SampleDraw.CurrentFont, new ImagePosition(positionX, positionY));
                    positionY += fontHeight;
                }

                reader.Close();
                stream.Close();
            }

            var texture = new Texture2D(width, height, false, PixelFormat.Rgba);

            texture.SetPixels(0, image.ToBuffer());
            image.Dispose();

            var sprite = new SampleSprite(texture, 0, 128);

            return(sprite);
        }
Esempio n. 10
0
 public static void AddSprite(string key, SampleSprite sprite)
 {
     if (spriteDict.ContainsKey(key) == false) {
     spriteDict.Add(key, sprite);
     }
 }
Esempio n. 11
0
 public static void AddSprite(SampleSprite sprite)
 {
     AddSprite("[nameless]:" + spriteNamelessCount, sprite);
     spriteNamelessCount++;
 }
Esempio n. 12
0
        public static void DrawSprite(SampleSprite sprite)
        {
            var modelMatrix = sprite.CreateModelMatrix();
            var worldViewProj = projectionMatrix * viewMatrix * modelMatrix;

            textureShaderProgram.SetUniformValue(0, ref worldViewProj);

            graphics.SetShaderProgram(textureShaderProgram);
            graphics.SetVertexBuffer(0, sprite.Vertices);
            graphics.SetTexture(0, sprite.Texture);

            graphics.Enable(EnableMode.Blend);
            graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha);

            graphics.DrawArrays(DrawMode.TriangleFan, 0, 4);

            sprite.SetLifeTimer();
        }
Esempio n. 13
0
 public static void AddSprite(SampleSprite sprite)
 {
     AddSprite("[nameless]:" + spriteNamelessCount, sprite);
     spriteNamelessCount++;
 }
Esempio n. 14
0
        public void TermSampleSprite()
        {
            if (null == sm_SampleSprite) {
                return;
            }

            sm_SampleSprite.Dispose();
            sm_SampleSprite = null;
        }
Esempio n. 15
0
        ////////////////////////////////////////////////////////////////
        public void InitSampleSprite()
        {
            if (null == sm_Texture2D) {
                return;
            }
            if (0 >= sm_Texture2D.Width || 0 >= sm_Texture2D.Height) {
                return;
            }

            TermSampleSprite();

            var positionX = (SampleDraw.Width - sm_Texture2D.Width) / 2;
            var positionY = (SampleDraw.Height - sm_Texture2D.Height) / 2;
            var scale =
                Math.Min(
                    (float)SampleDraw.Width / sm_Texture2D.Width,
                    (float)SampleDraw.Height / sm_Texture2D.Height);

            sm_SampleSprite = new SampleSprite(sm_Texture2D, positionX, positionY, 0, scale);
        }
Esempio n. 16
0
 public override void Dispose()
 {
     if (textSprite != null) {
     textSprite.Dispose();
     textSprite = null;
     }
 }