forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
73
Kha/Backends/WPF/kha/wpf/Font.hx
Normal file
73
Kha/Backends/WPF/kha/wpf/Font.hx
Normal file
@ -0,0 +1,73 @@
|
||||
package kha.wpf;
|
||||
|
||||
import kha.FontStyle;
|
||||
|
||||
@:classCode('
|
||||
private System.Windows.Media.FormattedText getFormat(string text = "ABC") {
|
||||
System.Windows.Media.FormattedText fText = new System.Windows.Media.FormattedText(text,
|
||||
System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight,
|
||||
new System.Windows.Media.Typeface(get_name()), get_size(), System.Windows.Media.Brushes.Black);
|
||||
if (get_style().getBold()) fText.SetFontWeight(System.Windows.FontWeights.Bold);
|
||||
if (get_style().getItalic()) fText.SetFontStyle(System.Windows.FontStyles.Italic);
|
||||
if (get_style().getUnderlined()) fText.SetTextDecorations(System.Windows.TextDecorations.Underline);
|
||||
return fText;
|
||||
}
|
||||
')
|
||||
class Font implements Resource {
|
||||
public var myName: String;
|
||||
public var myStyle: FontStyle;
|
||||
public var mySize: Float;
|
||||
|
||||
public function new(name: String, style: FontStyle, size: Float) {
|
||||
myName = name;
|
||||
myStyle = style;
|
||||
mySize = size;
|
||||
}
|
||||
|
||||
public var name(get, never): String;
|
||||
|
||||
function get_name(): String {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public var style(get, never): FontStyle;
|
||||
|
||||
function get_style(): FontStyle {
|
||||
return myStyle;
|
||||
}
|
||||
|
||||
public var size(get, never): Float;
|
||||
|
||||
function get_size(): Float {
|
||||
return mySize;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
return getFormat().Height;
|
||||
')
|
||||
public function getHeight(): Float {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function charWidth(ch: String): Float {
|
||||
return stringWidth(ch);
|
||||
}
|
||||
|
||||
public function charsWidth(ch: String, offset: Int, length: Int): Float {
|
||||
return stringWidth(ch.substr(offset, length));
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
return getFormat(str).WidthIncludingTrailingWhitespace;
|
||||
')
|
||||
public function stringWidth(str: String): Float {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
return getFormat().Baseline;
|
||||
')
|
||||
public function getBaselinePosition(): Float {
|
||||
return 0;
|
||||
}
|
||||
}
|
21
Kha/Backends/WPF/kha/wpf/Graphics.hx
Normal file
21
Kha/Backends/WPF/kha/wpf/Graphics.hx
Normal file
@ -0,0 +1,21 @@
|
||||
package kha.wpf;
|
||||
|
||||
class Graphics {
|
||||
public function new() {}
|
||||
|
||||
// public function createTexture(width: Int, height: Int, format: TextureFormat, usage: Usage): Image {
|
||||
// return new Image(width, height, format);
|
||||
// }
|
||||
|
||||
public function maxTextureSize(): Int {
|
||||
return 4096;
|
||||
}
|
||||
|
||||
public function vsynced(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function refreshRate(): Int {
|
||||
return 60;
|
||||
}
|
||||
}
|
7
Kha/Backends/WPF/kha/wpf/Mouse.hx
Normal file
7
Kha/Backends/WPF/kha/wpf/Mouse.hx
Normal file
@ -0,0 +1,7 @@
|
||||
package kha.wpf;
|
||||
|
||||
class Mouse extends kha.Mouse {
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
}
|
17
Kha/Backends/WPF/kha/wpf/Music.hx
Normal file
17
Kha/Backends/WPF/kha/wpf/Music.hx
Normal file
@ -0,0 +1,17 @@
|
||||
package kha.wpf;
|
||||
|
||||
import kha.audio1.MusicChannel;
|
||||
import system.io.Path;
|
||||
import system.Uri;
|
||||
import system.UriKind;
|
||||
import system.windows.controls.MediaElement;
|
||||
import system.windows.controls.MediaState;
|
||||
|
||||
class Music extends kha.Music {
|
||||
public var filename: String;
|
||||
|
||||
public function new(filename: String): Void {
|
||||
super();
|
||||
this.filename = filename;
|
||||
}
|
||||
}
|
181
Kha/Backends/WPF/kha/wpf/Painter.hx
Normal file
181
Kha/Backends/WPF/kha/wpf/Painter.hx
Normal file
@ -0,0 +1,181 @@
|
||||
package kha.wpf;
|
||||
|
||||
import kha.FontStyle;
|
||||
import kha.Image;
|
||||
import kha.Kravur;
|
||||
import kha.math.FastMatrix3;
|
||||
import kha.math.Matrix3;
|
||||
import kha.Rotation;
|
||||
import system.windows.media.Color;
|
||||
import system.windows.media.DrawingContext;
|
||||
import system.windows.media.DrawingVisual;
|
||||
import system.windows.media.imaging.BitmapSource;
|
||||
import system.windows.media.ImageBrush;
|
||||
import system.windows.media.MatrixTransform;
|
||||
|
||||
class Painter extends kha.graphics2.Graphics {
|
||||
public var context: DrawingContext;
|
||||
public var visual: DrawingVisual;
|
||||
public var image: BitmapSource;
|
||||
|
||||
var myColor: Color;
|
||||
var myKhaColor: kha.Color;
|
||||
var myFont: Kravur;
|
||||
var tx: Float;
|
||||
var ty: Float;
|
||||
|
||||
public var width: Int;
|
||||
public var height: Int;
|
||||
|
||||
static var garbageCounter: Int = 0;
|
||||
|
||||
public function new(width: Int, height: Int) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
tx = 0;
|
||||
ty = 0;
|
||||
// font = new Font("Arial", new FontStyle(false, false, false), 20);
|
||||
}
|
||||
|
||||
override public function begin(clear: Bool = true, clearColor: kha.Color = null): Void {
|
||||
if (visual != null)
|
||||
context = visual.RenderOpen();
|
||||
context.PushTransform(new MatrixTransform(transformation._00, transformation._01, transformation._10, transformation._11, transformation._20,
|
||||
transformation._21));
|
||||
if (clear)
|
||||
this.clear(clearColor);
|
||||
}
|
||||
|
||||
override public function clear(color: kha.Color = null): Void {
|
||||
var prevColor = myKhaColor;
|
||||
this.color = color == null ? Color.Black : color;
|
||||
fillRect(0, 0, width, height);
|
||||
this.color = prevColor;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
if (visual != null) {
|
||||
context.Close();
|
||||
((global::System.Windows.Media.Imaging.RenderTargetBitmap) image).Render(visual);
|
||||
++garbageCounter;
|
||||
if (garbageCounter > 30) {
|
||||
global::System.GC.Collect(); // Because rendering into an image is a really really bad thing in WPF
|
||||
}
|
||||
}
|
||||
')
|
||||
override public function end(): Void {}
|
||||
|
||||
override public function setTransformation(transformation: FastMatrix3): Void {
|
||||
context.Pop();
|
||||
context.PushTransform(new MatrixTransform(transformation._00, transformation._01, transformation._10, transformation._11, transformation._20,
|
||||
transformation._21));
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
var img = (Image)image;
|
||||
context.DrawImage(img.image, new global::System.Windows.Rect(tx + x, ty + y, img.get_width(), img.get_height()));
|
||||
')
|
||||
override public function drawImage(image: Image, x: Float, y: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
var img = (Image)image;
|
||||
//var cropped = new System.Windows.Media.Imaging.CroppedBitmap(img.image, new System.Windows.Int32Rect((int)sx, (int)sy, (int)sw, (int)sh));
|
||||
//context.DrawImage(cropped, new System.Windows.Rect(tx + dx, ty + dy, dw, dh)); //super slow
|
||||
img.brush.Viewbox = new global::System.Windows.Rect(sx / img.get_width(), sy / img.get_height(), sw / img.get_width(), sh / img.get_height());
|
||||
context.DrawRectangle(img.brush, null, new global::System.Windows.Rect(tx + dx, ty + dy, dw, dh));
|
||||
')
|
||||
override public function drawScaledSubImage(image: kha.Image, sx: Float, sy: Float, sw: Float, sh: Float, dx: Float, dy: Float, dw: Float,
|
||||
dh: Float): Void {}
|
||||
|
||||
/*@:functionCode('
|
||||
if (text != null) {
|
||||
text.Replace(\' \', (char)160); // Non-breaking space
|
||||
System.Windows.Media.FormattedText fText = new System.Windows.Media.FormattedText(text,
|
||||
System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight,
|
||||
new System.Windows.Media.Typeface(font.get_name()), font.get_size(), new System.Windows.Media.SolidColorBrush(color));
|
||||
if (font.get_style().getBold()) fText.SetFontWeight(System.Windows.FontWeights.Bold);
|
||||
if (font.get_style().getItalic()) fText.SetFontStyle(System.Windows.FontStyles.Italic);
|
||||
if (font.get_style().getUnderlined()) fText.SetTextDecorations(System.Windows.TextDecorations.Underline);
|
||||
context.DrawText(fText, new System.Windows.Point(tx + x, ty + y));
|
||||
}
|
||||
')
|
||||
override public function drawString(text : String, x : Float, y : Float) : Void {
|
||||
|
||||
}*/
|
||||
@:functionCode('
|
||||
var img = (Image)myFont._get(myFontSize, null).getTexture();
|
||||
var xpos = tx + x;
|
||||
var ypos = ty + y;
|
||||
for (int i = 0; i < text.Length; ++i) {
|
||||
var q = myFont._get(myFontSize, null).getBakedQuad(text[i] - 32, xpos, ypos);
|
||||
if (q != null) {
|
||||
var brush = new global::System.Windows.Media.ImageBrush(img.image);
|
||||
brush.Viewbox = new global::System.Windows.Rect(q.s0, q.t0, q.s1 - q.s0, q.t1 - q.t0);
|
||||
context.PushOpacityMask(brush);
|
||||
context.DrawRectangle(new global::System.Windows.Media.SolidColorBrush(myColor), null, new global::System.Windows.Rect(q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0));
|
||||
context.Pop();
|
||||
xpos += q.xadvance;
|
||||
}
|
||||
}
|
||||
')
|
||||
override public function drawString(text: String, x: Float, y: Float): Void {}
|
||||
|
||||
override function get_color(): kha.Color {
|
||||
return myKhaColor;
|
||||
}
|
||||
|
||||
override function set_color(color: kha.Color): kha.Color {
|
||||
setColorInternal(color.Ab, color.Rb, color.Gb, color.Bb);
|
||||
return myKhaColor = color;
|
||||
}
|
||||
|
||||
override function get_font(): kha.Font {
|
||||
return myFont;
|
||||
}
|
||||
|
||||
override function set_font(font: kha.Font): kha.Font {
|
||||
return this.myFont = cast(font, Kravur);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
myColor = global::System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
|
||||
')
|
||||
function setColorInternal(a: Int, r: Int, g: Int, b: Int): Void {}
|
||||
|
||||
@:functionCode('
|
||||
if (width < 0.0) {
|
||||
x += width;
|
||||
width = -width;
|
||||
}
|
||||
if (height < 0.0) {
|
||||
y += height;
|
||||
height = -height;
|
||||
}
|
||||
context.DrawRectangle(null, new global::System.Windows.Media.Pen(new global::System.Windows.Media.SolidColorBrush(myColor), strength.value), new global::System.Windows.Rect(tx + x, ty + y, width, height));
|
||||
')
|
||||
override public function drawRect(x: Float, y: Float, width: Float, height: Float, strength: Float = 1.0): Void {}
|
||||
|
||||
@:functionCode('
|
||||
if (width < 0.0) {
|
||||
x += width;
|
||||
width = -width;
|
||||
}
|
||||
if (height < 0.0) {
|
||||
y += height;
|
||||
height = -height;
|
||||
}
|
||||
context.DrawRectangle(new global::System.Windows.Media.SolidColorBrush(myColor), new global::System.Windows.Media.Pen(), new global::System.Windows.Rect(tx + x, ty + y, width, height));
|
||||
')
|
||||
override public function fillRect(x: Float, y: Float, width: Float, height: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
context.DrawLine(new global::System.Windows.Media.Pen(new global::System.Windows.Media.SolidColorBrush(myColor), 1), new global::System.Windows.Point(tx + x1, ty + y1), new global::System.Windows.Point(tx + x2, ty + y2));
|
||||
')
|
||||
override function drawLine(x1: Float, y1: Float, x2: Float, y2: Float, strength: Float = 1.0): Void {}
|
||||
|
||||
@:functionCode('
|
||||
context.DrawVideo(((Video)video).getPlayer(), new global::System.Windows.Rect(tx + x, ty + y, width, height));
|
||||
')
|
||||
override function drawVideo(video: kha.Video, x: Float, y: Float, width: Float, height: Float): Void {}
|
||||
}
|
19
Kha/Backends/WPF/kha/wpf/Sound.hx
Normal file
19
Kha/Backends/WPF/kha/wpf/Sound.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package kha.wpf;
|
||||
|
||||
import kha.audio1.AudioChannel;
|
||||
import system.io.Path;
|
||||
import system.Uri;
|
||||
import system.UriKind;
|
||||
import system.windows.controls.MediaElement;
|
||||
import system.windows.controls.MediaState;
|
||||
|
||||
class Sound extends kha.Sound {
|
||||
public var filename: String;
|
||||
|
||||
var channel: AudioChannel;
|
||||
|
||||
public function new(filename: String): Void {
|
||||
super();
|
||||
this.filename = filename;
|
||||
}
|
||||
}
|
60
Kha/Backends/WPF/kha/wpf/Video.hx
Normal file
60
Kha/Backends/WPF/kha/wpf/Video.hx
Normal file
@ -0,0 +1,60 @@
|
||||
package kha.wpf;
|
||||
|
||||
import system.io.Path;
|
||||
import system.Uri;
|
||||
import system.UriKind;
|
||||
import system.windows.media.MediaPlayer;
|
||||
|
||||
class Video extends kha.Video {
|
||||
var player: MediaPlayer;
|
||||
|
||||
public function new(filename: String): Void {
|
||||
super();
|
||||
player = new MediaPlayer();
|
||||
player.Open(new Uri(Path.GetFullPath(filename), UriKind.Absolute));
|
||||
}
|
||||
|
||||
public function getPlayer(): MediaPlayer {
|
||||
return player;
|
||||
}
|
||||
|
||||
public override function play(loop: Bool = false): Void {
|
||||
player.Play();
|
||||
}
|
||||
|
||||
public override function pause(): Void {
|
||||
player.Pause();
|
||||
}
|
||||
|
||||
public override function stop(): Void {
|
||||
player.Stop();
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
if (player.NaturalDuration.HasTimeSpan)
|
||||
return Math.round(player.NaturalDuration.TimeSpan.TotalMilliseconds);
|
||||
else return int.MaxValue;
|
||||
')
|
||||
public override function getLength(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
return Math.round(player.Position.TotalMilliseconds);
|
||||
')
|
||||
public override function getCurrentPos(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override function getVolume(): Float {
|
||||
return player.Volume;
|
||||
}
|
||||
|
||||
public override function setVolume(volume: Float): Void {
|
||||
player.Volume = volume;
|
||||
}
|
||||
|
||||
public override function unload(): Void {
|
||||
player = null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user