2025-09-06 21:25:33 +08:00

266 lines
12 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Using RenderingCanvas with DispEngine | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Using RenderingCanvas with DispEngine | HiAPI-C# 2025 ">
<link rel="icon" href="../../../../../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../../../../../public/docfx.min.css">
<link rel="stylesheet" href="../../../../../public/main.css">
<meta name="docfx:navrel" content="../../../../../toc.html">
<meta name="docfx:tocrel" content="../../../toc.html">
<meta name="docfx:rel" content="../../../../../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../../../../../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../../../../../index.html">
<img id="logo" class="svg" src="../../../../../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="">
<h1 id="using-renderingcanvas-with-dispengine">Using RenderingCanvas with DispEngine</h1>
<p>The <code>RenderingCanvas</code> is the primary UI component for displaying and interacting with 3D content across different platforms. This section explains how to use it with the <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> to create cross-platform applications.</p>
<h2 id="overview">Overview</h2>
<p>The <code>RenderingCanvas</code> class is available in frameworks:</p>
<ul>
<li><code>Hi.WinForm</code> for Windows Forms applications</li>
<li><code>Hi.Wpf</code> for WPF applications</li>
</ul>
<p>All implementations share a common architecture centered around the <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> class, enabling consistent rendering and interaction across platforms.</p>
<h2 id="core-concept-dispengine-and-idisplayee">Core Concept: DispEngine and IDisplayee</h2>
<p>At the heart of the rendering system is the relationship between <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> and <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a>:</p>
<ul>
<li><a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a>: The rendering engine that manages the OpenGL context and handles user interaction</li>
<li><a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a>: The interface that defines objects that can be rendered by the DispEngine</li>
</ul>
<p>This relationship is fundamental - <strong>the purpose of <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> is to render <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a> objects</strong>.</p>
<pre><code class="lang-mermaid">graph TD
A[IDisplayee Objects] --&gt;|Rendered by| B
B[DispEngine] &lt;--&gt; C[RenderingCanvas UI Component]
</code></pre>
<h3 id="working-with-idisplayee">Working with IDisplayee</h3>
<p>Objects implementing <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a> define what gets rendered. Typically, you'll use <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> objects or compose multiple IDisplayee objects together:</p>
<pre><code class="lang-csharp">// Create a composite displayee
public class MyCompositeDisplayee : IDisplayee
{
private List&lt;IDisplayee&gt; _displayees = new List&lt;IDisplayee&gt;();
public MyCompositeDisplayee()
{
// Add various displayees
_displayees.Add(new AxesDisplayee());
_displayees.Add(new ModelDisplayee());
}
public void Display(Bind bind)
{
// Render all contained displayees
foreach (var displayee in _displayees)
{
displayee.Display(bind);
}
}
public void ExpandToBox3d(Box3d box)
{
// Update bounding box based on all displayees
foreach (var displayee in _displayees)
{
displayee.ExpandToBox3d(box);
}
}
}
</code></pre>
<p>For more detailed information on creating displayees with <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a>, see the <a href="../drawing/index.html">Drawing</a> section.</p>
<h2 id="basic-usage">Basic Usage</h2>
<h3 id="apply-hiwinform">Apply Hi.WinForm</h3>
<pre><code class="lang-csharp">// Create a new instance with displayee objects
using Hi.WinForm.Disp;
// Create displayee object
var displayee = new MyCompositeDisplayee();
// Initialize canvas with the displayee
var canvas = new RenderingCanvas(displayee);
// Access the DispEngine for direct manipulation
DispEngine engine = canvas.DispEngine;
// Add to a form
myForm.Controls.Add(canvas);
</code></pre>
<h3 id="apply-hiwpf">Apply Hi.WPF</h3>
<pre><code class="lang-csharp">// Create a new instance
using Hi.Wpf.Disp;
// Create displayee object
var displayee = new MyCompositeDisplayee();
// Initialize the canvas
var canvas = new RenderingCanvas();
// Set displayee objects through the DispEngine
canvas.DispEngine.Displayee = displayee;
// Add to a container
myGrid.Children.Add(canvas);
</code></pre>
<h2 id="switching-displayees-at-runtime">Switching Displayees at Runtime</h2>
<p>You can dynamically change what's being displayed:</p>
<pre><code class="lang-csharp">// Switch to a different displayee
renderingCanvas.DispEngine.Displayee = alternativeDisplayee;
// Or update a DispList
var displayList = new DispList();
if (showModel) displayList.Add(modelDisplayee);
if (showGrid) displayList.Add(gridDisplayee);
renderingCanvas.DispEngine.Displayee = displayList;
</code></pre>
<h2 id="key-features-of-dispengine">Key Features of DispEngine</h2>
<p>The <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> provides cross-platform support for:</p>
<ul>
<li>Handles buffer swapping and image generation</li>
<li>Mouse/pointer events</li>
<li>Keyboard navigation</li>
<li>Touch gestures</li>
<li>Zoom, pan, and rotate operations</li>
<li>Resize and Visibility changed.</li>
<li>Camera positioning and orientation</li>
<li>Standard views (front, top, isometric, etc.)</li>
<li>Renders <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a> implementations</li>
</ul>
<h2 id="touch-and-gesture-support">Touch and Gesture Support</h2>
<p>The <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a> centralizes touch handling across all platforms with a unified API that supports:</p>
<ul>
<li>Single-finger pan</li>
<li>Two-finger rotate and scale</li>
<li>Multi-finger specialized operations</li>
</ul>
<p>The touch API is designed to be simple for UI implementations to use. Platform-specific UI components only need to capture touch events and forward them to the DispEngine.</p>
<h2 id="common-operations">Common Operations</h2>
<pre><code class="lang-csharp">// Accessing DispEngine (works on all platforms)
var engine = renderingCanvas.DispEngine;
// Set to standard views
engine.SetViewToHomeView();
engine.SetViewToFrontView();
// Manual camera manipulation
engine.Translate(dx, dy);
engine.Rotate(deltaX, deltaY);
// Resize handling
engine.Resize(width, height);
</code></pre>
<h2 id="implementation-details">Implementation Details</h2>
<p>For detailed implementation information, including:</p>
<ul>
<li>Full source code examples</li>
<li>Implementation details for each platform</li>
<li>Advanced touch handling</li>
<li>Custom implementation guidance</li>
</ul>
<p>See the <a href="custom-implementation.html">Building Your Own RenderingCanvas</a> guide.</p>
<h2 id="see-also">See Also</h2>
<ul>
<li><a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a></li>
<li><a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a></li>
<li><a class="xref" href="../../../../../api/Hi.Disp.DispList.html">DispList</a></li>
<li><a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a></li>
<li><a href="custom-implementation.html">Building Your Own RenderingCanvas</a></li>
</ul>
</article>
<div class="contribution d-print-none">
</div>
<div class="next-article d-print-none border-top" id="nextArticle"></div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>