commit UI module interfaces

This commit is contained in:
jerrywwl
2019-01-15 18:49:37 +08:00
parent 6d17dbe55a
commit 3e8d6c7e2a
6 changed files with 112 additions and 43 deletions
+17 -5
View File
@@ -3,12 +3,13 @@ import { GFXWindow, IGFXWindowInfo } from '../gfx/window';
import { ForwardPipeline } from '../pipeline/forward/forward-pipeline';
import { RenderPipeline } from '../pipeline/render-pipeline';
import { IRenderViewInfo, RenderView } from '../pipeline/render-view';
import { GUI } from '../renderer/gui/gui';
import { IRenderSceneInfo, RenderScene } from '../renderer/scene/render-scene';
import { UI } from '../renderer/ui/ui';
export let _createSceneFun;
export let _createViewFun;
// tslint:disable-next-line:no-empty-interface
export interface IRootInfo {
}
@@ -34,8 +35,8 @@ export class Root {
return this._pipeline as RenderPipeline;
}
public get gui (): GUI {
return this._gui as GUI;
public get ui (): UI {
return this._ui as UI;
}
public get scenes (): RenderScene[] {
@@ -57,7 +58,7 @@ export class Root {
private _windows: GFXWindow[] = [];
private _mainWindow: GFXWindow | null = null;
private _pipeline: RenderPipeline | null = null;
private _gui: GUI | null = null;
private _ui: UI | null = null;
private _scenes: RenderScene[] = [];
private _views: RenderView[] = [];
private _frameTime: number = 0;
@@ -79,12 +80,17 @@ export class Root {
const pipeline = new ForwardPipeline(this);
if (!pipeline.initialize()) {
this.destroy();
return false;
}
this._pipeline = pipeline;
this._gui = new GUI(this);
this._ui = new UI(this);
if (!this._ui.initialize()) {
this.destroy();
return false;
}
return true;
}
@@ -97,6 +103,11 @@ export class Root {
this._pipeline.destroy();
this._pipeline = null;
}
if (this._ui) {
this._ui.destroy();
this._ui = null;
}
}
public frameMove (deltaTime: number) {
@@ -106,6 +117,7 @@ export class Root {
for (const view of this._views) {
if (view.isEnable()) {
( this._pipeline as RenderPipeline).render(view);
( this._ui as UI).render(view);
}
}
-10
View File
@@ -43,16 +43,6 @@ export class WebGLGPUObject {
}
}
export interface IWebGLIndirectBuffer {
vertexCount: number;
firstVertex: number;
indexCount: number;
firstIndex: number;
vertexOffset: number;
instanceCount: number;
firstInstance: number;
}
export class WebGLGPUBuffer extends WebGLGPUObject {
public usage: GFXBufferUsage = GFXBufferUsageBit.NONE;
public memUsage: GFXMemoryUsage = GFXMemoryUsageBit.NONE;
-28
View File
@@ -1,28 +0,0 @@
import { Root } from '../../core/root';
import { RenderScene } from '../scene/render-scene';
import { RenderView } from '../../pipeline/render-view';
export class GUI {
public get root (): Root {
return this._root;
}
public get scene (): RenderScene {
return this._scene;
}
private _root: Root;
private _scene: RenderScene;
constructor (root: Root) {
this._root = root;
this._scene = this._root.createScene({
name: 'GUIScene',
});
}
public render (view: RenderView) {
}
}
+13
View File
@@ -0,0 +1,13 @@
import { UI } from './ui';
import { UIWidget, UIWidgetType } from './ui-widget';
export class LabelWidget extends UIWidget {
constructor (ui: UI) {
super(ui, UIWidgetType.LABEL);
}
public update () {
}
}
+25
View File
@@ -0,0 +1,25 @@
import { UI } from './ui';
export enum UIWidgetType {
LABEL,
SPRITE,
}
export abstract class UIWidget {
protected _ui: UI;
protected _type: UIWidgetType;
protected _vertices: Float32Array | null = null;
protected _indices: Uint16Array | null = null;
constructor (ui: UI, type: UIWidgetType) {
this._ui = ui;
this._type = type;
}
public type (): UIWidgetType {
return this._type;
}
public abstract update ();
}
+57
View File
@@ -0,0 +1,57 @@
import { Root } from '../../core/root';
import { RenderView } from '../../pipeline/render-view';
import { RenderScene } from '../scene/render-scene';
import { UIWidget } from './ui-widget';
export class UI {
public get root (): Root {
return this._root;
}
public get scene (): RenderScene {
return this._scene;
}
private _root: Root;
private _scene: RenderScene;
private _widgets: UIWidget[] = [];
constructor (root: Root) {
this._root = root;
this._scene = this._root.createScene({
name: 'GUIScene',
});
}
public initialize (): boolean {
return true;
}
public destroy () {
this.destroyWidgets();
}
public render (view: RenderView) {
}
public createWidget<T extends UIWidget> (clazz: new () => T): T {
const widget = new clazz();
this._widgets.push(widget);
return widget;
}
public destroyWidget (widget: UIWidget) {
for (let i = 0; i < this._widgets.length; ++i) {
if (this._widgets[i] === widget) {
this._widgets.splice(i);
return;
}
}
}
public destroyWidgets () {
this._widgets = [];
}
}