コード例 #1
0
 /// <summary>
 /// Handle mouse up to handle selection and link click.
 /// </summary>
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if (ContentSurface.Contains(e.Location))
     {
         OnMouseClick(e);
     }
     _htmlContainer?.HandleMouseUp(this, e);
     base.OnMouseUp(e);
 }
コード例 #2
0
        static void Main(string[] args)
        {
            SDL2.SDL2_CS_libs_bundle.Init();
            InitSDL2();

            var window = SDL.SDL_CreateWindow("HtmlRenderer.SDL2-CS.Demo", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
                                              640, 480, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);

            if (!window.ShowSDLError("Window could not be created!"))
            {
                Console.WriteLine("Window created!");
            }

            var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED);

            renderer.ShowSDLError("Renderer could not be created!");


            using (var hc = new HtmlContainer(renderer,
                                              fm_font_directory: "fonts", fm_serif: "PT Serif", fm_sans_serif: "PT Sans", fm_monospace: "PT Mono"))
            {
                //fm_font_directory: @"C:\Windows\Fonts\", fm_serif: "Segoe UI", fm_sans_serif: "Arial", fm_monospace: "Lucida Console");


                //string html_text = System.IO.File.ReadAllText(@"../../../HTML-Renderer/Source/Demo/Common/Samples/02.Text.htm");
                //string html_tables = System.IO.File.ReadAllText(@"../../../HTML-Renderer/Source/Demo/Common/TestSamples/13.Tables.htm");


                //string html_file = @"../../html/test.html";
                //string html_dir = "html/";

                string html_file = @"../../../HTML-Renderer/Source/Demo/Common/Samples/02.Text.htm";
                string html_dir  = @"../../../HTML-Renderer/Source/Demo/Common/Samples/";


                hc.SetHtml(System.IO.File.ReadAllText(html_file), html_dir);
                //hc.SetHtml(html_text);
                //hc.SetHtml(html_tables);

                bool exit = false;
                int  i    = 0;
                while (!exit)
                {
                    while (SDL.SDL_PollEvent(out SDL.SDL_Event e) == 1)
                    {
                        switch (e.type)
                        {
                        case SDL.SDL_EventType.SDL_QUIT:
                            exit = true;
                            break;

                        case SDL.SDL_EventType.SDL_KEYDOWN:
                            switch (e.key.keysym.scancode)
                            {
                            case SDL.SDL_Scancode.SDL_SCANCODE_F5:
                                Console.WriteLine("F5 - reload {0}", html_file);
                                hc.SetHtml(System.IO.File.ReadAllText(html_file), html_dir);
                                break;

                            case SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE:
                                exit = true;
                                break;
                            }

                            break;

                        case SDL.SDL_EventType.SDL_MOUSEMOTION:
                            hc.HandleMouseMove(e.motion);
                            break;

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                            hc.HandleMouseDown(e.button);
                            break;

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                            hc.HandleMouseUp(e.button);
                            break;
                        }
                    }


                    hc.MaxSize = hc.adapter.GetRendererRect().ToRSize();

                    /*
                     * var el = hc.document.getElementById("text");
                     * el.style["height"] = "" + i + "px";
                     * el.style["width"] = "" + i + "px";
                     * el.innerHTML = "" + i;
                     */
                    hc.PerformLayout();
                    hc.PerformPaint();
                    SDL.SDL_RenderPresent(renderer);
                    SDL.SDL_Delay(50);
                    i++;
                }
            }
            QuitSDL2();
        }