mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-03-26 04:50:20 +00:00
Remove SDL2
This commit is contained in:
168
CMakeLists.txt
168
CMakeLists.txt
@@ -51,28 +51,6 @@ src/Crypto/MbedHelpers.cpp
|
|||||||
src/TF_Init.cpp
|
src/TF_Init.cpp
|
||||||
src/wrapper.cpp
|
src/wrapper.cpp
|
||||||
src/HiddenField.cpp
|
src/HiddenField.cpp
|
||||||
src/SDL2/FontCache.cpp
|
|
||||||
src/SDL2/Stream.cpp
|
|
||||||
src/SDL2/GUI.cpp
|
|
||||||
src/SDL2/GUIWindow.cpp
|
|
||||||
src/SDL2/GUIPopup.cpp
|
|
||||||
src/SDL2/View.cpp
|
|
||||||
src/SDL2/Views/ButtonView.cpp
|
|
||||||
src/SDL2/Views/AbsoluteView.cpp
|
|
||||||
src/SDL2/Views/LabelView.cpp
|
|
||||||
src/SDL2/Views/TextListView.cpp
|
|
||||||
src/SDL2/Views/ScrollableTextListView.cpp
|
|
||||||
src/SDL2/Views/ProgressView.cpp
|
|
||||||
src/SDL2/Views/CheckView.cpp
|
|
||||||
src/SDL2/Views/MultilineEditTextView.cpp
|
|
||||||
src/SDL2/Views/EditTextView.cpp
|
|
||||||
src/SDL2/Views/PictureView.cpp
|
|
||||||
src/SDL2/Views/VScrollView.cpp
|
|
||||||
src/SDL2/Views/HScrollView.cpp
|
|
||||||
src/SDL2/Views/VStackView.cpp
|
|
||||||
src/SDL2/Views/HStackView.cpp
|
|
||||||
src/SDL2/Views/DropDownView.cpp
|
|
||||||
src/SDL2/Views/TabView.cpp
|
|
||||||
)
|
)
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
|
|
||||||
@@ -83,7 +61,7 @@ option(TESSESFRAMEWORK_ENABLE_NETWORKING "Enable Networking" ON)
|
|||||||
option(TESSESFRAMEWORK_ENABLE_THREADING "Enable Threading" ON)
|
option(TESSESFRAMEWORK_ENABLE_THREADING "Enable Threading" ON)
|
||||||
option(TESSESFRAMEWORK_ENABLE_SQLITE "Enable sqlite (embedded in source)" ON)
|
option(TESSESFRAMEWORK_ENABLE_SQLITE "Enable sqlite (embedded in source)" ON)
|
||||||
option(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS "Enable sago platformfolders (embedded in source)" ON)
|
option(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS "Enable sago platformfolders (embedded in source)" ON)
|
||||||
option(TESSESFRAMEWORK_DEFINE_SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS OFF)
|
|
||||||
if(TESSESFRAMEWORK_DEFINE_SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS)
|
if(TESSESFRAMEWORK_DEFINE_SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS)
|
||||||
add_definitions(-DSDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS=1)
|
add_definitions(-DSDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS=1)
|
||||||
endif()
|
endif()
|
||||||
@@ -105,7 +83,6 @@ option(TESSESFRAMEWORK_ENABLE_STATIC "Enable Tesses Framework Static Libraries"
|
|||||||
option(TESSESFRAMEWORK_ENABLE_SHARED "Enable Tesses Framework Shared Libraries" ON)
|
option(TESSESFRAMEWORK_ENABLE_SHARED "Enable Tesses Framework Shared Libraries" ON)
|
||||||
option(TESSESFRAMEWORK_ENABLE_SETDATE "Enable setting date to file" ON)
|
option(TESSESFRAMEWORK_ENABLE_SETDATE "Enable setting date to file" ON)
|
||||||
option(TESSESFRAMEWORK_LOGTOFILE "TessesFramework Log to file" OFF)
|
option(TESSESFRAMEWORK_LOGTOFILE "TessesFramework Log to file" OFF)
|
||||||
option(TESSESFRAMEWORK_ENABLE_SDL2 "Enable SDL2" OFF)
|
|
||||||
option(TESSESFRAMEWORK_FETCHCONTENT "TessesFramework fetchcontent" OFF)
|
option(TESSESFRAMEWORK_FETCHCONTENT "TessesFramework fetchcontent" OFF)
|
||||||
option(TESSESFRAMEWORK_VENDERCERTCHAIN "Use the ca-certificates.crt in project rather than system" ON)
|
option(TESSESFRAMEWORK_VENDERCERTCHAIN "Use the ca-certificates.crt in project rather than system" ON)
|
||||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||||
@@ -122,83 +99,11 @@ endif()
|
|||||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||||
|
|
||||||
include(cmake/bin2h.cmake)
|
include(cmake/bin2h.cmake)
|
||||||
if(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
|
|
||||||
find_package(PkgConfig)
|
|
||||||
pkg_search_module(SDL2 REQUIRED sdl2)
|
|
||||||
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
|
|
||||||
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
|
|
||||||
else()
|
|
||||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
|
||||||
function(sdl2_fix TessesFramework_TARGET)
|
|
||||||
target_include_directories(${TessesFramework_TARGET} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/_deps/sdl_image-src/include")
|
|
||||||
target_include_directories(${TessesFramework_TARGET} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/_deps/sdl_ttf-src")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
SDL
|
|
||||||
URL https://downloads.tesses.net/cache/libraries/source/SDL2-2.30.11.tar.gz
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
SDL_IMAGE
|
|
||||||
URL https://downloads.tesses.net/cache/libraries/source/SDL2_image-2.8.4.tar.gz
|
|
||||||
)
|
|
||||||
FetchContent_Declare(
|
|
||||||
FREETYPE
|
|
||||||
URL https://downloads.tesses.net/cache/libraries/source/freetype-2.13.3.tar.gz
|
|
||||||
)
|
|
||||||
FetchContent_Declare(
|
|
||||||
SDL_TTF
|
|
||||||
URL https://downloads.tesses.net/cache/libraries/source/SDL2_ttf-2.24.0.tar.gz
|
|
||||||
)
|
|
||||||
set(SDL2_DISABLE_UNINSTALL ON CACHE BOOL "" FORCE)
|
|
||||||
set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
|
|
||||||
|
|
||||||
# SDL main is only needed for desktop apps (more specifically Windows)
|
|
||||||
set(SDL2_DISABLE_SDL2MAIN ON CACHE BOOL "" FORCE)
|
|
||||||
|
|
||||||
set(SDL_CMAKE_DEBUG_POSTFIX "" CACHE STRING "" FORCE)
|
|
||||||
set(SDL2IMAGE_DEBUG_POSTFIX "" CACHE STRING "" FORCE)
|
|
||||||
if(NOT TESSESFRAMEWORK_ENABLE_SHARED)
|
|
||||||
#set(SDL_SHARED OFF)
|
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
|
||||||
|
|
||||||
endif()
|
|
||||||
set(SDL2TTF_VENDORED ON)
|
|
||||||
set(SDL2IMAGE_VENDORED ON)
|
|
||||||
FetchContent_MakeAvailable(SDL SDL_IMAGE SDL_TTF)
|
|
||||||
|
|
||||||
# Making sure libraries don't generate symlinks
|
# Making sure libraries don't generate symlinks
|
||||||
if(TESSESFRAMEWORK_ENABLE_SHARED)
|
|
||||||
set_property(TARGET SDL2 PROPERTY VERSION)
|
|
||||||
set_property(TARGET SDL2 PROPERTY SOVERSION)
|
|
||||||
set_property(TARGET SDL2_image PROPERTY VERSION)
|
|
||||||
set_property(TARGET SDL2_image PROPERTY SOVERSION)
|
|
||||||
|
|
||||||
set_property(TARGET SDL2_ttf PROPERTY VERSION)
|
|
||||||
set_property(TARGET SDL2_ttf PROPERTY SOVERSION)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_package(SDL2_image REQUIRED)
|
|
||||||
find_package(SDL2_ttf REQUIRED)
|
|
||||||
find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/TanoheSans-Regular.h" "#pragma once\n")
|
|
||||||
bin2h(SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/font/NonMono/TanoheSans-Regular.ttf" HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/TanoheSans-Regular.h" VARIABLE_NAME TanoheSansRegular APPEND NULL_TERMINATE)
|
|
||||||
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/TanoheSans-Regular.h" "\n")
|
|
||||||
|
|
||||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/aardvark-fixed-regular.h" "#pragma once\n")
|
|
||||||
bin2h(SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/font/Mono/aardvark-fixed-regular.ttf" HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/aardvark-fixed-regular.h" VARIABLE_NAME AardvarkFixedRegular APPEND NULL_TERMINATE)
|
|
||||||
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/aardvark-fixed-regular.h" "\n")
|
|
||||||
|
|
||||||
|
|
||||||
endif()
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||||
|
|
||||||
@@ -261,32 +166,6 @@ endif()
|
|||||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_FETCHCONTENT)
|
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_FETCHCONTENT)
|
||||||
endif()
|
endif()
|
||||||
if(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC ${SDL2_LIBRARIES})
|
|
||||||
target_include_directories(${TessesFramework_TARGET} PUBLIC ${SDL2_INCLUDE_DIRS})
|
|
||||||
target_compile_options(${TessesFramework_TARGET} PUBLIC ${SDL2_CFLAGS_OTHER})
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC ${SDL2_TTF_LIBRARIES})
|
|
||||||
target_include_directories(${TessesFramework_TARGET} PUBLIC ${SDL2_TTF_INCLUDE_DIRS})
|
|
||||||
target_compile_options(${TessesFramework_TARGET} PUBLIC ${SDL2_TTF_CFLAGS_OTHER})
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC ${SDL2_IMAGE_LIBRARIES})
|
|
||||||
target_include_directories(${TessesFramework_TARGET} PUBLIC ${SDL2_IMAGE_INCLUDE_DIRS})
|
|
||||||
target_compile_options(${TessesFramework_TARGET} PUBLIC ${SDL2_IMAGE_CFLAGS_OTHER})
|
|
||||||
else()
|
|
||||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
|
||||||
if(NOT TESSESFRAMEWORK_ENABLE_SHARED)
|
|
||||||
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC SDL2-static SDL2_image SDL2_ttf)
|
|
||||||
else()
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC SDL2 SDL2_image SDL2_ttf)
|
|
||||||
endif()
|
|
||||||
sdl2_fix(${TessesFramework_TARGET})
|
|
||||||
else()
|
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC SDL2::SDL2 SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
endif()
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_MBED)
|
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||||
@@ -376,19 +255,12 @@ target_link_libraries(tessesframework_shared PUBLIC mbedtls mbedx509 mbedcrypto)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
list(APPEND TessesFrameworkLibs tessesframework_shared)
|
list(APPEND TessesFrameworkLibs tessesframework_shared)
|
||||||
endif()
|
|
||||||
|
|
||||||
if((TESSESFRAMEWORK_ENABLE_STATIC OR TESSESFRAMEWORK_ENABLE_SHARED) AND TESSESFRAMEWORK_FETCHCONTENT AND TESSESFRAMEWORK_ENABLE_MBED)
|
if((TESSESFRAMEWORK_ENABLE_STATIC OR TESSESFRAMEWORK_ENABLE_SHARED) AND TESSESFRAMEWORK_FETCHCONTENT AND TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
list(APPEND TessesFrameworkLibs mbedtls mbedx509 mbedcrypto everest p256m)
|
list(APPEND TessesFrameworkLibs mbedtls mbedx509 mbedcrypto everest p256m)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if((TESSESFRAMEWORK_ENABLE_STATIC OR TESSESFRAMEWORK_ENABLE_SHARED) AND TESSESFRAMEWORK_FETCHCONTENT AND TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
if(NOT TESSESFRAMEWORK_ENABLE_SHARED)
|
|
||||||
|
|
||||||
list(APPEND TessesFrameworkLibs SDL2-static SDL2_image SDL2_ttf)
|
|
||||||
else()
|
|
||||||
list(APPEND TessesFrameworkLibs SDL2 SDL2_image SDL2_ttf)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
@@ -422,30 +294,7 @@ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
||||||
if(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_SQLITE AND TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
|
||||||
add_executable(databaseex examples/databaseex.cpp)
|
|
||||||
target_link_libraries(databaseex PUBLIC tessesframework)
|
|
||||||
#if(TARGET SDL2::SDL2main)
|
|
||||||
|
|
||||||
#target_link_libraries(databaseex PRIVATE SDL2::SDL2main)
|
|
||||||
#endif()
|
|
||||||
#if(TARGET SDL2main)
|
|
||||||
|
|
||||||
#target_link_libraries(databaseex PRIVATE SDL2main)
|
|
||||||
#endif()
|
|
||||||
endif()
|
|
||||||
add_executable(guikitchensink examples/guikitchensink.cpp)
|
|
||||||
target_link_libraries(guikitchensink PUBLIC tessesframework)
|
|
||||||
# if(TARGET SDL2::SDL2main)
|
|
||||||
|
|
||||||
# target_link_libraries(guikitchensink PRIVATE SDL2::SDL2main)
|
|
||||||
# endif()
|
|
||||||
# if(TARGET SDL2main)
|
|
||||||
|
|
||||||
# target_link_libraries(guikitchensink PRIVATE SDL2main)
|
|
||||||
# endif()
|
|
||||||
endif()
|
|
||||||
add_executable(copyfile examples/copyfile.cpp)
|
add_executable(copyfile examples/copyfile.cpp)
|
||||||
target_link_libraries(copyfile PUBLIC tessesframework)
|
target_link_libraries(copyfile PUBLIC tessesframework)
|
||||||
|
|
||||||
@@ -472,19 +321,6 @@ if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_APPS)
|
if(TESSESFRAMEWORK_ENABLE_APPS)
|
||||||
if(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
add_executable(tguilayouttester apps/guilayouttester.cpp)
|
|
||||||
target_link_libraries(tguilayouttester PUBLIC tessesframework)
|
|
||||||
#if(TARGET SDL2::SDL2main)
|
|
||||||
|
|
||||||
# target_link_libraries(tguilayouttester PRIVATE SDL2::SDL2main)
|
|
||||||
# endif()
|
|
||||||
# if(TARGET SDL2main)
|
|
||||||
|
|
||||||
# target_link_libraries(tguilayouttester PRIVATE SDL2main)
|
|
||||||
# endif()
|
|
||||||
install(TARGETS tguilayouttester DESTINATION bin)
|
|
||||||
endif()
|
|
||||||
add_executable(tanonydrop apps/tanonydrop.cpp)
|
add_executable(tanonydrop apps/tanonydrop.cpp)
|
||||||
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
||||||
install(TARGETS tanonydrop DESTINATION bin)
|
install(TARGETS tanonydrop DESTINATION bin)
|
||||||
|
|||||||
@@ -1,29 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define TESSES_FRAMEWORK_FLAG_OFF 0
|
#define TESSES_FRAMEWORK_FLAG_OFF 0
|
||||||
#define TESSES_FRAMEWORK_FLAG_ON 1
|
#define TESSES_FRAMEWORK_FLAG_ON 1
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_SQLITE@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_SQLITE@) && !defined(TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||||
#define TESSESFRAMEWORK_ENABLE_SQLITE
|
#define TESSESFRAMEWORK_ENABLE_SQLITE
|
||||||
#endif
|
#endif
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS@) && !defined(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
||||||
#define TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS
|
#define TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS
|
||||||
#endif
|
#endif
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_MBED@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_MBED@) && !defined(TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
#define TESSESFRAMEWORK_ENABLE_MBED
|
#define TESSESFRAMEWORK_ENABLE_MBED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_NETWORKING@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_NETWORKING@) && !defined(TESSESFRAMEWORK_ENABLE_NETWORKING)
|
||||||
#define TESSESFRAMEWORK_ENABLE_NETWORKING
|
#define TESSESFRAMEWORK_ENABLE_NETWORKING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_THREADING@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_THREADING@) && !defined(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||||
#define TESSESFRAMEWORK_ENABLE_THREADING
|
#define TESSESFRAMEWORK_ENABLE_THREADING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_LOGTOFILE@
|
#if defined(TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_LOGTOFILE@) && !defined(TESSESFRAMEWORK_LOGTOFILE)
|
||||||
#define TESSESFRAMEWORK_LOGTOFILE
|
#define TESSESFRAMEWORK_LOGTOFILE
|
||||||
#endif
|
#endif
|
||||||
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_SDL2@
|
|
||||||
#define TESSESFRAMEWORK_ENABLE_SDL2
|
|
||||||
#endif
|
|
||||||
#undef TESSES_FRAMEWORK_FLAG_OFF
|
#undef TESSES_FRAMEWORK_FLAG_OFF
|
||||||
#undef TESSES_FRAMEWORK_FLAG_ON
|
#undef TESSES_FRAMEWORK_FLAG_ON
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
|
||||||
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
#include "TessesFramework/TextStreams/StreamReader.hpp"
|
|
||||||
#include "TessesFramework/Streams/FileStream.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
using namespace Tesses::Framework;
|
|
||||||
using namespace Tesses::Framework::SDL2;
|
|
||||||
|
|
||||||
using namespace Tesses::Framework::Streams;
|
|
||||||
using namespace Tesses::Framework::TextStreams;
|
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
|
||||||
|
|
||||||
void Load(GUIWindow& window, std::string jsonFile)
|
|
||||||
{
|
|
||||||
FILE* f = fopen(jsonFile.c_str(),"rb");
|
|
||||||
if(f != NULL)
|
|
||||||
{
|
|
||||||
FileStream strm(f,true,"rb");
|
|
||||||
StreamReader r(&strm,false);
|
|
||||||
auto text = r.ReadToEnd();
|
|
||||||
try {
|
|
||||||
auto obj = Json::Decode(text);
|
|
||||||
window.SetView(obj);
|
|
||||||
} catch(...)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
|
||||||
{
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
if(argc < 2)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " layout.json" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
std::string jsonFile = argv[1];
|
|
||||||
TF_Init();
|
|
||||||
|
|
||||||
|
|
||||||
GUIPalette pal0(true,(SDL_Color){.r=255,.g=0,.b=0,.a=255},20);
|
|
||||||
GUIWindow window("Press ALT+R to Reload",640,480,SDL_WINDOW_RESIZABLE,pal0);
|
|
||||||
|
|
||||||
window.SDLEvent += std::make_shared<FunctionalEvent<View*,GUISDLEventEventArgs&>>([&window,jsonFile](View* sender, GUISDLEventEventArgs& e)->void{
|
|
||||||
if(e.event.type == SDL_KEYUP && (uint64_t)(e.event.key.keysym.mod & SDL_Keymod::KMOD_ALT) != 0 && e.event.key.keysym.sym == SDLK_r)
|
|
||||||
{
|
|
||||||
Load(window,jsonFile);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Load(window,jsonFile);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TF_RunEventLoop();
|
|
||||||
|
|
||||||
TF_Quit();
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/Platform/Environment.hpp"
|
|
||||||
#include "TessesFramework/Serialization/SQLite.hpp"
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Tesses::Framework::Filesystem;
|
|
||||||
using namespace Tesses::Framework::SDL2;
|
|
||||||
using namespace Tesses::Framework::Serialization;
|
|
||||||
using namespace Tesses::Framework;
|
|
||||||
using namespace Tesses::Framework::Platform::Environment::SpecialFolders;
|
|
||||||
|
|
||||||
|
|
||||||
VFSPath DatabasePath()
|
|
||||||
{
|
|
||||||
auto path = GetConfig() / "Tesses" / "Framework" / "Examples";
|
|
||||||
LocalFS.CreateDirectory(path);
|
|
||||||
return path / "databaseex.sqlite";
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateTable()
|
|
||||||
{
|
|
||||||
SQLiteDatabase db(DatabasePath());
|
|
||||||
db.Exec("CREATE TABLE IF NOT EXISTS names (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);");
|
|
||||||
}
|
|
||||||
void ClearTable()
|
|
||||||
{
|
|
||||||
SQLiteDatabase db(DatabasePath());
|
|
||||||
db.Exec("DROP TABLE names;");
|
|
||||||
db.Exec("CREATE TABLE IF NOT EXISTS names (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadDB(std::vector<std::string>& items)
|
|
||||||
{
|
|
||||||
SQLiteDatabase db(DatabasePath());
|
|
||||||
|
|
||||||
for(auto item : db.Exec("SELECT name FROM names;"))
|
|
||||||
{
|
|
||||||
for(auto kvp : item)
|
|
||||||
{
|
|
||||||
if(kvp.first == "name" && kvp.second)
|
|
||||||
items.push_back(kvp.second.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
void Append(std::string item)
|
|
||||||
{
|
|
||||||
SQLiteDatabase db(DatabasePath());
|
|
||||||
db.Exec("INSERT INTO names (name) VALUES (" + SQLiteDatabase::Escape(item) + ");");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
|
||||||
{
|
|
||||||
std::string json = "{\"Child\":{\"Items\":[{\"Bounds\":{\"Height\":50,\"Width\":440,\"X\":16,\"Y\":16},\"Hint\":\"Enter name\",\"Id\":\"name\",\"Type\":\"EditTextView\"},{\"Bounds\":{\"Height\":50,\"Width\":70,\"X\":470,\"Y\":17},\"Id\":\"addBtn\",\"Text\":\"Add\",\"Type\":\"ButtonView\"},{\"Bounds\":{\"Height\":50,\"Width\":70,\"X\":550,\"Y\":17},\"Id\":\"clearBtn\",\"Text\":\"Clear\",\"Type\":\"ButtonView\"},{\"Bounds\":{\"Height\":382,\"Width\":608,\"X\":16,\"Y\":82},\"Id\":\"listView\",\"Type\":\"TextListView\"}],\"Type\":\"AbsoluteView\"}}";
|
|
||||||
|
|
||||||
TF_Init();
|
|
||||||
CreateTable();
|
|
||||||
GUIPalette pal(true,{.r=255,.g=0,.b=0,.a=255});
|
|
||||||
|
|
||||||
GUIWindow window("Names",640,480,0,pal);
|
|
||||||
window.SetView(Json::Json::Decode(json));
|
|
||||||
|
|
||||||
auto name = dynamic_cast<Views::EditTextView*>(window.FindViewById("name"));
|
|
||||||
auto addBtn = dynamic_cast<Views::ButtonView*>(window.FindViewById("addBtn"));
|
|
||||||
auto clearBtn = dynamic_cast<Views::ButtonView*>(window.FindViewById("clearBtn"));
|
|
||||||
|
|
||||||
auto listView = dynamic_cast<Views::TextListView*>(window.FindViewById("listView"));
|
|
||||||
|
|
||||||
if(name == nullptr || addBtn == nullptr || clearBtn == nullptr || listView == nullptr)
|
|
||||||
{
|
|
||||||
TF_Quit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadDB(listView->items);
|
|
||||||
addBtn->Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&](View* view,GUIEventArgs& e)->void {
|
|
||||||
std::string text = name->GetText();
|
|
||||||
if(!text.empty())
|
|
||||||
{
|
|
||||||
name->SetText("");
|
|
||||||
Append(text);
|
|
||||||
listView->items.push_back(text);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
clearBtn->Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&](View* view,GUIEventArgs& e)->void {
|
|
||||||
listView->items.clear();
|
|
||||||
ClearTable();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TF_RunEventLoop();
|
|
||||||
TF_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/Streams/MemoryStream.hpp"
|
|
||||||
#include "TessesFramework/Http/HttpClient.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Stream.hpp"
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ScrollableTextListView.hpp"
|
|
||||||
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/PictureView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/VScrollView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/HScrollView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/VStackView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/HStackView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/DropDownView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/SDL_Headers.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
using namespace Tesses::Framework;
|
|
||||||
using namespace Tesses::Framework::SDL2;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void LoadImage(Views::PictureView& view)
|
|
||||||
{
|
|
||||||
using namespace Tesses::Framework::Streams;
|
|
||||||
using namespace Tesses::Framework::Http;
|
|
||||||
MemoryStream strm(true);
|
|
||||||
|
|
||||||
DownloadToStreamSimple("https://s.ytimg.com/vi/lItUxNQnzME/maxresdefault.jpg",strm);
|
|
||||||
strm.Seek(0L,SeekOrigin::Begin);
|
|
||||||
auto res = RwopsFromStream(&strm,false);
|
|
||||||
view.SetPicture(IMG_Load_RW(res,1),true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
|
||||||
{
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
TF_Init();
|
|
||||||
|
|
||||||
//std::cout << GUI_EXPAND_N(argc) << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::pair<SDL_Color,std::string>> colors={
|
|
||||||
std::pair<SDL_Color,std::string>({.r=255,.g=0,.b=128,.a=255},"Magenta"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=255,.g=0,.b=0,.a=255}, "Red"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=0,.g=255,.b=0,.a=255}, "Green"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=0,.g=0,.b=255,.a=255}, "Blue"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=255,.g=255,.b=0,.a=255}, "Yellow"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=143, .g=188, .b=143,.a=255},"Dark sea Green"),
|
|
||||||
std::pair<SDL_Color,std::string>({.r=63, .g=253, .b=170,.a=255},"Aqua")
|
|
||||||
};
|
|
||||||
|
|
||||||
bool darkMode=true;
|
|
||||||
size_t color_index=0;
|
|
||||||
|
|
||||||
|
|
||||||
GUIPalette pal0(darkMode,colors[color_index % colors.size()].first,20,2);
|
|
||||||
TF_LOG("Create pallete");
|
|
||||||
GUIWindow* window = new GUIWindow("My Window Title",1280,720,SDL_WINDOW_RESIZABLE,pal0);
|
|
||||||
TF_LOG("Created GUIWindow success");
|
|
||||||
|
|
||||||
Views::LabelView lbl("A random label\nThat spans lines.");
|
|
||||||
|
|
||||||
Views::ButtonView btn("Dark Mode");
|
|
||||||
Views::ButtonView btn2(colors[0].second);
|
|
||||||
Views::ButtonView btn3("Popup");
|
|
||||||
Views::ButtonView btn4("Window");
|
|
||||||
Views::ProgressView progress(42.42);
|
|
||||||
|
|
||||||
Views::CheckView cv(false,"Checkbox");
|
|
||||||
Views::CheckView cv2(false,"Another Checkbox");
|
|
||||||
Views::EditTextView edit("Enter some text");
|
|
||||||
Views::DropDownView ddv;
|
|
||||||
ddv.GetItems()={
|
|
||||||
"Al Gore",
|
|
||||||
"Demi Lovato",
|
|
||||||
"Steve Ballmer"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Views::ScrollableTextListView list;
|
|
||||||
for(int i = 0; i < 100; i++)
|
|
||||||
{
|
|
||||||
list.items.push_back(std::to_string(i));
|
|
||||||
}
|
|
||||||
/*for(auto item : Tesses::Framework::Filesystem::LocalFS.EnumeratePaths((std::string)"/usr/bin"))
|
|
||||||
{
|
|
||||||
list.items.push_back(item.GetFileName());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Views::LabelView labelView("My Sweet Label");
|
|
||||||
|
|
||||||
Views::AbsoluteView abs;
|
|
||||||
abs.Add({.x=0,.y=0,.w=400,.h=64},&lbl,false);
|
|
||||||
abs.Add({.x=32,.y=64,.w=200,.h=50},&btn,false);
|
|
||||||
abs.Add({.x=248,.y=64,.w=200,.h=50},&cv,false);
|
|
||||||
|
|
||||||
abs.Add({.x=32,.y=134,.w=200,.h=50},&btn2,false);
|
|
||||||
|
|
||||||
abs.Add({.x=248,.y=134,.w=200,.h=50},&cv2,false);
|
|
||||||
|
|
||||||
|
|
||||||
abs.Add({.x=32,.y=190,.w=200,.h=30},&progress,false);
|
|
||||||
|
|
||||||
abs.Add({.x=32,.y=230,.w=320,.h=240},&list,false);
|
|
||||||
|
|
||||||
abs.Add({.x=32,.y=478,.w=300,.h=200},&edit,false);
|
|
||||||
|
|
||||||
Views::VScrollView vscroll(0,0,10);
|
|
||||||
Views::HScrollView hscroll(0,0,10);
|
|
||||||
|
|
||||||
Views::LabelView lbl2("ScrollPos");
|
|
||||||
|
|
||||||
vscroll.ValueChanged += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>(
|
|
||||||
[&](View* sender,GUIEventArgs& e)->void {
|
|
||||||
lbl2.SetText("ScrollPos: " + std::to_string(vscroll.value));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//Views::PictureView img;
|
|
||||||
//LoadImage(img);
|
|
||||||
|
|
||||||
abs.Add({.x=1280-42,.y=2,.w=32,.h=720-20},&vscroll,false);
|
|
||||||
|
|
||||||
abs.Add({.x=720,.y=720-100,.w=200,.h=100},&lbl2,false);
|
|
||||||
|
|
||||||
|
|
||||||
Views::VStackView vstack;
|
|
||||||
vstack.Add(GUI_MIN,&edit,false);
|
|
||||||
vstack.Add(GUI_MIN,&btn3,false);
|
|
||||||
vstack.Add(32,&ddv,false);
|
|
||||||
vstack.Add(GUI_MIN,&btn4,false);
|
|
||||||
|
|
||||||
vstack.Add(GUI_EXPAND,&btn,false);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vstack.Add(GUI_EXPAND_N(10),&list,false);
|
|
||||||
vstack.Add(GUI_EXPAND,&btn2,false);
|
|
||||||
|
|
||||||
vstack.Add(GUI_MIN,&hscroll,false);
|
|
||||||
|
|
||||||
Views::HStackView hstack;
|
|
||||||
hstack.Add(GUI_EXPAND,&vstack,false);
|
|
||||||
hstack.Add(GUI_MIN,&vscroll,false);
|
|
||||||
|
|
||||||
window->SetView(&hstack,false);
|
|
||||||
//window.SetView(&abs,false);
|
|
||||||
window->SDLEvent += std::make_shared<FunctionalEvent<View*,GUISDLEventEventArgs&>>([&window,&lbl](View* sender, GUISDLEventEventArgs& e)->void {
|
|
||||||
std::string sdl2_event = "SDL_Event: " + std::to_string(e.event.type);
|
|
||||||
TF_LOG(sdl2_event);
|
|
||||||
if(e.event.type == SDL_EventType::SDL_WINDOWEVENT)
|
|
||||||
{
|
|
||||||
if(e.event.window.event == SDL_WINDOWEVENT_RESIZED)
|
|
||||||
{
|
|
||||||
std::string text ="A random label\nThat spans lines, WindowSize: "
|
|
||||||
+std::to_string(e.event.window.data1) + "x" + std::to_string(e.event.window.data2) + ".";
|
|
||||||
lbl.SetText(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btn.Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&window,&darkMode,&color_index,&colors,&btn](View* sender, GUIEventArgs& e)->void{
|
|
||||||
darkMode = !darkMode;
|
|
||||||
btn.SetText(darkMode ? "Light Mode" : "Dark Mode");
|
|
||||||
GUIPalette palette(darkMode,colors[color_index % colors.size()].first,20);
|
|
||||||
window->SetPalette(palette);
|
|
||||||
});
|
|
||||||
//"A random label\nThat spans lines."
|
|
||||||
|
|
||||||
btn2.Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&window,&darkMode,&color_index,&colors,&btn2](View* sender, GUIEventArgs& e)->void{
|
|
||||||
color_index++;
|
|
||||||
btn2.SetText(colors[color_index % colors.size()].second);
|
|
||||||
|
|
||||||
GUIPalette palette(darkMode,colors[color_index % colors.size()].first,20);
|
|
||||||
window->SetPalette(palette);
|
|
||||||
});
|
|
||||||
|
|
||||||
Views::LabelView lbl3;
|
|
||||||
|
|
||||||
GUIContainerPopup popup(42,42,300,200);
|
|
||||||
popup.SetView(&lbl3,false);
|
|
||||||
|
|
||||||
btn3.Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&](View* sender, GUIEventArgs& e)->void{
|
|
||||||
lbl3.SetText(edit.GetText());
|
|
||||||
window->ShowPopup(popup);
|
|
||||||
});
|
|
||||||
|
|
||||||
//window("My Window Title",1280,720,SDL_WINDOW_RESIZABLE,pal0);
|
|
||||||
btn4.Click += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([&](View* sender, GUIEventArgs& e)->void{
|
|
||||||
new GUIWindow("My Second Window",640,480,0,pal0);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
TF_RunEventLoop();
|
|
||||||
|
|
||||||
TF_Quit();
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
Font Attribution
|
|
||||||
================
|
|
||||||
|
|
||||||
- [Licensed under OFL (SIL Open Font License)](http://scripts.sil.org/OFL)
|
|
||||||
- [Get the font](https://fontlibrary.org/en/font/aardvark-sans)
|
|
||||||
- [Made by Belleve Invis](https://fontlibrary.org/en/font/aardvark-sans)
|
|
||||||
|
|
||||||
I didn't see a LICENSE file in the font ZIP
|
|
||||||
Binary file not shown.
@@ -1,95 +0,0 @@
|
|||||||
Copyright (c) 2014, Cooper Hewitt Smithsonian Design Museum
|
|
||||||
(cooperhewitt.org), with Reserved Font Name COOPER HEWITT.
|
|
||||||
Copyright (c) 2019-2020 by Cristiano Sobral (cssobral2013@gmail.com).
|
|
||||||
|
|
||||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
||||||
This license is copied below, and is also available with a FAQ at:
|
|
||||||
http://scripts.sil.org/OFL
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------
|
|
||||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
||||||
-----------------------------------------------------------
|
|
||||||
|
|
||||||
PREAMBLE
|
|
||||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
||||||
development of collaborative font projects, to support the font creation
|
|
||||||
efforts of academic and linguistic communities, and to provide a free and
|
|
||||||
open framework in which fonts may be shared and improved in partnership
|
|
||||||
with others.
|
|
||||||
|
|
||||||
The OFL allows the licensed fonts to be used, studied, modified and
|
|
||||||
redistributed freely as long as they are not sold by themselves. The
|
|
||||||
fonts, including any derivative works, can be bundled, embedded,
|
|
||||||
redistributed and/or sold with any software provided that any reserved
|
|
||||||
names are not used by derivative works. The fonts and derivatives,
|
|
||||||
however, cannot be released under any other type of license. The
|
|
||||||
requirement for fonts to remain under this license does not apply
|
|
||||||
to any document created using the fonts or their derivatives.
|
|
||||||
|
|
||||||
DEFINITIONS
|
|
||||||
"Font Software" refers to the set of files released by the Copyright
|
|
||||||
Holder(s) under this license and clearly marked as such. This may
|
|
||||||
include source files, build scripts and documentation.
|
|
||||||
|
|
||||||
"Reserved Font Name" refers to any names specified as such after the
|
|
||||||
copyright statement(s).
|
|
||||||
|
|
||||||
"Original Version" refers to the collection of Font Software components as
|
|
||||||
distributed by the Copyright Holder(s).
|
|
||||||
|
|
||||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
||||||
or substituting -- in part or in whole -- any of the components of the
|
|
||||||
Original Version, by changing formats or by porting the Font Software to a
|
|
||||||
new environment.
|
|
||||||
|
|
||||||
"Author" refers to any designer, engineer, programmer, technical
|
|
||||||
writer or other person who contributed to the Font Software.
|
|
||||||
|
|
||||||
PERMISSION & CONDITIONS
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
||||||
redistribute, and sell modified and unmodified copies of the Font
|
|
||||||
Software, subject to the following conditions:
|
|
||||||
|
|
||||||
1) Neither the Font Software nor any of its individual components,
|
|
||||||
in Original or Modified Versions, may be sold by itself.
|
|
||||||
|
|
||||||
2) Original or Modified Versions of the Font Software may be bundled,
|
|
||||||
redistributed and/or sold with any software, provided that each copy
|
|
||||||
contains the above copyright notice and this license. These can be
|
|
||||||
included either as stand-alone text files, human-readable headers or
|
|
||||||
in the appropriate machine-readable metadata fields within text or
|
|
||||||
binary files as long as those fields can be easily viewed by the user.
|
|
||||||
|
|
||||||
3) No Modified Version of the Font Software may use the Reserved Font
|
|
||||||
Name(s) unless explicit written permission is granted by the corresponding
|
|
||||||
Copyright Holder. This restriction only applies to the primary font name as
|
|
||||||
presented to the users.
|
|
||||||
|
|
||||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
||||||
Software shall not be used to promote, endorse or advertise any
|
|
||||||
Modified Version, except to acknowledge the contribution(s) of the
|
|
||||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
||||||
permission.
|
|
||||||
|
|
||||||
5) The Font Software, modified or unmodified, in part or in whole,
|
|
||||||
must be distributed entirely under this license, and must not be
|
|
||||||
distributed under any other license. The requirement for fonts to
|
|
||||||
remain under this license does not apply to any document created
|
|
||||||
using the Font Software.
|
|
||||||
|
|
||||||
TERMINATION
|
|
||||||
This license becomes null and void if any of the above conditions are
|
|
||||||
not met.
|
|
||||||
|
|
||||||
DISCLAIMER
|
|
||||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
||||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
||||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
||||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
||||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
||||||
Binary file not shown.
@@ -9,24 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "Threading/Mutex.hpp"
|
#include "Threading/Mutex.hpp"
|
||||||
class TextException : public std::exception {
|
|
||||||
|
|
||||||
std::string error_message;
|
|
||||||
public:
|
|
||||||
|
|
||||||
TextException(std::string ex)
|
|
||||||
{
|
|
||||||
error_message = "TextException: ";
|
|
||||||
error_message.append(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char * what() const noexcept override
|
|
||||||
{
|
|
||||||
return error_message.c_str();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
namespace Tesses::Framework
|
namespace Tesses::Framework
|
||||||
{
|
{
|
||||||
template<typename...TArgs>
|
template<typename...TArgs>
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include <array>
|
|
||||||
#include "SDL_Headers.hpp"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
class FontCache
|
|
||||||
{
|
|
||||||
std::array<SDL_Texture*,96> font_chrs;
|
|
||||||
int mw,mh,ps;
|
|
||||||
void Load(SDL_Renderer* renderer,TTF_Font* font);
|
|
||||||
public:
|
|
||||||
FontCache(SDL_Renderer* renderer,TTF_Font* font);
|
|
||||||
FontCache(SDL_Renderer* renderer,std::string font,int sz);
|
|
||||||
FontCache(SDL_Renderer* renderer,const uint8_t* mem,size_t cnt,int sz);
|
|
||||||
FontCache(SDL_Renderer* renderer,const std::vector<uint8_t>& v,int sz);
|
|
||||||
FontCache(SDL_Renderer* renderer,int sz);
|
|
||||||
SDL_Texture* operator[](char c);
|
|
||||||
SDL_Texture* GetCharOfColor(char c, const SDL_Color& color);
|
|
||||||
int MaxWidth();
|
|
||||||
int MaxHeight();
|
|
||||||
int PointSize();
|
|
||||||
void CalculateSize(std::string text, int& x,int& y);
|
|
||||||
void Render(SDL_Renderer* renderer,int x,int y, std::string text, const SDL_Color& color,size_t begin=0,size_t end=std::string::npos);
|
|
||||||
~FontCache();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,328 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "SDL_Headers.hpp"
|
|
||||||
#include "FontCache.hpp"
|
|
||||||
#include "../Filesystem/VFSFix.hpp"
|
|
||||||
#include "../Filesystem/VFS.hpp"
|
|
||||||
#include "../Common.hpp"
|
|
||||||
#include "../Serialization/Json.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
class GUIPalette {
|
|
||||||
public:
|
|
||||||
GUIPalette();
|
|
||||||
GUIPalette(bool isDarkMode, SDL_Color accent,int fontSize=24,int borderSize=2);
|
|
||||||
GUIPalette(SDL_Color accent, SDL_Color background, SDL_Color borderColor, SDL_Color borderHover, SDL_Color borderActive, SDL_Color borderHoverActive, int fontSize=24,int borderSize=2);
|
|
||||||
SDL_Color accent; //color is used for font when not over accent background
|
|
||||||
SDL_Color background;
|
|
||||||
SDL_Color borderColor; //color is used for font when over accent background
|
|
||||||
SDL_Color borderHover;
|
|
||||||
SDL_Color borderActive;
|
|
||||||
SDL_Color borderHoverActive;
|
|
||||||
int fontSize;
|
|
||||||
int borderSize;
|
|
||||||
|
|
||||||
SDL_Color& GetBorderColor(bool isHovering, bool isActive, bool isMouseDown);
|
|
||||||
};
|
|
||||||
|
|
||||||
class GUIEventArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual std::string Type();
|
|
||||||
virtual ~GUIEventArgs();
|
|
||||||
};
|
|
||||||
class View;
|
|
||||||
class GUIWindowClosingEventArgs : public GUIEventArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool cancel;
|
|
||||||
std::string Type();
|
|
||||||
};
|
|
||||||
class GUIMouseButtonEventArgs : public GUIEventArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Uint32 which;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
Uint8 button;
|
|
||||||
std::string Type();
|
|
||||||
};
|
|
||||||
class GUIJsonViewNotFoundEventArgs : public GUIEventArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string Type();
|
|
||||||
View* destView;
|
|
||||||
Tesses::Framework::Serialization::Json::JObject jsonObject;
|
|
||||||
std::string typeString;
|
|
||||||
};
|
|
||||||
class GUISDLEventEventArgs : public GUIEventArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string Type();
|
|
||||||
SDL_Event event;
|
|
||||||
};
|
|
||||||
constexpr uint64_t VIEWFLAG_HOVER_STATE=(uint64_t)1 << 0;
|
|
||||||
constexpr uint64_t VIEWFLAG_MOUSEDOWN_STATE =(uint64_t)1<<1;
|
|
||||||
constexpr uint64_t VIEWFLAG_ISACTIVE=(uint64_t)1<<2;
|
|
||||||
constexpr uint64_t VIEWFLAG_TABSTOP=(uint64_t)1<<3;
|
|
||||||
constexpr uint64_t VIEWFLAG_INTERCEPT_TAB=(uint64_t)1<<4;
|
|
||||||
constexpr uint64_t VIEWFLAG_CHECKED=(uint64_t)1<<5;
|
|
||||||
constexpr uint64_t VIEWFLAG_TOUCHED=(uint64_t)1<<6;
|
|
||||||
constexpr uint64_t VIEWFLAG_HOVER_B1STATE=(uint64_t)1<<7; //for scrollbar buttons
|
|
||||||
constexpr uint64_t VIEWFLAG_HOVER_B2STATE=(uint64_t)1<<8; //for scrollbar buttons
|
|
||||||
constexpr uint64_t VIEWFLAG_MOUSEDOWN_B1STATE=(uint64_t)1<<9; //for scrollbar buttons
|
|
||||||
constexpr uint64_t VIEWFLAG_MOUSEDOWN_B2STATE=(uint64_t)1<<10; //for scrollbar buttons
|
|
||||||
|
|
||||||
constexpr int GUI_EXPAND = -1;
|
|
||||||
constexpr int GUI_MIN = 0;
|
|
||||||
|
|
||||||
|
|
||||||
constexpr int GUI_EXPAND_N(int n)
|
|
||||||
{
|
|
||||||
if(n < 0) return n;
|
|
||||||
return -n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class GUIPopup;
|
|
||||||
class GUIWindow;
|
|
||||||
class ContainerView;
|
|
||||||
class View {
|
|
||||||
protected:
|
|
||||||
std::string text;
|
|
||||||
std::string id;
|
|
||||||
uint64_t flags;
|
|
||||||
protected:
|
|
||||||
|
|
||||||
View();
|
|
||||||
View(std::string text);
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual void OnDragDropFile(Tesses::Framework::Filesystem::VFSPath filePath,SDL_Rect myRect, SDL_Point dropLoc);
|
|
||||||
virtual void OnDragDropText(std::string text,SDL_Rect myRect, SDL_Point dropLoc);
|
|
||||||
virtual void OnEnter(GUIEventArgs& evt);
|
|
||||||
virtual void OnLeave(GUIEventArgs& evt);
|
|
||||||
virtual void OnMouseDown(GUIMouseButtonEventArgs& evt);
|
|
||||||
virtual void OnMouseUp(GUIMouseButtonEventArgs& evt);
|
|
||||||
virtual void OnClick(GUIEventArgs& evt);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
virtual void OnSetParent(View* v);
|
|
||||||
|
|
||||||
void CallOnDraw(View* view, SDL_Renderer* renderer, SDL_Rect& myRect)
|
|
||||||
{
|
|
||||||
view->OnDraw(renderer,myRect);
|
|
||||||
}
|
|
||||||
bool CallOnEvent(View* view,SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
return view->OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ContainerView* parent;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool GetViewFlag(uint64_t flag)
|
|
||||||
{
|
|
||||||
return (this->flags & flag) != 0;
|
|
||||||
}
|
|
||||||
void SetViewFlag(uint64_t flag, bool value)
|
|
||||||
{
|
|
||||||
if(value)
|
|
||||||
this->flags |= flag;
|
|
||||||
else
|
|
||||||
this->flags &= ~flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventList<View*,GUIMouseButtonEventArgs&> MouseUp;
|
|
||||||
EventList<View*,GUIMouseButtonEventArgs&> MouseDown;
|
|
||||||
EventList<View*,GUIEventArgs&> Click;
|
|
||||||
EventList<View*,GUIEventArgs&> Enter;
|
|
||||||
EventList<View*,GUIEventArgs&> Leave;
|
|
||||||
EventList<View*,GUISDLEventEventArgs&> SDLEvent;
|
|
||||||
virtual ~View();
|
|
||||||
friend class GUIWindow;
|
|
||||||
virtual GUIWindow* GetWindow();
|
|
||||||
virtual std::string GetText();
|
|
||||||
virtual void SetText(std::string text);
|
|
||||||
virtual void SetId(std::string id);
|
|
||||||
virtual std::string GetId();
|
|
||||||
virtual View* FindViewById(std::string id);
|
|
||||||
friend class ContainerView;
|
|
||||||
|
|
||||||
virtual std::pair<int,int> PreferedMinSize();
|
|
||||||
|
|
||||||
std::pair<int,int> GetCordFromEvent(SDL_Event& event);
|
|
||||||
|
|
||||||
};
|
|
||||||
class ContainerView : public View {
|
|
||||||
public:
|
|
||||||
virtual size_t ViewCount()=0;
|
|
||||||
virtual View* GetViewAt(size_t index)=0;
|
|
||||||
virtual View* FindViewById(std::string id);
|
|
||||||
protected:
|
|
||||||
ContainerView();
|
|
||||||
ContainerView(std::string text);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AssignChildParentToThis(View* view)
|
|
||||||
{
|
|
||||||
if(view != nullptr)
|
|
||||||
{
|
|
||||||
view->parent = this;
|
|
||||||
view->OnSetParent(this);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
enum class TabNextResult {
|
|
||||||
KeepGoing,
|
|
||||||
TabNext,
|
|
||||||
Done
|
|
||||||
};
|
|
||||||
class GUIPopup : public ContainerView {
|
|
||||||
protected:
|
|
||||||
bool closed=true;
|
|
||||||
virtual View* GetView()=0;
|
|
||||||
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
GUIPopup();
|
|
||||||
GUIPopup(SDL_Rect bounds);
|
|
||||||
GUIPopup(int x, int y,int w, int h);
|
|
||||||
SDL_Rect bounds;
|
|
||||||
bool closeIfClickOutside=true;
|
|
||||||
|
|
||||||
virtual void Close();
|
|
||||||
virtual bool IsClosed();
|
|
||||||
virtual ~GUIPopup();
|
|
||||||
|
|
||||||
size_t ViewCount();
|
|
||||||
View* GetViewAt(size_t index);
|
|
||||||
|
|
||||||
bool IsActive();
|
|
||||||
|
|
||||||
friend class GUIWindow;
|
|
||||||
};
|
|
||||||
class GUIContainerPopup : public GUIPopup
|
|
||||||
{
|
|
||||||
View* child;
|
|
||||||
bool ownsChild;
|
|
||||||
protected:
|
|
||||||
View* GetView();
|
|
||||||
public:
|
|
||||||
GUIContainerPopup();
|
|
||||||
GUIContainerPopup(SDL_Rect bounds);
|
|
||||||
GUIContainerPopup(int x, int y,int w, int h);
|
|
||||||
|
|
||||||
void SetView(View* view, bool owns=true);
|
|
||||||
|
|
||||||
~GUIContainerPopup();
|
|
||||||
};
|
|
||||||
class GUIDialog : public GUIPopup {
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
GUIDialog();
|
|
||||||
GUIDialog(SDL_Rect bounds);
|
|
||||||
GUIDialog(int x,int y, int w, int h);
|
|
||||||
virtual ~GUIDialog();
|
|
||||||
};
|
|
||||||
class GUIContainerDialog : public GUIDialog
|
|
||||||
{
|
|
||||||
View* v;
|
|
||||||
bool owns=false;
|
|
||||||
protected:
|
|
||||||
View* GetView();
|
|
||||||
public:
|
|
||||||
GUIContainerDialog();
|
|
||||||
GUIContainerDialog(SDL_Rect bounds);
|
|
||||||
GUIContainerDialog(int x, int y,int w, int h);
|
|
||||||
void SetView(View* view, bool owns=true);
|
|
||||||
size_t ViewCount();
|
|
||||||
View* GetViewAt(size_t index);
|
|
||||||
~GUIContainerDialog();
|
|
||||||
};
|
|
||||||
|
|
||||||
class GUIWindow : public ContainerView
|
|
||||||
{
|
|
||||||
std::vector<GUIPopup*> popups;
|
|
||||||
View* child;
|
|
||||||
bool ownsChild;
|
|
||||||
SDL_Window* window;
|
|
||||||
SDL_Renderer* renderer;
|
|
||||||
void Event(SDL_Event& event);
|
|
||||||
void Draw();
|
|
||||||
void DeactivateAll(View* view);
|
|
||||||
void TabNext(View* view,TabNextResult& nr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
|
|
||||||
bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
|
|
||||||
public:
|
|
||||||
EventList<View*,GUIJsonViewNotFoundEventArgs&> JsonViewNotFound;
|
|
||||||
EventList<View*,GUIWindowClosingEventArgs&> Closing;
|
|
||||||
size_t ViewCount();
|
|
||||||
View* GetViewAt(size_t index);
|
|
||||||
FontCache* normal_font;
|
|
||||||
FontCache* monospaced_font;
|
|
||||||
GUIPalette palette;
|
|
||||||
GUIWindow(std::string title, int w, int h, Uint32 flags, const GUIPalette& palette);
|
|
||||||
void SetPalette(const GUIPalette& palette);
|
|
||||||
void SetView(View* view,bool owns=true);
|
|
||||||
|
|
||||||
void ShowPopup(GUIPopup* popup);
|
|
||||||
void ShowPopup(GUIPopup& popup);
|
|
||||||
|
|
||||||
void MakeActive(View* view);
|
|
||||||
void TabNext();
|
|
||||||
GUIWindow* GetWindow();
|
|
||||||
|
|
||||||
~GUIWindow();
|
|
||||||
|
|
||||||
friend class GUI;
|
|
||||||
friend class GUIPopup;
|
|
||||||
friend class View;
|
|
||||||
|
|
||||||
void SetText(std::string text);
|
|
||||||
|
|
||||||
void SetView(Tesses::Framework::Serialization::Json::JToken json);
|
|
||||||
|
|
||||||
SDL_Window* GetSDLWindow();
|
|
||||||
SDL_Renderer* GetSDLRenderer();
|
|
||||||
|
|
||||||
View* CreateViewFromJson(Tesses::Framework::Serialization::Json::JObject json);
|
|
||||||
operator bool();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class GUI {
|
|
||||||
std::vector<GUIWindow*> windows;
|
|
||||||
public:
|
|
||||||
void Update();
|
|
||||||
void CloseWindows();
|
|
||||||
friend class GUIWindow;
|
|
||||||
};
|
|
||||||
extern GUI gui;
|
|
||||||
|
|
||||||
class Clipper {
|
|
||||||
SDL_Rect theRect;
|
|
||||||
SDL_Renderer* renderer;
|
|
||||||
bool isClipped;
|
|
||||||
public:
|
|
||||||
Clipper(SDL_Renderer* renderer, SDL_Rect& myRect);
|
|
||||||
bool Clip(SDL_Rect rect);
|
|
||||||
~Clipper();
|
|
||||||
static void ClipRect(SDL_Rect& child, SDL_Rect& parent);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
bool TryParseSDLColor(std::string str, SDL_Color& col);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <TessesFramework/TessesFrameworkFeatures.h>
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#define SDL_MAIN_HANDLED
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#if defined(TESSESFRAMEWORK_FETCHCONTENT)
|
|
||||||
#include <SDL_image.h>
|
|
||||||
#include <SDL_ttf.h>
|
|
||||||
#else
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../Streams/Stream.hpp"
|
|
||||||
#include <SDL2/SDL_rwops.h>
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
SDL_RWops* RwopsFromStream(Tesses::Framework::Streams::Stream* strm, bool owns=true);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class AbsoluteView : public ContainerView {
|
|
||||||
std::vector<std::pair<std::pair<View*,bool>,SDL_Rect>> views;
|
|
||||||
protected:
|
|
||||||
void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
|
|
||||||
bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
size_t ViewCount();
|
|
||||||
View* GetViewAt(size_t index);
|
|
||||||
AbsoluteView();
|
|
||||||
void Add(SDL_Rect rect, View* view, bool owns=true);
|
|
||||||
void Set(View* view, SDL_Rect rect);
|
|
||||||
void Remove(View* view);
|
|
||||||
~AbsoluteView();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/* class AbsoluteContainer : public View {
|
|
||||||
std::vector<std::pair<std::pair<View*,bool>,SDL_Rect>> views;
|
|
||||||
public:
|
|
||||||
void Add(SDL_Rect rect, View* view, bool owns=true);
|
|
||||||
void Set(View* view, SDL_Rect rect);
|
|
||||||
void Remove(View* view);
|
|
||||||
|
|
||||||
~AbsoluteContainer();
|
|
||||||
};*/
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class ButtonView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
|
|
||||||
public:
|
|
||||||
ButtonView();
|
|
||||||
ButtonView(std::string text);
|
|
||||||
virtual std::pair<int,int> PreferedMinSize();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class CheckView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnCheckChanged(GUIEventArgs& event);
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
|
|
||||||
public:
|
|
||||||
CheckView(bool checked, std::string label);
|
|
||||||
CheckView();
|
|
||||||
|
|
||||||
virtual bool GetChecked();
|
|
||||||
virtual void SetChecked(bool value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EventList<View*,GUIEventArgs&> CheckChanged;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
#include "ScrollableTextListView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class DropDownView : public View {
|
|
||||||
|
|
||||||
GUIContainerPopup popup;
|
|
||||||
ScrollableTextListView listView;
|
|
||||||
bool hasSet=false;
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
DropDownView();
|
|
||||||
std::vector<std::string>& GetItems();
|
|
||||||
void SetIndex(int index);
|
|
||||||
int GetIndex();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class EditTextView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
std::string hint;
|
|
||||||
size_t cursorPos;
|
|
||||||
size_t cursorEnd;
|
|
||||||
public:
|
|
||||||
EditTextView();
|
|
||||||
EditTextView(std::string hint);
|
|
||||||
virtual std::string GetHint();
|
|
||||||
virtual void SetHint(std::string hint);
|
|
||||||
virtual void SetText(std::string text);
|
|
||||||
virtual void TypeText(std::string text);
|
|
||||||
virtual std::pair<int,int> PreferedMinSize();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class HScrollView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnValueChanged(GUIEventArgs& e);
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
HScrollView();
|
|
||||||
HScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step=1);
|
|
||||||
uint64_t value;
|
|
||||||
uint64_t min;
|
|
||||||
uint64_t max;
|
|
||||||
uint64_t step;
|
|
||||||
EventList<View*,GUIEventArgs&> ValueChanged;
|
|
||||||
|
|
||||||
std::pair<int,int> PreferedMinSize();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class HStackView : public ContainerView {
|
|
||||||
|
|
||||||
std::vector<std::pair<int,std::pair<View*,bool>>> items;
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
HStackView();
|
|
||||||
int spacing=0;
|
|
||||||
|
|
||||||
void Add(int sz, View* view, bool owns=true);
|
|
||||||
void Remove(View* view);
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
virtual size_t ViewCount();
|
|
||||||
virtual View* GetViewAt(size_t index);
|
|
||||||
|
|
||||||
virtual ~HStackView();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class LabelView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
public:
|
|
||||||
LabelView();
|
|
||||||
LabelView(std::string text);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class MultilineEditTextView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
std::string hint;
|
|
||||||
std::vector<std::string> lines;
|
|
||||||
SDL_Point topLeft={.x=0,.y=0};
|
|
||||||
SDL_Point cursorPos={.x=0,.y=0};
|
|
||||||
SDL_Point cursorEnd={.x=-1,.y=-1};
|
|
||||||
public:
|
|
||||||
MultilineEditTextView();
|
|
||||||
MultilineEditTextView(std::string hint);
|
|
||||||
virtual std::string GetHint();
|
|
||||||
virtual void SetHint(std::string hint);
|
|
||||||
virtual std::string GetText();
|
|
||||||
virtual void SetText(std::string text);
|
|
||||||
virtual void TypeText(std::string text);
|
|
||||||
virtual std::pair<int,int> PreferedMinSize();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class PictureView : public View {
|
|
||||||
SDL_Texture* tex;
|
|
||||||
bool ownsTex;
|
|
||||||
SDL_Surface* surf;
|
|
||||||
bool ownsSurf;
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
public:
|
|
||||||
PictureView();
|
|
||||||
void SetPicture(SDL_Texture* tex, bool owns=true);
|
|
||||||
void SetPicture(SDL_Surface* surface,bool owns=true);
|
|
||||||
~PictureView();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class ProgressView : public View
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
public:
|
|
||||||
ProgressView();
|
|
||||||
ProgressView(double value);
|
|
||||||
double value;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class ScrollableTextListView : public View {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
ScrollableTextListView();
|
|
||||||
size_t firstIndex;
|
|
||||||
int selected;
|
|
||||||
std::vector<std::string> items;
|
|
||||||
|
|
||||||
EventList<View*,GUIEventArgs&> ValueChanged;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class TabView : public ContainerView {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<std::pair<std::string,std::pair<View*,bool>>> items;
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
|
|
||||||
public:
|
|
||||||
TabView();
|
|
||||||
TabView(bool tabsVisible);
|
|
||||||
bool tabsVisible;
|
|
||||||
size_t firstTab;
|
|
||||||
size_t selectedTab;
|
|
||||||
|
|
||||||
void AddTab(std::string name, View* view, bool owns=true);
|
|
||||||
void RemoveTab(View* view);
|
|
||||||
void Clear();
|
|
||||||
virtual size_t ViewCount();
|
|
||||||
virtual View* GetViewAt(size_t index);
|
|
||||||
~TabView();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class TextListView : public View {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
TextListView();
|
|
||||||
size_t firstIndex;
|
|
||||||
int selected;
|
|
||||||
std::vector<std::string> items;
|
|
||||||
|
|
||||||
EventList<View*,GUIEventArgs&> ValueChanged;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class VScrollView : public View {
|
|
||||||
protected:
|
|
||||||
virtual void OnValueChanged(GUIEventArgs& e);
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
VScrollView();
|
|
||||||
VScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step=1);
|
|
||||||
uint64_t value;
|
|
||||||
uint64_t min;
|
|
||||||
uint64_t max;
|
|
||||||
uint64_t step;
|
|
||||||
EventList<View*,GUIEventArgs&> ValueChanged;
|
|
||||||
|
|
||||||
std::pair<int,int> PreferedMinSize();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "../GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
class VStackView : public ContainerView {
|
|
||||||
|
|
||||||
std::vector<std::pair<int,std::pair<View*,bool>>> items;
|
|
||||||
protected:
|
|
||||||
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
|
||||||
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
|
||||||
public:
|
|
||||||
VStackView();
|
|
||||||
int spacing=0;
|
|
||||||
|
|
||||||
void Add(int sz, View* view, bool owns=true);
|
|
||||||
void Remove(View* view);
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
virtual size_t ViewCount();
|
|
||||||
virtual View* GetViewAt(size_t index);
|
|
||||||
|
|
||||||
virtual ~VStackView();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -37,4 +37,3 @@
|
|||||||
#include "Platform/Environment.hpp"
|
#include "Platform/Environment.hpp"
|
||||||
#include "Platform/Process.hpp"
|
#include "Platform/Process.hpp"
|
||||||
#include "Text/StringConverter.hpp"
|
#include "Text/StringConverter.hpp"
|
||||||
#include "SDL2/SDL_Headers.hpp"
|
|
||||||
@@ -300,14 +300,14 @@ namespace Tesses::Framework::Http
|
|||||||
|
|
||||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream* strm)
|
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream* strm)
|
||||||
{
|
{
|
||||||
if(strm == nullptr) throw TextException("strm is null");
|
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||||
HttpRequest request;
|
HttpRequest request;
|
||||||
request.url = url;
|
request.url = url;
|
||||||
request.unixSocket = unixSocket;
|
request.unixSocket = unixSocket;
|
||||||
request.followRedirects=true;
|
request.followRedirects=true;
|
||||||
request.method = "GET";
|
request.method = "GET";
|
||||||
HttpResponse response(request);
|
HttpResponse response(request);
|
||||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||||
response.CopyToStream(strm);
|
response.CopyToStream(strm);
|
||||||
}
|
}
|
||||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream& strm)
|
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream& strm)
|
||||||
@@ -317,16 +317,16 @@ namespace Tesses::Framework::Http
|
|||||||
|
|
||||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS* vfs, Tesses::Framework::Filesystem::VFSPath path)
|
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS* vfs, Tesses::Framework::Filesystem::VFSPath path)
|
||||||
{
|
{
|
||||||
if(vfs == nullptr) throw TextException("vfs is null");
|
if(vfs == nullptr) throw std::runtime_error("vfs is null");
|
||||||
auto strm = vfs->OpenFile(path,"wb");
|
auto strm = vfs->OpenFile(path,"wb");
|
||||||
if(strm == nullptr) throw TextException("strm is null");
|
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||||
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
||||||
delete strm;
|
delete strm;
|
||||||
}
|
}
|
||||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS& vfs, Tesses::Framework::Filesystem::VFSPath path)
|
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS& vfs, Tesses::Framework::Filesystem::VFSPath path)
|
||||||
{
|
{
|
||||||
auto strm = vfs.OpenFile(path,"wb");
|
auto strm = vfs.OpenFile(path,"wb");
|
||||||
if(strm == nullptr) throw TextException("strm is null");
|
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||||
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
||||||
delete strm;
|
delete strm;
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ namespace Tesses::Framework::Http
|
|||||||
request.followRedirects=true;
|
request.followRedirects=true;
|
||||||
request.method = "GET";
|
request.method = "GET";
|
||||||
HttpResponse response(request);
|
HttpResponse response(request);
|
||||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||||
return response.ReadAsString();
|
return response.ReadAsString();
|
||||||
}
|
}
|
||||||
void DownloadToStreamSimple(std::string url, Tesses::Framework::Streams::Stream* strm)
|
void DownloadToStreamSimple(std::string url, Tesses::Framework::Streams::Stream* strm)
|
||||||
@@ -373,7 +373,7 @@ namespace Tesses::Framework::Http
|
|||||||
request.followRedirects=true;
|
request.followRedirects=true;
|
||||||
request.method = "GET";
|
request.method = "GET";
|
||||||
HttpResponse response(request);
|
HttpResponse response(request);
|
||||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||||
return response.ReadAsString();
|
return response.ReadAsString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -730,8 +730,8 @@ namespace Tesses::Framework::Http
|
|||||||
void ServerContext::SendStream(Stream& strm)
|
void ServerContext::SendStream(Stream& strm)
|
||||||
{
|
{
|
||||||
if(sent) return;
|
if(sent) return;
|
||||||
if(!strm.CanRead()) throw TextException("Cannot read from stream");
|
if(!strm.CanRead()) throw std::runtime_error("Cannot read from stream");
|
||||||
if(strm.EndOfStream()) throw TextException("End of stream");
|
if(strm.EndOfStream()) throw std::runtime_error("End of stream");
|
||||||
if(strm.CanSeek())
|
if(strm.CanSeek())
|
||||||
{
|
{
|
||||||
int64_t len=strm.GetLength();
|
int64_t len=strm.GetLength();
|
||||||
@@ -1013,13 +1013,24 @@ namespace Tesses::Framework::Http
|
|||||||
ctx.SendNotFound();
|
ctx.SendNotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(std::exception& ex)
|
catch(std::exception& ex)
|
||||||
{
|
{
|
||||||
ctx.SendException(ex);
|
ctx.SendException(ex);
|
||||||
}
|
}
|
||||||
|
catch(std::string& ex)
|
||||||
|
{
|
||||||
|
std::runtime_error re(ex);
|
||||||
|
ctx.SendException(re);
|
||||||
|
}
|
||||||
|
catch(const char* ex)
|
||||||
|
{
|
||||||
|
std::runtime_error re(ex);
|
||||||
|
ctx.SendException(re);
|
||||||
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
TextException ex("An unknown error occurred");
|
std::runtime_error ex("An unknown error occurred");
|
||||||
ctx.SendException(ex);
|
ctx.SendException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,279 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/FontCache.hpp"
|
|
||||||
#include "TessesFramework/Http/HttpUtils.hpp"
|
|
||||||
#include "TessesFramework/TanoheSans-Regular.h"
|
|
||||||
using HU= Tesses::Framework::Http::HttpUtils;
|
|
||||||
namespace Tesses::Framework::SDL2 {
|
|
||||||
void FontCache::Load(SDL_Renderer* renderer,TTF_Font* font)
|
|
||||||
{
|
|
||||||
this->mw=0;
|
|
||||||
this->mh=0;
|
|
||||||
this->ps=ps;
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->font_chrs.size();i++)
|
|
||||||
{
|
|
||||||
SDL_Surface* surf = TTF_RenderGlyph_Blended(font,(Uint16)(i+32),{.r=255,.g=255,.b=255,.a=255});
|
|
||||||
if(surf->w > this->mw) mw = surf->w;
|
|
||||||
if(surf->h > this->mh) mh = surf->h;
|
|
||||||
this->font_chrs[i] = SDL_CreateTextureFromSurface(renderer,surf);
|
|
||||||
SDL_FreeSurface(surf);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FontCache::FontCache(SDL_Renderer* renderer,std::string font,int sz)
|
|
||||||
{
|
|
||||||
TTF_Font* f = TTF_OpenFont(font.c_str(),sz);
|
|
||||||
Load(renderer,f);
|
|
||||||
TTF_CloseFont(f);
|
|
||||||
}
|
|
||||||
FontCache::FontCache(SDL_Renderer* renderer,const uint8_t* mem,size_t cnt,int sz)
|
|
||||||
{
|
|
||||||
|
|
||||||
TTF_Font* f = TTF_OpenFontRW(SDL_RWFromConstMem(mem,cnt),1,sz);
|
|
||||||
Load(renderer,f);
|
|
||||||
TTF_CloseFont(f);
|
|
||||||
}
|
|
||||||
FontCache::FontCache(SDL_Renderer* renderer,const std::vector<uint8_t>& v,int sz) : FontCache(renderer,v.data(),v.size(),sz)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
FontCache::FontCache(SDL_Renderer* renderer,TTF_Font* font)
|
|
||||||
{
|
|
||||||
this->Load(renderer,font);
|
|
||||||
}
|
|
||||||
FontCache::FontCache(SDL_Renderer* renderer,int sz) : FontCache(renderer,TANOHESANSREGULAR,TANOHESANSREGULAR_SIZE,sz)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void FontCache::CalculateSize(std::string text, int& x,int& y)
|
|
||||||
{
|
|
||||||
int myX = 0;
|
|
||||||
x=0;
|
|
||||||
y=0;
|
|
||||||
int maxH = MaxHeight();
|
|
||||||
y=maxH;
|
|
||||||
for(auto c : text)
|
|
||||||
{
|
|
||||||
switch(c)
|
|
||||||
{
|
|
||||||
case '\n':
|
|
||||||
{
|
|
||||||
y += maxH;
|
|
||||||
if(myX > x) x = myX;
|
|
||||||
myX = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
{
|
|
||||||
auto tex = operator[](' ');
|
|
||||||
int wi;
|
|
||||||
SDL_QueryTexture(tex,NULL,NULL,&wi,NULL);
|
|
||||||
|
|
||||||
myX += wi * 4;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
auto tex = operator[](c);
|
|
||||||
int wi;
|
|
||||||
int he;
|
|
||||||
SDL_QueryTexture(tex,NULL,NULL,&wi,&he);
|
|
||||||
|
|
||||||
myX += wi;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(myX > x) x = myX;
|
|
||||||
}
|
|
||||||
void FontCache::Render(SDL_Renderer* renderer,int x,int y, std::string text,const SDL_Color& color, size_t begin, size_t end)
|
|
||||||
{
|
|
||||||
int myX = x;
|
|
||||||
int maxH = MaxHeight();
|
|
||||||
if(begin >= text.size()) return;
|
|
||||||
if(end > text.size()) end = text.size();
|
|
||||||
|
|
||||||
for(size_t i = begin; i < end; i++)
|
|
||||||
{
|
|
||||||
switch(text[i])
|
|
||||||
{
|
|
||||||
case '\n':
|
|
||||||
{
|
|
||||||
y += maxH;
|
|
||||||
myX = x;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
{
|
|
||||||
auto tex = GetCharOfColor(' ',color);
|
|
||||||
int wi;
|
|
||||||
SDL_QueryTexture(tex,NULL,NULL,&wi,NULL);
|
|
||||||
|
|
||||||
myX += wi * 4;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
auto tex = GetCharOfColor(text[i],color);
|
|
||||||
int wi;
|
|
||||||
int he;
|
|
||||||
SDL_QueryTexture(tex,NULL,NULL,&wi,&he);
|
|
||||||
SDL_Rect src={.x=0,.y=0,.w=wi,.h=he};
|
|
||||||
|
|
||||||
SDL_Rect dest={.x=myX,.y=y,.w=wi,.h=he};
|
|
||||||
|
|
||||||
myX += wi;
|
|
||||||
SDL_RenderCopy(renderer,tex,&src,&dest);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SDL_Texture* FontCache::GetCharOfColor(char c, const SDL_Color& color)
|
|
||||||
{
|
|
||||||
auto res = (c >= 32 && c <= 126) ? this->font_chrs[c-32] : this->font_chrs[95];
|
|
||||||
SDL_SetTextureColorMod(res,color.r,color.g,color.b);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
SDL_Texture* FontCache::operator[](char c)
|
|
||||||
{
|
|
||||||
return GetCharOfColor(c,{.r=255,.g=255,.b=255,.a=255});
|
|
||||||
}
|
|
||||||
FontCache::~FontCache()
|
|
||||||
{
|
|
||||||
for(auto item : this->font_chrs)
|
|
||||||
SDL_DestroyTexture(item);
|
|
||||||
}
|
|
||||||
int FontCache::MaxWidth()
|
|
||||||
{
|
|
||||||
return this->mw;
|
|
||||||
}
|
|
||||||
int FontCache::MaxHeight()
|
|
||||||
{
|
|
||||||
return this->mh;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FontCache::PointSize()
|
|
||||||
{
|
|
||||||
return this->ps;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryParseSDLColor(std::string str, SDL_Color& col)
|
|
||||||
{
|
|
||||||
str = HU::Replace(str," ","");
|
|
||||||
//rgba(255,255,255,1.0)
|
|
||||||
//rgb(197, 30, 30)
|
|
||||||
//#rgb
|
|
||||||
//#rgba
|
|
||||||
//#rrggbb
|
|
||||||
//#rrggbbaa
|
|
||||||
|
|
||||||
if(str.size() >= 4 && str[0] == '#')
|
|
||||||
{
|
|
||||||
if(str.size() == 4)
|
|
||||||
{
|
|
||||||
auto r = HU::HexToNibble(str[1]);
|
|
||||||
r |= r << 4;
|
|
||||||
auto g = HU::HexToNibble(str[2]);
|
|
||||||
g |= g << 4;
|
|
||||||
auto b = HU::HexToNibble(str[3]);
|
|
||||||
b |= b << 4;
|
|
||||||
col.r = r;
|
|
||||||
col.g = g;
|
|
||||||
col.b = b;
|
|
||||||
col.a = 255;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(str.size() == 5)
|
|
||||||
{
|
|
||||||
auto r = HU::HexToNibble(str[1]);
|
|
||||||
r |= r << 4;
|
|
||||||
auto g = HU::HexToNibble(str[2]);
|
|
||||||
g |= g << 4;
|
|
||||||
auto b = HU::HexToNibble(str[3]);
|
|
||||||
b |= b << 4;
|
|
||||||
auto a = HU::HexToNibble(str[4]);
|
|
||||||
a |= a << 4;
|
|
||||||
col.r = r;
|
|
||||||
col.g = g;
|
|
||||||
col.b = b;
|
|
||||||
col.a = a;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(str.size() == 7) {
|
|
||||||
auto r = HU::HexToNibble(str[1]);
|
|
||||||
r |= HU::HexToNibble(str[2]) << 4;
|
|
||||||
auto g = HU::HexToNibble(str[3]);
|
|
||||||
g |= HU::HexToNibble(str[4]) << 4;
|
|
||||||
auto b = HU::HexToNibble(str[5]);
|
|
||||||
b |= HU::HexToNibble(str[6]) << 4;
|
|
||||||
|
|
||||||
col.r = r;
|
|
||||||
col.g = g;
|
|
||||||
col.b = b;
|
|
||||||
col.a = 255;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(str.size() == 9)
|
|
||||||
{
|
|
||||||
auto r = HU::HexToNibble(str[1]);
|
|
||||||
r |= HU::HexToNibble(str[2]) << 4;
|
|
||||||
auto g = HU::HexToNibble(str[3]);
|
|
||||||
g |= HU::HexToNibble(str[4]) << 4;
|
|
||||||
auto b = HU::HexToNibble(str[5]);
|
|
||||||
b |= HU::HexToNibble(str[6]) << 4;
|
|
||||||
auto a = HU::HexToNibble(str[7]);
|
|
||||||
a |= HU::HexToNibble(str[8]) << 4;
|
|
||||||
|
|
||||||
col.r = r;
|
|
||||||
col.g = g;
|
|
||||||
col.b = b;
|
|
||||||
col.a = a;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(str.size() > 4 && strncmp(str.c_str(),"rgb(",4) == 0 && str[str.size()-1] == ')')
|
|
||||||
{
|
|
||||||
str = HU::Replace(str.substr(4),")","");
|
|
||||||
auto parts = HU::SplitString(str,",");
|
|
||||||
if(parts.size() != 3) return false;
|
|
||||||
try{
|
|
||||||
auto r = std::stoul(parts[0]);
|
|
||||||
auto g = std::stoul(parts[1]);
|
|
||||||
auto b = std::stoul(parts[2]);
|
|
||||||
col.r = (Uint8)r;
|
|
||||||
col.g = (Uint8)g;
|
|
||||||
col.b = (Uint8)b;
|
|
||||||
col.a = 255;
|
|
||||||
} catch(...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(str.size() > 5 && strncmp(str.c_str(),"rgba(",5) == 0 && str[str.size()-1] == ')')
|
|
||||||
{
|
|
||||||
str = HU::Replace(str.substr(5),")","");
|
|
||||||
auto parts = HU::SplitString(str,",");
|
|
||||||
if(parts.size() != 4) return false;
|
|
||||||
try{
|
|
||||||
auto r = std::stoul(parts[0]);
|
|
||||||
auto g = std::stoul(parts[1]);
|
|
||||||
auto b = std::stoul(parts[2]);
|
|
||||||
double a= std::stod(parts[3]);
|
|
||||||
col.r = (Uint8)r;
|
|
||||||
col.g = (Uint8)g;
|
|
||||||
col.b = (Uint8)b;
|
|
||||||
col.a = (Uint8)(a * 255);
|
|
||||||
} catch(...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
273
src/SDL2/GUI.cpp
273
src/SDL2/GUI.cpp
@@ -1,273 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
#if defined(__SWITCH__)
|
|
||||||
extern "C" {
|
|
||||||
#include <switch.h>
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
GUI gui;
|
|
||||||
void GUI::CloseWindows()
|
|
||||||
{
|
|
||||||
auto wins=this->windows;
|
|
||||||
for(auto win : wins) delete win;
|
|
||||||
this->windows.clear();
|
|
||||||
}
|
|
||||||
void GUI::Update()
|
|
||||||
{
|
|
||||||
if(this->windows.empty()) return;
|
|
||||||
for(auto index = this->windows.begin(); index != this->windows.end(); index++)
|
|
||||||
{
|
|
||||||
if(*index == nullptr)
|
|
||||||
{
|
|
||||||
this->windows.erase(index);
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this->windows.empty()) return;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Event event;
|
|
||||||
while(SDL_PollEvent(&event))
|
|
||||||
{
|
|
||||||
auto windows = this->windows;
|
|
||||||
for(auto& win : windows)
|
|
||||||
{
|
|
||||||
if(win == nullptr) continue;
|
|
||||||
auto id = SDL_GetWindowID(win->window);
|
|
||||||
switch(event.type)
|
|
||||||
{
|
|
||||||
case SDL_EventType::SDL_WINDOWEVENT:
|
|
||||||
if(event.window.windowID == id)
|
|
||||||
{
|
|
||||||
if(event.window.event == SDL_WINDOWEVENT_CLOSE)
|
|
||||||
{
|
|
||||||
GUIWindowClosingEventArgs e;
|
|
||||||
e.cancel=false;
|
|
||||||
win->Closing.Invoke(win,e);
|
|
||||||
if(!e.cancel)
|
|
||||||
{
|
|
||||||
delete win;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_FINGERDOWN:
|
|
||||||
case SDL_EventType::SDL_FINGERUP:
|
|
||||||
if(event.tfinger.windowID == id)
|
|
||||||
{
|
|
||||||
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_EventType::SDL_MOUSEBUTTONUP:
|
|
||||||
if(event.button.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_MOUSEMOTION:
|
|
||||||
if(event.motion.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_MOUSEWHEEL:
|
|
||||||
if(event.wheel.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_KEYUP:
|
|
||||||
case SDL_EventType::SDL_KEYDOWN:
|
|
||||||
if(event.key.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_TEXTEDITING:
|
|
||||||
if(event.edit.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_TEXTEDITING_EXT:
|
|
||||||
if(event.editExt.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_TEXTINPUT:
|
|
||||||
if(event.text.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EventType::SDL_DROPBEGIN:
|
|
||||||
case SDL_EventType::SDL_DROPCOMPLETE:
|
|
||||||
case SDL_EventType::SDL_DROPFILE:
|
|
||||||
case SDL_EventType::SDL_DROPTEXT:
|
|
||||||
if(event.drop.windowID == id)
|
|
||||||
{
|
|
||||||
win->Event(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
win->Event(event);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
TF_SetIsRunning(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(auto item : this->windows)
|
|
||||||
{
|
|
||||||
if(item != nullptr)
|
|
||||||
item->Draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Clipper::Clipper(SDL_Renderer* renderer, SDL_Rect& myRect)
|
|
||||||
{
|
|
||||||
this->isClipped=SDL_RenderIsClipEnabled(renderer);
|
|
||||||
SDL_RenderGetClipRect(renderer,&this->theRect);
|
|
||||||
if(!this->isClipped) this->theRect = myRect;
|
|
||||||
this->renderer = renderer;
|
|
||||||
}
|
|
||||||
void Clipper::ClipRect(SDL_Rect& child, SDL_Rect& parent)
|
|
||||||
{
|
|
||||||
if(child.x < parent.x)
|
|
||||||
{
|
|
||||||
int rem = parent.x- child.x;
|
|
||||||
child.x += rem;
|
|
||||||
child.w -= rem;
|
|
||||||
}
|
|
||||||
if(child.y < parent.y)
|
|
||||||
{
|
|
||||||
int rem = parent.y- child.y;
|
|
||||||
child.y += rem;
|
|
||||||
child.h -= rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((child.x + child.w) > (parent.x + parent.w))
|
|
||||||
child.w = (parent.x + parent.w) - child.x;
|
|
||||||
|
|
||||||
if((child.y + child.h) > (parent.y + parent.h))
|
|
||||||
child.h = (parent.y + parent.h) - child.y;
|
|
||||||
|
|
||||||
}
|
|
||||||
bool Clipper::Clip(SDL_Rect rect)
|
|
||||||
{
|
|
||||||
ClipRect(rect,this->theRect);
|
|
||||||
if(rect.w <= 0 || rect.h <= 0) return false;
|
|
||||||
|
|
||||||
SDL_RenderSetClipRect(renderer, &rect);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Clipper::~Clipper()
|
|
||||||
{
|
|
||||||
if(isClipped) SDL_RenderSetClipRect(renderer, &this->theRect);
|
|
||||||
else SDL_RenderSetClipRect(renderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIPalette::GUIPalette()
|
|
||||||
{
|
|
||||||
this->fontSize=24;
|
|
||||||
this->borderSize = 2;
|
|
||||||
}
|
|
||||||
SDL_Color& GUIPalette::GetBorderColor(bool isHovering, bool isActive, bool isMouseDown)
|
|
||||||
{
|
|
||||||
bool isHovering2=isHovering ^ isMouseDown;
|
|
||||||
if(isHovering2 && isActive)
|
|
||||||
return this->borderHoverActive;
|
|
||||||
if(isHovering2)
|
|
||||||
return this->borderHover;
|
|
||||||
if(isActive)
|
|
||||||
return this->borderActive;
|
|
||||||
return this->borderColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIPalette::GUIPalette(SDL_Color accent, SDL_Color background, SDL_Color border_color, SDL_Color border_hover, SDL_Color border_active, SDL_Color border_hover_active, int fontSize,int borderSize)
|
|
||||||
{
|
|
||||||
|
|
||||||
this->accent=accent;
|
|
||||||
this->background = background;
|
|
||||||
this->borderColor=border_color;
|
|
||||||
this->borderHover = border_hover;
|
|
||||||
this->borderActive = border_active;
|
|
||||||
this->borderHoverActive=border_hover_active;
|
|
||||||
this->fontSize = fontSize;
|
|
||||||
this->borderSize = borderSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GUIEventArgs::Type()
|
|
||||||
{
|
|
||||||
return "Base";
|
|
||||||
}
|
|
||||||
GUIEventArgs::~GUIEventArgs()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
std::string GUIMouseButtonEventArgs::Type()
|
|
||||||
{
|
|
||||||
return "MouseButton";
|
|
||||||
}
|
|
||||||
std::string GUIJsonViewNotFoundEventArgs::Type()
|
|
||||||
{
|
|
||||||
return "JsonViewNotFound";
|
|
||||||
}
|
|
||||||
std::string GUISDLEventEventArgs::Type()
|
|
||||||
{
|
|
||||||
return "SDLEvent";
|
|
||||||
}
|
|
||||||
std::string GUIWindowClosingEventArgs::Type()
|
|
||||||
{
|
|
||||||
return "WindowClosing";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GUIPalette::GUIPalette(bool isDarkMode, SDL_Color accent,int fontSize,int borderSize)
|
|
||||||
{
|
|
||||||
this->accent = accent;
|
|
||||||
this->fontSize = fontSize;
|
|
||||||
this->borderSize = borderSize;
|
|
||||||
|
|
||||||
if(isDarkMode)
|
|
||||||
{
|
|
||||||
this->background = {.r = 42,.g=42,.b=42,.a=255};
|
|
||||||
this->borderColor = {.r=0,.g=0,.b=0,.a=255};
|
|
||||||
this->borderHover = {.r=92,.g=92,.b=92,.a=255};
|
|
||||||
|
|
||||||
this->borderActive = {.r=200,.g=200,.b=200,.a=255};
|
|
||||||
this->borderHoverActive = {.r=(uint8_t)(255-accent.r),.g=(uint8_t)(255-accent.g),.b=(uint8_t)(255-accent.b),.a=255};
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->background = {.r=239,.g=239,.b=239,.a=255};
|
|
||||||
this->borderColor = {.r=0,.g=0,.b=0,.a=255};
|
|
||||||
|
|
||||||
this->borderActive = {.r=92,.g=92,.b=92,.a=255};
|
|
||||||
|
|
||||||
this->borderHover = {.r=200,.g=200,.b=200,.a=255};
|
|
||||||
|
|
||||||
this->borderHoverActive = {.r=(uint8_t)(255-accent.r),.g=(uint8_t)(255-accent.g),.b=(uint8_t)(255-accent.b),.a=255};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2 {
|
|
||||||
size_t GUIPopup::ViewCount()
|
|
||||||
{
|
|
||||||
return this->GetView() != nullptr ? 1 : 0;
|
|
||||||
}
|
|
||||||
View* GUIPopup::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
if(index > 0) return nullptr;
|
|
||||||
return this->GetView();
|
|
||||||
}
|
|
||||||
GUIPopup::GUIPopup() : GUIPopup(0,0,0,0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
GUIPopup::GUIPopup(SDL_Rect bounds)
|
|
||||||
{
|
|
||||||
this->bounds = bounds;
|
|
||||||
}
|
|
||||||
GUIPopup::GUIPopup(int x, int y,int w, int h)
|
|
||||||
{
|
|
||||||
this->bounds.x = x;
|
|
||||||
this->bounds.y = y;
|
|
||||||
this->bounds.w = w;
|
|
||||||
this->bounds.h = h;
|
|
||||||
}
|
|
||||||
View* GUIContainerPopup::GetView()
|
|
||||||
{
|
|
||||||
return this->child;
|
|
||||||
}
|
|
||||||
GUIContainerPopup::GUIContainerPopup() : GUIPopup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
GUIContainerPopup::GUIContainerPopup(SDL_Rect bounds) : GUIPopup(bounds)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
GUIContainerPopup::GUIContainerPopup(int x, int y,int w, int h) : GUIPopup(x,y,w,h)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GUIContainerPopup::SetView(View* view, bool owns)
|
|
||||||
{
|
|
||||||
if(this->ownsChild && this->child != view)
|
|
||||||
delete this->child;
|
|
||||||
this->child = view;
|
|
||||||
this->ownsChild=owns;
|
|
||||||
this->AssignChildParentToThis(view);
|
|
||||||
}
|
|
||||||
GUIContainerPopup::~GUIContainerPopup()
|
|
||||||
{
|
|
||||||
if(this->ownsChild)
|
|
||||||
delete this->child;
|
|
||||||
}
|
|
||||||
GUIPopup::~GUIPopup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIPopup::Close()
|
|
||||||
{
|
|
||||||
|
|
||||||
this->closed=true;
|
|
||||||
}
|
|
||||||
bool GUIPopup::IsClosed()
|
|
||||||
{
|
|
||||||
return this->closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIPopup::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.background.r,win->palette.background.g,win->palette.background.b,win->palette.background.a);
|
|
||||||
SDL_RenderFillRect(renderer,&r);
|
|
||||||
auto view = GetView();
|
|
||||||
if(view != nullptr)
|
|
||||||
CallOnDraw(view,renderer,r);
|
|
||||||
}
|
|
||||||
bool GUIPopup::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
|
||||||
{
|
|
||||||
auto view = GetView();
|
|
||||||
if(view != nullptr)
|
|
||||||
{
|
|
||||||
if(CallOnEvent(view,event,myBounds,myVisibleBounds)) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GUIPopup::IsActive()
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
if(win == nullptr) return false;
|
|
||||||
if(win->popups.empty()) return false;
|
|
||||||
|
|
||||||
return win->popups.back() == this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,772 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#include "TessesFramework/aardvark-fixed-regular.h"
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/MultilineEditTextView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/PictureView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/ScrollableTextListView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/HScrollView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/VScrollView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/HStackView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/VStackView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/DropDownView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/TabView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/ParseColor.hpp"
|
|
||||||
|
|
||||||
#if defined(__SWITCH__)
|
|
||||||
extern "C" {
|
|
||||||
#include <switch.h>
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
GUIWindow::operator bool()
|
|
||||||
{
|
|
||||||
if(this == nullptr) return false;
|
|
||||||
for(auto item : gui.windows)
|
|
||||||
if(item == this) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void GUIWindow::MakeActive(View* view)
|
|
||||||
{
|
|
||||||
if(!view->GetViewFlag(VIEWFLAG_TABSTOP)) return;
|
|
||||||
if(view->GetViewFlag(VIEWFLAG_ISACTIVE)) return;
|
|
||||||
if(this->popups.empty())
|
|
||||||
DeactivateAll(this);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeactivateAll(this->popups.back());
|
|
||||||
}
|
|
||||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,true);
|
|
||||||
}
|
|
||||||
void GUIWindow::DeactivateAll(View* view)
|
|
||||||
{
|
|
||||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,false);
|
|
||||||
auto cv = dynamic_cast<ContainerView*>(view);
|
|
||||||
if(cv != nullptr)
|
|
||||||
{
|
|
||||||
for(size_t i = 0; i < cv->ViewCount();i++)
|
|
||||||
{
|
|
||||||
DeactivateAll(cv->GetViewAt(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void GUIWindow::TabNext(View* view,TabNextResult& nr)
|
|
||||||
{
|
|
||||||
if(nr == TabNextResult::Done)
|
|
||||||
return;
|
|
||||||
auto cv = dynamic_cast<ContainerView*>(view);
|
|
||||||
if(cv != nullptr)
|
|
||||||
{
|
|
||||||
for(size_t i = 0; i < cv->ViewCount();i++)
|
|
||||||
{
|
|
||||||
TabNext(cv->GetViewAt(i),nr);
|
|
||||||
if(nr == TabNextResult::Done)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(view->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
if(view->GetViewFlag(VIEWFLAG_INTERCEPT_TAB))
|
|
||||||
{
|
|
||||||
SDL_Rect r;
|
|
||||||
r.x=0;
|
|
||||||
r.y=0;
|
|
||||||
r.w=0;
|
|
||||||
r.h=0;
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_KEYDOWN;
|
|
||||||
event.key.keysym.mod = SDL_Keymod::KMOD_NONE;
|
|
||||||
event.key.keysym.scancode = SDL_SCANCODE_TAB;
|
|
||||||
event.key.keysym.sym = SDL_KeyCode::SDLK_TAB;
|
|
||||||
view->CallOnEvent(view,event,r,r);
|
|
||||||
nr = TabNextResult::Done;
|
|
||||||
}
|
|
||||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,false);
|
|
||||||
nr= TabNextResult::TabNext;
|
|
||||||
}
|
|
||||||
else if(view->GetViewFlag(VIEWFLAG_TABSTOP) && nr == TabNextResult::TabNext)
|
|
||||||
{
|
|
||||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,true);
|
|
||||||
nr = TabNextResult::Done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void GUIWindow::TabNext()
|
|
||||||
{
|
|
||||||
TabNextResult nr=TabNextResult::KeepGoing;
|
|
||||||
TabNext(this,nr);
|
|
||||||
if(nr != TabNextResult::Done)
|
|
||||||
{
|
|
||||||
nr = TabNextResult::TabNext;
|
|
||||||
TabNext(this,nr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIWindow::SetView(View* view,bool owns)
|
|
||||||
{
|
|
||||||
if(this->ownsChild && this->child != view)
|
|
||||||
delete this->child;
|
|
||||||
this->child = view;
|
|
||||||
this->ownsChild = owns;
|
|
||||||
if(view != nullptr)
|
|
||||||
view->parent = this;
|
|
||||||
}
|
|
||||||
GUIWindow* GUIWindow::GetWindow()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
size_t GUIWindow::ViewCount()
|
|
||||||
{
|
|
||||||
return this->child != nullptr ? 1 : 0;
|
|
||||||
}
|
|
||||||
View* GUIWindow::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
if(index > 0) return nullptr;
|
|
||||||
return this->child;
|
|
||||||
}
|
|
||||||
void GUIWindow::Draw()
|
|
||||||
{
|
|
||||||
int w,h;
|
|
||||||
SDL_GetWindowSize(window,&w,&h);
|
|
||||||
SDL_Rect r={.x=0,.y=0,.w=w,.h=h};
|
|
||||||
OnDraw(renderer,r);
|
|
||||||
}
|
|
||||||
void GUIWindow::Event(SDL_Event& event)
|
|
||||||
{
|
|
||||||
|
|
||||||
int w,h;
|
|
||||||
SDL_GetWindowSize(window,&w,&h);
|
|
||||||
SDL_Rect r={.x=0,.y=0,.w=w,.h=h};
|
|
||||||
OnEvent(event,r,r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIWindow::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,this->palette.background.r,this->palette.background.g,this->palette.background.b,this->palette.background.a);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
if(this->child != nullptr)
|
|
||||||
this->child->OnDraw(renderer,r);
|
|
||||||
for(auto popup : this->popups)
|
|
||||||
popup->OnDraw(renderer,popup->bounds);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
|
||||||
bool GUIWindow::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(event.type == SDL_EventType::SDL_KEYDOWN && event.key.keysym.sym ==SDL_KeyCode::SDLK_TAB)
|
|
||||||
{
|
|
||||||
GUISDLEventEventArgs sdle;
|
|
||||||
sdle.event = event;
|
|
||||||
this->SDLEvent.Invoke(this,sdle);
|
|
||||||
if(this->popups.empty())
|
|
||||||
TabNext();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TabNextResult nr=TabNextResult::KeepGoing;
|
|
||||||
TabNext(this->popups.back(),nr);
|
|
||||||
if(nr != TabNextResult::Done)
|
|
||||||
{
|
|
||||||
nr = TabNextResult::TabNext;
|
|
||||||
TabNext(this->popups.back(),nr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->child != nullptr) {
|
|
||||||
GUISDLEventEventArgs sdle;
|
|
||||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);
|
|
||||||
retry:
|
|
||||||
if(this->popups.empty())
|
|
||||||
return this->child->OnEvent(event,myBounds,myVisibleBounds);
|
|
||||||
else {
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
auto popup = this->popups.back();
|
|
||||||
if(event.button.x >= popup->bounds.x && event.button.x < popup->bounds.x+popup->bounds.w && event.button.y >= popup->bounds.y && event.button.y < popup->bounds.y+popup->bounds.h)
|
|
||||||
{
|
|
||||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
|
||||||
}
|
|
||||||
else if(popup->closeIfClickOutside) {
|
|
||||||
popup->closed=true;
|
|
||||||
this->popups.pop_back();
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
auto popup = this->popups.back();
|
|
||||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retry2:
|
|
||||||
if(!this->popups.empty())
|
|
||||||
{
|
|
||||||
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
auto popup = this->popups.back();
|
|
||||||
if(event.button.x >= popup->bounds.x && event.button.x < popup->bounds.x+popup->bounds.w && event.button.y >= popup->bounds.y && event.button.y < popup->bounds.y+popup->bounds.h)
|
|
||||||
{
|
|
||||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
|
||||||
}
|
|
||||||
else if(popup->closeIfClickOutside)
|
|
||||||
{
|
|
||||||
popup->closed=true;
|
|
||||||
this->popups.pop_back();
|
|
||||||
goto retry2;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto popup = this->popups.back();
|
|
||||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
|
||||||
}
|
|
||||||
GUIWindow::GUIWindow(std::string title, int w, int h, Uint32 flags, const GUIPalette& palette) : ContainerView(title)
|
|
||||||
{
|
|
||||||
TF_LOG("About to create window");
|
|
||||||
|
|
||||||
#if defined(__SWITCH__)
|
|
||||||
auto nxwin = nwindowGetDefault();
|
|
||||||
w = (int)nxwin->default_width;
|
|
||||||
h = (int)nxwin->default_height;
|
|
||||||
flags = 0;
|
|
||||||
std::string onSwitch = "On switch: " + std::to_string(w) + "x" + std::to_string(h);
|
|
||||||
TF_LOG(onSwitch);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->window = SDL_CreateWindow(title.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,w,h,flags);
|
|
||||||
std::string sdl_window_is_null = "SDL_Window is";
|
|
||||||
|
|
||||||
if(this->window != nullptr)
|
|
||||||
sdl_window_is_null.append(" not");
|
|
||||||
|
|
||||||
sdl_window_is_null.append(" null");
|
|
||||||
|
|
||||||
if(this->window == nullptr)
|
|
||||||
{
|
|
||||||
sdl_window_is_null.append(" reason ");
|
|
||||||
sdl_window_is_null.append(SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LOG(sdl_window_is_null);
|
|
||||||
/*#if defined(__SWITCH__) || defined(__PS2__) || defined(GEKKO)
|
|
||||||
|
|
||||||
this->renderer = SDL_CreateRenderer(this->window,-1,SDL_RENDERER_SOFTWARE);
|
|
||||||
#else*/
|
|
||||||
TF_LOG("About to create renderer");
|
|
||||||
this->renderer = SDL_CreateRenderer(this->window,-1,SDL_RENDERER_ACCELERATED);
|
|
||||||
sdl_window_is_null = "SDL_Renderer is";
|
|
||||||
|
|
||||||
if(this->renderer!= nullptr)
|
|
||||||
sdl_window_is_null.append(" not");
|
|
||||||
|
|
||||||
sdl_window_is_null.append(" null");
|
|
||||||
|
|
||||||
if(this->renderer == nullptr)
|
|
||||||
{
|
|
||||||
sdl_window_is_null.append(" reason ");
|
|
||||||
sdl_window_is_null.append(SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LOG(sdl_window_is_null);
|
|
||||||
//#endif
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer,SDL_BlendMode::SDL_BLENDMODE_BLEND);
|
|
||||||
TF_LOG("Renderer blend mode set");
|
|
||||||
this->child=nullptr;
|
|
||||||
this->parent=nullptr;
|
|
||||||
this->ownsChild=false;
|
|
||||||
this->normal_font=nullptr;
|
|
||||||
this->monospaced_font=nullptr;
|
|
||||||
gui.windows.push_back(this);
|
|
||||||
this->SetPalette(palette);
|
|
||||||
}
|
|
||||||
void GUIWindow::SetText(std::string text)
|
|
||||||
{
|
|
||||||
this->text = text;
|
|
||||||
SDL_SetWindowTitle(this->window,text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIWindow::SetPalette(const GUIPalette& palette)
|
|
||||||
{
|
|
||||||
this->palette = palette;
|
|
||||||
if(this->normal_font != nullptr)
|
|
||||||
delete this->normal_font;
|
|
||||||
if(this->monospaced_font != nullptr)
|
|
||||||
delete this->monospaced_font;
|
|
||||||
this->normal_font = new FontCache(this->renderer,this->palette.fontSize);
|
|
||||||
this->monospaced_font = new FontCache(this->renderer,AARDVARKFIXEDREGULAR,AARDVARKFIXEDREGULAR_SIZE,this->palette.fontSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIWindow::~GUIWindow()
|
|
||||||
{
|
|
||||||
if(this->ownsChild)
|
|
||||||
delete this->child;
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
|
|
||||||
for(auto index = gui.windows.begin(); index < gui.windows.end(); index++)
|
|
||||||
{
|
|
||||||
if(*index == this)
|
|
||||||
{
|
|
||||||
*index = nullptr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIWindow::ShowPopup(GUIPopup* popup)
|
|
||||||
{
|
|
||||||
popup->closed=false;
|
|
||||||
bool has = false;
|
|
||||||
for(auto item : this->popups)
|
|
||||||
if(item == popup) { has=true; break;}
|
|
||||||
if(!has)
|
|
||||||
this->popups.push_back(popup);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AssignChildParentToThis(popup);
|
|
||||||
|
|
||||||
auto v = popup->GetView();
|
|
||||||
if(v != nullptr) this->MakeActive(v);
|
|
||||||
|
|
||||||
while(!popup->IsClosed() && TF_IsRunning())
|
|
||||||
{
|
|
||||||
TF_RunEventLoopItteration();
|
|
||||||
}
|
|
||||||
if(!this->popups.empty() && this->popups.back() == popup)
|
|
||||||
this->popups.pop_back();
|
|
||||||
popup->closed=true;
|
|
||||||
}
|
|
||||||
void GUIWindow::ShowPopup(GUIPopup& popup)
|
|
||||||
{
|
|
||||||
ShowPopup(&popup);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUIWindow::SetView(Tesses::Framework::Serialization::Json::JToken item)
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject dict;
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject o;
|
|
||||||
Tesses::Framework::Serialization::Json::JObject sz;
|
|
||||||
Tesses::Framework::Serialization::Json::JObject pal0;
|
|
||||||
std::string title;
|
|
||||||
if(dict.TryGetValueAsType("Child",o))
|
|
||||||
{
|
|
||||||
this->SetView(CreateViewFromJson(o));
|
|
||||||
}
|
|
||||||
if(dict.TryGetValueAsType("Size",sz))
|
|
||||||
{
|
|
||||||
int w0,h0;
|
|
||||||
|
|
||||||
|
|
||||||
SDL_GetWindowSize(this->window,&w0,&h0);
|
|
||||||
int64_t w=w0;
|
|
||||||
int64_t h=h0;
|
|
||||||
|
|
||||||
sz.TryGetValueAsType("Width",w);
|
|
||||||
sz.TryGetValueAsType("Height",h);
|
|
||||||
|
|
||||||
SDL_SetWindowSize(this->window,(int)w,(int)h);
|
|
||||||
}
|
|
||||||
if(dict.TryGetValueAsType("Palette",pal0))
|
|
||||||
{
|
|
||||||
bool darkMode=true;
|
|
||||||
SDL_Color accent={.r=255,.g=0,.b=0,.a=255};
|
|
||||||
std::string _str;
|
|
||||||
int64_t fontSize=20;
|
|
||||||
|
|
||||||
pal0.TryGetValueAsType("IsDarkMode",darkMode);
|
|
||||||
pal0.TryGetValueAsType("FontSize",fontSize);
|
|
||||||
if(pal0.TryGetValueAsType("Accent",_str))
|
|
||||||
TryParseSDLColor(_str,accent);
|
|
||||||
|
|
||||||
GUIPalette pal(darkMode,accent,fontSize);
|
|
||||||
if(pal0.TryGetValueAsType("Background",_str))
|
|
||||||
TryParseSDLColor(_str,pal.background);
|
|
||||||
if(pal0.TryGetValueAsType("Border",_str))
|
|
||||||
TryParseSDLColor(_str,pal.borderColor);
|
|
||||||
if(pal0.TryGetValueAsType("BorderActive",_str))
|
|
||||||
TryParseSDLColor(_str,pal.borderActive);
|
|
||||||
if(pal0.TryGetValueAsType("BorderHover",_str))
|
|
||||||
TryParseSDLColor(_str,pal.borderHover);
|
|
||||||
if(pal0.TryGetValueAsType("BorderHoverActive",_str))
|
|
||||||
TryParseSDLColor(_str,pal.borderHoverActive);
|
|
||||||
this->SetPalette(pal);
|
|
||||||
}
|
|
||||||
if(dict.TryGetValueAsType("Title",title) || dict.TryGetValueAsType("Text",title))
|
|
||||||
{
|
|
||||||
this->SetText(title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SDL_Window* GUIWindow::GetSDLWindow()
|
|
||||||
{
|
|
||||||
return this->window;
|
|
||||||
}
|
|
||||||
SDL_Renderer* GUIWindow::GetSDLRenderer()
|
|
||||||
{
|
|
||||||
return this->renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int szStr2size(std::string sz)
|
|
||||||
{
|
|
||||||
if(sz.empty()) return GUI_MIN;
|
|
||||||
if(sz == "min") return GUI_MIN;
|
|
||||||
if(sz == "*") return GUI_EXPAND;
|
|
||||||
if(sz[0] == '*') {
|
|
||||||
return GUI_EXPAND_N(std::stoi(sz.substr(1)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return std::stoi(sz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
View* GUIWindow::CreateViewFromJson(Tesses::Framework::Serialization::Json::JObject json)
|
|
||||||
{
|
|
||||||
std::string type;
|
|
||||||
if(json.TryGetValueAsType("Type",type))
|
|
||||||
{
|
|
||||||
std::string id={};
|
|
||||||
std::string text={};
|
|
||||||
bool active=false;
|
|
||||||
json.TryGetValueAsType("Id",id);
|
|
||||||
json.TryGetValueAsType("Text",text);
|
|
||||||
json.TryGetValueAsType("Active",active);
|
|
||||||
if(type == "ButtonView")
|
|
||||||
{
|
|
||||||
auto btn = new Views::ButtonView(text);
|
|
||||||
btn->SetId(id);
|
|
||||||
btn->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
|
||||||
return btn;
|
|
||||||
}
|
|
||||||
else if(type == "CheckView")
|
|
||||||
{
|
|
||||||
bool checked;
|
|
||||||
json.TryGetValueAsType("Checked",checked);
|
|
||||||
auto cv = new Views::CheckView(checked,text);
|
|
||||||
cv->SetId(id);
|
|
||||||
|
|
||||||
cv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
|
||||||
return cv;
|
|
||||||
}
|
|
||||||
else if(type == "LabelView")
|
|
||||||
{
|
|
||||||
auto lv = new Views::LabelView(text);
|
|
||||||
lv->SetId(id);
|
|
||||||
return lv;
|
|
||||||
}
|
|
||||||
else if(type == "ProgressView")
|
|
||||||
{
|
|
||||||
double v=0;
|
|
||||||
json.TryGetValueAsType("Value",v);
|
|
||||||
auto pv = new Views::ProgressView(v);
|
|
||||||
pv->SetId(id);
|
|
||||||
return pv;
|
|
||||||
}
|
|
||||||
else if(type == "TextListView")
|
|
||||||
{
|
|
||||||
std::vector<std::string> items;
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
std::string str;
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int64_t index=-1;
|
|
||||||
int64_t first=0;
|
|
||||||
json.TryGetValueAsType("SelectedIndex",index);
|
|
||||||
json.TryGetValueAsType("FirstIndex",first);
|
|
||||||
|
|
||||||
auto tlv = new Views::TextListView();
|
|
||||||
|
|
||||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
|
||||||
tlv->SetId(id);
|
|
||||||
tlv->items = items;
|
|
||||||
tlv->firstIndex = (size_t)first;
|
|
||||||
tlv->selected = (int)index;
|
|
||||||
return tlv;
|
|
||||||
}
|
|
||||||
else if(type == "ScrollableTextListView")
|
|
||||||
{
|
|
||||||
std::vector<std::string> items;
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
std::string str;
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int64_t index=-1;
|
|
||||||
int64_t first=0;
|
|
||||||
json.TryGetValueAsType("SelectedIndex",index);
|
|
||||||
json.TryGetValueAsType("FirstIndex",first);
|
|
||||||
|
|
||||||
auto tlv = new Views::ScrollableTextListView();
|
|
||||||
|
|
||||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
|
||||||
tlv->SetId(id);
|
|
||||||
tlv->items = items;
|
|
||||||
tlv->firstIndex = (size_t)first;
|
|
||||||
tlv->selected = (int)index;
|
|
||||||
return tlv;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(type == "AbsoluteView")
|
|
||||||
{
|
|
||||||
auto av = new Views::AbsoluteView();
|
|
||||||
av->SetId(id);
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject dict;
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject boundsDict;
|
|
||||||
SDL_Rect r={.x=0,.y=0,.w=200,.h=200};
|
|
||||||
|
|
||||||
if(dict.TryGetValueAsType("Bounds",boundsDict))
|
|
||||||
{
|
|
||||||
int64_t n;
|
|
||||||
if(boundsDict.TryGetValueAsType("X",n)) r.x = (int)n;
|
|
||||||
if(boundsDict.TryGetValueAsType("Y",n)) r.y = (int)n;
|
|
||||||
if(boundsDict.TryGetValueAsType("Width",n)) r.w = (int)n;
|
|
||||||
if(boundsDict.TryGetValueAsType("Height",n)) r.h = (int)n;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto myO = CreateViewFromJson(dict);
|
|
||||||
if(myO != nullptr)
|
|
||||||
{
|
|
||||||
av->Add(r,myO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return av;
|
|
||||||
}
|
|
||||||
else if(type == "EditTextView")
|
|
||||||
{
|
|
||||||
auto etv = new Views::EditTextView();
|
|
||||||
etv->SetId(id);
|
|
||||||
etv->SetText(text);
|
|
||||||
std::string hint;
|
|
||||||
json.TryGetValueAsType("Hint",hint);
|
|
||||||
etv->SetHint(hint);
|
|
||||||
return etv;
|
|
||||||
}
|
|
||||||
else if(type == "MultilineEditTextView")
|
|
||||||
{
|
|
||||||
auto etv = new Views::MultilineEditTextView();
|
|
||||||
etv->SetId(id);
|
|
||||||
etv->SetText(text);
|
|
||||||
std::string hint;
|
|
||||||
json.TryGetValueAsType("Hint",hint);
|
|
||||||
etv->SetHint(hint);
|
|
||||||
return etv;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(type == "PictureView")
|
|
||||||
{
|
|
||||||
auto pv = new Views::PictureView();
|
|
||||||
pv->SetId(id);
|
|
||||||
return pv;
|
|
||||||
}
|
|
||||||
else if(type == "DropDownView")
|
|
||||||
{
|
|
||||||
std::vector<std::string> items;
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
std::string str;
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int64_t index=-1;
|
|
||||||
int64_t first=0;
|
|
||||||
json.TryGetValueAsType("SelectedIndex",index);
|
|
||||||
|
|
||||||
auto tlv = new Views::DropDownView();
|
|
||||||
|
|
||||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
|
||||||
tlv->SetId(id);
|
|
||||||
tlv->GetItems() = items;
|
|
||||||
|
|
||||||
tlv->SetIndex((int)index);
|
|
||||||
return tlv;
|
|
||||||
}
|
|
||||||
else if(type == "VScrollView")
|
|
||||||
{
|
|
||||||
int64_t value=0;
|
|
||||||
int64_t min = 0;
|
|
||||||
int64_t max = 10;
|
|
||||||
json.TryGetValueAsType("Value",value);
|
|
||||||
|
|
||||||
json.TryGetValueAsType("Min",min);
|
|
||||||
|
|
||||||
json.TryGetValueAsType("Max",max);
|
|
||||||
auto vscroll=new Views::VScrollView();
|
|
||||||
vscroll->value = (uint64_t)value;
|
|
||||||
vscroll->min = (uint64_t)min;
|
|
||||||
vscroll->max = (uint64_t)max;
|
|
||||||
vscroll->SetId(id);
|
|
||||||
return vscroll;
|
|
||||||
}
|
|
||||||
else if(type == "HScrollView")
|
|
||||||
{
|
|
||||||
int64_t value=0;
|
|
||||||
int64_t min = 0;
|
|
||||||
int64_t max = 10;
|
|
||||||
json.TryGetValueAsType("Value",value);
|
|
||||||
|
|
||||||
json.TryGetValueAsType("Min",min);
|
|
||||||
|
|
||||||
json.TryGetValueAsType("Max",max);
|
|
||||||
auto hscroll=new Views::VScrollView();
|
|
||||||
hscroll->value = (uint64_t)value;
|
|
||||||
hscroll->min = (uint64_t)min;
|
|
||||||
hscroll->max = (uint64_t)max;
|
|
||||||
hscroll->SetId(id);
|
|
||||||
return hscroll;
|
|
||||||
}
|
|
||||||
else if(type == "VStackView")
|
|
||||||
{
|
|
||||||
auto sv = new Views::VStackView();
|
|
||||||
sv->SetId(id);
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject dict;
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
|
||||||
{
|
|
||||||
std::string n="min";
|
|
||||||
|
|
||||||
dict.TryGetValueAsType("Size",n);
|
|
||||||
|
|
||||||
|
|
||||||
auto myO = CreateViewFromJson(dict);
|
|
||||||
if(myO != nullptr)
|
|
||||||
{
|
|
||||||
sv->Add(szStr2size(n),myO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sv;
|
|
||||||
}
|
|
||||||
else if(type == "HStackView")
|
|
||||||
{
|
|
||||||
auto sv = new Views::HStackView();
|
|
||||||
sv->SetId(id);
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject dict;
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
|
||||||
{
|
|
||||||
std::string n="min";
|
|
||||||
|
|
||||||
dict.TryGetValueAsType("Size",n);
|
|
||||||
|
|
||||||
|
|
||||||
auto myO = CreateViewFromJson(dict);
|
|
||||||
if(myO != nullptr)
|
|
||||||
{
|
|
||||||
sv->Add(szStr2size(n),myO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sv;
|
|
||||||
}
|
|
||||||
else if(type == "TabView")
|
|
||||||
{
|
|
||||||
//Item.TabLabel
|
|
||||||
auto tv = new Views::TabView();
|
|
||||||
tv->SetId(id);
|
|
||||||
int64_t firstTab=0;
|
|
||||||
int64_t curTab=0;
|
|
||||||
bool tabsVisible=true;
|
|
||||||
|
|
||||||
json.TryGetValueAsType("SelectedTab",curTab);
|
|
||||||
|
|
||||||
json.TryGetValueAsType("FirstTab",firstTab);
|
|
||||||
json.TryGetValueAsType("TabsVisible", tabsVisible);
|
|
||||||
|
|
||||||
tv->firstTab = (int64_t)firstTab;
|
|
||||||
tv->selectedTab = (int64_t)curTab;
|
|
||||||
tv->tabsVisible=tabsVisible;
|
|
||||||
|
|
||||||
|
|
||||||
Tesses::Framework::Serialization::Json::JArray arr;
|
|
||||||
|
|
||||||
if(json.TryGetValueAsType("Items",arr))
|
|
||||||
{
|
|
||||||
for(auto item : arr)
|
|
||||||
{
|
|
||||||
Tesses::Framework::Serialization::Json::JObject dict;
|
|
||||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
|
||||||
{
|
|
||||||
std::string n="";
|
|
||||||
|
|
||||||
dict.TryGetValueAsType("TabText",n);
|
|
||||||
|
|
||||||
|
|
||||||
auto myO = CreateViewFromJson(dict);
|
|
||||||
if(myO != nullptr)
|
|
||||||
{
|
|
||||||
tv->AddTab(n,myO,true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tv;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
GUIJsonViewNotFoundEventArgs e;
|
|
||||||
e.destView = nullptr;
|
|
||||||
e.jsonObject = json;
|
|
||||||
e.typeString = type;
|
|
||||||
|
|
||||||
JsonViewNotFound.Invoke(this,e);
|
|
||||||
|
|
||||||
return e.destView;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Stream.hpp"
|
|
||||||
namespace Tesses::Framework::SDL2 {
|
|
||||||
|
|
||||||
static SDLCALL size_t rwops_stream_read(struct SDL_RWops * context, void *ptr,
|
|
||||||
size_t size, size_t maxnum)
|
|
||||||
{
|
|
||||||
if(context->hidden.unknown.data1 == nullptr) return 0;
|
|
||||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
|
||||||
if(ctx->CanRead())
|
|
||||||
return ctx->Read((uint8_t*)ptr,size*maxnum) / size;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static SDLCALL size_t rwops_stream_write(struct SDL_RWops * context, const void *ptr,
|
|
||||||
size_t size, size_t maxnum)
|
|
||||||
{
|
|
||||||
if(context->hidden.unknown.data1 == nullptr) return 0;
|
|
||||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
|
||||||
if(ctx->CanWrite())
|
|
||||||
return ctx->Write((const uint8_t*)ptr,size*maxnum) / size;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static SDLCALL Sint64 rwops_stream_seek(struct SDL_RWops * context, Sint64 offset,
|
|
||||||
int whence)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(context->hidden.unknown.data1 == nullptr) return -1;
|
|
||||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
|
||||||
if(!ctx->CanSeek()) return -1;
|
|
||||||
|
|
||||||
switch(whence)
|
|
||||||
{
|
|
||||||
case RW_SEEK_SET:
|
|
||||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::Begin);
|
|
||||||
break;
|
|
||||||
case RW_SEEK_CUR:
|
|
||||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::Current);
|
|
||||||
break;
|
|
||||||
case RW_SEEK_END:
|
|
||||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::End);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return ctx->GetPosition();
|
|
||||||
}
|
|
||||||
static SDLCALL Sint64 rwops_stream_size(struct SDL_RWops * context)
|
|
||||||
{
|
|
||||||
if(context->hidden.unknown.data1 == nullptr) return -1;
|
|
||||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
|
||||||
return ctx->GetLength();
|
|
||||||
}
|
|
||||||
static SDLCALL int rwops_stream_close(struct SDL_RWops* context)
|
|
||||||
{
|
|
||||||
if(context->hidden.unknown.data2 == nullptr) return 0;
|
|
||||||
delete static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
SDL_RWops* RwopsFromStream(Tesses::Framework::Streams::Stream* strm, bool owns)
|
|
||||||
{
|
|
||||||
auto rw=SDL_AllocRW();
|
|
||||||
rw->type = SDL_RWOPS_UNKNOWN;
|
|
||||||
rw->hidden.unknown.data1 = static_cast<void*>(strm);
|
|
||||||
rw->hidden.unknown.data2 = (void*)(uintptr_t)(owns?1:0);
|
|
||||||
rw->read = rwops_stream_read;
|
|
||||||
rw->write = rwops_stream_write;
|
|
||||||
rw->seek = rwops_stream_seek;
|
|
||||||
rw->size = rwops_stream_size;
|
|
||||||
rw->close = rwops_stream_close;
|
|
||||||
|
|
||||||
|
|
||||||
return rw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
namespace Tesses::Framework::SDL2
|
|
||||||
{
|
|
||||||
ContainerView::ContainerView() : View()
|
|
||||||
{
|
|
||||||
this->flags = 0;
|
|
||||||
}
|
|
||||||
ContainerView::ContainerView(std::string text) : View(text)
|
|
||||||
{
|
|
||||||
this->flags = 0;
|
|
||||||
}
|
|
||||||
View::View() : View((std::string){})
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
View::View(std::string text)
|
|
||||||
{
|
|
||||||
this->text = text;
|
|
||||||
this->flags=VIEWFLAG_TABSTOP;
|
|
||||||
}
|
|
||||||
void View::SetText(std::string text)
|
|
||||||
{
|
|
||||||
this->text=text;
|
|
||||||
}
|
|
||||||
std::string View::GetText()
|
|
||||||
{
|
|
||||||
return this->text;
|
|
||||||
}
|
|
||||||
void View::OnMouseUp(GUIMouseButtonEventArgs& click)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void View::OnMouseDown(GUIMouseButtonEventArgs& click)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void View::OnClick(GUIEventArgs& click)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
GUIWindow* View::GetWindow()
|
|
||||||
{
|
|
||||||
if(this->parent ==nullptr) return nullptr;
|
|
||||||
return this->parent->GetWindow();
|
|
||||||
}
|
|
||||||
void View::OnDragDropFile(Tesses::Framework::Filesystem::VFSPath filePath,SDL_Rect myRect, SDL_Point dropLoc)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void View::OnDragDropText(std::string text,SDL_Rect myRect, SDL_Point dropLoc)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::OnEnter(GUIEventArgs& evt)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void View::OnLeave(GUIEventArgs& evt)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void View::OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void View::OnSetParent(View* v)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool View::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
|
||||||
{
|
|
||||||
GUISDLEventEventArgs sdle;
|
|
||||||
sdle.event = event;
|
|
||||||
this->SDLEvent.Invoke(this,sdle);
|
|
||||||
if(event.type == SDL_FINGERUP)
|
|
||||||
{
|
|
||||||
auto cord = this->GetCordFromEvent(event);
|
|
||||||
if(cord.first >= myVisibleBounds.x && cord.first < myVisibleBounds.x+myVisibleBounds.w && cord.second >= myVisibleBounds.y && cord.second < myVisibleBounds.y+myVisibleBounds.h) {
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
|
||||||
OnMouseDown(cea);
|
|
||||||
this->MouseDown.Invoke(this,cea);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
bool inside = event.motion.x >= myVisibleBounds.x && event.motion.x < myVisibleBounds.x+myVisibleBounds.w && event.motion.y >= myVisibleBounds.y && event.motion.y < myVisibleBounds.y+myVisibleBounds.h;
|
|
||||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
if(inside && !hoverFlag)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnEnter(e);
|
|
||||||
this->Enter.Invoke(this,e);
|
|
||||||
}
|
|
||||||
else if(!inside && hoverFlag)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnLeave(e);
|
|
||||||
this->Leave.Invoke(this,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string View::GetId()
|
|
||||||
{
|
|
||||||
return this->id;
|
|
||||||
}
|
|
||||||
void View::SetId(std::string id)
|
|
||||||
{
|
|
||||||
this->id = id;
|
|
||||||
}
|
|
||||||
View* View::FindViewById(std::string id)
|
|
||||||
{
|
|
||||||
if(this->GetId() == id) return this;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
View* ContainerView::FindViewById(std::string id)
|
|
||||||
{
|
|
||||||
if(this->GetId() == id) return this;
|
|
||||||
for(size_t i = 0; i <this->ViewCount(); i++)
|
|
||||||
{
|
|
||||||
auto v = this->GetViewAt(i);
|
|
||||||
auto v2 = v->FindViewById(id);
|
|
||||||
if(v2 != nullptr) return v2;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
std::pair<int,int> View::PreferedMinSize()
|
|
||||||
{
|
|
||||||
return std::pair<int,int>(-1,-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<int,int> View::GetCordFromEvent(SDL_Event& event)
|
|
||||||
{
|
|
||||||
switch(event.type)
|
|
||||||
{
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
return std::pair<int,int>(event.button.x,event.button.y);
|
|
||||||
break;
|
|
||||||
case SDL_FINGERUP:
|
|
||||||
case SDL_FINGERDOWN:
|
|
||||||
{
|
|
||||||
GUIWindow* win = this->GetWindow();
|
|
||||||
int w,h;
|
|
||||||
SDL_GetWindowSize(win->window,&w,&h);
|
|
||||||
return std::pair<int,int>(w*event.tfinger.x,h*event.tfinger.y);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return std::pair<int,int>(-1,-1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
View::~View()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void AbsoluteView::OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect)
|
|
||||||
{
|
|
||||||
Clipper clipper(renderer,myRect);
|
|
||||||
SDL_Rect oldClip;
|
|
||||||
bool isClipped=SDL_RenderIsClipEnabled(renderer);
|
|
||||||
SDL_RenderGetClipRect(renderer,&oldClip);
|
|
||||||
if(!isClipped) oldClip = myRect;
|
|
||||||
|
|
||||||
for(auto& ctrl : this->views)
|
|
||||||
{
|
|
||||||
SDL_Rect childRect = ctrl.second;
|
|
||||||
childRect.x += oldClip.x;
|
|
||||||
childRect.y += oldClip.y;
|
|
||||||
|
|
||||||
|
|
||||||
if(clipper.Clip(childRect))
|
|
||||||
CallOnDraw(ctrl.first.first,renderer,childRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
bool AbsoluteView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
bool handled=false;
|
|
||||||
|
|
||||||
for(auto& item : this->views)
|
|
||||||
{
|
|
||||||
SDL_Rect theirBounds = item.second;
|
|
||||||
theirBounds.x += myBounds.x;
|
|
||||||
theirBounds.y += myBounds.y;
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = item.second;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
|
|
||||||
|
|
||||||
if(CallOnEvent(item.first.first,event,theirBounds, theirVisibleBounds))
|
|
||||||
handled=true;
|
|
||||||
if(handled && event.type != SDL_MOUSEBUTTONUP && event.type != SDL_MOUSEMOTION && event.type != SDL_FINGERUP)
|
|
||||||
{
|
|
||||||
GUISDLEventEventArgs sdle;
|
|
||||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(handled) {GUISDLEventEventArgs sdle;
|
|
||||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);return true;}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
size_t AbsoluteView::ViewCount()
|
|
||||||
{
|
|
||||||
return this->views.size();
|
|
||||||
}
|
|
||||||
View* AbsoluteView::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
return this->views.at(index).first.first;
|
|
||||||
}
|
|
||||||
AbsoluteView::AbsoluteView() : ContainerView()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void AbsoluteView::Add(SDL_Rect rect, View* view, bool owns)
|
|
||||||
{
|
|
||||||
for(auto& item : this->views)
|
|
||||||
{
|
|
||||||
if(item.first.first == view) return;
|
|
||||||
}
|
|
||||||
this->AssignChildParentToThis(view);
|
|
||||||
this->views.push_back(std::pair<std::pair<View*,bool>,SDL_Rect>(std::pair<View*,bool>(view,owns),rect));
|
|
||||||
}
|
|
||||||
void AbsoluteView::Set(View* view, SDL_Rect rect)
|
|
||||||
{
|
|
||||||
for(auto& item : this->views)
|
|
||||||
{
|
|
||||||
if(item.first.first == view)
|
|
||||||
{
|
|
||||||
item.second = rect;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void AbsoluteView::Remove(View* view)
|
|
||||||
{
|
|
||||||
for(auto index = this->views.begin(); index != this->views.end(); index++)
|
|
||||||
{
|
|
||||||
if(index->first.first == view)
|
|
||||||
{
|
|
||||||
if(index->first.second) delete index->first.first;
|
|
||||||
this->views.erase(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AbsoluteView::~AbsoluteView()
|
|
||||||
{
|
|
||||||
for(auto& item : this->views)
|
|
||||||
{
|
|
||||||
if(item.first.second) delete item.first.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
ButtonView::ButtonView() : View()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
ButtonView::ButtonView(std::string text) : View(text)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
std::pair<int,int> ButtonView::PreferedMinSize()
|
|
||||||
{
|
|
||||||
int w=-2;
|
|
||||||
int h=-2;
|
|
||||||
|
|
||||||
auto win = GetWindow();
|
|
||||||
if(win != nullptr)
|
|
||||||
{
|
|
||||||
win->normal_font->CalculateSize(text,w,h);
|
|
||||||
|
|
||||||
w += win->palette.borderSize*3;
|
|
||||||
|
|
||||||
h += win->palette.borderSize*3;
|
|
||||||
}
|
|
||||||
return std::pair<int,int>(w,h);
|
|
||||||
}
|
|
||||||
bool ButtonView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
if(event.type == SDL_KEYUP)
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDL_KeyCode::SDLK_SPACE:
|
|
||||||
{
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnClick(e);
|
|
||||||
this->Click.Invoke(this,e);
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_FINGERUP)
|
|
||||||
{
|
|
||||||
auto pos = this->GetCordFromEvent(event);
|
|
||||||
if(pos.first >= myVisibleBounds.x && pos.first < myVisibleBounds.x+myVisibleBounds.w && pos.second >= myVisibleBounds.y && pos.second < myVisibleBounds.y+myVisibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
|
||||||
}
|
|
||||||
void ButtonView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_RenderFillRect(renderer,&r);
|
|
||||||
int textW;
|
|
||||||
int textH;
|
|
||||||
win->normal_font->CalculateSize(this->text,textW,textH);
|
|
||||||
|
|
||||||
int x=(r.w/2)-(textW/2);
|
|
||||||
int y=(r.h/2)-(textH/2);
|
|
||||||
x+=r.x;
|
|
||||||
y+=r.y;
|
|
||||||
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
win->normal_font->Render(renderer,x,y,this->text,color);
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
SDL_Rect r2={.x=r.x,.y=r.y,.w=r.w,.h=r.h};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&r2);
|
|
||||||
r2.x++;
|
|
||||||
r2.y++;
|
|
||||||
r2.w-=2;
|
|
||||||
r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void CheckView::OnCheckChanged(GUIEventArgs& event)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void CheckView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
|
|
||||||
const int checkSz=32;
|
|
||||||
|
|
||||||
SDL_Rect checkBoxRect={.x=r.x,.y=r.y+((r.h/2)-(checkSz/2)),.w=checkSz,.h=checkSz};
|
|
||||||
|
|
||||||
int textW;
|
|
||||||
int textH;
|
|
||||||
win->normal_font->CalculateSize(this->text,textW,textH);
|
|
||||||
|
|
||||||
//we only need the y
|
|
||||||
|
|
||||||
int x = r.x+checkSz+(win->palette.borderSize*2);
|
|
||||||
int y = r.y+((r.h/2)-(textH/2));
|
|
||||||
|
|
||||||
win->normal_font->Render(renderer,x,y,text,win->palette.accent);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_CHECKED))
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
|
|
||||||
//x=0,y=0.5, x=0.5, y=1
|
|
||||||
|
|
||||||
int x1=checkBoxRect.x+win->palette.borderSize;
|
|
||||||
int y1=checkBoxRect.y+win->palette.borderSize+((checkSz-(win->palette.borderSize*2))/2);
|
|
||||||
int x2=checkBoxRect.x+win->palette.borderSize+((checkSz-(win->palette.borderSize*2))/2);
|
|
||||||
int y2=checkBoxRect.y+win->palette.borderSize+(checkSz-(win->palette.borderSize*8));
|
|
||||||
|
|
||||||
int x3=checkBoxRect.x+win->palette.borderSize+(checkSz-(win->palette.borderSize*2));
|
|
||||||
int y3=checkBoxRect.y+win->palette.borderSize;
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,x1,y1-i,x2,y2-i);
|
|
||||||
SDL_RenderDrawLine(renderer,x2-i,y2,x3-i,y3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&checkBoxRect);
|
|
||||||
checkBoxRect.x++;
|
|
||||||
checkBoxRect.y++;
|
|
||||||
checkBoxRect.w-=2;
|
|
||||||
checkBoxRect.h-=2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool CheckView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
if(event.type == SDL_KEYUP)
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDL_KeyCode::SDLK_SPACE:
|
|
||||||
{
|
|
||||||
GUIEventArgs e;
|
|
||||||
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
|
||||||
this->OnClick(e);
|
|
||||||
this->Click.Invoke(this,e);
|
|
||||||
this->OnCheckChanged(e);
|
|
||||||
this->CheckChanged.Invoke(this,e);
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_FINGERUP)
|
|
||||||
{
|
|
||||||
auto pos = this->GetCordFromEvent(event);
|
|
||||||
if(pos.first >= visibleBounds.x && pos.first < visibleBounds.x+visibleBounds.w && pos.second >= visibleBounds.y && pos.second < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnCheckChanged(e);
|
|
||||||
this->CheckChanged.Invoke(this,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnCheckChanged(e);
|
|
||||||
this->CheckChanged.Invoke(this,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckView::CheckView(bool checked, std::string label) : View(label)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,checked);
|
|
||||||
}
|
|
||||||
CheckView::CheckView() : View()
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckView::GetChecked()
|
|
||||||
{
|
|
||||||
return this->GetViewFlag(VIEWFLAG_CHECKED);
|
|
||||||
}
|
|
||||||
void CheckView::SetChecked(bool value)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_CHECKED,true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/DropDownView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views {
|
|
||||||
|
|
||||||
void DropDownView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
std::string text = this->text;
|
|
||||||
if(this->listView.selected > -1 && this->listView.selected < this->listView.items.size())
|
|
||||||
{
|
|
||||||
text = this->listView.items[this->listView.selected];
|
|
||||||
}
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
|
|
||||||
int textW;
|
|
||||||
int textH;
|
|
||||||
win->normal_font->CalculateSize(text,textW,textH);
|
|
||||||
|
|
||||||
int x=win->palette.borderSize*2;
|
|
||||||
int y=(r.h/2)-(textH/2);
|
|
||||||
x+=r.x;
|
|
||||||
y+=r.y;
|
|
||||||
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
win->normal_font->Render(renderer,x,y,text,win->palette.accent);
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
SDL_Rect r2={.x=r.x,.y=r.y,.w=r.w,.h=r.h};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&r2);
|
|
||||||
r2.x++;
|
|
||||||
r2.y++;
|
|
||||||
r2.w-=2;
|
|
||||||
r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
bool DropDownView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
win->MakeActive(this);
|
|
||||||
this->popup.bounds.x = myBounds.x;
|
|
||||||
this->popup.bounds.y = myBounds.y+myBounds.h;
|
|
||||||
this->popup.bounds.w = myBounds.w;
|
|
||||||
this->popup.bounds.h = 150;
|
|
||||||
auto pu = &this->popup;
|
|
||||||
if(!this->hasSet) {
|
|
||||||
|
|
||||||
this->listView.ValueChanged += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([pu](View* view,GUIEventArgs& args)->void {
|
|
||||||
pu->Close();
|
|
||||||
});
|
|
||||||
|
|
||||||
this->popup.SetView(&this->listView,false);
|
|
||||||
this->hasSet=true;
|
|
||||||
}
|
|
||||||
win->ShowPopup(pu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_KEYDOWN && this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_UP:
|
|
||||||
{
|
|
||||||
this->listView.selected--;
|
|
||||||
if(this->listView.selected < 0 || this->listView.selected >= this->listView.items.size())
|
|
||||||
{
|
|
||||||
this->listView.selected = (int)(this->listView.items.size()-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDLK_DOWN:
|
|
||||||
{
|
|
||||||
this->listView.selected++;
|
|
||||||
if(this->listView.selected < -1 || this->listView.selected >= this->listView.items.size())
|
|
||||||
{
|
|
||||||
this->listView.selected=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DropDownView::DropDownView() : View("--PLEASE SELECT ONE--")
|
|
||||||
{
|
|
||||||
this->hasSet=false;
|
|
||||||
|
|
||||||
}
|
|
||||||
std::vector<std::string>& DropDownView::GetItems()
|
|
||||||
{
|
|
||||||
return this->listView.items;
|
|
||||||
}
|
|
||||||
void DropDownView::SetIndex(int index)
|
|
||||||
{
|
|
||||||
this->listView.selected = index;
|
|
||||||
}
|
|
||||||
int DropDownView::GetIndex()
|
|
||||||
{
|
|
||||||
return this->listView.selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
EditTextView::EditTextView() : EditTextView(std::string())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
EditTextView::EditTextView(std::string hint) : View()
|
|
||||||
{
|
|
||||||
this->hint = hint;
|
|
||||||
this->cursorPos=0;
|
|
||||||
this->cursorEnd=std::string::npos;
|
|
||||||
}
|
|
||||||
void EditTextView::TypeText(std::string text)
|
|
||||||
{
|
|
||||||
size_t cursorBegin = this->cursorPos;
|
|
||||||
size_t cursorEnd = this->cursorEnd;
|
|
||||||
if(cursorBegin > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorBegin;
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size())
|
|
||||||
{
|
|
||||||
this->text.erase(cursorBegin,cursorEnd-cursorBegin);
|
|
||||||
this->text.insert(cursorBegin,text);
|
|
||||||
}
|
|
||||||
else if(cursorBegin <= this->text.size()) {
|
|
||||||
this->text.insert(cursorBegin,text);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this->cursorPos = cursorBegin+text.size();
|
|
||||||
this->cursorEnd = std::string::npos;
|
|
||||||
|
|
||||||
}
|
|
||||||
void EditTextView::SetText(std::string text)
|
|
||||||
{
|
|
||||||
View::SetText(text);
|
|
||||||
this->cursorPos=0;
|
|
||||||
this->cursorEnd = std::string::npos;
|
|
||||||
|
|
||||||
}
|
|
||||||
void EditTextView::SetHint(std::string hint)
|
|
||||||
{
|
|
||||||
this->hint = hint;
|
|
||||||
}
|
|
||||||
std::string EditTextView::GetHint()
|
|
||||||
{
|
|
||||||
return this->hint;
|
|
||||||
}
|
|
||||||
std::pair<int,int> EditTextView::PreferedMinSize()
|
|
||||||
{
|
|
||||||
int x=-1;
|
|
||||||
int y=-1;
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
if(win != nullptr)
|
|
||||||
{
|
|
||||||
x=-1;
|
|
||||||
y=win->monospaced_font->MaxHeight()+(win->palette.borderSize*4);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::pair<int,int>(x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EditTextView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
if(event.type == SDL_TEXTINPUT)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_TOUCHED))
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_TOUCHED,false);
|
|
||||||
|
|
||||||
if(!this->text.empty())
|
|
||||||
{
|
|
||||||
this->cursorPos=0;
|
|
||||||
this->cursorEnd=this->text.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TypeText(event.text.text);
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDL_KeyCode::SDLK_c:
|
|
||||||
{
|
|
||||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
|
||||||
{
|
|
||||||
size_t cursorBegin = cursorPos;
|
|
||||||
size_t cursorEnd = this->cursorEnd;
|
|
||||||
if(cursorBegin > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorBegin;
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size() && this->text.size() > 0)
|
|
||||||
{
|
|
||||||
std::string res = this->text.substr(cursorBegin,cursorEnd-cursorBegin);
|
|
||||||
//SDL_GetClipboardText()
|
|
||||||
SDL_SetClipboardText(res.c_str());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_v:
|
|
||||||
{
|
|
||||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
|
||||||
{
|
|
||||||
if(SDL_HasClipboardText())
|
|
||||||
{
|
|
||||||
char* text = SDL_GetClipboardText();
|
|
||||||
if(text != NULL)
|
|
||||||
{
|
|
||||||
TypeText(text);
|
|
||||||
}
|
|
||||||
SDL_free(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_x:
|
|
||||||
{
|
|
||||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
|
||||||
{
|
|
||||||
size_t cursorBegin = cursorPos;
|
|
||||||
size_t cursorEnd = this->cursorEnd;
|
|
||||||
if(cursorBegin > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorBegin;
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size() && this->text.size() > 0)
|
|
||||||
{
|
|
||||||
std::string res = this->text.substr(cursorBegin,cursorEnd-cursorBegin);
|
|
||||||
//SDL_GetClipboardText()
|
|
||||||
SDL_SetClipboardText(res.c_str());
|
|
||||||
|
|
||||||
TypeText("");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_a:
|
|
||||||
{
|
|
||||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
|
||||||
{
|
|
||||||
this->cursorPos=0;
|
|
||||||
this->cursorEnd=this->text.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_BACKSPACE:
|
|
||||||
{
|
|
||||||
if(this->cursorEnd == std::string::npos)
|
|
||||||
{
|
|
||||||
if(this->cursorPos > 0)
|
|
||||||
{
|
|
||||||
this->cursorPos--;
|
|
||||||
this->text.erase(this->cursorPos,1);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TypeText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_DELETE:
|
|
||||||
{
|
|
||||||
if(this->cursorEnd == std::string::npos)
|
|
||||||
{
|
|
||||||
if(this->cursorPos + 1 <= this->text.size())
|
|
||||||
{
|
|
||||||
this->text.erase(this->cursorPos,1);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TypeText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_LEFT:
|
|
||||||
{
|
|
||||||
if((event.key.keysym.mod & KMOD_SHIFT) != 0)
|
|
||||||
{
|
|
||||||
if(this->cursorEnd > this->text.size())
|
|
||||||
this->cursorEnd = this->cursorPos;
|
|
||||||
|
|
||||||
this->cursorEnd--;
|
|
||||||
|
|
||||||
|
|
||||||
if(this->cursorEnd > this->text.size()) this->cursorEnd=0;
|
|
||||||
if(this->cursorEnd == this->cursorPos) this->cursorEnd = std::string::npos;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(cursorPos > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorPos ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorPos;
|
|
||||||
cursorPos ^= cursorEnd;
|
|
||||||
}
|
|
||||||
this->cursorPos--;
|
|
||||||
this->cursorEnd=std::string::npos;
|
|
||||||
if(this->cursorPos > this->text.size()) this->cursorPos=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KeyCode::SDLK_RIGHT:
|
|
||||||
if((event.key.keysym.mod & KMOD_SHIFT) != 0)
|
|
||||||
{
|
|
||||||
if(this->cursorEnd == std::string::npos)
|
|
||||||
this->cursorEnd = this->cursorPos;
|
|
||||||
|
|
||||||
this->cursorEnd++;
|
|
||||||
|
|
||||||
|
|
||||||
if(this->cursorEnd > this->text.size()) this->cursorEnd=this->text.size();
|
|
||||||
if(this->cursorEnd == this->cursorPos) this->cursorEnd = std::string::npos;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(cursorPos > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorPos ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorPos;
|
|
||||||
cursorPos ^= cursorEnd;
|
|
||||||
}
|
|
||||||
if(cursorEnd != std::string::npos)
|
|
||||||
{
|
|
||||||
this->cursorPos=cursorEnd+1;
|
|
||||||
|
|
||||||
}else {
|
|
||||||
this->cursorPos++;
|
|
||||||
}
|
|
||||||
this->cursorEnd=std::string::npos;
|
|
||||||
if(this->cursorPos > this->text.size()) this->cursorPos=this->text.size();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_TOUCHED,false);
|
|
||||||
|
|
||||||
SDL_StartTextInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_FINGERDOWN)
|
|
||||||
{
|
|
||||||
auto pos = this->GetCordFromEvent(event);
|
|
||||||
if(pos.first >= myVisibleBounds.x && pos.first < myVisibleBounds.x+myVisibleBounds.w && pos.second >= myVisibleBounds.y && pos.second < myVisibleBounds.y+myVisibleBounds.h)
|
|
||||||
{
|
|
||||||
this->GetWindow()->MakeActive(this);
|
|
||||||
|
|
||||||
this->SetViewFlag(VIEWFLAG_TOUCHED,true);
|
|
||||||
SDL_StartTextInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
|
||||||
}
|
|
||||||
void EditTextView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
size_t cursorBegin = this->cursorPos;
|
|
||||||
size_t cursorEnd = this->cursorEnd;
|
|
||||||
if(cursorBegin > cursorEnd)
|
|
||||||
{
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
cursorEnd ^= cursorBegin;
|
|
||||||
cursorBegin ^= cursorEnd;
|
|
||||||
}
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
//SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
//SDL_RenderFillRect(renderer,&r);
|
|
||||||
|
|
||||||
int textW=win->monospaced_font->MaxWidth()+2;
|
|
||||||
int textH=win->monospaced_font->MaxHeight();
|
|
||||||
|
|
||||||
int noChars = (r.w-(win->palette.borderSize*4)) / textW;
|
|
||||||
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=(r.h/2)-((textH+(win->palette.borderSize*4))/2);
|
|
||||||
x+=r.x+(win->palette.borderSize*2);
|
|
||||||
y+=r.y+(win->palette.borderSize*2);
|
|
||||||
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
size_t tracking = this->cursorPos;
|
|
||||||
if(cursorEnd != std::string::npos)
|
|
||||||
tracking = this->cursorEnd;
|
|
||||||
|
|
||||||
|
|
||||||
size_t off = noChars == 0 ? (size_t)0 : ((tracking / (size_t)noChars) * (size_t)noChars);
|
|
||||||
|
|
||||||
|
|
||||||
std::string& datext = this->text.empty() ? this->hint : this->text;
|
|
||||||
|
|
||||||
//printf("%i %i %i\n",(int) tracking,(int)off,(int)noChars);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < (size_t)noChars; i++)
|
|
||||||
{
|
|
||||||
if(cursorEnd == std::string::npos && (i+off) == cursorBegin)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
int x1=((int)i*textW)+x;
|
|
||||||
int y1 = y;
|
|
||||||
int y2 = y+textH;
|
|
||||||
SDL_RenderDrawLine(renderer,x1,y1,x1,y2);
|
|
||||||
}
|
|
||||||
if(i + off < datext.size())
|
|
||||||
{
|
|
||||||
if(cursorEnd != std::string::npos && (i+off) >= cursorBegin && (i+off) < cursorEnd)
|
|
||||||
{
|
|
||||||
SDL_Rect r0={.x=((int)i*textW)+x,.y=y,.w=textW,.h=textH+8};
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_RenderFillRect(renderer,&r0);
|
|
||||||
|
|
||||||
auto ch=win->monospaced_font->GetCharOfColor(datext[i+off],color);
|
|
||||||
|
|
||||||
SDL_Rect src={.x=0,.y=0,.w=0,.h=0};
|
|
||||||
SDL_QueryTexture(ch,NULL,NULL,&src.w,&src.h);
|
|
||||||
SDL_Rect dest = {.x=((int)i*textW)+x+1,.y=y,.w=src.w,.h=src.h};
|
|
||||||
SDL_RenderCopy(renderer,ch,&src,&dest);
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto ch=win->monospaced_font->GetCharOfColor(datext[i+off],this->text.empty() ? color : win->palette.accent);
|
|
||||||
|
|
||||||
SDL_Rect src={.x=0,.y=0,.w=0,.h=0};
|
|
||||||
SDL_QueryTexture(ch,NULL,NULL,&src.w,&src.h);
|
|
||||||
SDL_Rect dest = {.x=((int)i*textW)+x+1,.y=y,.w=src.w,.h=src.h};
|
|
||||||
SDL_RenderCopy(renderer,ch,&src,&dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
SDL_Rect r2={.x=r.x,.y=y-(win->palette.borderSize*2),.w=r.w,.h=textH+16};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&r2);
|
|
||||||
r2.x++;
|
|
||||||
r2.y++;
|
|
||||||
r2.w-=2;
|
|
||||||
r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Views/HScrollView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
std::pair<int,int> HScrollView::PreferedMinSize()
|
|
||||||
{
|
|
||||||
return std::pair<int,int>(-1,32);
|
|
||||||
}
|
|
||||||
void HScrollView::OnValueChanged(GUIEventArgs& e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
HScrollView::HScrollView() : HScrollView(0, 0, 100)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
HScrollView::HScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step) : View()
|
|
||||||
{
|
|
||||||
this->value = value;
|
|
||||||
this->min = min;
|
|
||||||
this->max = max;
|
|
||||||
|
|
||||||
this->step=step;
|
|
||||||
}
|
|
||||||
void HScrollView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto leftIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto leftIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
|
||||||
|
|
||||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
|
|
||||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
|
|
||||||
auto rightIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
|
|
||||||
auto rightIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
|
||||||
|
|
||||||
SDL_Color& leftColor = win->palette.GetBorderColor(leftIsHovering,isActive,leftIsMouseDown);
|
|
||||||
SDL_Color& leftMiddleColor = win->palette.GetBorderColor(leftIsHovering||middleIsHovering,isActive,leftIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
|
||||||
SDL_Color& rightMiddleColor = win->palette.GetBorderColor(rightIsHovering||middleIsHovering,isActive,rightIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& rightColor = win->palette.GetBorderColor(rightIsHovering,isActive,rightIsMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,leftColor.r,leftColor.g,leftColor.b,leftColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+i,r.y,r.x+i,r.y+r.h); //horizontal
|
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,r.y+i,r.x+32,r.y+i); //horizontal
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,r.y+r.h-(1+i),r.x+32,r.y+r.h-(1+i)); //horizontal
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,leftMiddleColor.r,leftMiddleColor.g,leftMiddleColor.b,leftMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,(r.x+32)-i,r.y,(r.x+32)-i,r.y+r.h); //horizontal
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+33,r.y+i,r.x+(r.w-33),r.y+i); //horizontal
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+33,r.y+r.h-(1+i),r.x+(r.w-33),r.y+r.h-(1+i)); //horizontal
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,rightColor.r,rightColor.g,rightColor.b,rightColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,(r.x+r.w)-(i+1),r.y,(r.x+r.w)-(i+1),r.y+r.h); //horizontal
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+(r.w-32),r.y+i,r.x+r.w,r.y+i); //horizontal
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+(r.w-32),r.y+r.h-(1+i),r.x+r.w,r.y+r.h-(1+i)); //horizonal
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,rightMiddleColor.r,rightMiddleColor.g,rightMiddleColor.b,rightMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,(r.x+(r.w-32))+i,r.y,(r.x+(r.w-32))+i,r.y+r.h); //horizontal
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
int y1 = 15;
|
|
||||||
int x1 = 8 + i;
|
|
||||||
|
|
||||||
int y2 = 9;
|
|
||||||
int x2 = 18 + i;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+r.x,y1+r.y,x2+r.x,y2+r.y);
|
|
||||||
|
|
||||||
int y3 = 31-y1;
|
|
||||||
int y4 = 31-y2;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+r.x,y3+r.y,x2+r.x,y4+r.y);
|
|
||||||
|
|
||||||
int x3 = 31-x1;
|
|
||||||
int x4 = 31-x2;
|
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x3+r.x+(r.w-32),y1+r.y,x4+r.x+(r.w-32),y2+r.y);
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x3+r.x+(r.w-32),y3+r.y,x4+r.x+(r.w-32),y4+r.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t width = (uint64_t)r.w - 66;
|
|
||||||
uint64_t scrollSize = 4;
|
|
||||||
uint64_t dif = max-min;
|
|
||||||
if(dif > 0)
|
|
||||||
scrollSize = width / dif;
|
|
||||||
|
|
||||||
if(scrollSize < 4) scrollSize=4;
|
|
||||||
|
|
||||||
|
|
||||||
double scroll = 0;
|
|
||||||
if(dif > 0)
|
|
||||||
scroll = (double)(value-min) / (double)dif;
|
|
||||||
|
|
||||||
uint64_t scrollX = scroll * (width-scrollSize);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(scrollX > width-scrollSize) scrollX = width-scrollSize;
|
|
||||||
SDL_Rect r2={.x=(int)scrollX+r.x+32,.y=r.y+win->palette.borderSize,.w=(int)scrollSize,.h = r.h-(win->palette.borderSize*2)};
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
}
|
|
||||||
bool HScrollView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
if(event.type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
|
||||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
if(inside && !hoverFlag)
|
|
||||||
{
|
|
||||||
int x = event.motion.x - myBounds.x;
|
|
||||||
if(x <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(x >= myBounds.w-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnEnter(e);
|
|
||||||
this->Enter.Invoke(this,e);
|
|
||||||
}
|
|
||||||
else if(!inside && hoverFlag)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnLeave(e);
|
|
||||||
this->Leave.Invoke(this,e);
|
|
||||||
} else if(inside) {
|
|
||||||
int x = event.motion.x - myBounds.x;
|
|
||||||
if(x <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(x >= myBounds.w-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
int x = event.motion.x - myBounds.x;
|
|
||||||
if(x <= 32)
|
|
||||||
{
|
|
||||||
value = min;
|
|
||||||
}
|
|
||||||
else if(x >= myBounds.w-32)
|
|
||||||
{
|
|
||||||
value=max;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint64_t width = (uint64_t)myBounds.w - 66;
|
|
||||||
uint64_t x2 = x-33;
|
|
||||||
|
|
||||||
double off = (double)x2 / (double)width;
|
|
||||||
|
|
||||||
value = round((max-min)*off)+min;
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
if(cea.x <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
|
||||||
}
|
|
||||||
else if(cea.x >= myBounds.w-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
|
||||||
|
|
||||||
uint64_t width = (uint64_t)myBounds.w - 66;
|
|
||||||
uint64_t x2 = cea.x-33;
|
|
||||||
|
|
||||||
double off = (double)x2 / (double)width;
|
|
||||||
|
|
||||||
value = round((max-min)*off)+min;
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
}
|
|
||||||
OnMouseDown(cea);
|
|
||||||
this->MouseDown.Invoke(this,cea);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
this->value -= step;
|
|
||||||
if(this->value < min) this->value=min;
|
|
||||||
if(this->value >= max) this->value=min;
|
|
||||||
OnValueChanged(cea2);
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
this->value += step;
|
|
||||||
if(this->value > max) this->value=max;
|
|
||||||
OnValueChanged(cea2);
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/HStackView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void HStackView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
int numberOfCells = 0;
|
|
||||||
int freeWidth = r.w;
|
|
||||||
std::vector<int> sizes;
|
|
||||||
sizes.resize(this->items.size());
|
|
||||||
|
|
||||||
freeWidth -= (this->items.size() - 1) * this->spacing;
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first > 0)
|
|
||||||
{
|
|
||||||
//static size
|
|
||||||
sizes[i] = this->items[i].first;
|
|
||||||
freeWidth-= this->items[i].first;
|
|
||||||
}
|
|
||||||
else if(this->items[i].first == 0)
|
|
||||||
{
|
|
||||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(prefered.first > 0)
|
|
||||||
{
|
|
||||||
sizes[i] = prefered.first;
|
|
||||||
freeWidth -= prefered.first;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sizes[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numberOfCells -= this->items[i].first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int cellSize = numberOfCells == 0 ? 0 : freeWidth / numberOfCells;
|
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < this->items.size();i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first < 0)
|
|
||||||
{
|
|
||||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(minSz.first > myWidth) {
|
|
||||||
sizes[i] = minSz.first;
|
|
||||||
freeWidth-= minSz.first;
|
|
||||||
numberOfCells -= -(this->items[i].first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
|
||||||
int x = 0;
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(i > 0) x += spacing;
|
|
||||||
|
|
||||||
if(sizes[i] == 0)
|
|
||||||
{
|
|
||||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x =x,
|
|
||||||
.y=0,
|
|
||||||
.w=myWidth,
|
|
||||||
.h=r.h
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
theirBounds.x += r.x;
|
|
||||||
theirBounds.y += r.y;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
|
||||||
x+=myWidth;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x =x,
|
|
||||||
.y=0,
|
|
||||||
.w=sizes[i],
|
|
||||||
.h=r.h
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
theirBounds.x += r.x;
|
|
||||||
theirBounds.y += r.y;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
|
||||||
x+=sizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool HStackView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
int numberOfCells = 0;
|
|
||||||
int freeWidth = myBounds.w;
|
|
||||||
std::vector<int> sizes;
|
|
||||||
sizes.resize(this->items.size());
|
|
||||||
|
|
||||||
|
|
||||||
freeWidth -= (this->items.size() - 1) * this->spacing;
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first > 0)
|
|
||||||
{
|
|
||||||
//static size
|
|
||||||
sizes[i] = this->items[i].first;
|
|
||||||
freeWidth-= this->items[i].first;
|
|
||||||
}
|
|
||||||
else if(this->items[i].first == 0)
|
|
||||||
{
|
|
||||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(prefered.first > 0)
|
|
||||||
{
|
|
||||||
sizes[i] = prefered.first;
|
|
||||||
freeWidth -= prefered.first;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sizes[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numberOfCells -= this->items[i].first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
|
||||||
|
|
||||||
for(int i = 0; i < this->items.size();i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first < 0)
|
|
||||||
{
|
|
||||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(minSz.first > myWidth) {
|
|
||||||
sizes[i] = minSz.first;
|
|
||||||
myWidth -= minSz.first;
|
|
||||||
numberOfCells -= -(this->items[i].first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
|
||||||
int x = 0;
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(i > 0) x += spacing;
|
|
||||||
if(sizes[i] == 0)
|
|
||||||
{
|
|
||||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(minSz.first > myWidth) myWidth = minSz.first;
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = x,
|
|
||||||
.y=0,
|
|
||||||
.w=myWidth,
|
|
||||||
.h=myBounds.h
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = theirBounds;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
|
|
||||||
theirBounds.x += myBounds.x;
|
|
||||||
theirBounds.y += myBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
|
||||||
|
|
||||||
x+=myWidth;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = x,
|
|
||||||
.y=0,
|
|
||||||
.w=sizes[i],
|
|
||||||
.h=myBounds.h
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = theirBounds;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
|
|
||||||
theirBounds.x += myBounds.x;
|
|
||||||
theirBounds.y += myBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
|
||||||
|
|
||||||
x+=sizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
HStackView::HStackView() : ContainerView()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void HStackView::Add(int sz, View* view, bool owns)
|
|
||||||
{
|
|
||||||
this->items.push_back(std::pair<int,std::pair<View*,bool>>(sz,std::pair<View*,bool>(view,owns)));
|
|
||||||
this->AssignChildParentToThis(view);
|
|
||||||
}
|
|
||||||
void HStackView::Remove(View* view)
|
|
||||||
{
|
|
||||||
for(auto index = this->items.begin(); index < this->items.end(); index++)
|
|
||||||
{
|
|
||||||
if(index->second.first == view)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(index->second.first != nullptr && index->second.second)
|
|
||||||
delete view;
|
|
||||||
this->items.erase(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void HStackView::Clear()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
|
||||||
items = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t HStackView::ViewCount()
|
|
||||||
{
|
|
||||||
return this->items.size();
|
|
||||||
}
|
|
||||||
View* HStackView::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
return this->items.at(index).second.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
HStackView::~HStackView()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void LabelView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win =this->GetWindow();
|
|
||||||
win->normal_font->Render(renderer,r.x+win->palette.borderSize,r.y+win->palette.borderSize,text,win->palette.accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
LabelView::LabelView() : View()
|
|
||||||
{
|
|
||||||
this->flags &= ~VIEWFLAG_TABSTOP;
|
|
||||||
}
|
|
||||||
LabelView::LabelView(std::string text) : View(text)
|
|
||||||
{
|
|
||||||
this->flags &= ~VIEWFLAG_TABSTOP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/MultilineEditTextView.hpp"
|
|
||||||
#include "TessesFramework/Http/HttpUtils.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
static int numberWidth(size_t n)
|
|
||||||
{
|
|
||||||
if(n == 0) return 1;
|
|
||||||
size_t digits = 0;
|
|
||||||
while(n != 0)
|
|
||||||
{
|
|
||||||
n /= 10;
|
|
||||||
digits++;
|
|
||||||
}
|
|
||||||
return digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultilineEditTextView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
//1 |
|
|
||||||
|
|
||||||
// 9 |
|
|
||||||
//10 |
|
|
||||||
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto w = win->monospaced_font->MaxWidth();
|
|
||||||
auto h = win->monospaced_font->MaxHeight();
|
|
||||||
auto digitsTotal = numberWidth(this->lines.size());
|
|
||||||
|
|
||||||
auto numLines = (r.h - (win->palette.borderSize*4)) / h;
|
|
||||||
|
|
||||||
if(numLines+this->topLeft.y > this->lines.size()) numLines = this->lines.size() - this->topLeft.y;
|
|
||||||
|
|
||||||
for(size_t i = 0; i < numLines; i++)
|
|
||||||
{
|
|
||||||
win->monospaced_font->Render(renderer, r.x+(win->palette.borderSize*2),r.y+(h*i), Http::HttpUtils::LeftPad(std::to_string(i+this->topLeft.y+1),digitsTotal,' '),win->palette.accent);
|
|
||||||
win->monospaced_font->Render(renderer,r.x+(win->palette.borderSize*2)+(w*(digitsTotal+5)),r.y+(h*i),this->lines[i+this->topLeft.y],win->palette.accent,this->topLeft.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
bool MultilineEditTextView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
if(event.type == SDL_TEXTINPUT)
|
|
||||||
{
|
|
||||||
TypeText(event.text.text);
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_RETURN:
|
|
||||||
TypeText("\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
MultilineEditTextView::MultilineEditTextView() :MultilineEditTextView(std::string())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
MultilineEditTextView::MultilineEditTextView(std::string hint) : View()
|
|
||||||
{
|
|
||||||
this->hint = hint;
|
|
||||||
}
|
|
||||||
std::string MultilineEditTextView::GetHint()
|
|
||||||
{
|
|
||||||
return this->hint;
|
|
||||||
}
|
|
||||||
void MultilineEditTextView::SetHint(std::string hint)
|
|
||||||
{
|
|
||||||
this->hint = hint;
|
|
||||||
}
|
|
||||||
std::string MultilineEditTextView::GetText()
|
|
||||||
{
|
|
||||||
if(this->lines.empty()) return {};
|
|
||||||
std::string text = this->lines.front();
|
|
||||||
for(size_t i = 1; i < this->lines.size(); i++)
|
|
||||||
{
|
|
||||||
text.push_back('\n');
|
|
||||||
text.append(this->lines[i]);
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
void MultilineEditTextView::SetText(std::string text)
|
|
||||||
{
|
|
||||||
lines.clear();
|
|
||||||
std::string line = "";
|
|
||||||
for(auto c : text)
|
|
||||||
{
|
|
||||||
if(c == '\n') {
|
|
||||||
lines.push_back(line);
|
|
||||||
line = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
line += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!line.empty()) lines.push_back(line);
|
|
||||||
|
|
||||||
this->cursorPos.x=0;
|
|
||||||
this->cursorPos.y=0;
|
|
||||||
this->cursorEnd.x=-1;
|
|
||||||
this->cursorEnd.y=-1;
|
|
||||||
}
|
|
||||||
void MultilineEditTextView::TypeText(std::string text)
|
|
||||||
{
|
|
||||||
|
|
||||||
SDL_Point cursorBegin = this->cursorPos;
|
|
||||||
SDL_Point cursorEnd = this->cursorEnd;
|
|
||||||
if((cursorBegin.y > cursorEnd.y || ((cursorBegin.y == cursorEnd.y) && (cursorBegin.x > cursorEnd.x))) && this->cursorEnd.x != -1 && this->cursorEnd.y != -1)
|
|
||||||
{
|
|
||||||
cursorBegin.y ^= cursorEnd.y;
|
|
||||||
cursorEnd.y ^= cursorBegin.y;
|
|
||||||
cursorBegin.y ^= cursorEnd.y;
|
|
||||||
|
|
||||||
cursorBegin.x ^= cursorEnd.x;
|
|
||||||
cursorEnd.x ^= cursorBegin.x;
|
|
||||||
cursorBegin.x ^= cursorEnd.x;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size())
|
|
||||||
{
|
|
||||||
this->text.erase(cursorBegin,cursorEnd-cursorBegin);
|
|
||||||
this->text.insert(cursorBegin,text);
|
|
||||||
}
|
|
||||||
else if(cursorBegin <= this->text.size()) {
|
|
||||||
this->text.insert(cursorBegin,text);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this->cursorPos = cursorBegin+text.size();
|
|
||||||
this->cursorEnd = std::string::npos;*/
|
|
||||||
|
|
||||||
if(this->cursorEnd.y != -1 && this->cursorEnd.x != -1)
|
|
||||||
{
|
|
||||||
int line = cursorBegin.y;
|
|
||||||
for(int y = cursorBegin.y; y <= cursorEnd.y && y < lines.size(); y++)
|
|
||||||
{
|
|
||||||
if(y == cursorBegin.y && y == cursorEnd.y && cursorBegin.x == 0 && cursorEnd.x == this->lines[y].size()-1)
|
|
||||||
{
|
|
||||||
this->lines.erase(this->lines.begin()+line);
|
|
||||||
}
|
|
||||||
else if(y == cursorBegin.y && y == cursorEnd.y)
|
|
||||||
{
|
|
||||||
this->lines[line]=this->lines[line].substr(0,cursorBegin.x) + this->lines[line].substr(cursorEnd.x);
|
|
||||||
line++;
|
|
||||||
}
|
|
||||||
else if(y == cursorBegin.y && cursorBegin.x == 0)
|
|
||||||
{
|
|
||||||
this->lines.erase(this->lines.begin()+line);
|
|
||||||
}
|
|
||||||
else if(y == cursorBegin.y)
|
|
||||||
{
|
|
||||||
this->lines[line]=this->lines[line].substr(0,cursorBegin.x);
|
|
||||||
line++;
|
|
||||||
}
|
|
||||||
else if(y > cursorBegin.y && y < cursorEnd.y)
|
|
||||||
{
|
|
||||||
this->lines.erase(this->lines.begin()+line);
|
|
||||||
}
|
|
||||||
else if(y == cursorEnd.y && cursorEnd.x < this->lines[line].size()-1)
|
|
||||||
{
|
|
||||||
this->lines[line]=this->lines[line].substr(cursorBegin.x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->lines.erase(this->lines.begin()+line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto mylines = text == "\n" ? std::vector<std::string>({"",""}) : Http::HttpUtils::SplitString(text,"\n");
|
|
||||||
|
|
||||||
if(!mylines.empty())
|
|
||||||
{
|
|
||||||
int setXTo = 0;
|
|
||||||
if(mylines.size()==1)
|
|
||||||
{
|
|
||||||
setXTo=mylines[0].size()+cursorBegin.x;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setXTo=mylines.back().size();
|
|
||||||
}
|
|
||||||
if(cursorBegin.y < this->lines.size())
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
if(cursorBegin.x > 0)
|
|
||||||
{
|
|
||||||
mylines[0] = this->lines[cursorBegin.y].substr(0,cursorBegin.x) + mylines[0];
|
|
||||||
}
|
|
||||||
if(cursorBegin.x < this->lines[cursorBegin.y].size())
|
|
||||||
{
|
|
||||||
mylines.back() += this->lines[cursorBegin.y].substr(cursorBegin.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this->lines.erase(this->lines.begin()+cursorBegin.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool first=true;
|
|
||||||
for(auto& item : mylines)
|
|
||||||
{
|
|
||||||
if(!first)
|
|
||||||
{
|
|
||||||
cursorBegin.y++;
|
|
||||||
}
|
|
||||||
this->lines.insert(this->lines.begin()+cursorBegin.y,{item});
|
|
||||||
first=false;
|
|
||||||
}
|
|
||||||
cursorBegin.x = setXTo;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this->cursorPos = cursorBegin;
|
|
||||||
this->cursorEnd = {.x=-1,.y=-1};
|
|
||||||
}
|
|
||||||
std::pair<int,int> MultilineEditTextView::PreferedMinSize()
|
|
||||||
{
|
|
||||||
return std::pair<int,int>(128,128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/PictureView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
PictureView::PictureView()
|
|
||||||
{
|
|
||||||
this->tex = nullptr;
|
|
||||||
this->ownsTex=false;
|
|
||||||
this->surf = nullptr;
|
|
||||||
this->ownsSurf=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PictureView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
if(this->surf != nullptr)
|
|
||||||
{
|
|
||||||
this->SetPicture(SDL_CreateTextureFromSurface(renderer,this->surf));
|
|
||||||
if(this->ownsSurf) SDL_FreeSurface(this->surf);
|
|
||||||
this->surf=nullptr;
|
|
||||||
}
|
|
||||||
if(this->tex != nullptr)
|
|
||||||
{
|
|
||||||
SDL_Rect sr={.x=0,.y=0};
|
|
||||||
SDL_QueryTexture(this->tex,nullptr,nullptr,&sr.w,&sr.h);
|
|
||||||
SDL_RenderCopy(renderer,this->tex,&sr,&r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PictureView::SetPicture(SDL_Texture* tex, bool owns)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(this->tex != nullptr && this->tex != tex && this->ownsTex)
|
|
||||||
SDL_DestroyTexture(this->tex);
|
|
||||||
this->tex = tex;
|
|
||||||
this->ownsTex = owns;
|
|
||||||
}
|
|
||||||
void PictureView::SetPicture(SDL_Surface* surface,bool owns)
|
|
||||||
{
|
|
||||||
if(this->surf != nullptr && this->surf != surf && this->ownsSurf)
|
|
||||||
SDL_FreeSurface(this->surf);
|
|
||||||
this->surf = surface;
|
|
||||||
this->ownsSurf = owns;
|
|
||||||
}
|
|
||||||
|
|
||||||
PictureView::~PictureView()
|
|
||||||
{
|
|
||||||
if(this->tex != nullptr && this->ownsTex)
|
|
||||||
SDL_DestroyTexture(this->tex);
|
|
||||||
if(this->surf != nullptr && this->ownsSurf)
|
|
||||||
SDL_FreeSurface(this->surf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
ProgressView::ProgressView() : ProgressView(0.0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
ProgressView::ProgressView(double v) : View()
|
|
||||||
{
|
|
||||||
this->value = v;
|
|
||||||
this->SetViewFlag(VIEWFLAG_TABSTOP,false);
|
|
||||||
}
|
|
||||||
void ProgressView::OnDraw(SDL_Renderer* renderer, SDL_Rect& rect)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.borderColor.r,win->palette.borderColor.g,win->palette.borderColor.b,win->palette.borderColor.a);
|
|
||||||
|
|
||||||
SDL_Rect r2={.x=rect.x,.y=rect.y,.w=rect.w,.h=rect.h};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&r2);
|
|
||||||
r2.x++;
|
|
||||||
r2.y++;
|
|
||||||
r2.w-=2;
|
|
||||||
r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto res = (int)((rect.w-(win->palette.borderSize*2))*(this->value/100.0));
|
|
||||||
r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize,.w=res,.h=rect.h-8};
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,444 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Views/ScrollableTextListView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
ScrollableTextListView::ScrollableTextListView() : View()
|
|
||||||
{
|
|
||||||
this->firstIndex=0;
|
|
||||||
this->selected=-1;
|
|
||||||
}
|
|
||||||
bool ScrollableTextListView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
|
||||||
auto no_items = (myBounds.h-(win->palette.borderSize*2)) / item_height;
|
|
||||||
auto max_items = no_items;
|
|
||||||
|
|
||||||
if(this->firstIndex + no_items > this->items.size())
|
|
||||||
{
|
|
||||||
|
|
||||||
no_items = this->items.size()-this->firstIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(event.type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_RETURN:
|
|
||||||
{
|
|
||||||
|
|
||||||
GUIEventArgs e;
|
|
||||||
if(this->selected > -1)
|
|
||||||
this->ValueChanged.Invoke(this,e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDLK_HOME:
|
|
||||||
this->selected=0;
|
|
||||||
this->firstIndex=0;
|
|
||||||
break;
|
|
||||||
case SDLK_END:
|
|
||||||
this->selected = (int)(this->items.size()-1);
|
|
||||||
|
|
||||||
this->firstIndex= this->selected-(this->selected % max_items);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case SDLK_DOWN:
|
|
||||||
this->selected++;
|
|
||||||
if(this->selected < -1 || this->selected >= this->items.size())
|
|
||||||
{
|
|
||||||
this->selected=0;
|
|
||||||
}
|
|
||||||
this->firstIndex= this->selected-(this->selected % max_items);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case SDLK_UP:
|
|
||||||
this->selected--;
|
|
||||||
if(this->selected < 0 || this->selected >= this->items.size())
|
|
||||||
{
|
|
||||||
this->selected = (int)(this->items.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->firstIndex= this->selected-(this->selected % max_items);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(event.type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
|
||||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
if(inside && !hoverFlag)
|
|
||||||
{
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnEnter(e);
|
|
||||||
this->Enter.Invoke(this,e);
|
|
||||||
}
|
|
||||||
else if(!inside && hoverFlag)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnLeave(e);
|
|
||||||
this->Leave.Invoke(this,e);
|
|
||||||
} else if(inside) {
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
this->firstIndex = 0;
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
this->firstIndex = count*max_items;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
|
||||||
uint64_t y2 = y-33;
|
|
||||||
|
|
||||||
double off = (double)y2 / (double)height;
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
this->firstIndex = round(off*count) * max_items;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
int x= event.button.x - myBounds.x;
|
|
||||||
int y = event.button.y - myBounds.y;
|
|
||||||
|
|
||||||
if(x >= myBounds.w-32)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
|
||||||
|
|
||||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
|
||||||
uint64_t y2 = y-33;
|
|
||||||
|
|
||||||
double off = (double)y2 / (double)height;
|
|
||||||
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
this->firstIndex = round(off*count) * max_items;
|
|
||||||
//value = round((max-min)*off)+min;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
int x= event.button.x - myBounds.x;
|
|
||||||
if(x < myBounds.w-32 && event.button.x >= (visibleBounds.x+win->palette.borderSize) && event.button.y >= (visibleBounds.y+win->palette.borderSize) && event.button.y < (visibleBounds.y+visibleBounds.h)-(win->palette.borderSize*2))
|
|
||||||
{
|
|
||||||
win->MakeActive(this);
|
|
||||||
auto myRealY=event.button.y - (myBounds.y+win->palette.borderSize);
|
|
||||||
auto yThing = myRealY / item_height;
|
|
||||||
|
|
||||||
if(yThing < no_items)
|
|
||||||
{
|
|
||||||
auto high= yThing+this->firstIndex;
|
|
||||||
this->selected = (int)high;
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->ValueChanged.Invoke(this,e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
|
|
||||||
win->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
|
||||||
{
|
|
||||||
|
|
||||||
win->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
|
||||||
|
|
||||||
//this->value -= step;
|
|
||||||
//if(this->value < min) this->value=min;
|
|
||||||
//if(this->value >= max) this->value=min;
|
|
||||||
//OnValueChanged(cea2);
|
|
||||||
//this->ValueChanged.Invoke(this,cea2);
|
|
||||||
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
auto c = max_items == 0 ? 0 : (this->firstIndex / max_items);
|
|
||||||
c--;
|
|
||||||
if(c > count) c = 0;
|
|
||||||
this->firstIndex = c * max_items;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
|
||||||
{
|
|
||||||
|
|
||||||
win->MakeActive(this);
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
|
||||||
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
auto c = max_items == 0 ? 0 : (this->firstIndex / max_items);
|
|
||||||
c++;
|
|
||||||
if(c > count) c = count;
|
|
||||||
this->firstIndex = c * max_items;
|
|
||||||
//this->value += step;
|
|
||||||
//if(this->value > max) this->value=max;
|
|
||||||
//OnValueChanged(cea2);
|
|
||||||
//this->ValueChanged.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScrollableTextListView::OnDraw(SDL_Renderer* renderer,SDL_Rect& rect)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
|
||||||
auto no_items = (rect.h-(win->palette.borderSize*2)) / item_height;
|
|
||||||
auto max_items = no_items;
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(this->firstIndex + no_items > this->items.size())
|
|
||||||
{
|
|
||||||
|
|
||||||
no_items = this->items.size()-this->firstIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect _r2={.x=rect.x,.y=rect.y,.w=rect.w-32,.h=rect.h};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&_r2);
|
|
||||||
_r2.x++;
|
|
||||||
_r2.y++;
|
|
||||||
_r2.w-=2;
|
|
||||||
_r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < no_items; i++)
|
|
||||||
{
|
|
||||||
int realI = i+(int)firstIndex;
|
|
||||||
if(realI == this->selected)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_Rect r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize+(item_height*i),.w=rect.w-(win->palette.borderSize*2)-32,.h=item_height};
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],color);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],win->palette.accent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto scrollX = (rect.w-32)+rect.x;
|
|
||||||
auto topIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
|
||||||
|
|
||||||
auto topIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
|
||||||
|
|
||||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
|
|
||||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
|
|
||||||
auto bottomIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
|
|
||||||
auto bottomIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
|
||||||
|
|
||||||
SDL_Color& topcolor = win->palette.GetBorderColor(topIsHovering,isActive,topIsMouseDown);
|
|
||||||
SDL_Color& topMiddleColor = win->palette.GetBorderColor(topIsHovering||middleIsHovering,isActive,topIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
|
||||||
SDL_Color& bottomMiddleColor = win->palette.GetBorderColor(bottomIsHovering||middleIsHovering,isActive,bottomIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& bottomColor = win->palette.GetBorderColor(bottomIsHovering,isActive,bottomIsMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,topcolor.r,topcolor.g,topcolor.b,topcolor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX,rect.y+i,scrollX+32,rect.y+i);
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y,scrollX+i,rect.y+32);
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y,scrollX+32-(1+i),rect.y+32);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,topMiddleColor.r,topMiddleColor.g,topMiddleColor.b,topMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+32)-i,scrollX+32,(rect.y+32)-i);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y+33,scrollX+i,rect.y+(rect.h-33));
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y+33,scrollX+32-(1+i),rect.y+(rect.h-33));
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,bottomColor.r,bottomColor.g,bottomColor.b,bottomColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+rect.h)-(i+1),scrollX+32,(rect.y+rect.h)-(i+1));
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y+(rect.h-32),scrollX+i,rect.y+rect.h);
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y+(rect.h-32),scrollX+32-(1+i),rect.y+rect.h);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,bottomMiddleColor.r,bottomMiddleColor.g,bottomMiddleColor.b,bottomMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+(rect.h-32))+i,scrollX+32,(rect.y+(rect.h-32))+i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
int x1 = 15;
|
|
||||||
int y1 = 8 + i;
|
|
||||||
|
|
||||||
int x2 = 9;
|
|
||||||
int y2 = 18 + i;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+scrollX,y1+rect.y,x2+scrollX,y2+rect.y);
|
|
||||||
|
|
||||||
int x3 = 31-x1;
|
|
||||||
int x4 = 31-x2;
|
|
||||||
SDL_RenderDrawLine(renderer,x3+scrollX,y1+rect.y,x4+scrollX,y2+rect.y);
|
|
||||||
|
|
||||||
int y3 = 31-y1;
|
|
||||||
int y4 = 31-y2;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+scrollX,y3+rect.y+(rect.h-32),x2+scrollX,y4+rect.y+(rect.h-32));
|
|
||||||
SDL_RenderDrawLine(renderer,x3+scrollX,y3+rect.y+(rect.h-32),x4+scrollX,y4+rect.y+(rect.h-32));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t height = (uint64_t)rect.h - 66;
|
|
||||||
uint64_t scrollSize = 4;
|
|
||||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
|
||||||
|
|
||||||
if((items.size() % max_items) == 0) count--;
|
|
||||||
|
|
||||||
if(count > 0)
|
|
||||||
scrollSize = height / count;
|
|
||||||
|
|
||||||
if(scrollSize < 4) scrollSize=4;
|
|
||||||
|
|
||||||
|
|
||||||
double scroll = 0;
|
|
||||||
if(count > 0 && max_items > 0)
|
|
||||||
scroll = (double)(this->firstIndex / max_items) / (double)count;
|
|
||||||
|
|
||||||
uint64_t scrollY = scroll * (height-scrollSize);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(scrollY > height-scrollSize) scrollY = height-scrollSize;
|
|
||||||
SDL_Rect r2={.x=scrollX+win->palette.borderSize,.y=(int)scrollY+rect.y+32,.w = 32-(win->palette.borderSize*2),.h=(int)scrollSize};
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,245 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/TabView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void TabView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto view = this->GetViewAt(0);
|
|
||||||
auto win =this->GetWindow();
|
|
||||||
if(this->tabsVisible)
|
|
||||||
{
|
|
||||||
|
|
||||||
int h =
|
|
||||||
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
|
||||||
int w = win->monospaced_font->MaxWidth() + (win->palette.borderSize*3);
|
|
||||||
|
|
||||||
size_t noItems = this->items.size();
|
|
||||||
size_t offset = 0;
|
|
||||||
size_t width = noItems == 0 ? 0 : (r.w / noItems);
|
|
||||||
if(noItems > 0 && (r.w / noItems) < w*5)
|
|
||||||
{
|
|
||||||
offset=this->firstTab;
|
|
||||||
noItems = (r.w - (w*2)) / (w * 5);
|
|
||||||
width = noItems == 0 ? 0 : ((r.w - (w*2)) / noItems);
|
|
||||||
if(offset > items.size())
|
|
||||||
offset = items.size()-3;
|
|
||||||
if((offset+noItems)>items.size()) noItems = items.size()-offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i = 0; i < noItems; i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
Clipper clipper(renderer,r);
|
|
||||||
int yBottom = (h - 1)+r.y;
|
|
||||||
//auto bc = win->palette.GetBorderColor(false,(i+offset)==this->selectedTab,false);
|
|
||||||
std::string text = this->items[i+offset].first;
|
|
||||||
int textW;
|
|
||||||
int textH;
|
|
||||||
win->monospaced_font->CalculateSize(text,textW,textH);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*if(i>0)
|
|
||||||
{
|
|
||||||
//auto bc2 = win->palette.GetBorderColor(false,(i+offset)==this->selectedTab || ((i+offset)-1)==this->selectedTab,false);
|
|
||||||
//SDL_SetRenderDrawColor(renderer,bc2.r,bc2.g,bc2.b,bc2.a);
|
|
||||||
// SDL_RenderDrawLine(renderer,(width*i)+r.x,r.y,(width*i)+r.x,yBottom);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//SDL_SetRenderDrawColor(renderer,bc.r,bc.g,bc.b,bc.a);
|
|
||||||
if((i+offset)==this->selectedTab)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_Rect r0={.x=(int)(width*i+1)+r.x,.y=r.y,.w=(int)width-2,.h=yBottom-r.y};
|
|
||||||
SDL_RenderFillRect(renderer,&r0);
|
|
||||||
}
|
|
||||||
//SDL_RenderDrawLine(renderer,(width*i+1)+r.x,yBottom,(width*(i+1)-2),yBottom);
|
|
||||||
clipper.Clip({.x=(int)(width*i+1)+r.x,.y=r.y,.w=(int)width-2,.h=yBottom-r.y});
|
|
||||||
int textX = ((width-2)/2) - (textW/2);
|
|
||||||
int textY = ((yBottom-r.y)/2) - (textH/2);
|
|
||||||
|
|
||||||
win->monospaced_font->Render(renderer,textX+r.x+(width*i+2),textY+r.y,text,((i+offset)==this->selectedTab) ? win->palette.background : win->palette.accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(noItems != items.size())
|
|
||||||
{
|
|
||||||
auto greaterThanX=(r.w-w)+r.x;
|
|
||||||
auto lessThanX = greaterThanX-w;
|
|
||||||
int lgtX;
|
|
||||||
int lgtY;
|
|
||||||
win->monospaced_font->CalculateSize("<",lgtX,lgtY);
|
|
||||||
lgtX = (w/2)-(lgtX/2);
|
|
||||||
lgtY = (h/2)-(lgtY/2);
|
|
||||||
win->monospaced_font->Render(renderer,lessThanX+lgtX,r.y+lgtY,"<",win->palette.accent);
|
|
||||||
|
|
||||||
win->monospaced_font->CalculateSize(">",lgtX,lgtY);
|
|
||||||
lgtX = (w/2)-(lgtX/2);
|
|
||||||
lgtY = (h/2)-(lgtY/2);
|
|
||||||
win->monospaced_font->Render(renderer,greaterThanX+lgtX,r.y+lgtY,">",win->palette.accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect viewBounds = {
|
|
||||||
.x=r.x,
|
|
||||||
.y=h+r.y,
|
|
||||||
.w=r.w,
|
|
||||||
.h=r.h-h
|
|
||||||
};
|
|
||||||
CallOnDraw(view,renderer,viewBounds);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(view != nullptr) CallOnDraw(view,renderer,r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool TabView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
auto view = this->GetViewAt(0);
|
|
||||||
auto win =this->GetWindow();
|
|
||||||
if(this->tabsVisible)
|
|
||||||
{
|
|
||||||
int h =
|
|
||||||
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
|
||||||
|
|
||||||
int w = win->monospaced_font->MaxWidth() + (win->palette.borderSize*3);
|
|
||||||
int yBottom = (h - 1)+myBounds.y;
|
|
||||||
size_t noItems = this->items.size();
|
|
||||||
size_t offset = 0;
|
|
||||||
|
|
||||||
size_t width = noItems == 0 ? 0 : (myBounds.w / noItems);
|
|
||||||
if(noItems > 0 && (myBounds.w / noItems) < w*5)
|
|
||||||
{
|
|
||||||
offset=this->firstTab;
|
|
||||||
noItems = (myBounds.w - (w*2)) / (w * 5);
|
|
||||||
width = noItems == 0 ? 0 : ((myBounds.w - (w*2)) / noItems);
|
|
||||||
if(offset > items.size())
|
|
||||||
offset = items.size()-3;
|
|
||||||
if((offset+noItems)>items.size()) noItems = items.size()-offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
int width_total = width*noItems;
|
|
||||||
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(event.button.y < myBounds.y+h && event.button.x < myBounds.x+width_total)
|
|
||||||
{
|
|
||||||
this->selectedTab = offset + ((event.button.x-myBounds.x) / width);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(event.button.y < myBounds.y+h && event.button.x < myBounds.x+myBounds.w)
|
|
||||||
{
|
|
||||||
if(noItems != items.size())
|
|
||||||
{
|
|
||||||
auto greaterThanX=myBounds.w-w+myBounds.x;
|
|
||||||
auto lessThanX = greaterThanX-w;
|
|
||||||
|
|
||||||
|
|
||||||
if(event.button.x >= lessThanX && event.button.x < greaterThanX)
|
|
||||||
{
|
|
||||||
firstTab--;
|
|
||||||
if(firstTab >= items.size())
|
|
||||||
firstTab=0;
|
|
||||||
}
|
|
||||||
else if(event.button.x >= greaterThanX)
|
|
||||||
{
|
|
||||||
firstTab++;
|
|
||||||
if(firstTab >= items.size())
|
|
||||||
firstTab = items.size()-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Rect viewBounds = {
|
|
||||||
.x=0,
|
|
||||||
.y=h,
|
|
||||||
.w=myBounds.w,
|
|
||||||
.h=myBounds.h-h
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = viewBounds;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
|
|
||||||
viewBounds.x += myBounds.x;
|
|
||||||
viewBounds.y += myBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
return CallOnEvent(view,event,viewBounds,theirVisibleBounds);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(view != nullptr) return CallOnEvent(view,event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TabView::TabView() : TabView(true)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
TabView::TabView(bool tabsVisible) : ContainerView()
|
|
||||||
{
|
|
||||||
this->tabsVisible=tabsVisible;
|
|
||||||
this->firstTab=0;
|
|
||||||
this->selectedTab=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TabView::AddTab(std::string name, View* view, bool owns)
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
{
|
|
||||||
if(item.second.first == view) return;
|
|
||||||
}
|
|
||||||
this->AssignChildParentToThis(view);
|
|
||||||
this->items.push_back(std::pair<std::string,std::pair<View*,bool>>(name,std::pair<View*,bool>(view,owns)));
|
|
||||||
}
|
|
||||||
void TabView::RemoveTab(View* view)
|
|
||||||
{
|
|
||||||
for(auto index = this->items.begin(); index != this->items.end(); index++)
|
|
||||||
{
|
|
||||||
if(index->second.first == view)
|
|
||||||
{
|
|
||||||
if(index->second.second) delete index->second.first;
|
|
||||||
this->items.erase(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void TabView::Clear()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
{
|
|
||||||
if(item.second.second) delete item.second.first;
|
|
||||||
}
|
|
||||||
items.clear();
|
|
||||||
}
|
|
||||||
size_t TabView::ViewCount()
|
|
||||||
{
|
|
||||||
return this->items.empty() ? 0 : 1;
|
|
||||||
}
|
|
||||||
View* TabView::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
if(this->items.empty()) return nullptr;
|
|
||||||
if(this->selectedTab >= this->items.size()) return this->items.back().second.first;
|
|
||||||
return this->items[this->selectedTab].second.first;
|
|
||||||
}
|
|
||||||
TabView::~TabView()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
{
|
|
||||||
if(item.second.second) delete item.second.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
TextListView::TextListView() : View()
|
|
||||||
{
|
|
||||||
this->firstIndex=0;
|
|
||||||
this->selected=-1;
|
|
||||||
}
|
|
||||||
bool TextListView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
|
||||||
auto no_items = (myBounds.h-(win->palette.borderSize*2)) / item_height;
|
|
||||||
|
|
||||||
if(this->items.size() > no_items)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(this->items.size() - this->firstIndex < no_items)
|
|
||||||
{
|
|
||||||
this->firstIndex = this->items.size() - no_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->firstIndex=0;
|
|
||||||
|
|
||||||
no_items = (int)this->items.size();
|
|
||||||
}
|
|
||||||
if(event.type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
|
||||||
{
|
|
||||||
switch(event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_HOME:
|
|
||||||
this->selected=0;
|
|
||||||
this->firstIndex=0;
|
|
||||||
break;
|
|
||||||
case SDLK_END:
|
|
||||||
this->selected = (int)(this->items.size()-1);
|
|
||||||
this->firstIndex = (this->selected/no_items) * no_items;
|
|
||||||
|
|
||||||
break;
|
|
||||||
case SDLK_DOWN:
|
|
||||||
this->selected++;
|
|
||||||
if(this->selected < -1 || this->selected >= this->items.size())
|
|
||||||
{
|
|
||||||
this->selected=0;
|
|
||||||
}
|
|
||||||
this->firstIndex = (this->selected/no_items) * no_items;
|
|
||||||
break;
|
|
||||||
case SDLK_UP:
|
|
||||||
this->selected--;
|
|
||||||
if(this->selected < 0 || this->selected >= this->items.size())
|
|
||||||
{
|
|
||||||
this->selected = (int)(this->items.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->firstIndex = (this->selected/no_items) * no_items;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONUP && event.button.x >= (visibleBounds.x+win->palette.borderSize) && event.button.x < (visibleBounds.x+visibleBounds.w)-(win->palette.borderSize*2) && event.button.y >= (visibleBounds.y+win->palette.borderSize) && event.button.y < (visibleBounds.y+visibleBounds.h)-(win->palette.borderSize*2))
|
|
||||||
{
|
|
||||||
win->MakeActive(this);
|
|
||||||
auto myRealY=event.button.y - (myBounds.y+win->palette.borderSize);
|
|
||||||
auto yThing = myRealY / item_height;
|
|
||||||
|
|
||||||
if(yThing < no_items)
|
|
||||||
{
|
|
||||||
auto high= yThing+this->firstIndex;
|
|
||||||
this->selected = (int)high;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextListView::OnDraw(SDL_Renderer* renderer,SDL_Rect& rect)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
|
||||||
auto no_items = (rect.h-(win->palette.borderSize*2)) / item_height;
|
|
||||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(this->items.size() > no_items)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(this->items.size() - this->firstIndex < no_items)
|
|
||||||
{
|
|
||||||
this->firstIndex = this->items.size() - no_items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->firstIndex=0;
|
|
||||||
no_items = (int)this->items.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect r2={.x=rect.x,.y=rect.y,.w=rect.w,.h=rect.h};
|
|
||||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawRect(renderer,&r2);
|
|
||||||
r2.x++;
|
|
||||||
r2.y++;
|
|
||||||
r2.w-=2;
|
|
||||||
r2.h-=2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < no_items; i++)
|
|
||||||
{
|
|
||||||
int realI = i+(int)firstIndex;
|
|
||||||
if(realI == this->selected)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
SDL_Rect r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize+(item_height*i),.w=rect.w-(win->palette.borderSize*2),.h=item_height};
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],color);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],win->palette.accent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
|
|
||||||
#include "TessesFramework/SDL2/Views/VScrollView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
std::pair<int,int> VScrollView::PreferedMinSize()
|
|
||||||
{
|
|
||||||
return std::pair<int,int>(32,-1);
|
|
||||||
}
|
|
||||||
void VScrollView::OnValueChanged(GUIEventArgs& e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
VScrollView::VScrollView() : VScrollView(0, 0, 100)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
VScrollView::VScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step) : View()
|
|
||||||
{
|
|
||||||
this->value = value;
|
|
||||||
this->min = min;
|
|
||||||
this->max = max;
|
|
||||||
|
|
||||||
this->step=step;
|
|
||||||
}
|
|
||||||
void VScrollView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
auto win = this->GetWindow();
|
|
||||||
auto topIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
|
||||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
|
||||||
auto topIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
|
||||||
|
|
||||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
|
||||||
|
|
||||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
|
||||||
|
|
||||||
|
|
||||||
auto bottomIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
|
|
||||||
auto bottomIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
|
||||||
|
|
||||||
SDL_Color& topcolor = win->palette.GetBorderColor(topIsHovering,isActive,topIsMouseDown);
|
|
||||||
SDL_Color& topMiddleColor = win->palette.GetBorderColor(topIsHovering||middleIsHovering,isActive,topIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
|
||||||
SDL_Color& bottomMiddleColor = win->palette.GetBorderColor(bottomIsHovering||middleIsHovering,isActive,bottomIsMouseDown||middleIsMouseDown);
|
|
||||||
SDL_Color& bottomColor = win->palette.GetBorderColor(bottomIsHovering,isActive,bottomIsMouseDown);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,topcolor.r,topcolor.g,topcolor.b,topcolor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,r.y+i,r.x+r.w,r.y+i);
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+i,r.y,r.x+i,r.y+32);
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y,r.x+r.w-(1+i),r.y+32);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,topMiddleColor.r,topMiddleColor.g,topMiddleColor.b,topMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,(r.y+32)-i,r.x+r.w,(r.y+32)-i);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+i,r.y+33,r.x+i,r.y+(r.h-33));
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y+33,r.x+r.w-(1+i),r.y+(r.h-33));
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,bottomColor.r,bottomColor.g,bottomColor.b,bottomColor.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,(r.y+r.h)-(i+1),r.x+r.w,(r.y+r.h)-(i+1));
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+i,r.y+(r.h-32),r.x+i,r.y+r.h);
|
|
||||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y+(r.h-32),r.x+r.w-(1+i),r.y+r.h);
|
|
||||||
}
|
|
||||||
SDL_SetRenderDrawColor(renderer,bottomMiddleColor.r,bottomMiddleColor.g,bottomMiddleColor.b,bottomMiddleColor.a);
|
|
||||||
for(int i = 0; i < win->palette.borderSize; i++)
|
|
||||||
{
|
|
||||||
SDL_RenderDrawLine(renderer,r.x,(r.y+(r.h-32))+i,r.x+r.w,(r.y+(r.h-32))+i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
int x1 = 15;
|
|
||||||
int y1 = 8 + i;
|
|
||||||
|
|
||||||
int x2 = 9;
|
|
||||||
int y2 = 18 + i;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+r.x,y1+r.y,x2+r.x,y2+r.y);
|
|
||||||
|
|
||||||
int x3 = 31-x1;
|
|
||||||
int x4 = 31-x2;
|
|
||||||
SDL_RenderDrawLine(renderer,x3+r.x,y1+r.y,x4+r.x,y2+r.y);
|
|
||||||
|
|
||||||
int y3 = 31-y1;
|
|
||||||
int y4 = 31-y2;
|
|
||||||
|
|
||||||
SDL_RenderDrawLine(renderer,x1+r.x,y3+r.y+(r.h-32),x2+r.x,y4+r.y+(r.h-32));
|
|
||||||
SDL_RenderDrawLine(renderer,x3+r.x,y3+r.y+(r.h-32),x4+r.x,y4+r.y+(r.h-32));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t height = (uint64_t)r.h - 66;
|
|
||||||
uint64_t scrollSize = 4;
|
|
||||||
uint64_t dif = max-min;
|
|
||||||
if(dif > 0)
|
|
||||||
scrollSize = height / dif;
|
|
||||||
|
|
||||||
if(scrollSize < 4) scrollSize=4;
|
|
||||||
|
|
||||||
|
|
||||||
double scroll = 0;
|
|
||||||
if(dif > 0)
|
|
||||||
scroll = (double)(value-min) / (double)dif;
|
|
||||||
|
|
||||||
uint64_t scrollY = scroll * (height-scrollSize);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(scrollY > height-scrollSize) scrollY = height-scrollSize;
|
|
||||||
SDL_Rect r2={.x=r.x+win->palette.borderSize,.y=(int)scrollY+r.y+32,.w = r.w-(win->palette.borderSize*2),.h=(int)scrollSize};
|
|
||||||
SDL_RenderFillRect(renderer,&r2);
|
|
||||||
}
|
|
||||||
bool VScrollView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
if(event.type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
|
||||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
|
||||||
if(inside && !hoverFlag)
|
|
||||||
{
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnEnter(e);
|
|
||||||
this->Enter.Invoke(this,e);
|
|
||||||
}
|
|
||||||
else if(!inside && hoverFlag)
|
|
||||||
{
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
GUIEventArgs e;
|
|
||||||
this->OnLeave(e);
|
|
||||||
this->Leave.Invoke(this,e);
|
|
||||||
} else if(inside) {
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
|
||||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
int y = event.motion.y - myBounds.y;
|
|
||||||
if(y <= 32)
|
|
||||||
{
|
|
||||||
value = min;
|
|
||||||
}
|
|
||||||
else if(y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
value=max;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
|
||||||
uint64_t y2 = y-33;
|
|
||||||
|
|
||||||
double off = (double)y2 / (double)height;
|
|
||||||
|
|
||||||
value = round((max-min)*off)+min;
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
{
|
|
||||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
if(cea.y <= 32)
|
|
||||||
{
|
|
||||||
//up btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
|
||||||
}
|
|
||||||
else if(cea.y >= myBounds.h-32)
|
|
||||||
{
|
|
||||||
//down btn
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
|
||||||
|
|
||||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
|
||||||
uint64_t y2 = cea.y-33;
|
|
||||||
|
|
||||||
double off = (double)y2 / (double)height;
|
|
||||||
|
|
||||||
value = round((max-min)*off)+min;
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
}
|
|
||||||
OnMouseDown(cea);
|
|
||||||
this->MouseDown.Invoke(this,cea);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
this->value -= step;
|
|
||||||
if(this->value < min) this->value=min;
|
|
||||||
if(this->value >= max) this->value=min;
|
|
||||||
OnValueChanged(cea2);
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
|
||||||
{
|
|
||||||
GUIMouseButtonEventArgs cea;
|
|
||||||
cea.button = (int)event.button.button;
|
|
||||||
cea.x = event.button.x - myBounds.x;
|
|
||||||
cea.y = event.button.y - myBounds.y;
|
|
||||||
cea.which = event.button.which;
|
|
||||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
|
||||||
OnMouseUp(cea);
|
|
||||||
this->MouseUp.Invoke(this,cea);
|
|
||||||
GUIEventArgs cea2;
|
|
||||||
OnClick(cea2);
|
|
||||||
this->Click.Invoke(this,cea2);
|
|
||||||
this->value += step;
|
|
||||||
if(this->value > max) this->value=max;
|
|
||||||
OnValueChanged(cea2);
|
|
||||||
this->ValueChanged.Invoke(this,cea2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return View::OnEvent(event,myBounds,visibleBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,270 +0,0 @@
|
|||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include "TessesFramework/SDL2/Views/VStackView.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::SDL2::Views
|
|
||||||
{
|
|
||||||
void VStackView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
|
||||||
{
|
|
||||||
int numberOfCells = 0;
|
|
||||||
int freeHeight = r.h;
|
|
||||||
std::vector<int> sizes;
|
|
||||||
sizes.resize(this->items.size());
|
|
||||||
|
|
||||||
freeHeight -= (this->items.size() - 1) * this->spacing;
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first > 0)
|
|
||||||
{
|
|
||||||
//static size
|
|
||||||
sizes[i] = this->items[i].first;
|
|
||||||
freeHeight-= this->items[i].first;
|
|
||||||
}
|
|
||||||
else if(this->items[i].first == 0)
|
|
||||||
{
|
|
||||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(prefered.second > 0)
|
|
||||||
{
|
|
||||||
sizes[i] = prefered.second;
|
|
||||||
freeHeight -= prefered.second;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sizes[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numberOfCells -= this->items[i].first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < this->items.size();i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first < 0)
|
|
||||||
{
|
|
||||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(minSz.second > myHeight) {
|
|
||||||
sizes[i] = minSz.second;
|
|
||||||
freeHeight -= minSz.second;
|
|
||||||
numberOfCells -= -(this->items[i].first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
|
||||||
int y = 0;
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(i > 0) y += spacing;
|
|
||||||
|
|
||||||
if(sizes[i] == 0)
|
|
||||||
{
|
|
||||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = 0,
|
|
||||||
.y=y,
|
|
||||||
.w=r.w,
|
|
||||||
.h=myHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
theirBounds.x += r.x;
|
|
||||||
theirBounds.y += r.y;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
|
||||||
y+=myHeight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = 0,
|
|
||||||
.y=y,
|
|
||||||
.w=r.w,
|
|
||||||
.h=sizes[i]
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
theirBounds.x += r.x;
|
|
||||||
theirBounds.y += r.y;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
|
||||||
y+=sizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool VStackView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
|
||||||
{
|
|
||||||
int numberOfCells = 0;
|
|
||||||
int freeHeight = myBounds.h;
|
|
||||||
std::vector<int> sizes;
|
|
||||||
sizes.resize(this->items.size());
|
|
||||||
|
|
||||||
|
|
||||||
freeHeight -= (this->items.size() - 1) * this->spacing;
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first > 0)
|
|
||||||
{
|
|
||||||
//static size
|
|
||||||
sizes[i] = this->items[i].first;
|
|
||||||
freeHeight-= this->items[i].first;
|
|
||||||
}
|
|
||||||
else if(this->items[i].first == 0)
|
|
||||||
{
|
|
||||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(prefered.second > 0)
|
|
||||||
{
|
|
||||||
sizes[i] = prefered.second;
|
|
||||||
freeHeight -= prefered.second;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sizes[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numberOfCells -= this->items[i].first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
|
||||||
|
|
||||||
for(int i = 0; i < this->items.size();i++)
|
|
||||||
{
|
|
||||||
if(this->items[i].first < 0)
|
|
||||||
{
|
|
||||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
|
||||||
if(minSz.second > myHeight) {
|
|
||||||
sizes[i] = minSz.second;
|
|
||||||
freeHeight -= minSz.second;
|
|
||||||
numberOfCells -= -(this->items[i].first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
|
||||||
int y = 0;
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->items.size(); i++)
|
|
||||||
{
|
|
||||||
if(i > 0) y += spacing;
|
|
||||||
if(sizes[i] == 0)
|
|
||||||
{
|
|
||||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = 0,
|
|
||||||
.y=y,
|
|
||||||
.w=myBounds.w,
|
|
||||||
.h=myHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = theirBounds;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
|
|
||||||
theirBounds.x += myBounds.x;
|
|
||||||
theirBounds.y += myBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
|
||||||
|
|
||||||
y+=myHeight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
SDL_Rect theirBounds = {
|
|
||||||
.x = 0,
|
|
||||||
.y=y,
|
|
||||||
.w=myBounds.w,
|
|
||||||
.h=sizes[i]
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Rect theirVisibleBounds = theirBounds;
|
|
||||||
theirVisibleBounds.x += visibleBounds.x;
|
|
||||||
theirVisibleBounds.y += visibleBounds.y;
|
|
||||||
|
|
||||||
theirBounds.x += myBounds.x;
|
|
||||||
theirBounds.y += myBounds.y;
|
|
||||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
|
||||||
|
|
||||||
y+=sizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
VStackView::VStackView() : ContainerView()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VStackView::Add(int sz, View* view, bool owns)
|
|
||||||
{
|
|
||||||
this->items.push_back(std::pair<int,std::pair<View*,bool>>(sz,std::pair<View*,bool>(view,owns)));
|
|
||||||
this->AssignChildParentToThis(view);
|
|
||||||
}
|
|
||||||
void VStackView::Remove(View* view)
|
|
||||||
{
|
|
||||||
for(auto index = this->items.begin(); index < this->items.end(); index++)
|
|
||||||
{
|
|
||||||
if(index->second.first == view)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(index->second.first != nullptr && index->second.second)
|
|
||||||
delete view;
|
|
||||||
this->items.erase(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void VStackView::Clear()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
|
||||||
items = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t VStackView::ViewCount()
|
|
||||||
{
|
|
||||||
return this->items.size();
|
|
||||||
}
|
|
||||||
View* VStackView::GetViewAt(size_t index)
|
|
||||||
{
|
|
||||||
return this->items.at(index).second.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
VStackView::~VStackView()
|
|
||||||
{
|
|
||||||
for(auto& item : this->items)
|
|
||||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -203,7 +203,7 @@ namespace Tesses::Framework::Serialization::Json
|
|||||||
}
|
}
|
||||||
if((v & 0xFC00) != 0xDC00)
|
if((v & 0xFC00) != 0xDC00)
|
||||||
{
|
{
|
||||||
throw TextException("Not a lower utf-16 surrogate pair.");
|
throw std::runtime_error("Not a lower utf-16 surrogate pair.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ namespace Tesses::Framework::Serialization::Json
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
throw TextException("Could not read lower utf-16 surrogate pair.");
|
throw std::runtime_error("Could not read lower utf-16 surrogate pair.");
|
||||||
}
|
}
|
||||||
if(v2 <= 0x7F)
|
if(v2 <= 0x7F)
|
||||||
{
|
{
|
||||||
@@ -297,7 +297,7 @@ namespace Tesses::Framework::Serialization::Json
|
|||||||
size_t tokenIndex=0;
|
size_t tokenIndex=0;
|
||||||
|
|
||||||
std::function<std::pair<std::string,bool>()> pop_token=[&tokens,&tokenIndex]()->std::pair<std::string,bool> {
|
std::function<std::pair<std::string,bool>()> pop_token=[&tokens,&tokenIndex]()->std::pair<std::string,bool> {
|
||||||
if(tokenIndex >= tokens.size()) throw TextException("Json tokens out of bounds.");
|
if(tokenIndex >= tokens.size()) throw std::runtime_error("Json tokens out of bounds.");
|
||||||
return tokens[tokenIndex++];
|
return tokens[tokenIndex++];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ namespace Tesses::Framework::Serialization::Json
|
|||||||
tkn = pop_token();
|
tkn = pop_token();
|
||||||
if(tkn.second || tkn.first != ":")
|
if(tkn.second || tkn.first != ":")
|
||||||
{
|
{
|
||||||
throw TextException("Invalid JSON key value seperator.");
|
throw std::runtime_error("Invalid JSON key value seperator.");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto value = read_token();
|
auto value = read_token();
|
||||||
@@ -341,7 +341,7 @@ namespace Tesses::Framework::Serialization::Json
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
throw TextException("Invalid JSON object.");
|
throw std::runtime_error("Invalid JSON object.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Tesses::Framework::Serialization {
|
|||||||
if(rc)
|
if(rc)
|
||||||
{
|
{
|
||||||
std::string error = sqlite3_errmsg(sqlite);
|
std::string error = sqlite3_errmsg(sqlite);
|
||||||
throw TextException(error);
|
throw std::runtime_error(error);
|
||||||
}
|
}
|
||||||
this->data = static_cast<void*>(sqlite);
|
this->data = static_cast<void*>(sqlite);
|
||||||
#endif
|
#endif
|
||||||
@@ -54,7 +54,9 @@ namespace Tesses::Framework::Serialization {
|
|||||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> SQLiteDatabase::Exec(std::string statement)
|
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> SQLiteDatabase::Exec(std::string statement)
|
||||||
{
|
{
|
||||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> items;
|
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> items;
|
||||||
|
|
||||||
Exec(statement,items);
|
Exec(statement,items);
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
void SQLiteDatabase::Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& items)
|
void SQLiteDatabase::Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& items)
|
||||||
@@ -67,7 +69,7 @@ namespace Tesses::Framework::Serialization {
|
|||||||
{
|
{
|
||||||
std::string errstr = err == nullptr ? "" : err;
|
std::string errstr = err == nullptr ? "" : err;
|
||||||
sqlite3_free(err);
|
sqlite3_free(err);
|
||||||
throw TextException(errstr);
|
throw std::runtime_error(errstr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ namespace Tesses::Framework::Streams
|
|||||||
uint8_t ByteReader::ReadU8()
|
uint8_t ByteReader::ReadU8()
|
||||||
{
|
{
|
||||||
auto r = this->strm->ReadByte();
|
auto r = this->strm->ReadByte();
|
||||||
if(r < 0) throw TextException("End of file");
|
if(r < 0) throw std::runtime_error("End of file");
|
||||||
return (uint8_t)r;
|
return (uint8_t)r;
|
||||||
}
|
}
|
||||||
uint16_t ByteReader::ReadU16BE()
|
uint16_t ByteReader::ReadU16BE()
|
||||||
{
|
{
|
||||||
uint8_t data[2];
|
uint8_t data[2];
|
||||||
if(this->strm->ReadBlock(data,2) != 2) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,2) != 2) throw std::runtime_error("End of file");
|
||||||
uint16_t n = 0;
|
uint16_t n = 0;
|
||||||
n |= (uint16_t)data[0] << 8;
|
n |= (uint16_t)data[0] << 8;
|
||||||
n |= (uint16_t)data[1];
|
n |= (uint16_t)data[1];
|
||||||
@@ -33,7 +33,7 @@ namespace Tesses::Framework::Streams
|
|||||||
uint16_t ByteReader::ReadU16LE()
|
uint16_t ByteReader::ReadU16LE()
|
||||||
{
|
{
|
||||||
uint8_t data[2];
|
uint8_t data[2];
|
||||||
if(this->strm->ReadBlock(data,2) != 2) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,2) != 2) throw std::runtime_error("End of file");
|
||||||
uint16_t n = 0;
|
uint16_t n = 0;
|
||||||
n |= (uint16_t)data[0];
|
n |= (uint16_t)data[0];
|
||||||
n |= (uint16_t)data[1] << 8;
|
n |= (uint16_t)data[1] << 8;
|
||||||
@@ -45,7 +45,7 @@ namespace Tesses::Framework::Streams
|
|||||||
{
|
{
|
||||||
|
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
if(this->strm->ReadBlock(data,4) != 4) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,4) != 4) throw std::runtime_error("End of file");
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
n |= (uint32_t)data[0] << 24;
|
n |= (uint32_t)data[0] << 24;
|
||||||
n |= (uint32_t)data[1] << 16;
|
n |= (uint32_t)data[1] << 16;
|
||||||
@@ -57,7 +57,7 @@ namespace Tesses::Framework::Streams
|
|||||||
uint32_t ByteReader::ReadU32LE()
|
uint32_t ByteReader::ReadU32LE()
|
||||||
{
|
{
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
if(this->strm->ReadBlock(data,4) != 4) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,4) != 4) throw std::runtime_error("End of file");
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
n |= (uint32_t)data[0];
|
n |= (uint32_t)data[0];
|
||||||
n |= (uint32_t)data[1] << 8;
|
n |= (uint32_t)data[1] << 8;
|
||||||
@@ -68,7 +68,7 @@ namespace Tesses::Framework::Streams
|
|||||||
uint64_t ByteReader::ReadU64BE()
|
uint64_t ByteReader::ReadU64BE()
|
||||||
{
|
{
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
if(this->strm->ReadBlock(data,8) != 8) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,8) != 8) throw std::runtime_error("End of file");
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
n |= (uint64_t)data[0] << 56;
|
n |= (uint64_t)data[0] << 56;
|
||||||
n |= (uint64_t)data[1] << 48;
|
n |= (uint64_t)data[1] << 48;
|
||||||
@@ -84,7 +84,7 @@ namespace Tesses::Framework::Streams
|
|||||||
uint64_t ByteReader::ReadU64LE()
|
uint64_t ByteReader::ReadU64LE()
|
||||||
{
|
{
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
if(this->strm->ReadBlock(data,8) != 8) throw TextException("End of file");
|
if(this->strm->ReadBlock(data,8) != 8) throw std::runtime_error("End of file");
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
n |= (uint64_t)data[0];
|
n |= (uint64_t)data[0];
|
||||||
n |= (uint64_t)data[1] << 8;
|
n |= (uint64_t)data[1] << 8;
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ namespace Tesses::Framework::Streams
|
|||||||
}
|
}
|
||||||
size_t FileStream::Read(uint8_t* buff, size_t sz)
|
size_t FileStream::Read(uint8_t* buff, size_t sz)
|
||||||
{
|
{
|
||||||
if(!CanRead()) throw TextException("Cannot read from stream");
|
if(!CanRead()) throw std::runtime_error("Cannot read from stream");
|
||||||
return fread(buff,1, sz, this->f);
|
return fread(buff,1, sz, this->f);
|
||||||
}
|
}
|
||||||
size_t FileStream::Write(const uint8_t* buff, size_t sz)
|
size_t FileStream::Write(const uint8_t* buff, size_t sz)
|
||||||
{
|
{
|
||||||
if(!CanWrite()) throw TextException("Cannot write to stream");
|
if(!CanWrite()) throw std::runtime_error("Cannot write to stream");
|
||||||
return fwrite(buff,1, sz, f);
|
return fwrite(buff,1, sz, f);
|
||||||
}
|
}
|
||||||
bool FileStream::CanRead()
|
bool FileStream::CanRead()
|
||||||
|
|||||||
@@ -45,23 +45,10 @@ static GXRModeObj *rmode = NULL;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
|
|
||||||
#include "TessesFramework/Threading/Mutex.hpp"
|
|
||||||
#endif
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#if defined(TESSESFRAMEWORK_FETCHCONTENT)
|
|
||||||
#include <SDL_ttf.h>
|
|
||||||
#include <SDL_image.h>
|
|
||||||
#else
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
#endif
|
|
||||||
#include "TessesFramework/SDL2/GUI.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Tesses::Framework
|
namespace Tesses::Framework
|
||||||
{
|
{
|
||||||
|
|
||||||
EventList<uint64_t> OnItteraton;
|
EventList<uint64_t> OnItteraton;
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
||||||
namespace Threading
|
namespace Threading
|
||||||
@@ -104,11 +91,6 @@ namespace Tesses::Framework
|
|||||||
static void _sigInt(int c)
|
static void _sigInt(int c)
|
||||||
{
|
{
|
||||||
isRunningSig=false;
|
isRunningSig=false;
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
SDL_Event quitEvent;
|
|
||||||
quitEvent.type = SDL_QUIT;
|
|
||||||
SDL_PushEvent(&quitEvent);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
void TF_RunEventLoop()
|
void TF_RunEventLoop()
|
||||||
{
|
{
|
||||||
@@ -177,9 +159,7 @@ namespace Tesses::Framework
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
Tesses::Framework::SDL2::gui.Update();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
void TF_SetIsRunning(bool _isRunning)
|
void TF_SetIsRunning(bool _isRunning)
|
||||||
{
|
{
|
||||||
@@ -191,11 +171,7 @@ namespace Tesses::Framework
|
|||||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
||||||
Tesses::Framework::Threading::JoinAllThreads();
|
Tesses::Framework::Threading::JoinAllThreads();
|
||||||
#endif
|
#endif
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
SDL_Quit();
|
|
||||||
Tesses::Framework::SDL2::gui.CloseWindows();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
void TF_Init()
|
void TF_Init()
|
||||||
{
|
{
|
||||||
@@ -206,20 +182,6 @@ namespace Tesses::Framework
|
|||||||
sqlite3_vfs_register(sqlite3_demovfs(),1);
|
sqlite3_vfs_register(sqlite3_demovfs(),1);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
|
||||||
//SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS,"1");
|
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
|
||||||
TTF_Init();
|
|
||||||
int r = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF | IMG_INIT_WEBP
|
|
||||||
#if !defined(GEKKO) && !defined(__SWITCH__) && !defined(__PS2__)
|
|
||||||
| IMG_INIT_JXL |IMG_INIT_AVIF
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
IMG_Init(
|
|
||||||
r
|
|
||||||
);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user