Skip to content

Commit 7b10915

Browse files
committed
Make it work !
1 parent 71e5ac0 commit 7b10915

File tree

10 files changed

+76
-25
lines changed

10 files changed

+76
-25
lines changed

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ endif()
5050
# Targets
5151
if (YUP_BUILD_EXAMPLES)
5252
message (STATUS "YUP -- Building examples")
53-
#add_subdirectory (examples/app)
54-
#add_subdirectory (examples/console)
53+
add_subdirectory (examples/app)
54+
add_subdirectory (examples/console)
5555
add_subdirectory (examples/graphics)
56-
#add_subdirectory (examples/render)
57-
if (NOT "${yup_platform}" STREQUAL "emscripten")
58-
#add_subdirectory (examples/plugin)
56+
add_subdirectory (examples/render)
57+
if (NOT "${yup_platform}" MATCHES "^(emscripten|android)$" AND NOT YUP_TARGET_ANDROID)
58+
add_subdirectory (examples/plugin)
5959
endif()
6060
endif()
6161

62-
if (YUP_BUILD_TESTS)
63-
#message (STATUS "YUP -- Building tests")
64-
#add_subdirectory (tests)
62+
if (YUP_BUILD_TESTS AND NOT YUP_TARGET_ANDROID)
63+
message (STATUS "YUP -- Building tests")
64+
add_subdirectory (tests)
6565
endif()

cmake/platforms/android/app/src/main/AndroidManifest.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:roundIcon="@mipmap/ic_launcher_round"
99
android:theme="@style/Theme.Application"
1010
android:fullBackupContent="@xml/backup_rules"
11+
android:screenOrientation="portrait"
1112
-->
1213

1314
<application

cmake/yup.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ function (yup_add_module module_path)
758758
list (APPEND module_dependencies ${module_android_dependencies})
759759
list (APPEND module_libs ${module_android_libs})
760760
list (APPEND module_defines ${module_android_defines})
761+
list (APPEND module_include_paths "${ANDROID_NDK}/sources/android/native_app_glue")
761762
elseif ("${yup_platform}" MATCHES "^(win32|uwp)$")
762763
list (APPEND module_dependencies ${module_windows_dependencies})
763764
list (APPEND module_defines ${module_windows_defines})
@@ -1075,6 +1076,7 @@ function (yup_add_embedded_binary_resources library_name)
10751076

10761077
set (binary_path "${CMAKE_CURRENT_BINARY_DIR}/${YUP_ARG_OUT_DIR}")
10771078
set (binary_header_path "${binary_path}/${YUP_ARG_HEADER}")
1079+
set (binary_sources "")
10781080

10791081
add_library (${library_name} OBJECT)
10801082

@@ -1103,7 +1105,7 @@ function (yup_add_embedded_binary_resources library_name)
11031105

11041106
# Add symbol to header
11051107
file (APPEND "${binary_header_path}"
1106-
"extern const uint8_t ${resource_name}[];\n"
1108+
"extern const uint8_t ${resource_name}_data[];\n"
11071109
"extern const std::size_t ${resource_name}_size;\n"
11081110
"\n")
11091111

@@ -1136,11 +1138,10 @@ function (yup_add_embedded_binary_resources library_name)
11361138
"} // namespace ${YUP_ARG_NAMESPACE}\n")
11371139
endif()
11381140

1139-
target_sources (${library_name} PRIVATE "${full_resource_unit_path}")
1140-
11411141
_yup_file_to_byte_array (${resource} resource_byte_array)
11421142
file (WRITE "${full_resource_hex_path}" "${resource_byte_array}")
11431143

1144+
list (APPEND binary_sources "${full_resource_unit_path}")
11441145
list (APPEND resources_hex_files "${full_resource_hex_path}")
11451146
endforeach()
11461147

@@ -1149,7 +1150,10 @@ function (yup_add_embedded_binary_resources library_name)
11491150
"} // namespace ${YUP_ARG_NAMESPACE}\n")
11501151
endif()
11511152

1152-
target_sources (${library_name} PUBLIC "${binary_header_path}")
1153+
target_sources (${library_name}
1154+
PUBLIC "${binary_header_path}"
1155+
PRIVATE "${binary_sources}")
1156+
11531157
target_include_directories (${library_name} PUBLIC "${binary_path}")
11541158

11551159
add_custom_target ("${library_name}_content" DEPENDS "${resources_hex_files}")

examples/console/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ cmake_minimum_required(VERSION 3.28)
2323
set (target_name example_console)
2424
set (target_version "1.0.0")
2525

26+
# ==== Prepare Android build
27+
if (ANDROID AND NOT YUP_TARGET_ANDROID_BUILD_GRADLE)
28+
# project (${target_name} VERSION ${target_version})
29+
include (../../cmake/yup.cmake)
30+
_yup_setup_platform()
31+
_yup_add_default_modules ("${CMAKE_CURRENT_LIST_DIR}/../..")
32+
endif()
33+
34+
# ==== Prepare target
2635
yup_standalone_app (
2736
TARGET_NAME ${target_name}
2837
TARGET_VERSION ${target_version}
@@ -38,6 +47,8 @@ yup_standalone_app (
3847
)
3948

4049
# ==== Prepare sources
41-
file (GLOB_RECURSE sources "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")
42-
source_group (TREE ${CMAKE_CURRENT_LIST_DIR}/ FILES ${sources})
43-
target_sources (${target_name} PRIVATE ${sources})
50+
if (NOT YUP_TARGET_ANDROID_BUILD_GRADLE)
51+
file (GLOB_RECURSE sources "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")
52+
source_group (TREE ${CMAKE_CURRENT_LIST_DIR}/ FILES ${sources})
53+
target_sources (${target_name} PRIVATE ${sources})
54+
endif()

examples/render/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,24 @@ if ("${yup_platform}" MATCHES "^(emscripten)$")
2929
endif()
3030

3131
# ==== Prepare Android build
32+
set (link_libraries "")
3233
if (ANDROID AND NOT YUP_TARGET_ANDROID_BUILD_GRADLE)
3334
# project (${target_name} VERSION ${target_version})
3435
include (../../cmake/yup.cmake)
3536
_yup_setup_platform()
3637
_yup_add_default_modules ("${CMAKE_CURRENT_LIST_DIR}/../..")
38+
39+
yup_add_embedded_binary_resources (
40+
BinaryData
41+
OUT_DIR BinaryData
42+
HEADER BinaryData.h
43+
NAMESPACE yup
44+
RESOURCE_NAMES
45+
RiveFile
46+
RESOURCES
47+
${CMAKE_CURRENT_LIST_DIR}/data/alien.riv
48+
)
49+
set (link_libraries BinaryData)
3750
endif()
3851

3952
# ==== Prepare target
@@ -56,6 +69,7 @@ yup_standalone_app (
5669
sheenbidi
5770
rive
5871
rive_renderer
72+
${link_libraries}
5973
)
6074

6175
# ==== Prepare sources

examples/render/source/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
#include <memory>
2828

29+
#if JUCE_ANDROID
30+
#include <BinaryData.h>
31+
#endif
32+
2933
//==============================================================================
3034

3135
class CustomWindow
@@ -54,7 +58,12 @@ class CustomWindow
5458
auto art = artboards.add (std::make_unique<yup::Artboard> (yup::String ("art") + yup::String (i)));
5559
addAndMakeVisible (art);
5660

61+
#if JUCE_ANDROID
62+
yup::MemoryInputStream is(yup::RiveFile_data, yup::RiveFile_size, false);
63+
art->loadFromStream (is, 0, false);
64+
#else
5765
art->loadFromFile (riveFilePath, 0, false);
66+
#endif
5867
}
5968

6069
// Grab focus

modules/yup_gui/artboard/yup_Artboard.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,28 @@ Artboard::Artboard (StringRef componentID)
3131

3232
//==============================================================================
3333

34-
Result Artboard::loadFromFile (const juce::File& file, int defaultArtboardIndex, bool shouldUseStateMachines)
34+
Result Artboard::loadFromFile (const File& file, int defaultArtboardIndex, bool shouldUseStateMachines)
3535
{
36-
jassert (getNativeComponent() != nullptr); // Must be added to a NativeComponent !
37-
38-
rive::Factory* factory = getNativeComponent()->getFactory();
39-
if (factory == nullptr)
40-
return Result::fail ("Failed to create a graphics context");
41-
4236
if (! file.existsAsFile())
4337
return Result::fail ("Failed to find file to load");
4438

4539
auto is = file.createInputStream();
4640
if (is == nullptr || ! is->openedOk())
4741
return Result::fail ("Failed to open file for reading");
4842

43+
return loadFromStream (*is, defaultArtboardIndex, shouldUseStateMachines);
44+
}
45+
46+
Result Artboard::loadFromStream (InputStream& is, int defaultArtboardIndex, bool shouldUseStateMachines)
47+
{
48+
jassert (getNativeComponent() != nullptr); // Must be added to a NativeComponent !
49+
50+
rive::Factory* factory = getNativeComponent()->getFactory();
51+
if (factory == nullptr)
52+
return Result::fail ("Failed to create a graphics context");
53+
4954
yup::MemoryBlock mb;
50-
is->readIntoMemoryBlock (mb);
55+
is.readIntoMemoryBlock (mb);
5156

5257
rivFile = rive::File::import ({ static_cast<const uint8_t*> (mb.getData()), mb.getSize() }, factory);
5358
artboardIndex = jlimit (-1, static_cast<int> (rivFile->artboardCount()) - 1, defaultArtboardIndex);

modules/yup_gui/artboard/yup_Artboard.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class JUCE_API Artboard : public Component
3030
Artboard (StringRef componentID);
3131

3232
//==============================================================================
33-
Result loadFromFile (const juce::File& file, int defaultArtboardIndex = -1, bool shouldUseStateMachines = true);
33+
Result loadFromFile (const File& file, int defaultArtboardIndex = -1, bool shouldUseStateMachines = true);
34+
Result loadFromStream (InputStream& is, int defaultArtboardIndex = -1, bool shouldUseStateMachines = true);
3435

3536
//==============================================================================
3637
bool isPaused() const;

modules/yup_gui/native/yup_Windowing_glfw.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,9 @@ void* GLFWComponentNative::getNativeHandle() const
912912
#elif JUCE_LINUX
913913
return reinterpret_cast<void*> (glfwGetX11Window (window));
914914

915+
#elif JUCE_ANDROID
916+
return reinterpret_cast<void*> (glfwGetAndroidApp (window)->window);
917+
915918
#else
916919
return nullptr;
917920

@@ -997,6 +1000,9 @@ void GLFWComponentNative::renderContext()
9971000
jassert (context != nullptr);
9981001

9991002
auto [contentWidth, contentHeight] = getContentSize();
1003+
if (contentWidth == 0 || contentHeight == 0)
1004+
return;
1005+
10001006
auto renderContinuous = shouldRenderContinuous.load (std::memory_order_relaxed);
10011007

10021008
if (forceSizeChange || currentContentWidth != contentWidth || currentContentHeight != contentHeight)

modules/yup_gui/yup_gui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
#elif JUCE_ANDROID
8181
#define GLFW_INCLUDE_NONE
82-
//#define GLFW_EXPOSE_NATIVE_ANDROID
82+
#define GLFW_EXPOSE_NATIVE_ANDROID
8383
#include <GLFW/glfw3.h>
8484
#include <GLFW/glfw3native.h>
8585

0 commit comments

Comments
 (0)