Esempio n. 1
0
    public static Scene MakeMultiTouchScene()
    {
        Trail <Vector2>[] touch       = new Trail <Vector2> [Input2.Touch.MaxTouch];
        Grid[]            trail_polys = new Grid[Input2.Touch.MaxTouch];

        for (int i = 0; i < touch.Length; ++i)
        {
            touch[i] = new Trail <Vector2>(16);
        }

        Vector2i grid_size = new Vector2i(20, 24);

        for (int i = 0; i < trail_polys.Length; ++i)
        {
            trail_polys[i] = new Grid(grid_size);
        }

        Vector2[] curve_points  = new Vector2[grid_size.Y];
        Vector2[] circle_points = new Vector2[grid_size.X];
        for (int i = 0; i < circle_points.Length; ++i)
        {
            circle_points[i] = Vector2.Rotation(Math.TwicePi * (float)i / (float)(circle_points.Length - 1));
        }

        List <Vector2> control_points = new List <Vector2>();

        Vector4[] colors =
        {
//			Colors.Black,
            Colors.Red,
            Colors.Green,
            Colors.Yellow,
            Colors.Blue,
            Colors.Magenta,
            Colors.Cyan,
            Colors.White,
            Colors.Lime,
            Colors.LightBlue,
            Colors.Pink,
            Colors.Orange,
            Colors.LightCyan,
            Colors.Purple,
        };

        var scene = new Scene();

        {
            var info = new Label();
            info.Camera      = UICamera;
            info.Position    = UICamera.CalcBounds().Point00;
            info.FontMap     = UIFontMap;
            info.HeightScale = UICamera.GetPixelSize();
            info.Text        = "try touch the screen at multiple points at the same time";

            scene.AddChild(info);
        }

        scene.OnExitEvents += () => {
            foreach (Grid grid in trail_polys)
            {
                grid.Dispose();
            }
            trail_polys = null;
        };

        scene.AdHocDraw += () =>

        {
            BlendFunc blend_func = Director.Instance.GL.Context.GetBlendFunc();
            DepthFunc depth_func = Director.Instance.GL.Context.GetDepthFunc();

            for (int k = 0; k < touch.Length; ++k)
            {
                bool    down  = Input2.Touch.GetData(0)[k].Down;
                bool    press = Input2.Touch.GetData(0)[k].Press;
                Vector2 p     = Director.Instance.CurrentScene.GetTouchPos(k);

                if (!down)
                {
                    continue;
                }

                // press means a new touch data has just been "created"
                // -> fill the whole trail to the new position
                if (press)
                {
                    touch[k].Fill(p);
                }

                touch[k].Add(p);

                control_points.Clear();
                control_points.Add(touch[k].At(0));
                for (int i = 0; i < touch[k].Count; ++i)
                {
                    control_points.Add(touch[k].At(i));
                }

                {
                    Vector4 start_color  = colors[k];
                    Vector4 end_color    = Math.SetAlpha(start_color, 0.0f);
                    float   start_radius = 2.0f;
                    float   end_radius   = 1.8f;

                    Grid grid = trail_polys[k];

                    for (int i = 0; i < curve_points.Length; ++i)
                    {
                        curve_points[i] = Curves.CatmullRom((float)i / (float)(curve_points.Length - 1), control_points, false);
                    }

                    for (int j = 0; j < grid.Size.Y; ++j)
                    {
                        float y = (float)j / (float)(grid.Size.Y - 1);

                        for (int i = 0; i < grid.Size.X; ++i)
                        {
                            grid.TmpVertices[i + j * grid.Size.X] = new DrawHelpers.Vertex((curve_points[j] + circle_points[i] * Math.Lerp(start_radius, end_radius, y)).Xy01
                                                                                           , Math.Lerp(start_color, end_color, y));
                        }
                    }

                    grid.VertexBuffer.SetVertices(grid.TmpVertices, 0, 0, grid.NumVertices);
                    Director.Instance.GL.SetBlendMode(BlendMode.Normal);
                    Director.Instance.DrawHelpers.ShaderPush();
                    grid.Draw();

                    {
                        Director.Instance.DrawHelpers.ImmBegin(DrawMode.TriangleFan, (uint)grid.Size.X);
                        for (int i = 0; i < grid.Size.X; ++i)
                        {
                            Director.Instance.DrawHelpers.ImmVertex(new DrawHelpers.Vertex((curve_points[0] + circle_points[i] * start_radius).Xy01
                                                                                           , start_color));
                        }
                        Director.Instance.DrawHelpers.ImmEnd();
                    }

                    Director.Instance.DrawHelpers.ShaderPop();
                }
            }

            // restore states

            Director.Instance.GL.Context.Disable(EnableMode.DepthTest);

            Director.Instance.GL.Context.SetDepthFunc(depth_func);
            Director.Instance.GL.Context.SetBlendFunc(blend_func);
        };

        return(scene);
    }
Esempio n. 2
0
        public override void Draw()
        {
            DepthFunc depth_func = Director.Instance.GL.Context.GetDepthFunc();

            Director.Instance.GL.Context.Disable(EnableMode.DepthTest);

            if (!m_select_tile_screen)
            {
//				DrawExampleSourceImage();

                DrawWorld();

                if (!is_erase_mode() && !navigating)
                {
                    DrawBrush();
                }

                DrawIsometricTilesRulers();

                {
                    m_gui_camera.SetViewFromViewport();
                    m_gui_camera.Push();

                    float   h         = m_gui_camera.GetPixelSize() * EmbeddedDebugFontData.CharSizei.Y;
                    Vector2 line_incr = new Vector2(0, (EmbeddedDebugFontData.CharSizei.Y + 1) * m_gui_camera.GetPixelSize());
                    Vector2 pos       = line_incr * 9;

                    Vector3i coord = m_world_edit_cell;

                    string text = "";
                    text += "commands:\n";
                    text += "- triangle/W + drag          : zoom\n";
                    text += "- square/A + drag            : translate\n";
                    text += "- hold cross/S               : bring tile image select screen\n";
                    text += "- hold circle/D + touch/drag : put tile at selected world cell\n";
                    text += "- up                         : increment edit z\n";
                    text += "- down                       : decrement edit z\n";
                    text += "- right                      : toggle secondary object\n";

                    text += "SECOND OBJECT=" + m_second_object + "\n";

                    if (IsValidIndex(coord))
                    {
                        text += "SELECTED TILE=" + coord + "\n";
                    }

                    Director.Instance.GL.SetBlendMode(BlendMode.Normal);
                    Director.Instance.SpriteRenderer.DrawTextDebug(text, pos, h);
                    m_gui_camera.Pop();
                }
            }
            else
            {
                DrawTilesForSelection();

                {
                    m_gui_camera.SetViewFromViewport();
                    m_gui_camera.Push();

                    float   h         = m_gui_camera.GetPixelSize() * EmbeddedDebugFontData.CharSizei.Y;
                    Vector2 line_incr = new Vector2(0, (EmbeddedDebugFontData.CharSizei.Y + 1) * m_gui_camera.GetPixelSize());
                    Vector2 pos       = line_incr * 4;

                    Director.Instance.GL.SetBlendMode(BlendMode.Normal);

                    string text = "";
                    text += "commands:\n";
                    text += "- touch             : scroll the tile map and select a tile\n";
                    text += "- touch empty space : set erase mode\n";
                    text += "- release cross/S   : back to world edit screen\n";

                    text += "SELECTED TILE=" + m_selected_tile + "\n";

                    Director.Instance.SpriteRenderer.DrawTextDebug(text, pos, h);
                    m_gui_camera.Pop();
                }
            }

            Director.Instance.GL.Context.SetDepthFunc(depth_func);
        }