/// <summary> /// Handle mouse move to handle hover cursor and text selection. /// </summary> protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); if (_htmlContainer != null) { _htmlContainer.HandleMouseMove(this, e.GetPosition(this)); } }
/// <summary> /// Adjust the scrollbar of the panel on html element by the given id.<br/> /// The top of the html element rectangle will be at the top of the panel, if there /// is not enough height to scroll to the top the scroll will be at maximum.<br/> /// </summary> /// <param name="elementId">the id of the element to scroll to</param> public void ScrollToElement(string elementId) { ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId"); if (_htmlContainer != null) { var rect = _htmlContainer.GetElementRectangle(elementId); if (rect.HasValue) { AutoScrollPosition = Point.Round(rect.Value.Location); _htmlContainer.HandleMouseMove(this, new MouseEventArgs(MouseButtons, 0, MousePosition.X, MousePosition.Y, 0)); } } }
/// <summary> /// Handle mouse move to handle hover cursor and text selection. /// </summary> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (ContentSurface.Contains(e.Location)) { _htmlContainer?.HandleMouseMove(this, e); } else { Cursor = DefaultCursor; } }
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(); }