/// <summary> /// 渲染当前组件画面于指定绘图器之上 /// </summary> /// /// <param name="g"></param> public virtual void CreateUI(GLEx g) { if (isClose) { return; } if (!this.visible) { return; } int width = this.GetWidth(); int height = this.GetHeight(); if (rotation != 0) { float centerX = this.screenX + width / 2; float centerY = this.screenY + height / 2; g.Rotate(centerX, centerY, rotation); } else if (!(scaleX == 1f && scaleY == 1f)) { g.Scale(scaleX, scaleY); } else if (this.elastic) { g.SetClip(this.screenX, this.screenY, width, height); } // 变更透明度 if (alpha > 0.1f && alpha < 1.0f) { g.SetAlpha(alpha); if (background != null) { g.DrawTexture(background, this.screenX, this.screenY, this.width, this.height); } if (this.customRendering) { this.CreateCustomUI(g, this.screenX, this.screenY, this.width, this.height); } else { this.CreateUI(g, this.screenX, this.screenY, this, this.imageUI); } g.SetAlpha(1.0F); // 不变更 } else { if (background != null) { g.DrawTexture(background, this.screenX, this.screenY, this.width, this.height); } if (this.customRendering) { this.CreateCustomUI(g, this.screenX, this.screenY, this.width, this.height); } else { this.CreateUI(g, this.screenX, this.screenY, this, this.imageUI); } } if (rotation != 0 || !(scaleX == 1f && scaleY == 1f)) { g.Restore(); } else if (this.elastic) { g.ClearClip(); } }
public virtual void CreateUI(GLEx g) { if (!isVisible) { return; } this.Setup(); int pointsLength = points.Count; CycleProgress point; int index; int frameD; int indexD; float size = (pointsLength * this.trailLength); for (float i = -1, l = size; ++i < l && !this.stopped;) { index = (int)(frame + i); if (index < pointsLength) { point = points[index]; } else { point = points[index - pointsLength]; } this.alpha = (i / (l - 1)); frameD = frame / (pointsLength - 1); indexD = (int)alpha; if (lineWidth > 0) { g.SetLineWidth(lineWidth); } if (scaleX != 1 || scaleY != 1) { g.Scale(scaleX, scaleY); } if (alpha > 0 && alpha < 1) { g.SetAlpha(alpha); } g.SetColor(color); Step(g, point, indexD, frameD, color, alpha); g.ResetColor(); if (alpha > 0 && alpha < 1) { g.SetAlpha(1); } if (lineWidth > 0) { g.ResetLineWidth(); } if (scaleX != 1 || scaleY != 1) { g.Restore(); } } }
public override void Draw(GL g) { this.m_onRunning = false; this.m_onPause = false; this.m_onDestroy = false; this.m_onResume = false; lock (m_sync) { m_onRunning = LSystem.isRunning; m_onPause = LSystem.isPaused; m_onDestroy = LSystem.isDestroy; m_onResume = LSystem.isResume; if (LSystem.isResume) { LSystem.isResume = false; } if (LSystem.isPaused) { LSystem.isPaused = false; JavaRuntime.NotifyAll(m_sync); } if (LSystem.isDestroy) { LSystem.isDestroy = false; JavaRuntime.NotifyAll(m_sync); } if (m_onResume) { m_log.I("m_onResume"); timer = LSystem.GetSystemTimer(); lastTimeMicros = timer.GetTimeMicros(); elapsedTime = 0; remainderMicros = 0; m_process.OnResume(); } if (m_onRunning) { if (LSystem.isLogo) { if (logoFlag == null) { LSystem.isLogo = false; return; } logoFlag.Draw(m_process.gl); if (logoFlag.finish) { m_process.gl.SetAlpha(1.0f); m_process.gl.DrawClear(LColor.black); LSystem.isLogo = false; logoFlag.Dispose(); logoFlag = null; return; } return; } if (!m_process.Next()) { return; } m_process.Load(); m_process.Calls(); goalTimeMicros = lastTimeMicros + 1000000L / maxFrames; currTimeMicros = timer.SleepTimeMicros(goalTimeMicros); elapsedTimeMicros = currTimeMicros - lastTimeMicros + remainderMicros; elapsedTime = MathUtils.Max(0, (elapsedTimeMicros / 1000)); remainderMicros = elapsedTimeMicros - elapsedTime * 1000; lastTimeMicros = currTimeMicros; timerContext.millisSleepTime = remainderMicros; timerContext.timeSinceLastUpdate = elapsedTime; ActionControl.Update(elapsedTime); m_process.RunTimer(timerContext); if (LSystem.AUTO_REPAINT) { GLEx gl = m_process.gl; if (gl != null) { if (!m_process.Next()) { return; } //设定graphics.PreferredBackBufferWidth和graphics.PreferredBackBufferHeight时WP会自动缩放画面, //此处无需再缩放一次。 /*if (LSystem.scaleWidth != 1f || LSystem.scaleHeight != 1f) * { * gl.Scale(LSystem.scaleWidth, * LSystem.scaleHeight); * }*/ int repaintMode = m_process.GetRepaintMode(); switch (repaintMode) { case Screen.SCREEN_BITMAP_REPAINT: gl.Reset(true); if (m_process.GetX() == 0 && m_process.GetY() == 0) { gl.DrawTexture(m_process.GetBackground(), 0, 0); } else { gl.DrawTexture(m_process.GetBackground(), m_process.GetX(), m_process.GetY()); } break; case Screen.SCREEN_COLOR_REPAINT: LColor c = m_process.GetColor(); if (c != null) { gl.DrawClear(c); } break; case Screen.SCREEN_CANVAS_REPAINT: gl.Reset(true); break; case Screen.SCREEN_NOT_REPAINT: gl.Reset(true); break; default: gl.Reset(true); if (m_process.GetX() == 0 && m_process.GetY() == 0) { gl.DrawTexture( m_process.GetBackground(), repaintMode / 2 - LSystem.random.Next(repaintMode), repaintMode / 2 - LSystem.random.Next(repaintMode)); } else { gl.DrawTexture(m_process.GetBackground(), m_process.GetX() + repaintMode / 2 - LSystem.random.Next(repaintMode), m_process.GetY() + repaintMode / 2 - LSystem.random.Next(repaintMode)); } break; } m_process.Draw(); m_process.Drawable(elapsedTime); if (isFPS) { this.TickFrames(); fpsFont.DrawString(string.Format(numformat, "FPS:{0}", frameRate), 5, 5, 0, LColor.white); } m_process.DrawEmulator(); m_process.Unload(); gl.Restore(); } } } } }