Prep
Now using sln for project Changed a lot of the control's getting ready to move to https://git.jacobtech.com
This commit is contained in:
parent
91db2b6471
commit
b10a10fede
428
.gitignore
vendored
428
.gitignore
vendored
@ -1,350 +1,78 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
16
GraphicsManager.sln
Normal file
16
GraphicsManager.sln
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphicsManager", "GraphicsManager\GraphicsManager.csproj", "{5C6FC242-E345-4244-BDDE-FD5132BD7889}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5C6FC242-E345-4244-BDDE-FD5132BD7889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5C6FC242-E345-4244-BDDE-FD5132BD7889}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5C6FC242-E345-4244-BDDE-FD5132BD7889}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5C6FC242-E345-4244-BDDE-FD5132BD7889}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
1
GraphicsManager/Enums/ObjectAnchor.cs
Normal file → Executable file
1
GraphicsManager/Enums/ObjectAnchor.cs
Normal file → Executable file
@ -1,5 +1,6 @@
|
||||
namespace GraphicsManager.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum ObjectAnchor
|
||||
{
|
||||
Left = 0b_0001,
|
||||
|
7
GraphicsManager/Enums/Rendertype.cs
Executable file
7
GraphicsManager/Enums/Rendertype.cs
Executable file
@ -0,0 +1,7 @@
|
||||
namespace GraphicsManager.Enums;
|
||||
|
||||
public enum Rendertype
|
||||
{
|
||||
Limit = 0b_0001,
|
||||
ControlUpdates = 0b_0010,
|
||||
}
|
@ -1,20 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
<Authors>JacobTech</Authors>
|
||||
<Company>JacobTech, LLC</Company>
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<RepositoryUrl>https://github.com/JacobTech-com/GraphicsManager</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>1.0.0-alpha2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources/**"></EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources/**"></EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="freetype6.dll">
|
||||
<Pack>true</Pack>
|
||||
<PackagePath>lib\$(TargetFramework)</PackagePath>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTK" Version="4.7.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
|
||||
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CustomActionsAfterPack" AfterTargets="Pack">
|
||||
<Message Text="Actions AfterPack: $(PackageId).$(PackageVersion).nupkg" Importance="high" />
|
||||
<Exec Command="nuget push -Source https://nuget.jacobtech.com/v3/index.json bin/Release/$(PackageId).$(PackageVersion).nupkg" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTK" Version="4.7.1" />
|
||||
<PackageReference Include="SharpFontCore" Version="0.1.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
|
||||
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
5
GraphicsManager/Interfaces/IParent.cs
Normal file → Executable file
5
GraphicsManager/Interfaces/IParent.cs
Normal file → Executable file
@ -5,9 +5,12 @@ namespace GraphicsManager.Interfaces;
|
||||
|
||||
public interface IParent
|
||||
{
|
||||
public Vector2 LocationAsFloat { get; }
|
||||
public IParent? Parent { get; }
|
||||
public Vector2i Size { get; }
|
||||
public void Resize(ResizeEventArgs e);
|
||||
public void ParentResize(ResizeEventArgs e);
|
||||
public float[] RctToFloat(int x, int y, int Width, int Height, bool hastexture = false, float z = 0.0f);
|
||||
public Vector3 PointToVector(int x, int y, float z = 0.0f);
|
||||
public float IntToFloat(int p, bool Invert = false);
|
||||
public float FloatToInt(float p, bool Invert = false);
|
||||
public event Action<MouseButtonEventArgs> MouseDown;
|
||||
|
0
GraphicsManager/Interfaces/IRenderObject.cs
Normal file → Executable file
0
GraphicsManager/Interfaces/IRenderObject.cs
Normal file → Executable file
0
GraphicsManager/Interfaces/ITextureObject.cs
Normal file → Executable file
0
GraphicsManager/Interfaces/ITextureObject.cs
Normal file → Executable file
119
GraphicsManager/Objects/Core/Font.cs
Normal file → Executable file
119
GraphicsManager/Objects/Core/Font.cs
Normal file → Executable file
@ -1,9 +1,14 @@
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using SharpFont;
|
||||
|
||||
namespace GraphicsManager.Objects.Core;
|
||||
|
||||
public class Font
|
||||
{
|
||||
private List<Face> _Faces = new();
|
||||
private Library lib;
|
||||
public IReadOnlyList<Face> Faces => _Faces.AsReadOnly();
|
||||
public void SetEmbeddedFont(string Font, Assembly? Assembly = null)
|
||||
{
|
||||
_ = Font ?? throw new ArgumentNullException(nameof(Font));
|
||||
@ -15,45 +20,127 @@ public class Font
|
||||
public static Font MakeEmbeddedFont(string Font, Assembly? Assembly = null)
|
||||
{
|
||||
_ = Font ?? throw new ArgumentNullException(nameof(Font));
|
||||
return new Font()
|
||||
Font fontclass = new Font()
|
||||
{
|
||||
Assembly = Assembly,
|
||||
Embeded = true,
|
||||
Name = Font,
|
||||
};
|
||||
Library lib = new();
|
||||
string Base = "GraphicsManager.Resources.Fonts.";
|
||||
if (Assembly is not null) Base = string.Empty;
|
||||
byte[] f = (Assembly is null
|
||||
? Tools.GetResourceBytes(Base + Font)
|
||||
: Tools.GetResourceBytes(Assembly!, $"{Base}{Font}"));
|
||||
fontclass._Faces.Add(new Face(lib, f, 0));
|
||||
//load the fucking system fonts
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
try
|
||||
{
|
||||
Process proc = new()
|
||||
{
|
||||
};
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
string[] files = proc.StandardOutput.ReadToEnd().Split($":{Environment.NewLine}");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
fontclass._Faces.Add(new Face(lib, files[i], 0));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return fontclass;
|
||||
}
|
||||
|
||||
public static Font MakeFontFromSystem()
|
||||
{
|
||||
|
||||
Font fontclass = new()
|
||||
{
|
||||
Assembly = null,
|
||||
Embeded = false,
|
||||
Name = default!,
|
||||
lib = new()
|
||||
};
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
try
|
||||
{
|
||||
Process proc = new()
|
||||
{
|
||||
StartInfo = new()
|
||||
{
|
||||
FileName = "/bin/bash",
|
||||
Arguments = "-c \"fc-list ':' file\"",
|
||||
RedirectStandardOutput = true,
|
||||
}
|
||||
};
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
fontclass._Faces.Add(new Face(fontclass.lib, files[i], 0));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return fontclass;
|
||||
}
|
||||
|
||||
public static Font MakeFontFromFile(string Font)
|
||||
{
|
||||
_ = Font ?? throw new ArgumentNullException(nameof(Font));
|
||||
return new Font()
|
||||
Font fontclass = new Font()
|
||||
{
|
||||
Assembly = null,
|
||||
Embeded = false,
|
||||
Name = Font,
|
||||
};
|
||||
fontclass.lib = new();
|
||||
fontclass._Faces.Add(new Face(fontclass.lib, File.ReadAllBytes(Font), 0));
|
||||
//load the fucking system fonts
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
try
|
||||
{
|
||||
Process proc = new()
|
||||
{
|
||||
};
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
string[] files = proc.StandardOutput.ReadToEnd().Split($":{Environment.NewLine}");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
fontclass._Faces.Add(new Face(fontclass.lib, files[i], 0));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return fontclass;
|
||||
}
|
||||
|
||||
public void SetFontFile(string Font)
|
||||
{
|
||||
_ = Font ?? throw new ArgumentNullException(nameof(Font));
|
||||
_Faces.RemoveAt(0);
|
||||
_Faces.Reverse();
|
||||
_Faces.Add(new Face(lib, File.ReadAllBytes(Font), 0));
|
||||
_Faces.Reverse();
|
||||
this.Assembly = null;
|
||||
this.Embeded = false;
|
||||
this.Name = Font;
|
||||
}
|
||||
|
||||
public byte[] GetData()
|
||||
{
|
||||
if (Embeded)
|
||||
{
|
||||
string Base = "GraphicsManager.Resources.Fonts.";
|
||||
if (Assembly is not null) Base = string.Empty;
|
||||
return (Assembly is null ? Tools.GetResourceBytes(Base + Name) : Tools.GetResourceBytes(Assembly!, $"{Base}{Name}"));
|
||||
}
|
||||
return File.ReadAllBytes(Name);
|
||||
}
|
||||
|
||||
public string Name { get; private set; } = "shal be default";
|
||||
|
||||
public string Name { get; private set; } = default!;
|
||||
public bool Embeded { get; private set; }
|
||||
public Assembly? Assembly { get; private set; }
|
||||
}
|
||||
|
0
GraphicsManager/Objects/Core/Shader.cs
Normal file → Executable file
0
GraphicsManager/Objects/Core/Shader.cs
Normal file → Executable file
76
GraphicsManager/Objects/Core/Texture.cs
Normal file → Executable file
76
GraphicsManager/Objects/Core/Texture.cs
Normal file → Executable file
@ -41,44 +41,56 @@ public class Texture
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
||||
}
|
||||
|
||||
internal Texture(Label l, char charter, uint PixelHeight, Face face)
|
||||
private Texture()
|
||||
{
|
||||
if (!Label._characters.ContainsKey(l)) Label._characters.Add(l, new Dictionary<uint, Character>());
|
||||
face.SetPixelSizes(0, PixelHeight);
|
||||
}
|
||||
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
face.SelectCharmap(Encoding.Unicode);
|
||||
ushort temp = ((ushort)charter);
|
||||
|
||||
try
|
||||
internal static Texture TextureForChar(Label l, char charter, uint PixelHeight, Face[] faces)
|
||||
{
|
||||
Texture t = new();
|
||||
for (int i = 0; i < faces.Length; i++)
|
||||
{
|
||||
face.LoadChar(temp, LoadFlags.Render, LoadTarget.Normal);
|
||||
GlyphSlot glyph = face.Glyph;
|
||||
FTBitmap bitmap = glyph.Bitmap;
|
||||
|
||||
handel = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, handel);
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
||||
PixelInternalFormat.R8, bitmap.Width, bitmap.Rows, 0,
|
||||
PixelFormat.Red, PixelType.UnsignedByte, bitmap.Buffer);
|
||||
|
||||
|
||||
Character cha = new()
|
||||
try
|
||||
{
|
||||
Size = new Vector2(bitmap.Width, bitmap.Rows),
|
||||
Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop),
|
||||
Advance = (int)glyph.Advance.X.Value,
|
||||
Texture = this,
|
||||
};
|
||||
if (!Label._characters.ContainsKey(l)) Label._characters.Add(l, new Dictionary<uint, Character>());
|
||||
if (Label._characters[l].ContainsKey(charter)) return Label._characters[l][(ushort)charter].Texture;
|
||||
faces[i].SetPixelSizes(0, PixelHeight);
|
||||
|
||||
Label._characters[l].Add(temp, cha);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
faces[i].SelectCharmap(Encoding.Unicode);
|
||||
ushort temp = ((ushort)charter);
|
||||
if (faces[i].GetCharIndex(temp) == 0) continue;
|
||||
faces[i].LoadChar(temp, LoadFlags.Render, LoadTarget.Normal);
|
||||
GlyphSlot glyph = faces[i].Glyph;
|
||||
FTBitmap bitmap = glyph.Bitmap;
|
||||
|
||||
t.handel = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, t.handel);
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
||||
PixelInternalFormat.R8, bitmap.Width, bitmap.Rows, 0,
|
||||
PixelFormat.Red, PixelType.UnsignedByte, bitmap.Buffer);
|
||||
|
||||
|
||||
Character cha = new()
|
||||
{
|
||||
Size = new Vector2(bitmap.Width, bitmap.Rows),
|
||||
Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop),
|
||||
Advance = (int)glyph.Advance.X.Value,
|
||||
Texture = t,
|
||||
};
|
||||
|
||||
Label._characters[l].Add(temp, cha);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public void LoadText()
|
||||
|
16
GraphicsManager/Objects/Core/Uniform.cs
Executable file
16
GraphicsManager/Objects/Core/Uniform.cs
Executable file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK.Mathematics;
|
||||
using Vector4 = OpenTK.Mathematics.Vector4;
|
||||
|
||||
namespace GraphicsManager.Objects.Core;
|
||||
|
||||
public record Uniform<TVertex> where TVertex : struct
|
||||
{
|
||||
public int Location { get; set; }
|
||||
public TVertex Value { get; set; }
|
||||
}
|
16
GraphicsManager/Objects/Core/Uniforms.cs
Executable file
16
GraphicsManager/Objects/Core/Uniforms.cs
Executable file
@ -0,0 +1,16 @@
|
||||
using OpenTK.Mathematics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GraphicsManager.Objects.Core;
|
||||
|
||||
public class Uniforms
|
||||
{
|
||||
public List<Uniform<Vector4>> Uniform4 { get; set; } = new();
|
||||
public List<Uniform<Vector3>> Uniform3 { get; set; } = new();
|
||||
public List<Uniform<Vector2>> Uniform2 { get; set; } = new();
|
||||
public List<Uniform<float>> Uniform1 { get; set; } = new();
|
||||
}
|
66
GraphicsManager/Objects/Label.cs
Normal file → Executable file
66
GraphicsManager/Objects/Label.cs
Normal file → Executable file
@ -5,7 +5,6 @@ using GraphicsManager.Structs;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
using SharpFont;
|
||||
using System.Reflection;
|
||||
using Encoding = SharpFont.Encoding;
|
||||
|
||||
namespace GraphicsManager.Objects;
|
||||
@ -31,33 +30,25 @@ public class Label : IRenderObject
|
||||
get => text;
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
if (Loaded)
|
||||
{
|
||||
Library lib = new();
|
||||
Face face = new(lib, Font.GetData(), 0);
|
||||
|
||||
face.SetPixelSizes(0, PixelHeight);
|
||||
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
|
||||
face.SelectCharmap(Encoding.Unicode);
|
||||
if (!_characters.ContainsKey(this)) _characters.Add(this, new Dictionary<uint, Character>());
|
||||
foreach (char character in value)
|
||||
{
|
||||
if (_characters[this].ContainsKey(character) == false)
|
||||
{
|
||||
var f = new Texture(this, character, PixelHeight, face);
|
||||
f.LoadText();
|
||||
}
|
||||
if (_characters[this].ContainsKey(character)) continue;
|
||||
var f = Texture.TextureForChar(this, character, PixelHeight, Font.Faces.ToArray());
|
||||
f.LoadText();
|
||||
}
|
||||
if (Window is not null && Window.CanControleUpdate && Loaded) Window.DrawFrame();
|
||||
}
|
||||
text = value;
|
||||
}
|
||||
}
|
||||
public uint PixelHeight { get; set; } = 20;
|
||||
public float Scale { get; set; } = 1.2f;
|
||||
public Shader Shader { get; } = DefaultTextShader;
|
||||
public Font Font { get; set; } = Font.MakeEmbeddedFont("TektonPro-Regular.otf");
|
||||
public float Scale { get; set; } = 1.0f;
|
||||
public Shader Shader { get; set; } = DefaultTextShader;
|
||||
public Font Font { get; set; } = Font.MakeFontFromSystem();
|
||||
|
||||
public Vector4 Color { get; set; } = new Vector4(1, 1, 1, 1);
|
||||
public Vector2i Distance { get; private set; }
|
||||
@ -71,10 +62,10 @@ public class Label : IRenderObject
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
loc_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
locc_ = new(value.X + Parent.Position.X, value.Y + Parent.Position.Y);
|
||||
locc_ = new((int)Window.FloatToInt(Parent.IntToFloat(value.X)), (int)Window.FloatToInt(Parent.IntToFloat(value.Y, true), true));
|
||||
if (Window.CanControleUpdate && Loaded) Window.DrawFrame();
|
||||
}
|
||||
}
|
||||
public Vector2i Size { get; set; }
|
||||
@ -86,7 +77,7 @@ public class Label : IRenderObject
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (Visible & loadd)
|
||||
if (Visible & Loaded)
|
||||
{
|
||||
Shader.Use();
|
||||
GL.Enable(EnableCap.Blend);
|
||||
@ -103,19 +94,10 @@ public class Label : IRenderObject
|
||||
Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(locc_.X, locc_.Y, 0f));
|
||||
|
||||
float char_x = 0.0f;
|
||||
|
||||
Library lib = new();
|
||||
|
||||
Face face = new(lib, Font.GetData(), 0);
|
||||
|
||||
face.SetPixelSizes(0, PixelHeight);
|
||||
|
||||
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
face.SelectCharmap(Encoding.Unicode);
|
||||
|
||||
|
||||
|
||||
float hhh = 0f;
|
||||
foreach (char c in Text)
|
||||
{
|
||||
@ -155,16 +137,16 @@ public class Label : IRenderObject
|
||||
|
||||
public void LoadToParent(IParent window, Window win)
|
||||
{
|
||||
if (Loaded) return;
|
||||
if (!_characters.ContainsKey(this)) _characters.Add(this, new Dictionary<uint, Character>());
|
||||
Parent = window;
|
||||
Window = win;
|
||||
//X = window.FloatToInt(X, window.Size.X);
|
||||
//Y = window.FloatToInt(Y, window.Size.Y, true);
|
||||
Library lib = new();
|
||||
|
||||
Face face = new(lib, Font.GetData(), 0);
|
||||
face.SetPixelSizes(0, PixelHeight);
|
||||
//Face face = new(lib, Font.Faces.First(), 0);
|
||||
//face.SetPixelSizes(0, PixelHeight);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
face.SelectCharmap(Encoding.Unicode);
|
||||
//face.SelectCharmap(Encoding.Unicode);
|
||||
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
|
||||
|
||||
@ -182,7 +164,7 @@ public class Label : IRenderObject
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 4 * 6 * 4, vquad, BufferUsageHint.StaticDraw);
|
||||
|
||||
VAO = GL.GenVertexArray();
|
||||
VAO = GL.GenVertexArray();/*
|
||||
if (!_characters.ContainsKey(this)) _characters.Add(this, new Dictionary<uint, Character>());
|
||||
foreach (char character in Text)
|
||||
{
|
||||
@ -191,7 +173,7 @@ public class Label : IRenderObject
|
||||
var f = new Texture(this, character, PixelHeight, face);
|
||||
f.LoadText();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
GL.BindVertexArray(VAO);
|
||||
GL.EnableVertexAttribArray(0);
|
||||
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * 4, 0);
|
||||
@ -200,15 +182,15 @@ public class Label : IRenderObject
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.BindVertexArray(0);
|
||||
Text = text;
|
||||
loadd = true;
|
||||
|
||||
Loaded = true;
|
||||
Text = Text;
|
||||
Location = Location;
|
||||
Distance = new(window.Size.X - Size.X - Location.X, window.Size.Y - Size.Y - Location.Y);
|
||||
}
|
||||
|
||||
private bool loadd = false;
|
||||
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public bool Loaded => loadd;
|
||||
public bool Loaded { get; private set; } = false;
|
||||
}
|
||||
|
49
GraphicsManager/Objects/Rectangle.cs
Normal file → Executable file
49
GraphicsManager/Objects/Rectangle.cs
Normal file → Executable file
@ -3,6 +3,7 @@ using GraphicsManager.Interfaces;
|
||||
using GraphicsManager.Objects.Core;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Windowing.GraphicsLibraryFramework;
|
||||
|
||||
namespace GraphicsManager.Objects;
|
||||
|
||||
@ -31,17 +32,32 @@ public class Rectangle : ITextureObject
|
||||
}
|
||||
}
|
||||
|
||||
public Vector4 Color { get; set; }
|
||||
public Uniforms Uniforms { get; } = new() { Uniform4 = new() { new() { Location = 0, Value = new(0,0,0,1) } } };
|
||||
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (Visible)
|
||||
if (Visible && Loaded)
|
||||
{
|
||||
if (Texture is not null) Texture.Use();
|
||||
Shader.Use();
|
||||
GL.Uniform4(0, Color);
|
||||
for (int i = 0; i < Uniforms.Uniform4.Count; i++)
|
||||
{
|
||||
GL.Uniform4(Uniforms.Uniform4[i].Location, Uniforms.Uniform4[i].Value);
|
||||
}
|
||||
for (int i = 0; i < Uniforms.Uniform3.Count; i++)
|
||||
{
|
||||
GL.Uniform3(Uniforms.Uniform3[i].Location, Uniforms.Uniform3[i].Value);
|
||||
}
|
||||
for (int i = 0; i < Uniforms.Uniform2.Count; i++)
|
||||
{
|
||||
GL.Uniform2(Uniforms.Uniform2[i].Location, Uniforms.Uniform2[i].Value);
|
||||
}
|
||||
for (int i = 0; i < Uniforms.Uniform1.Count; i++)
|
||||
{
|
||||
GL.Uniform1(Uniforms.Uniform1[i].Location, Uniforms.Uniform1[i].Value);
|
||||
}
|
||||
if (Texture is not null)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
@ -62,6 +78,7 @@ public class Rectangle : ITextureObject
|
||||
|
||||
public void LoadToParent(IParent Parent, Window Window)
|
||||
{
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
int pos = Points.Length - 3;
|
||||
@ -88,9 +105,7 @@ public class Rectangle : ITextureObject
|
||||
ElementBufferObject = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
||||
load = true;
|
||||
loadd = true;
|
||||
|
||||
Loaded = true;
|
||||
Window.MouseDown += Window_MouseDown;
|
||||
Location = Location;
|
||||
Distance = new(Parent.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y);
|
||||
@ -101,7 +116,14 @@ public class Rectangle : ITextureObject
|
||||
|
||||
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
|
||||
{
|
||||
if (Clicked is not null && e.Button == OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button1 && Location.X <= Parent?.MousePosition.X && Size.X + Location.X >= Parent?.MousePosition.X && Location.Y + Size.Y >= Parent?.MousePosition.Y && Location.Y <= Parent?.MousePosition.Y) Clicked.Invoke(this);
|
||||
if (e.Button == MouseButton.Button1 &&
|
||||
Parent?.IntToFloat(Location.X) <= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Size.X + Location.X) >= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true) &&
|
||||
Parent?.IntToFloat(Location.Y, true) >= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true))
|
||||
{
|
||||
if (Clicked is not null) Clicked.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
~Rectangle()
|
||||
@ -116,7 +138,6 @@ public class Rectangle : ITextureObject
|
||||
public int ArrayObject { get; private set; }
|
||||
private float[] Points_;
|
||||
private Vector2i size_ = new(), loc_ = new();
|
||||
bool load = false;
|
||||
|
||||
public float[] Points
|
||||
{
|
||||
@ -129,7 +150,7 @@ public class Rectangle : ITextureObject
|
||||
Points_ = value;
|
||||
try
|
||||
{
|
||||
if (load)
|
||||
if (Loaded)
|
||||
{
|
||||
int add = 3;
|
||||
if (Texture is not null) add = 5;
|
||||
@ -142,6 +163,7 @@ public class Rectangle : ITextureObject
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
||||
if (Window is not null && Window.CanControleUpdate && Loaded) Window.DrawFrame();
|
||||
}
|
||||
}
|
||||
catch (AccessViolationException v)
|
||||
@ -154,11 +176,10 @@ public class Rectangle : ITextureObject
|
||||
public uint[] Indexs { get; set; } = new uint[6] { 0, 1, 3, 1, 2, 3 };
|
||||
public BufferUsageHint Hint { get; set; } = BufferUsageHint.StaticDraw;
|
||||
|
||||
private bool loadd = false;
|
||||
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public bool Loaded => loadd;
|
||||
public bool Loaded { get; private set; } = false;
|
||||
public Vector2i Distance { get; private set; }
|
||||
|
||||
public Vector2i Size
|
||||
@ -172,7 +193,7 @@ public class Rectangle : ITextureObject
|
||||
size_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
float[] temp = Points;
|
||||
saf = new Vector2(Window.IntToFloat(value.X + loc_.X + Parent.Position.X, false), Window.IntToFloat(value.Y + loc_.Y + Parent.Position.Y, true));
|
||||
saf = new Vector2(Parent.IntToFloat(value.X + loc_.X, false), Parent.IntToFloat(value.Y + loc_.Y, true));
|
||||
temp[0] = saf.X;
|
||||
temp[(Texture is null ? 3 : 5)] = saf.X;
|
||||
temp[(Texture is null ? 4 : 6)] = saf.Y;
|
||||
@ -192,12 +213,12 @@ public class Rectangle : ITextureObject
|
||||
loc_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
float[] temp = Points;
|
||||
laf = new Vector2(Window.IntToFloat(value.X + Parent.Position.X, false), Window.IntToFloat(value.Y + Parent.Position.Y, true));
|
||||
laf = new Vector2(Parent.IntToFloat(value.X, false), Parent.IntToFloat(value.Y, true));
|
||||
temp[(Texture is null ? 6 : 10)] = laf.X;
|
||||
temp[(Texture is null ? 9 : 15)] = laf.X;
|
||||
temp[1] = laf.Y;
|
||||
temp[(Texture is null ? 10 : 16)] = laf.Y;
|
||||
saf = new Vector2(Window.IntToFloat(Size.X + value.X + Parent.Position.X, false), Window.IntToFloat(Size.Y + value.Y + Parent.Position.Y, true));
|
||||
saf = new Vector2(Parent.IntToFloat(Size.X + value.X, false), Parent.IntToFloat(Size.Y + value.Y, true));
|
||||
temp[0] = saf.X;
|
||||
temp[(Texture is null ? 3 : 5)] = saf.X;
|
||||
temp[(Texture is null ? 4 : 6)] = saf.Y;
|
||||
|
317
GraphicsManager/Objects/RoundedRectangle.cs
Executable file
317
GraphicsManager/Objects/RoundedRectangle.cs
Executable file
@ -0,0 +1,317 @@
|
||||
using GraphicsManager.Enums;
|
||||
using GraphicsManager.Interfaces;
|
||||
using GraphicsManager.Objects.Core;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Windowing.GraphicsLibraryFramework;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace GraphicsManager.Objects;
|
||||
|
||||
public class RoundedRectangle : IRenderObject
|
||||
{
|
||||
public static readonly Shader DefaultShader = Rectangle.DefaultShader;
|
||||
|
||||
public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top;
|
||||
private const int sn = 4, r = 5;
|
||||
private int sn_ = sn, r_ = r;
|
||||
|
||||
public RoundedRectangle()
|
||||
{
|
||||
Points_ = new float[36 + (((sn - 1) * 4) * 3)];
|
||||
}
|
||||
|
||||
public Uniforms Uniforms { get; set; } = new() { Uniform4 = new() { new() { Location = 0, Value = new(0,0,0,1) } } };
|
||||
public int Radius
|
||||
{
|
||||
get
|
||||
{
|
||||
return r_;
|
||||
}
|
||||
set
|
||||
{
|
||||
r_ = value;
|
||||
Location = Location;
|
||||
}
|
||||
}
|
||||
|
||||
public int Smoothness
|
||||
{
|
||||
get
|
||||
{
|
||||
return sn_;
|
||||
}
|
||||
set
|
||||
{
|
||||
sn_ = value;
|
||||
List<uint> Indexs = this.Indexs.ToList().GetRange(0, 30);
|
||||
uint wall = 5;
|
||||
uint last = 12;
|
||||
for (uint i = 0; i < 4; i++)
|
||||
{
|
||||
if (value == 1)
|
||||
{
|
||||
Indexs.Add(i);
|
||||
Indexs.Add(wall);
|
||||
wall++;
|
||||
if (wall == 12) wall = 4;
|
||||
Indexs.Add(wall);
|
||||
wall++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint j = 0; j < value; j++)
|
||||
{
|
||||
Indexs.Add(i);
|
||||
if (j == 0 || j == value - 1)
|
||||
{
|
||||
if (wall == 12) wall = 4;
|
||||
Indexs.Add(wall);
|
||||
wall++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Indexs.Add(last);
|
||||
last++;
|
||||
}
|
||||
Indexs.Add(last);
|
||||
|
||||
}
|
||||
last++;
|
||||
}
|
||||
}
|
||||
this.Indexs = Indexs.ToArray();
|
||||
Location = Location;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (Visible && Loaded)
|
||||
{
|
||||
GL.Enable(EnableCap.Multisample);
|
||||
GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
|
||||
GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
|
||||
GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest);
|
||||
GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
|
||||
Shader.Use();
|
||||
for (int i = 0; i < Uniforms.Uniform4.Count; i++)
|
||||
{
|
||||
GL.Uniform4(Uniforms.Uniform4[i].Location, Uniforms.Uniform4[i].Value);
|
||||
}
|
||||
for (int i = 0; i < Uniforms.Uniform3.Count; i++)
|
||||
{
|
||||
GL.Uniform3(Uniforms.Uniform3[i].Location, Uniforms.Uniform3[i].Value);
|
||||
}
|
||||
for (int i = 0; i < Uniforms.Uniform2.Count; i++)
|
||||
{
|
||||
GL.Uniform2(Uniforms.Uniform2[i].Location, Uniforms.Uniform2[i].Value);
|
||||
}
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
|
||||
GL.DrawElements(PrimitiveType.Triangles, Indexs.Length, DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.DeleteBuffer(BufferObject);
|
||||
}
|
||||
|
||||
public void LoadToParent(IParent Parent, Window Window)
|
||||
{
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
int pos = Points.Length - 3;
|
||||
pos = 4;
|
||||
|
||||
BufferObject = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
ArrayObject = GL.GenVertexArray();
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
int add = 3;
|
||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0);
|
||||
GL.EnableVertexAttribArray(0);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, Points.Length * sizeof(float), Points, Hint);
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
ElementBufferObject = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
||||
Loaded = true;
|
||||
Window.MouseDown += Window_MouseDown;
|
||||
Location = Location;
|
||||
Distance = new(Parent.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y);
|
||||
}
|
||||
|
||||
public IParent? Parent { get; private set; }
|
||||
public Window? Window { get; private set; }
|
||||
|
||||
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButton.Button1 &&
|
||||
Parent?.IntToFloat(Location.X) <= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Size.X + Location.X) >= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true) &&
|
||||
Parent?.IntToFloat(Location.Y, true) >= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true))
|
||||
{
|
||||
if (Clicked is not null) Clicked.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
~RoundedRectangle()
|
||||
{
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.DeleteBuffer(BufferObject);
|
||||
}
|
||||
|
||||
public Shader Shader { get; set; } = DefaultShader;
|
||||
public int ElementBufferObject { get; private set; }
|
||||
public int BufferObject { get; private set; }
|
||||
public int ArrayObject { get; private set; }
|
||||
private float[] Points_;
|
||||
private Vector2i size_ = new(), loc_ = new();
|
||||
|
||||
public float[] Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return Points_;
|
||||
}
|
||||
set
|
||||
{
|
||||
Points_ = value;
|
||||
try
|
||||
{
|
||||
if (Loaded)
|
||||
{
|
||||
int add = 3;
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0);
|
||||
GL.EnableVertexAttribArray(0);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, Points_.Length * sizeof(float), Points_, Hint);
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
||||
if (Window is not null && Window.CanControleUpdate && Loaded) Window.DrawFrame();
|
||||
}
|
||||
}
|
||||
catch (AccessViolationException v)
|
||||
{
|
||||
Console.WriteLine(v.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint[] Indexs { get; set; } = new uint[30 + ((sn * 4) * 3)] { 0, 1, 3, 1, 2, 3, 0, 3, 4, 0, 4, 5, 0, 1, 7, 0, 6, 7, 1, 2, 9, 1, 8, 9, 2, 3, 11, 2, 10, 11,
|
||||
0, 5, 12,
|
||||
0, 12, 13,
|
||||
0, 13, 14,
|
||||
0, 6, 14,
|
||||
|
||||
1, 7, 15,
|
||||
1, 15, 16,
|
||||
1, 16, 17,
|
||||
1, 8, 17,
|
||||
|
||||
2, 9, 18,
|
||||
2, 18, 19,
|
||||
2, 19, 20,
|
||||
2, 10, 20,
|
||||
|
||||
3, 11, 21,
|
||||
3, 21, 22,
|
||||
3, 22, 23,
|
||||
3, 4, 23};
|
||||
public BufferUsageHint Hint { get; set; } = BufferUsageHint.StaticDraw;
|
||||
|
||||
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public bool Loaded { get; private set; } = false;
|
||||
public Vector2i Distance { get; private set; }
|
||||
|
||||
public Vector2i Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
set
|
||||
{
|
||||
size_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
Location = Location;
|
||||
saf = new Vector2(Parent.IntToFloat(value.X + loc_.X, false), Parent.IntToFloat(value.Y + loc_.Y, true));
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2i Location
|
||||
{
|
||||
get
|
||||
{
|
||||
return loc_;
|
||||
}
|
||||
set
|
||||
{
|
||||
loc_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
List<float> temp;
|
||||
saf = new Vector2(Parent.IntToFloat(Size.X + loc_.X, false), Parent.IntToFloat(Size.Y + loc_.Y, true));
|
||||
Vector3 _0 = Parent.PointToVector(value.X + Size.X - Radius, value.Y + Radius, 0);
|
||||
Vector3 _1 = Parent.PointToVector(value.X + Size.X - Radius, value.Y + Size.Y - Radius, 0);
|
||||
Vector3 _2 = Parent.PointToVector(value.X + Radius, value.Y + Size.Y - Radius, 0);
|
||||
Vector3 _3 = Parent.PointToVector(value.X + Radius, value.Y + Radius, 0);
|
||||
Vector3 _4 = Parent.PointToVector(value.X + Radius, value.Y, 0);
|
||||
Vector3 _5 = Parent.PointToVector(value.X + Size.X - Radius, value.Y, 0);
|
||||
Vector3 _6 = Parent.PointToVector(value.X + Size.X, value.Y + Radius, 0);
|
||||
Vector3 _7 = Parent.PointToVector(value.X + Size.X, value.Y + Size.Y - Radius, 0);
|
||||
Vector3 _8 = Parent.PointToVector(value.X + Size.X - Radius, value.Y + Size.Y, 0);
|
||||
Vector3 _9 = Parent.PointToVector(value.X + Radius, value.Y + Size.Y, 0);
|
||||
Vector3 _10 = Parent.PointToVector(value.X, value.Y + Size.Y - Radius, 0);
|
||||
Vector3 _11 = Parent.PointToVector(value.X, value.Y + Radius, 0);
|
||||
int[] ff = new int[]
|
||||
{
|
||||
value.X + Size.X - Radius,
|
||||
value.X + Size.X - Radius,
|
||||
value.X + Radius,
|
||||
value.X + Radius,
|
||||
value.Y + Radius,
|
||||
value.Y + Size.Y - Radius,
|
||||
value.Y + Size.Y - Radius,
|
||||
value.Y + Radius
|
||||
};
|
||||
float rotation = 90f / (Smoothness);
|
||||
temp = new()
|
||||
{
|
||||
_0.X, _0.Y, _0.Z, _1.X, _1.Y, _1.Z, _2.X, _2.Y, _2.Z, _3.X, _3.Y, _3.Z, _4.X, _4.Y, _4.Z, _5.X, _5.Y, _5.Z, _6.X, _6.Y, _6.Z, _7.X, _7.Y, _7.Z, _8.X, _8.Y, _8.Z, _9.X, _9.Y, _9.Z, _10.X, _10.Y, _10.Z, _11.X, _11.Y, _11.Z
|
||||
};
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
int start = 90 - (j * 90);
|
||||
for (int i = 0; i < Smoothness - 1; i++)
|
||||
{
|
||||
var degpre = (rotation * (i + 1));
|
||||
var deg = start - degpre;
|
||||
double y = ff[j + 4] - (Math.Sin(MathHelper.DegreesToRadians(deg)) * Radius);
|
||||
double x = (Math.Cos(MathHelper.DegreesToRadians(deg)) * Radius) + ff[j];
|
||||
Vector3 tri = Parent.PointToVector((int)x, (int)y, 0f);
|
||||
temp.Add(tri.X);
|
||||
temp.Add(tri.Y);
|
||||
temp.Add(tri.Z);
|
||||
}
|
||||
}
|
||||
Points = temp.ToArray();
|
||||
}
|
||||
}
|
||||
private Vector2 laf = new(), saf = new();
|
||||
|
||||
public Vector2 LocationAsFloat { get { return laf; } }
|
||||
public Vector2 SizeAsFloat { get { return saf; } }
|
||||
}
|
193
GraphicsManager/Objects/Textbox.cs
Normal file → Executable file
193
GraphicsManager/Objects/Textbox.cs
Normal file → Executable file
@ -6,116 +6,155 @@ using OpenTK.Windowing.GraphicsLibraryFramework;
|
||||
|
||||
namespace GraphicsManager.Objects;
|
||||
|
||||
public class Textbox : ITextureObject
|
||||
public class Textbox : IRenderObject
|
||||
{
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
public Rectangle Bounds;
|
||||
public Label Label;
|
||||
public IParent Parent { get; private set; }
|
||||
public Textbox(Texture texture = null!)
|
||||
private RoundedRectangle _bounds, _inside;
|
||||
private Label _label;
|
||||
public Textbox()
|
||||
{
|
||||
Bounds = new Rectangle(texture ?? new Texture(Tools.GetResourceBytes("GraphicsManager.Resources.Textures.Textbox.png")));
|
||||
Label = new Label()
|
||||
{
|
||||
Text = nameof(Textbox)
|
||||
};
|
||||
_bounds = new RoundedRectangle();
|
||||
_inside = new RoundedRectangle();
|
||||
_label = new Label();
|
||||
}
|
||||
public Vector2i Size { get { return Bounds.Size; } set { Bounds.Size = value; } }
|
||||
public Vector2i Location { get { return Bounds.Location; } set { Bounds.Location = value; } }
|
||||
public Vector2i Distance { get { return Bounds.Distance; }}
|
||||
public Texture Texture => Bounds.Texture!;
|
||||
|
||||
public string Text { get => Label.Text; set => Label.Text = value; }
|
||||
public Font Font { get => Label.Font; set => Label.Font = value; }
|
||||
public Vector4 BackgroundColor { get => Bounds.Color; set => Bounds.Color = value; }
|
||||
public float[] Points
|
||||
public int Radius { get => _bounds.Radius; set { _bounds.Radius = value; _inside.Radius = value; } }
|
||||
public int Border { get; set; } = 2;
|
||||
public int Smoothness { get => _bounds.Smoothness; set { _bounds.Smoothness = value; _inside.Smoothness = value; } }
|
||||
public ObjectAnchor Anchor { get => _bounds.Anchor; set { _bounds.Anchor = value; _inside.Anchor = value; _label.Anchor = value; } }
|
||||
public Font Font { get => _label.Font; set => _label.Font = value; }
|
||||
public string Text { get => _label.Text; set => _label.Text = value; }
|
||||
public bool Loaded { get; private set; } = false;
|
||||
public Vector2i Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return Bounds.Points;
|
||||
return _bounds.Size;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Label is not null && Parent is not null)
|
||||
{
|
||||
Label.Location = new Vector2i((int)Parent.FloatToInt(value[10] + ((-1 - Parent.IntToFloat(10)) * -1)), (int)Parent.FloatToInt(value[6] + (-1 - Parent.IntToFloat(5)) * -1, true));
|
||||
}
|
||||
Bounds.Points = value;
|
||||
_bounds.Size = value;
|
||||
_inside.Size = new(value.X - (Border * 2), value.Y - (Border * 2));
|
||||
}
|
||||
}
|
||||
public Vector2i Location {
|
||||
get => _bounds.Location;
|
||||
set
|
||||
{
|
||||
_bounds.Location = value;
|
||||
_label.Location = new(value.X + Radius + 5, value.Y + Size.Y - Radius - 5);
|
||||
_inside.Location = new(value.X + Border, value.Y + Border);
|
||||
}
|
||||
}
|
||||
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
|
||||
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
||||
public Vector2i Distance { get => _bounds.Distance; }
|
||||
public IParent? Parent { get; private set; } = null;
|
||||
public Window? Window { get; private set; } = null;
|
||||
|
||||
public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top;
|
||||
|
||||
private bool _loaded = false;
|
||||
public bool Loaded => _loaded;
|
||||
|
||||
public Color4 InsideColor
|
||||
{
|
||||
get
|
||||
{
|
||||
Uniform<Vector4> u4 = _inside.Uniforms.Uniform4.Where(u => u.Location == 0).First();
|
||||
if (u4 is null) u4 = new() { Location = 0, Value = new(1, 1, 0, 1) };
|
||||
return new Color4(u4.Value.X, u4.Value.X, u4.Value.X, u4.Value.X);
|
||||
}
|
||||
set
|
||||
{
|
||||
Uniform<Vector4> u4 = _inside.Uniforms.Uniform4.Where(u => u.Location == 0).First();
|
||||
if (u4 is not null) _inside.Uniforms.Uniform4.Remove(u4);
|
||||
if (u4 is null) u4 = new() { Location = 0 };
|
||||
u4.Value = new(value.R, value.G, value.B, value.A);
|
||||
_inside.Uniforms.Uniform4.Add(u4);
|
||||
}
|
||||
}
|
||||
public Color4 BorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
Uniform<Vector4> u4 = _bounds.Uniforms.Uniform4.Where(u => u.Location == 0).First();
|
||||
if (u4 is null) u4 = new() { Location = 0, Value = new(1, 1, 0, 1) };
|
||||
return new Color4(u4.Value.X, u4.Value.X, u4.Value.X, u4.Value.X);
|
||||
}
|
||||
set
|
||||
{
|
||||
Uniform<Vector4> u4 = _bounds.Uniforms.Uniform4.Where(u => u.Location == 0).First();
|
||||
if (u4 is not null) _bounds.Uniforms.Uniform4.Remove(u4);
|
||||
if (u4 is null) u4 = new() { Location = 0 };
|
||||
u4.Value = new(value.R, value.G, value.B, value.A);
|
||||
_bounds.Uniforms.Uniform4.Add(u4);
|
||||
}
|
||||
}
|
||||
public bool Visible { get; set; } = true;
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
Bounds.Clean();
|
||||
Label.Clean();
|
||||
_bounds.Clean();
|
||||
_inside.Clean();
|
||||
_label.Clean();
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
Bounds.Draw();
|
||||
Label.Draw();
|
||||
}
|
||||
public Window? Window { get; private set; }
|
||||
public void LoadToParent(IParent Parent, Window Window)
|
||||
{
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
this.Parent.MouseDown += Parrent_MouseDown;
|
||||
this.Parent.KeyDown += Parrent_KeyDown;
|
||||
Bounds.LoadToParent(Parent, Window);
|
||||
Points = Points;
|
||||
Label.LoadToParent(Parent, Window);
|
||||
_loaded = true;
|
||||
if (!Visible || !Loaded) return;
|
||||
_bounds.Draw();
|
||||
_inside.Draw();
|
||||
_label.Draw();
|
||||
}
|
||||
|
||||
private void Parrent_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj)
|
||||
public void LoadToParent(IParent Parent, Window Window)
|
||||
{
|
||||
if (use)
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
this.Window.MouseDown += Window_MouseDown;
|
||||
this.Window.KeyDown += Window_KeyDown;
|
||||
Loaded = true;
|
||||
_bounds.LoadToParent(Parent, Window);
|
||||
_inside.LoadToParent(Parent, Window);
|
||||
_label.LoadToParent(Parent, Window);
|
||||
Location = Location;
|
||||
}
|
||||
private bool use = false;
|
||||
private void Window_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj)
|
||||
{
|
||||
if (!use) return;
|
||||
if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return;
|
||||
if (obj.Key == Keys.Backspace)
|
||||
{
|
||||
if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return;
|
||||
if (obj.Key == Keys.Backspace)
|
||||
{
|
||||
if (!(Text.Length > 0)) return;
|
||||
Text = Text.Remove(Text.Length - 1, 1);
|
||||
}
|
||||
else if (obj.Key == Keys.Delete)
|
||||
{
|
||||
if (!(Text.Length > 0)) return;
|
||||
Text = Text.Remove(Text.Length - 1, 1);
|
||||
}
|
||||
else if (obj.Shift)
|
||||
{
|
||||
if (obj.Key == Keys.Enter || obj.Key == Keys.KeyPadEnter) Text += '\n';
|
||||
else if (obj.Key == Keys.LeftShift || obj.Key == Keys.KeyPadEnter || obj.Key == Keys.Enter || obj.Key == Keys.End || obj.Key == Keys.Down) return;
|
||||
else Text += ((char)obj.Key).ToString().ToUpper();
|
||||
}
|
||||
else if (obj.Command || obj.Alt || obj.Control) { }
|
||||
else
|
||||
{
|
||||
Text += ((char)obj.Key).ToString().ToLower();
|
||||
}
|
||||
if (!(Text.Length > 0)) return;
|
||||
Text = Text.Remove(Text.Length - 1, 1);
|
||||
}
|
||||
else if (obj.Key == Keys.Delete)
|
||||
{
|
||||
if (!(Text.Length > 0)) return;
|
||||
Text = Text.Remove(Text.Length - 1, 1);
|
||||
}
|
||||
else if (obj.Shift)
|
||||
{
|
||||
if (obj.Key == Keys.Enter || obj.Key == Keys.KeyPadEnter) Text += '\n';
|
||||
else if (obj.Key == Keys.LeftShift || obj.Key == Keys.KeyPadEnter || obj.Key == Keys.Enter || obj.Key == Keys.End || obj.Key == Keys.Down) return;
|
||||
else Text += ((char)obj.Key).ToString().ToUpper();
|
||||
}
|
||||
else if (obj.Command || obj.Alt || obj.Control) { }
|
||||
else
|
||||
{
|
||||
Text += ((char)obj.Key).ToString().ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
bool use = false;
|
||||
|
||||
private void Parrent_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
|
||||
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButton.Button1 && Location.X <= Parent?.MousePosition.X && Size.X + Location.X >= Parent?.MousePosition.X && Location.Y + Size.Y >= Parent?.MousePosition.Y && Location.Y <= Parent?.MousePosition.Y)
|
||||
if (e.Button == MouseButton.Button1 &&
|
||||
Parent?.IntToFloat(Location.X) <= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Size.X + Location.X) >= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true) &&
|
||||
Parent?.IntToFloat(Location.Y, true) >= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true))
|
||||
{
|
||||
use = true;
|
||||
if (Clicked is not null) Clicked.Invoke(this);
|
||||
}
|
||||
else use = false;
|
||||
}
|
||||
|
||||
public Vector2 LocationAsFloat { get { return Bounds.LocationAsFloat; } }
|
||||
public Vector2 SizeAsFloat { get { return Bounds.SizeAsFloat; } }
|
||||
}
|
||||
|
38
GraphicsManager/Objects/UserControl.cs
Normal file → Executable file
38
GraphicsManager/Objects/UserControl.cs
Normal file → Executable file
@ -1,5 +1,6 @@
|
||||
using GraphicsManager.Enums;
|
||||
using GraphicsManager.Interfaces;
|
||||
using GraphicsManager.Objects.Core;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Windowing.Common;
|
||||
|
||||
@ -23,7 +24,7 @@ public class UserControl : IRenderObject, IParent
|
||||
|
||||
public ICollection<IRenderObject> Controls { get; } = new List<IRenderObject>();
|
||||
public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; }
|
||||
public Vector4 Color { get => _bounds.Color; set => _bounds.Color = value; }
|
||||
public Uniforms Uniforms { get => _bounds.Uniforms; }
|
||||
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; }
|
||||
public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; }
|
||||
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
|
||||
@ -39,18 +40,19 @@ public class UserControl : IRenderObject, IParent
|
||||
public Window? Window { get; private set; }
|
||||
public bool Loaded { get; private set; } = false;
|
||||
|
||||
public Vector2 MousePosition => throw new NotImplementedException();
|
||||
public Vector2 MousePosition => Window!.MousePosition;
|
||||
|
||||
public void LoadToParent(IParent Parent, Window Window)
|
||||
{
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
Loaded = true;
|
||||
_bounds.LoadToParent(Parent, Window);
|
||||
foreach (IRenderObject obj in Controls)
|
||||
{
|
||||
obj.LoadToParent(this, Window);
|
||||
}
|
||||
Loaded = true;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
@ -83,7 +85,7 @@ public class UserControl : IRenderObject, IParent
|
||||
_bounds.Clean();
|
||||
}
|
||||
|
||||
public void Resize(ResizeEventArgs e)
|
||||
public void ParentResize(ResizeEventArgs e)
|
||||
{
|
||||
if (e.Width == 0 && e.Height == 0) return;
|
||||
foreach (IRenderObject Control in Controls)
|
||||
@ -102,6 +104,10 @@ public class UserControl : IRenderObject, IParent
|
||||
int sx = (right ? Size.X - Control.Distance.X - lx : Control.Size.X);
|
||||
Control.Size = new(sx, sy);
|
||||
Control.Location = new(lx, ly);
|
||||
if (Control is IParent parent)
|
||||
{
|
||||
parent.ParentResize(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,9 +135,21 @@ public class UserControl : IRenderObject, IParent
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 PointToVector(int x, int y, float z = 0.0f)
|
||||
{
|
||||
return new Vector3(IntToFloat(x), IntToFloat(y, true), z);
|
||||
}
|
||||
|
||||
public float IntToFloat(int p, bool Invert = false)
|
||||
{
|
||||
int Size = (Invert ? this.Size.Y : this.Size.X);
|
||||
p += (Invert ? Location.Y : Location.X);
|
||||
IParent? tempp = Parent;
|
||||
while (tempp is not null)
|
||||
{
|
||||
p += (Invert ? tempp.Position.Y : tempp.Position.X);
|
||||
tempp = tempp.Parent;
|
||||
}
|
||||
int Size = (Invert ? Window!.Size.Y : Window!.Size.X);
|
||||
double half = Math.Round((double)Size / (double)2, 1);
|
||||
double Per = Math.Round((double)1 / half, 15);
|
||||
if (p == half) return 0.0f;
|
||||
@ -149,7 +167,15 @@ public class UserControl : IRenderObject, IParent
|
||||
|
||||
public float FloatToInt(float p, bool Invert = false)
|
||||
{
|
||||
int Size = (Invert ? this.Size.Y : this.Size.X);
|
||||
p += (Invert ? LocationAsFloat.Y : LocationAsFloat.X);
|
||||
IParent? tempp = Parent;
|
||||
while (tempp is not null)
|
||||
{
|
||||
p += (Invert ? tempp.LocationAsFloat.Y : tempp.LocationAsFloat.X);
|
||||
tempp = tempp.Parent;
|
||||
}
|
||||
|
||||
int Size = (Invert ? Window!.Size.Y : Window!.Size.X);
|
||||
double half = Math.Round((double)Size / (double)2, 15);
|
||||
if (p == 0) return (int)half;
|
||||
if (Invert)
|
||||
|
0
GraphicsManager/Resources/Fonts/TektonPro-Regular.otf
Normal file → Executable file
0
GraphicsManager/Resources/Fonts/TektonPro-Regular.otf
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Label.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Label.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Label.vert
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Label.vert
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Rectangle.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Rectangle.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Rectangle.vert
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/Rectangle.vert
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/RectangleTexture.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/RectangleTexture.frag
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/RectangleTexture.vert
Normal file → Executable file
0
GraphicsManager/Resources/Shaders/RectangleTexture.vert
Normal file → Executable file
Binary file not shown.
Before Width: | Height: | Size: 267 B |
0
GraphicsManager/Structs/Character.cs
Normal file → Executable file
0
GraphicsManager/Structs/Character.cs
Normal file → Executable file
0
GraphicsManager/Tools.cs
Normal file → Executable file
0
GraphicsManager/Tools.cs
Normal file → Executable file
60
GraphicsManager/Window.cs
Normal file → Executable file
60
GraphicsManager/Window.cs
Normal file → Executable file
@ -9,6 +9,8 @@ namespace GraphicsManager;
|
||||
|
||||
public class Window : NativeWindow , IParent
|
||||
{
|
||||
public IParent? Parent { get; } = null;
|
||||
public Vector2 LocationAsFloat { get; } = new Vector2(0f, 0f);
|
||||
public Window(NativeWindowSettings nativeWindowSettings) : base(nativeWindowSettings)
|
||||
{
|
||||
}
|
||||
@ -44,6 +46,11 @@ public class Window : NativeWindow , IParent
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 PointToVector(int x, int y, float z = 0.0f)
|
||||
{
|
||||
return new Vector3(IntToFloat(x), IntToFloat(y, true), z);
|
||||
}
|
||||
|
||||
public float IntToFloat(int p, bool Invert = false)
|
||||
{
|
||||
int Size = (Invert ? this.Size.Y : this.Size.X);
|
||||
@ -96,53 +103,60 @@ public class Window : NativeWindow , IParent
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Resize(ResizeEventArgs e)
|
||||
public void ParentResize(ResizeEventArgs e)
|
||||
{
|
||||
if (e.Width == 0 && e.Height == 0) return;
|
||||
base.OnResize(e);
|
||||
GL.Viewport(0, 0, e.Width, e.Height);
|
||||
foreach (IRenderObject Control in Controls)
|
||||
{
|
||||
if (Control.Loaded)
|
||||
if (!Control.Loaded) continue;
|
||||
bool top = (Control.Anchor & ObjectAnchor.Top) == ObjectAnchor.Top;
|
||||
bool left = (Control.Anchor & ObjectAnchor.Left) == ObjectAnchor.Left;
|
||||
bool right = (Control.Anchor & ObjectAnchor.Right) == ObjectAnchor.Right;
|
||||
bool bottom = (Control.Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom;
|
||||
if (!top && !bottom) { Control.Anchor |= ObjectAnchor.Top; top = true; }
|
||||
if (!left && !right) { Control.Anchor |= ObjectAnchor.Left; left = true; }
|
||||
int lx = (left ? Control.Location.X : Size.X - Control.Distance.X - Control.Size.X);
|
||||
int ly = (top ? Control.Location.Y : Size.Y - Control.Distance.Y - Control.Size.Y);
|
||||
int sy = (bottom ? Size.Y - Control.Distance.Y - ly : Control.Size.Y);
|
||||
int sx = (right ? Size.X - Control.Distance.X - lx : Control.Size.X);
|
||||
Control.Size = new(sx, sy);
|
||||
Control.Location = new(lx, ly);
|
||||
if (Control is IParent parent)
|
||||
{
|
||||
bool top = (Control.Anchor & ObjectAnchor.Top) == ObjectAnchor.Top;
|
||||
bool left = (Control.Anchor & ObjectAnchor.Left) == ObjectAnchor.Left;
|
||||
bool right = (Control.Anchor & ObjectAnchor.Right) == ObjectAnchor.Right;
|
||||
bool bottom = (Control.Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom;
|
||||
if (!top && !bottom) { Control.Anchor |= ObjectAnchor.Top; top = true; }
|
||||
if (!left && !right) { Control.Anchor |= ObjectAnchor.Left; left = true; }
|
||||
int lx = (left ? Control.Location.X : Size.X - Control.Distance.X - Control.Size.X);
|
||||
int ly = (top ? Control.Location.Y : Size.Y - Control.Distance.Y - Control.Size.Y);
|
||||
int sy = (bottom ? Size.Y - Control.Distance.Y - ly : Control.Size.Y);
|
||||
int sx = (right ? Size.X - Control.Distance.X - lx : Control.Size.X);
|
||||
Control.Size = new(sx, sy);
|
||||
Control.Location = new(lx, ly);
|
||||
if (Control is IParent)
|
||||
{
|
||||
IParent parent = (IParent)Control;
|
||||
parent.Resize(e);
|
||||
}
|
||||
parent.ParentResize(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
Resize(e);
|
||||
ParentResize(e);
|
||||
}
|
||||
|
||||
public Rendertype Rendertype { get; set; } = Rendertype.ControlUpdates;
|
||||
|
||||
internal bool CanControleUpdate { get; private set; } = true;
|
||||
|
||||
public int FPS { get; set; } = 0;
|
||||
|
||||
public void StartRender()
|
||||
{
|
||||
Context.MakeCurrent();
|
||||
ProcessEvents();
|
||||
DrawFrame();
|
||||
while (Exists && IsVisible && !IsExiting)
|
||||
{
|
||||
DrawFrame();
|
||||
ProcessEvents();
|
||||
bool u = (Rendertype & Rendertype.ControlUpdates) == Rendertype.ControlUpdates;
|
||||
if (!u) DrawFrame();
|
||||
Thread.Sleep(8);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawFrame()
|
||||
{
|
||||
ProcessEvents();
|
||||
GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, (BackgroundColor.A * -1) + 1);
|
||||
IEnumerable<IRenderObject> needload = Controls.Where(a => a.Loaded == false);
|
||||
|
||||
@ -160,6 +174,6 @@ public class Window : NativeWindow , IParent
|
||||
if (obj.Loaded) obj.Draw();
|
||||
}
|
||||
Context.SwapBuffers();
|
||||
Thread.Sleep(8);
|
||||
|
||||
}
|
||||
}
|
BIN
GraphicsManager/freetype6.dll
Executable file
BIN
GraphicsManager/freetype6.dll
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user