mirror of
https://onedev.site.tesses.net/crosslang/crosslang-gfx
synced 2026-02-08 09:35:45 +00:00
First commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.vscode
|
||||||
|
build
|
||||||
84
CMakeLists.txt
Normal file
84
CMakeLists.txt
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(CrossGFX)
|
||||||
|
|
||||||
|
option(CROSSGFX_ISPLUGIN "Is this a plugin or a static library for something, if not a plugin it will fetchcontent crosslang and tessesframework-gfx" ON)
|
||||||
|
option(CROSSGFX_SHARED_CROSSLANG "Is crosslang shared if not plugin" ON)
|
||||||
|
list(APPEND CROSSGFX_SOURCES
|
||||||
|
src/reg.cpp
|
||||||
|
src/size.cpp
|
||||||
|
src/point.cpp
|
||||||
|
src/rect.cpp
|
||||||
|
src/color.cpp
|
||||||
|
src/format.cpp
|
||||||
|
src/image.cpp
|
||||||
|
src/webcam.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
if(CROSSGFX_ISPLUGIN)
|
||||||
|
find_package(TessesCrossLang REQUIRED)
|
||||||
|
|
||||||
|
find_package(TessesFrameworkGFX REQUIRED)
|
||||||
|
add_library(crosslang_gfx SHARED src/plugin.cpp ${CROSSGFX_SOURCES})
|
||||||
|
target_link_libraries(crosslang_gfx PUBLIC TessesCrossLang::crosslang_shared)
|
||||||
|
target_link_libraries(crosslang_gfx PUBLIC TessesFrameworkGFX::tessesframework_gfx_shared)
|
||||||
|
target_include_directories(crosslang_gfx PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
install(TARGETS crosslang_gfx DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||||
|
else()
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
TessesCrossLang
|
||||||
|
GIT_REPOSITORY https://onedev.site.tesses.net/crosslang.git
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
TessesFrameworkGFX
|
||||||
|
GIT_REPOSITORY https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(TessesFrameworkGFX)
|
||||||
|
FetchContent_MakeAvailable(TessesCrossLang)
|
||||||
|
|
||||||
|
add_library(crosslang_gfx STATIC ${CROSSGFX_SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(crosslang_gfx PUBLIC tessesframework_gfx)
|
||||||
|
if(CROSSGFX_SHARED_CROSSLANG)
|
||||||
|
target_link_libraries(crosslang_gfx PUBLIC crosslang_shared)
|
||||||
|
else()
|
||||||
|
target_link_libraries(crosslang_gfx PUBLIC crosslang_static)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(crosslang_gfx
|
||||||
|
PUBLIC
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
install(FILES include/CrossLangGFX.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
|
install(TARGETS ${CrossLangGFXLibs}
|
||||||
|
EXPORT CrossLangGFXTargets
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
install(EXPORT CrossLangGFXTargets
|
||||||
|
FILE CrossLangGFXTargets.cmake
|
||||||
|
NAMESPACE CrossLangGFX::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CrossLangGFX
|
||||||
|
)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/CrossLangGFXConfig.cmake"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CrossLangGFX)
|
||||||
|
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}CrossLangGFXConfig.cmake"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CrossLangGFX)
|
||||||
|
|
||||||
|
endif()
|
||||||
7
Config.cmake.in
Normal file
7
Config.cmake.in
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/TessesCrossLangGFXTargets.cmake")
|
||||||
|
|
||||||
|
check_required_components(TessesCrossLangGFX)
|
||||||
|
find_package(TessesFrameworkGFX REQUIRED)
|
||||||
|
find_package(TessesCrossLang REQUIRED)
|
||||||
7
include/CrossLangGFX.hpp
Normal file
7
include/CrossLangGFX.hpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <CrossLang.hpp>
|
||||||
|
#include <TessesFrameworkGFX/TessesFrameworkGFX.hpp>
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX {
|
||||||
|
void RegisterGFX(GC* gc, TRootEnvironment* env);
|
||||||
|
}
|
||||||
87
src/color.cpp
Normal file
87
src/color.cpp
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TColor::TColor() : color()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TColor::TColor(const Color& c) : color(c)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TColor::TColor(uint8_t r, uint8_t g,uint8_t b) : color(r,g,b)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TColor::TColor(uint8_t r, uint8_t g,uint8_t b,uint8_t a) : color(r,g,b,a)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TObject TColor::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
if(key == "getRed")
|
||||||
|
{
|
||||||
|
return (int64_t)(uint64_t)this->color.Red;
|
||||||
|
}
|
||||||
|
if(key == "getGreen")
|
||||||
|
{
|
||||||
|
return (int64_t)(uint64_t)this->color.Green;
|
||||||
|
}
|
||||||
|
if(key == "getBlue")
|
||||||
|
{
|
||||||
|
return (int64_t)(uint64_t)this->color.Blue;
|
||||||
|
}
|
||||||
|
if(key == "getAlpha")
|
||||||
|
{
|
||||||
|
return (int64_t)(uint64_t)this->color.Alpha;
|
||||||
|
}
|
||||||
|
if(key == "setRed")
|
||||||
|
{
|
||||||
|
int64_t v;
|
||||||
|
if(GetArgument(args,0,v))
|
||||||
|
{
|
||||||
|
this->color.Red = (uint8_t)(uint64_t)v;
|
||||||
|
return (int64_t)(uint64_t)this->color.Red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setGreen")
|
||||||
|
{
|
||||||
|
int64_t v;
|
||||||
|
if(GetArgument(args,0,v))
|
||||||
|
{
|
||||||
|
this->color.Green = (uint8_t)(uint64_t)v;
|
||||||
|
return (int64_t)(uint64_t)this->color.Green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setBlue")
|
||||||
|
{
|
||||||
|
int64_t v;
|
||||||
|
if(GetArgument(args,0,v))
|
||||||
|
{
|
||||||
|
this->color.Blue = (uint8_t)(uint64_t)v;
|
||||||
|
return (int64_t)(uint64_t)this->color.Blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setAlpha")
|
||||||
|
{
|
||||||
|
int64_t v;
|
||||||
|
if(GetArgument(args,0,v))
|
||||||
|
{
|
||||||
|
this->color.Alpha = (uint8_t)(uint64_t)v;
|
||||||
|
return (int64_t)(uint64_t)this->color.Alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "ToString")
|
||||||
|
{
|
||||||
|
return this->color.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TColor::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Color";
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/format.cpp
Normal file
54
src/format.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TFormat::TFormat(ImageFormats::ImageFormat* fmt) : imgFmt(fmt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TObject TFormat::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
if(key == "Load")
|
||||||
|
{
|
||||||
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
|
TImage* image;
|
||||||
|
TByteArray* ba;
|
||||||
|
if(GetArgument(args,0,strm) && GetArgumentHeap(args,1,image))
|
||||||
|
{
|
||||||
|
imgFmt->Load(strm,&image->img);
|
||||||
|
}
|
||||||
|
else if(GetArgumentHeap(args,0,ba) && GetArgumentHeap(args,1,image))
|
||||||
|
{
|
||||||
|
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(false);
|
||||||
|
strm2->GetBuffer() = ba->data;
|
||||||
|
imgFmt->Load(strm2,&image->img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "Save")
|
||||||
|
{
|
||||||
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
|
TImage* image;
|
||||||
|
if(GetArgument(args,0,strm) && GetArgumentHeap(args,1,image))
|
||||||
|
{
|
||||||
|
std::string flags="";
|
||||||
|
GetArgument(args,2,flags);
|
||||||
|
imgFmt->Save(strm,&image->img, flags);
|
||||||
|
}
|
||||||
|
else if(GetArgumentHeap(args,0,image))
|
||||||
|
{
|
||||||
|
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
|
||||||
|
std::string flags="";
|
||||||
|
GetArgument(args,1,flags);
|
||||||
|
imgFmt->Save(strm2,&image->img, flags);
|
||||||
|
auto ba =TByteArray::Create(ls);
|
||||||
|
ba->data = strm2->GetBuffer();
|
||||||
|
return ba;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TFormat::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Format";
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/gfx.hpp
Normal file
67
src/gfx.hpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "CrossLangGFX.hpp"
|
||||||
|
using namespace Tesses::Framework::Graphics;
|
||||||
|
namespace Tesses::CrossLang::GFX {
|
||||||
|
class TPoint : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Point pt;
|
||||||
|
TPoint();
|
||||||
|
TPoint(int32_t x, int32_t y);
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
class TSize : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Size sz;
|
||||||
|
TSize();
|
||||||
|
TSize(int32_t square);
|
||||||
|
TSize(int32_t w, int32_t h);
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
class TRectangle : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Rectangle rect;
|
||||||
|
TRectangle();
|
||||||
|
TRectangle(const Point& pt, const Size& sz);
|
||||||
|
TRectangle(int32_t x, int32_t y, int32_t square);
|
||||||
|
TRectangle(int32_t x, int32_t y, int32_t width, int32_t height);
|
||||||
|
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
class TWebcam : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Webcam webcam;
|
||||||
|
TWebcam(uint8_t id, const Size& sz, uint8_t fps=10);
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
|
||||||
|
class TColor : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Color color;
|
||||||
|
TColor();
|
||||||
|
TColor(const Color& col);
|
||||||
|
TColor(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||||
|
|
||||||
|
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
class TImage : public TNativeObject {
|
||||||
|
public:
|
||||||
|
Image img;
|
||||||
|
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
class TFormat : public TNativeObject {
|
||||||
|
public:
|
||||||
|
ImageFormats::ImageFormat* imgFmt;
|
||||||
|
TFormat(ImageFormats::ImageFormat* fmt);
|
||||||
|
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args);
|
||||||
|
std::string TypeName();
|
||||||
|
};
|
||||||
|
}
|
||||||
163
src/image.cpp
Normal file
163
src/image.cpp
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX {
|
||||||
|
|
||||||
|
TObject TImage::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
if(key == "getWidth")
|
||||||
|
{
|
||||||
|
return (int64_t)this->img.Width();
|
||||||
|
}
|
||||||
|
if(key == "getHeight")
|
||||||
|
{
|
||||||
|
return (int64_t)this->img.Height();
|
||||||
|
}
|
||||||
|
if(key == "GetPixel")
|
||||||
|
{
|
||||||
|
int64_t x;
|
||||||
|
int64_t y;
|
||||||
|
if(GetArgument(args,0,x) && GetArgument(args,1,y))
|
||||||
|
{
|
||||||
|
auto c = TNativeObject::Create<TColor>(ls);
|
||||||
|
c->color = this->img.GetPixel((uint32_t)x,(uint32_t)y);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "SetPixel")
|
||||||
|
{
|
||||||
|
int64_t x;
|
||||||
|
int64_t y;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgument(args,0,x) && GetArgument(args,1,y) && GetArgumentHeap(args,2,col))
|
||||||
|
{
|
||||||
|
this->img.SetPixel((uint32_t)x,(uint32_t)y,col->color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "DrawLine")
|
||||||
|
{
|
||||||
|
TPoint* pt1;
|
||||||
|
TPoint* pt2;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgumentHeap(args,0, pt1) && GetArgumentHeap(args,1,pt2) && GetArgumentHeap(args,2,col))
|
||||||
|
{
|
||||||
|
int64_t bs=1;
|
||||||
|
GetArgument(args,3,bs);
|
||||||
|
|
||||||
|
this->img.DrawLine(pt1->pt,pt2->pt,col->color,(int)bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "DrawRectangle")
|
||||||
|
{
|
||||||
|
TRectangle* rect;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgumentHeap(args,0, rect) && GetArgumentHeap(args,1,col))
|
||||||
|
{
|
||||||
|
int64_t bs=1;
|
||||||
|
GetArgument(args,2,bs);
|
||||||
|
this->img.DrawRectangle(rect->rect,col->color,(int)bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "FillRectangle")
|
||||||
|
{
|
||||||
|
TRectangle* rect;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgumentHeap(args,0, rect) && GetArgumentHeap(args,1,col))
|
||||||
|
{
|
||||||
|
this->img.FillRectangle(rect->rect,col->color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "Resize")
|
||||||
|
{
|
||||||
|
TImage* img;
|
||||||
|
TSize* sz;
|
||||||
|
int64_t algo;
|
||||||
|
if(GetArgumentHeap(args,0,img) && GetArgumentHeap(args,1,sz))
|
||||||
|
{
|
||||||
|
if(GetArgument(args,2,algo))
|
||||||
|
{
|
||||||
|
this->img.Resize(&img->img,sz->sz,(Tesses::Framework::Graphics::ScaleAlgorithm)algo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->img.Resize(&img->img,sz->sz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(key == "DrawImage")
|
||||||
|
{
|
||||||
|
TImage* img;
|
||||||
|
TPoint* pt;
|
||||||
|
int64_t effect;
|
||||||
|
if(GetArgumentHeap(args,0,img) && GetArgumentHeap(args,1,pt))
|
||||||
|
{
|
||||||
|
if(GetArgument(args,2,effect))
|
||||||
|
{
|
||||||
|
this->img.DrawImage(&img->img,pt->pt,(Tesses::Framework::Graphics::ImageCopyEffect)effect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->img.DrawImage(&img->img,pt->pt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "DrawString")
|
||||||
|
{
|
||||||
|
std::string text;
|
||||||
|
TPoint* pt;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgument(args,0, text) && GetArgumentHeap(args,1,pt) && GetArgumentHeap(args,2,col))
|
||||||
|
{
|
||||||
|
this->img.DrawString(text,pt->pt,col->color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "DrawChar")
|
||||||
|
{
|
||||||
|
char chr;
|
||||||
|
TPoint* pt;
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgument(args,0, chr) && GetArgumentHeap(args,1,pt) && GetArgumentHeap(args,2,col))
|
||||||
|
{
|
||||||
|
this->img.DrawChar(chr,pt->pt,col->color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setSize")
|
||||||
|
{
|
||||||
|
TSize* sz;
|
||||||
|
if(GetArgumentHeap(args,0,sz))
|
||||||
|
{
|
||||||
|
this->img.SetSize((uint32_t)sz->sz.Width,(uint32_t)sz->sz.Height);
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "getSize")
|
||||||
|
{
|
||||||
|
auto sz = TNativeObject::Create<TSize>(ls);
|
||||||
|
sz->sz.Width = (int32_t)this->img.Width();
|
||||||
|
sz->sz.Height = (int32_t)this->img.Height();
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
if(key == "SetSize")
|
||||||
|
{
|
||||||
|
int64_t w, h;
|
||||||
|
if(GetArgument(args,0,w) && GetArgument(args,1,h))
|
||||||
|
{
|
||||||
|
TColor* col;
|
||||||
|
if(GetArgumentHeap(args,2,col))
|
||||||
|
{
|
||||||
|
this->img.SetSize((uint32_t)w,(uint32_t)h,col->color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->img.SetSize((uint32_t)w,(uint32_t)h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TImage::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Image";
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/plugin.cpp
Normal file
6
src/plugin.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
CROSSLANG_PLUGIN(RegisterGFX);
|
||||||
|
}
|
||||||
55
src/point.cpp
Normal file
55
src/point.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TPoint::TPoint() : pt()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TPoint::TPoint(int32_t x, int32_t y) : pt(x,y)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TObject TPoint::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(key == "getX")
|
||||||
|
{
|
||||||
|
return (int64_t)this->pt.X;
|
||||||
|
}
|
||||||
|
if(key == "getY")
|
||||||
|
{
|
||||||
|
return (int64_t)this->pt.Y;
|
||||||
|
}
|
||||||
|
if(key == "setX")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->pt.X = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setY")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->pt.Y = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "ToString")
|
||||||
|
{
|
||||||
|
return this->pt.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TPoint::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Point";
|
||||||
|
}
|
||||||
|
}
|
||||||
128
src/rect.cpp
Normal file
128
src/rect.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TRectangle::TRectangle() : rect()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TRectangle::TRectangle(const Point& pt, const Size& sz) : rect(pt,sz)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TRectangle::TRectangle(int32_t x, int32_t y,int32_t square) : rect(x,y,square)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TRectangle::TRectangle(int32_t x, int32_t y,int32_t w, int32_t h) : rect(x,y,w,h)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TObject TRectangle::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(key == "getX")
|
||||||
|
{
|
||||||
|
return (int64_t)this->rect.Location.X;
|
||||||
|
}
|
||||||
|
if(key == "getY")
|
||||||
|
{
|
||||||
|
return (int64_t)this->rect.Location.Y;
|
||||||
|
}
|
||||||
|
if(key == "setX")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->rect.Location.X = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setY")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->rect.Location.Y = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "getWidth")
|
||||||
|
{
|
||||||
|
return (int64_t)this->rect.Size.Width;
|
||||||
|
}
|
||||||
|
if(key == "getHeight")
|
||||||
|
{
|
||||||
|
return (int64_t)this->rect.Size.Height;
|
||||||
|
}
|
||||||
|
if(key == "setWidth")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->rect.Size.Width = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setHeight")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->rect.Size.Height = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "getLocation")
|
||||||
|
{
|
||||||
|
auto loc = TNativeObject::Create<TPoint>(ls);
|
||||||
|
loc->pt = this->rect.Location;
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
if(key == "getSize")
|
||||||
|
{
|
||||||
|
auto sz = TNativeObject::Create<TSize>(ls);
|
||||||
|
sz->sz = this->rect.Size;
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
if(key == "setLocation")
|
||||||
|
{
|
||||||
|
TPoint* pt;
|
||||||
|
if(GetArgumentHeap(args,0,pt))
|
||||||
|
{
|
||||||
|
this->rect.Location= pt->pt;
|
||||||
|
return pt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setSize")
|
||||||
|
{
|
||||||
|
TSize* sz;
|
||||||
|
if(GetArgumentHeap(args,0,sz))
|
||||||
|
{
|
||||||
|
this->rect.Size= sz->sz;
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "Intersects")
|
||||||
|
{
|
||||||
|
TPoint* pt;
|
||||||
|
if(GetArgumentHeap(args,0,pt))
|
||||||
|
{
|
||||||
|
return this->rect.Intersects(pt->pt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "ToString")
|
||||||
|
{
|
||||||
|
return this->rect.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TRectangle::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Rectangle";
|
||||||
|
}
|
||||||
|
}
|
||||||
166
src/reg.cpp
Normal file
166
src/reg.cpp
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX {
|
||||||
|
static TObject New_GFX_Image(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
return TNativeObject::Create<TImage>(ls);
|
||||||
|
}
|
||||||
|
static TObject New_GFX_Point(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
int64_t x;
|
||||||
|
int64_t y;
|
||||||
|
if(GetArgument(args,0,x) && GetArgument(args,1,y))
|
||||||
|
{
|
||||||
|
return TNativeObject::Create<TPoint>(ls, (int32_t)x, (int32_t)y);
|
||||||
|
}
|
||||||
|
return TNativeObject::Create<TPoint>(ls);
|
||||||
|
}
|
||||||
|
static TObject New_GFX_Size(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
int64_t h;
|
||||||
|
if(GetArgument(args,0,w) && GetArgument(args,1,h))
|
||||||
|
{
|
||||||
|
return TNativeObject::Create<TSize>(ls, (int32_t)w, (int32_t)h);
|
||||||
|
}
|
||||||
|
return TNativeObject::Create<TSize>(ls);
|
||||||
|
}
|
||||||
|
static TObject New_GFX_Rectangle(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
int64_t h;
|
||||||
|
int64_t x;
|
||||||
|
int64_t y;
|
||||||
|
TPoint* pt;
|
||||||
|
TSize* sz;
|
||||||
|
if(GetArgument(args,0,x) && GetArgument(args,1,y) && GetArgument(args,2,w))
|
||||||
|
{
|
||||||
|
if(GetArgument(args,3,y))
|
||||||
|
return TNativeObject::Create<TRectangle>(ls, (int32_t)x, (int32_t)y, (int32_t)w, (int32_t)h);
|
||||||
|
return TNativeObject::Create<TRectangle>(ls, (int32_t)x, (int32_t)y, (int32_t)w);
|
||||||
|
}
|
||||||
|
if(GetArgumentHeap(args,0,pt) && GetArgumentHeap(args,1,sz))
|
||||||
|
{
|
||||||
|
TNativeObject::Create<TRectangle>(ls,pt->pt,sz->sz);
|
||||||
|
}
|
||||||
|
return TNativeObject::Create<TRectangle>(ls);
|
||||||
|
}
|
||||||
|
static TObject New_GFX_Color(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
int64_t r;
|
||||||
|
int64_t g;
|
||||||
|
int64_t b;
|
||||||
|
int64_t a;
|
||||||
|
if(GetArgument(args,0,r) && GetArgument(args,1,g) && GetArgument(args,2,b))
|
||||||
|
{
|
||||||
|
if(GetArgument(args,3,a))
|
||||||
|
return TNativeObject::Create<TRectangle>(ls, (uint8_t)(uint64_t)r, (uint8_t)(uint64_t)g, (uint8_t)(uint64_t)a);
|
||||||
|
return TNativeObject::Create<TRectangle>(ls, (uint8_t)(uint64_t)r, (uint8_t)(uint64_t)g, (uint8_t)(uint64_t)b);
|
||||||
|
}
|
||||||
|
return TNativeObject::Create<TColor>(ls);
|
||||||
|
}
|
||||||
|
static TObject GFX_Color_Parse(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
std::string colorStr;
|
||||||
|
Color color;
|
||||||
|
if(GetArgument(args,0,colorStr) && Color::TryParse(colorStr, color))
|
||||||
|
{
|
||||||
|
return TNativeObject::Create<TColor>(ls,color);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
static TObject GFX_Formats_FromExtension(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
std::string ext;
|
||||||
|
if(GetArgument(args,0,ext))
|
||||||
|
{
|
||||||
|
auto ptr = ImageFormats::Formats::FromExtension(ext);
|
||||||
|
if(ptr != nullptr) return TNativeObject::Create<TFormat>(ls,ptr);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
static TObject GFX_Webcam_getWebcams(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
std::vector<WebcamInfo> info;
|
||||||
|
Webcam::GetWebcams(info);
|
||||||
|
ls.GetGC()->BarrierBegin();
|
||||||
|
auto list = TList::Create(ls);
|
||||||
|
for(auto& item : info)
|
||||||
|
{
|
||||||
|
TList* reso = TList::Create(ls);
|
||||||
|
for(auto& res : item.Resolutions)
|
||||||
|
{
|
||||||
|
reso->Add(TNativeObject::Create<TSize>(ls,res.Width,res.Height));
|
||||||
|
}
|
||||||
|
list->Add(
|
||||||
|
TDictionary::Create(ls,
|
||||||
|
{
|
||||||
|
TDItem("Name", item.Name),
|
||||||
|
TDItem("Device", (int64_t)(uint64_t)item.Device),
|
||||||
|
TDItem("Resolutions",reso)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ls.GetGC()->BarrierEnd();
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
static TObject New_GFX_Webcam(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
int64_t id;
|
||||||
|
TSize* sz;
|
||||||
|
int64_t fps=10;
|
||||||
|
if(GetArgument(args,0,id) && GetArgumentHeap(args,1,sz))
|
||||||
|
{
|
||||||
|
GetArgument(args,2,fps);
|
||||||
|
return TNativeObject::Create<TWebcam>(ls,(uint8_t)(uint64_t)id, sz->sz, (uint8_t)(uint64_t)fps);
|
||||||
|
}
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
void RegisterGFX(GC* gc, TRootEnvironment* env)
|
||||||
|
{
|
||||||
|
gc->BarrierBegin();
|
||||||
|
GCList ls(gc);
|
||||||
|
auto gfx=env->EnsureDictionary(gc,"GFX");
|
||||||
|
gfx->SetValue("Color",
|
||||||
|
TDictionary::Create(ls,
|
||||||
|
{
|
||||||
|
TDItem("Parse", TExternalMethod::Create(ls, "Parse a color",{"str"},GFX_Color_Parse))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
gfx->SetValue("Formats",
|
||||||
|
TDictionary::Create(ls,
|
||||||
|
{
|
||||||
|
TDItem("Bitmap", TNativeObject::Create<TFormat>(ls, &ImageFormats::Formats::Bitmap)),
|
||||||
|
TDItem("Jpeg", TNativeObject::Create<TFormat>(ls, &ImageFormats::Formats::Jpeg)),
|
||||||
|
TDItem("Png", TNativeObject::Create<TFormat>(ls, &ImageFormats::Formats::Png)),
|
||||||
|
TDItem("FromExtension", TExternalMethod::Create(ls,"Get format from extension",{"ext"},GFX_Formats_FromExtension))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
gfx->SetValue("Webcam",
|
||||||
|
TDictionary::Create(ls,
|
||||||
|
{
|
||||||
|
TDItem("getWebcams", TExternalMethod::Create(ls, "enumerate webcams",{},GFX_Webcam_getWebcams)),
|
||||||
|
TDItem("getIsEnabled", TExternalMethod::Create(ls, "is webcam api enabled",{},[](GCList& gc, std::vector<TObject> args)->TObject {return Webcam::IsEnabled();}))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
auto newO = env->EnsureDictionary(gc, "New");
|
||||||
|
|
||||||
|
newO->SetValue("GFX",TDictionary::Create(
|
||||||
|
ls,
|
||||||
|
{
|
||||||
|
TDItem("Point", TExternalMethod::Create(ls,"Create a point",{"$x","$y"},New_GFX_Point)),
|
||||||
|
TDItem("Size", TExternalMethod::Create(ls,"Create a size",{"$w","$y"},New_GFX_Size)),
|
||||||
|
TDItem("Rectangle", TExternalMethod::Create(ls,"Create a rectangle",{"$xOrPt","$yOrSz","$wOrSquare","$h"},New_GFX_Rectangle)),
|
||||||
|
TDItem("Color", TExternalMethod::Create(ls,"Create a color",{"$r","$g","$b","$a"},New_GFX_Color)),
|
||||||
|
TDItem("Image", TExternalMethod::Create(ls,"Create an image",{},New_GFX_Image)),
|
||||||
|
TDItem("Webcam", TExternalMethod::Create(ls,"Create a webcam device",{"id","resolution","$fps=10"}, New_GFX_Webcam))
|
||||||
|
}
|
||||||
|
));
|
||||||
|
gc->BarrierEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/size.cpp
Normal file
58
src/size.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TSize::TSize() : sz()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TSize::TSize(int32_t square) : sz(square)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TSize::TSize(int32_t w, int32_t h) : sz(w,h)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TObject TSize::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(key == "getWidth")
|
||||||
|
{
|
||||||
|
return (int64_t)this->sz.Width;
|
||||||
|
}
|
||||||
|
if(key == "getHeight")
|
||||||
|
{
|
||||||
|
return (int64_t)this->sz.Height;
|
||||||
|
}
|
||||||
|
if(key == "setWidth")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->sz.Width = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "setHeight")
|
||||||
|
{
|
||||||
|
int64_t w;
|
||||||
|
if(GetArgument(args,0,w))
|
||||||
|
{
|
||||||
|
this->sz.Height = (int32_t)w;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == "ToString")
|
||||||
|
{
|
||||||
|
return this->sz.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TSize::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Size";
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/webcam.cpp
Normal file
35
src/webcam.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "gfx.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::CrossLang::GFX
|
||||||
|
{
|
||||||
|
TWebcam::TWebcam(uint8_t id, const Size& sz, uint8_t fps) : webcam(id,sz, fps)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TObject TWebcam::CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
if(key == "Open")
|
||||||
|
{
|
||||||
|
this->webcam.Open();
|
||||||
|
}
|
||||||
|
if(key == "ReadFrame")
|
||||||
|
{
|
||||||
|
TImage* img;
|
||||||
|
if(GetArgumentHeap(args,0,img))
|
||||||
|
{
|
||||||
|
this->webcam.ReadFrame(&img->img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == "Close")
|
||||||
|
{
|
||||||
|
this->webcam.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
std::string TWebcam::TypeName()
|
||||||
|
{
|
||||||
|
return "GFX.Webcam";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user