commit 0190f7223cf8bf6f4640dbd82f0103fecebeb822 Author: Mike Nolan Date: Sun Nov 2 18:11:55 2025 -0600 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a8bc10 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2f72612 --- /dev/null +++ b/CMakeLists.txt @@ -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 + "$" + "$" +) + + +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() diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..6f1b981 --- /dev/null +++ b/Config.cmake.in @@ -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) diff --git a/include/CrossLangGFX.hpp b/include/CrossLangGFX.hpp new file mode 100644 index 0000000..76cc0f1 --- /dev/null +++ b/include/CrossLangGFX.hpp @@ -0,0 +1,7 @@ +#pragma once +#include +#include + +namespace Tesses::CrossLang::GFX { + void RegisterGFX(GC* gc, TRootEnvironment* env); +} \ No newline at end of file diff --git a/src/color.cpp b/src/color.cpp new file mode 100644 index 0000000..1ec2558 --- /dev/null +++ b/src/color.cpp @@ -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 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"; + } +} \ No newline at end of file diff --git a/src/format.cpp b/src/format.cpp new file mode 100644 index 0000000..ed33b51 --- /dev/null +++ b/src/format.cpp @@ -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 args) + { + if(key == "Load") + { + std::shared_ptr 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(false); + strm2->GetBuffer() = ba->data; + imgFmt->Load(strm2,&image->img); + } + } + if(key == "Save") + { + std::shared_ptr 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(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"; + } +} \ No newline at end of file diff --git a/src/gfx.hpp b/src/gfx.hpp new file mode 100644 index 0000000..0d4684b --- /dev/null +++ b/src/gfx.hpp @@ -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 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 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 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 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 args); + std::string TypeName(); + }; + class TImage : public TNativeObject { + public: + Image img; + + TObject CallMethod(GCList& ls, std::string key, std::vector 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 args); + std::string TypeName(); + }; +} \ No newline at end of file diff --git a/src/image.cpp b/src/image.cpp new file mode 100644 index 0000000..64a2a3f --- /dev/null +++ b/src/image.cpp @@ -0,0 +1,163 @@ +#include "gfx.hpp" + +namespace Tesses::CrossLang::GFX { + + TObject TImage::CallMethod(GCList& ls, std::string key, std::vector 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(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(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"; + } +} \ No newline at end of file diff --git a/src/plugin.cpp b/src/plugin.cpp new file mode 100644 index 0000000..2f4b540 --- /dev/null +++ b/src/plugin.cpp @@ -0,0 +1,6 @@ +#include "gfx.hpp" + +namespace Tesses::CrossLang::GFX +{ + CROSSLANG_PLUGIN(RegisterGFX); +} \ No newline at end of file diff --git a/src/point.cpp b/src/point.cpp new file mode 100644 index 0000000..9215a60 --- /dev/null +++ b/src/point.cpp @@ -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 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"; + } +} \ No newline at end of file diff --git a/src/rect.cpp b/src/rect.cpp new file mode 100644 index 0000000..21c3b64 --- /dev/null +++ b/src/rect.cpp @@ -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 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(ls); + loc->pt = this->rect.Location; + return loc; + } + if(key == "getSize") + { + auto sz = TNativeObject::Create(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"; + } +} \ No newline at end of file diff --git a/src/reg.cpp b/src/reg.cpp new file mode 100644 index 0000000..7ead454 --- /dev/null +++ b/src/reg.cpp @@ -0,0 +1,166 @@ +#include "gfx.hpp" + +namespace Tesses::CrossLang::GFX { + static TObject New_GFX_Image(GCList& ls, std::vector args) + { + return TNativeObject::Create(ls); + } + static TObject New_GFX_Point(GCList& ls, std::vector args) + { + int64_t x; + int64_t y; + if(GetArgument(args,0,x) && GetArgument(args,1,y)) + { + return TNativeObject::Create(ls, (int32_t)x, (int32_t)y); + } + return TNativeObject::Create(ls); + } + static TObject New_GFX_Size(GCList& ls, std::vector args) + { + int64_t w; + int64_t h; + if(GetArgument(args,0,w) && GetArgument(args,1,h)) + { + return TNativeObject::Create(ls, (int32_t)w, (int32_t)h); + } + return TNativeObject::Create(ls); + } + static TObject New_GFX_Rectangle(GCList& ls, std::vector 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(ls, (int32_t)x, (int32_t)y, (int32_t)w, (int32_t)h); + return TNativeObject::Create(ls, (int32_t)x, (int32_t)y, (int32_t)w); + } + if(GetArgumentHeap(args,0,pt) && GetArgumentHeap(args,1,sz)) + { + TNativeObject::Create(ls,pt->pt,sz->sz); + } + return TNativeObject::Create(ls); + } + static TObject New_GFX_Color(GCList& ls, std::vector 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(ls, (uint8_t)(uint64_t)r, (uint8_t)(uint64_t)g, (uint8_t)(uint64_t)a); + return TNativeObject::Create(ls, (uint8_t)(uint64_t)r, (uint8_t)(uint64_t)g, (uint8_t)(uint64_t)b); + } + return TNativeObject::Create(ls); + } + static TObject GFX_Color_Parse(GCList& ls, std::vector args) + { + std::string colorStr; + Color color; + if(GetArgument(args,0,colorStr) && Color::TryParse(colorStr, color)) + { + return TNativeObject::Create(ls,color); + } + return nullptr; + } + static TObject GFX_Formats_FromExtension(GCList& ls, std::vector args) + { + std::string ext; + if(GetArgument(args,0,ext)) + { + auto ptr = ImageFormats::Formats::FromExtension(ext); + if(ptr != nullptr) return TNativeObject::Create(ls,ptr); + } + return nullptr; + } + static TObject GFX_Webcam_getWebcams(GCList& ls, std::vector args) + { + std::vector 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(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 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(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(ls, &ImageFormats::Formats::Bitmap)), + TDItem("Jpeg", TNativeObject::Create(ls, &ImageFormats::Formats::Jpeg)), + TDItem("Png", TNativeObject::Create(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 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(); + } +} \ No newline at end of file diff --git a/src/size.cpp b/src/size.cpp new file mode 100644 index 0000000..21bce21 --- /dev/null +++ b/src/size.cpp @@ -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 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"; + } +} \ No newline at end of file diff --git a/src/webcam.cpp b/src/webcam.cpp new file mode 100644 index 0000000..7f3211a --- /dev/null +++ b/src/webcam.cpp @@ -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 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"; + } +} \ No newline at end of file