From: start1a Date: Tue, 6 Oct 2020 06:21:16 +0000 (+0900) Subject: rename directory rlottiePlayer to win32Player X-Git-Tag: submit/tizen/20201101.231042~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52d614e80e1957565f619e3f36cecfa1055ce78a;p=platform%2Fcore%2Fuifw%2Flottie-player.git rename directory rlottiePlayer to win32Player --- diff --git a/example/rlottiePlayer/Source.cpp b/example/rlottiePlayer/Source.cpp deleted file mode 100644 index 99ea876..0000000 --- a/example/rlottiePlayer/Source.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "rlottie.h" -#include "animation.h" -using namespace rlottie; - -std::unique_ptr anim; -uint32_t *buffer; -size_t width, height; -size_t bytesPerLine; -uint32_t curColor = UINT32_MAX; - -void setAnimationSize(size_t w, size_t h) -{ - width = w; - height = h; - bytesPerLine = width * sizeof(uint32_t); - - if (buffer != NULL) freeAnimation(); - buffer = (uint32_t*)calloc(bytesPerLine * height, sizeof(uint32_t)); -} - -void setAnimation(char* path, size_t* w, size_t* h) -{ - anim = Animation::loadFromFile(path); - anim->size(*w, *h); - setAnimationSize(*w, *h); -} - -uint32_t* renderRLottieAnimation(uint32_t frameNum) -{ - Surface surface = Surface(buffer, width, height, bytesPerLine); - anim->renderSync(frameNum, surface); - // background color - for (int i = 0; i < height; i++) - for (int j = 0; j < width; ++j) - { - uint32_t* v = buffer + i * width + j; - if (*v == 0) *v = curColor; - } - return buffer; -} - -void setAnimationColor(int r, int g, int b) -{ - curColor = ((255 << 16) * r) + ((255 << 8) * g) + 255 * b; -} - -size_t getTotalFrame() -{ - return anim->totalFrame(); -} - -bool isAnimNULL() -{ - return anim == NULL; -} - -void freeAnimation() -{ - free(buffer); -} \ No newline at end of file diff --git a/example/rlottiePlayer/animation.h b/example/rlottiePlayer/animation.h deleted file mode 100644 index 483cb3f..0000000 --- a/example/rlottiePlayer/animation.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -void setAnimation(char* path, size_t* w, size_t* h); -void setAnimationSize(size_t w, size_t h); -uint32_t* renderRLottieAnimation(uint32_t frameNum); -size_t getTotalFrame(); -bool isAnimNULL(); -void setAnimationColor(int r, int g, int b); -void freeAnimation(); \ No newline at end of file diff --git a/example/rlottiePlayer/framework.h b/example/rlottiePlayer/framework.h deleted file mode 100644 index 33a6be6..0000000 --- a/example/rlottiePlayer/framework.h +++ /dev/null @@ -1,15 +0,0 @@ -// header.h : include file for standard system include files, -// or project specific include files -// - -#pragma once - -#include "targetver.h" -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files -#include -// C RunTime Header Files -#include -#include -#include -#include diff --git a/example/rlottiePlayer/resource.h b/example/rlottiePlayer/resource.h deleted file mode 100644 index ac46939..0000000 --- a/example/rlottiePlayer/resource.h +++ /dev/null @@ -1,40 +0,0 @@ -//{{NO_DEPENDENCIES}} -// This is an include file generated by Microsoft Visual C++. -// It is being used in rlottiePlayer.rc. -// -#define IDC_MYICON 2 -#define IDD_RLOTTIEPLAYER_DIALOG 102 -#define IDS_APP_TITLE 103 -#define IDD_ABOUTBOX 103 -#define IDM_ABOUT 104 -#define IDM_EXIT 105 -#define IDI_RLOTTIEPLAYER 107 -#define IDI_SMALL 108 -#define IDC_RLOTTIEPLAYER 109 -#define IDR_MAINFRAME 128 -#define MAIN_WINDOW 130 -#define BTN_BROWSE 1004 -#define BTN_WHITE 1005 -#define BTN_BLACK 1006 -#define BTN_RED 1007 -#define BTN_GREEN 1008 -#define BTN_BLUE 1009 -#define SLIDER_CANVAS_RESIZE 1010 -#define BTN_PLAY 1011 -#define SLIDER_PLAY 1012 -#define TEXT_FILENAME 1013 -#define PICCTRL_RLOTTIE 1014 -#define TIMER_PLAY_ANIM 1015 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 131 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1017 -#define _APS_NEXT_SYMED_VALUE 110 -#endif -#endif diff --git a/example/rlottiePlayer/rlottie.dll b/example/rlottiePlayer/rlottie.dll deleted file mode 100644 index 296f70a..0000000 Binary files a/example/rlottiePlayer/rlottie.dll and /dev/null differ diff --git a/example/rlottiePlayer/rlottie.lib b/example/rlottiePlayer/rlottie.lib deleted file mode 100644 index 2625916..0000000 Binary files a/example/rlottiePlayer/rlottie.lib and /dev/null differ diff --git a/example/rlottiePlayer/rlottiePlayer.cpp b/example/rlottiePlayer/rlottiePlayer.cpp deleted file mode 100644 index b2d0431..0000000 --- a/example/rlottiePlayer/rlottiePlayer.cpp +++ /dev/null @@ -1,521 +0,0 @@ -// rlottiePlayer.cpp : Defines the entry point for the application. -// - - -#include "framework.h" -#include "rlottiePlayer.h" -using namespace Gdiplus; - -#define MAX_LOADSTRING 100 - -// Global Variables: -HINSTANCE hInst; // current instance -WCHAR szTitle[MAX_LOADSTRING]; // The title bar text -WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name -HWND mainWindow; // Main Window Instance -HWND hTextFileToBeOpened; // openDialog file path -HWND hBtnPlay; -HWND hSliderPlay, hSliderCanvasResize; -UINT curFrame = 0; -RlottieBitmap anim; // rendered Animation Bitmap -RECT animRect, backRect; -size_t animWidth, animHeight; -Gdiplus::Color backColor(255, 255, 255, 255); -Gdiplus::Color borderColor(255, 0, 0, 0); -bool isViewChanged = false; - -// Forward declarations of functions included in this code module: -ATOM MyRegisterClass(HINSTANCE hInstance); -BOOL InitInstance(HINSTANCE, int); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -void openJSONFileDialog(HWND); -void initUIControl(HWND); -void dlgUICommand(HWND, WPARAM); -void resizeCanvas(HWND, int); -void changeBackgroundColor(int r, int g, int b); - -// Animation Rendering Functions -void draw(HDC); -Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height); -void renderAnimation(UINT); - -int APIENTRY wWinMain(_In_ HINSTANCE hInstance, - _In_opt_ HINSTANCE hPrevInstance, - _In_ LPWSTR lpCmdLine, - _In_ int nCmdShow) -{ - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - - // initialize Gdiplus - Gdiplus::GdiplusStartupInput gdiplusStartUpInput; - ULONG_PTR gdiplustoken; - Gdiplus::GdiplusStartup(&gdiplustoken, &gdiplusStartUpInput, nullptr); - - // Initialize global strings - LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadStringW(hInstance, IDC_RLOTTIEPLAYER, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); - - // Perform application initialization: - if (!InitInstance(hInstance, nCmdShow)) - { - return FALSE; - } - - HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_RLOTTIEPLAYER)); - - MSG msg; - - // Main message loop: - while (GetMessage(&msg, nullptr, 0, 0)) - { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - Gdiplus::GdiplusShutdown(gdiplustoken); - return (int)msg.wParam; -} - - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEXW wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_RLOTTIEPLAYER)); - wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_RLOTTIEPLAYER); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); - - return RegisterClassExW(&wcex); -} - -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - hInst = hInstance; // Store instance handle in our global variable - - DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; - mainWindow = CreateWindowEx(0, szWindowClass, szTitle, dwStyle, - CW_USEDEFAULT, CW_USEDEFAULT, WND_WIDTH, WND_HEIGHT, nullptr, nullptr, hInstance, nullptr); - - if (!mainWindow) - { - return FALSE; - } - - ShowWindow(mainWindow, nCmdShow); - UpdateWindow(mainWindow); - SetMenu(mainWindow, NULL); - - return TRUE; -} - -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - static bool isplay = false; - int wmId = LOWORD(wParam); - - switch (message) - { - case WM_CREATE: - { - initUIControl(hWnd); - break; - } - case WM_TIMER: - { - switch (wmId) - { - case TIMER_PLAY_ANIM: - { - renderAnimation(curFrame + 1); - SendMessage(hSliderPlay, TBM_SETPOS, TRUE, curFrame); - break; - } - default: - break; - } - break; - } - case WM_COMMAND: - { - // Parse the menu selections: - switch (wmId) - { - case IDM_ABOUT: - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); - break; - - case IDM_EXIT: - DestroyWindow(hWnd); - break; - - case BTN_BROWSE: - openJSONFileDialog(hWnd); - break; - - case BTN_PLAY: - { - LPWSTR textBtnPlay; - USES_CONVERSION; - if (isplay) - { - isplay = false; - textBtnPlay = A2W("Play"); - KillTimer(hWnd, TIMER_PLAY_ANIM); - } - else - { - isplay = true; - textBtnPlay = A2W("Pause"); - SetTimer(hWnd, TIMER_PLAY_ANIM, 10, NULL); - } - SetWindowText(hBtnPlay, textBtnPlay); - break; - } - - case WM_DROPFILES: - break; - case BTN_WHITE: - changeBackgroundColor(1, 1, 1); - break; - case BTN_BLACK: - changeBackgroundColor(0, 0, 0); - break; - case BTN_RED: - changeBackgroundColor(1, 0, 0); - break; - case BTN_GREEN: - changeBackgroundColor(0, 1, 0); - break; - case BTN_BLUE: - changeBackgroundColor(0, 0, 1); - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - } - break; - - case WM_HSCROLL: - { - if ((lParam != 0) && (reinterpret_cast(lParam) == hSliderPlay)) - { - UINT frameNum = SendDlgItemMessage(hWnd, SLIDER_PLAY, TBM_GETPOS, 0, 0); - renderAnimation(frameNum); - } - else if ((lParam != 0) && (reinterpret_cast(lParam) == hSliderCanvasResize)) - { - static int curSize = anim.width / RESIZE_LENGTH; - int newSize = SendDlgItemMessage(hWnd, SLIDER_CANVAS_RESIZE, TBM_GETPOS, 0, 0); - resizeCanvas(hWnd, (curSize - newSize) * RESIZE_LENGTH); - curSize = newSize; - } - break; - } - - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc = BeginPaint(hWnd, &ps); - draw(hdc); - EndPaint(hWnd, &ps); - } - break; - case WM_CTLCOLORSTATIC: - { - static HBRUSH hBrushEdit = CreateSolidBrush(RGB(255, 255, 255)); - return (LRESULT)hBrushEdit; - } - - case WM_DESTROY: - freeAnimation(); - PostQuitMessage(0); - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} - -// Message handler for about box. -INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - return (INT_PTR)TRUE; - - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; - } - break; - } - return (INT_PTR)FALSE; -} - -void openJSONFileDialog(HWND hDlg) -{ - OPENFILENAME ofn; // common dialog box structure - TCHAR szFile[260] = { 0 }; // if using TCHAR macros - - // Initialize OPENFILENAME - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = hDlg; - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = _T("JSON\0*.json\0"); - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - - isViewChanged = true; - if (GetOpenFileName(&ofn)) - { - isViewChanged = true; - SetWindowText(hTextFileToBeOpened, ofn.lpstrFile); - // LPWSTR(w_char*) -> LPSTR(char*) - USES_CONVERSION; - LPSTR path = W2A(ofn.lpstrFile); - - setAnimation(path, &animWidth, &animHeight); - // init play slider - SendMessage(hSliderPlay, TBM_SETRANGE, FALSE, MAKELPARAM(0, getTotalFrame())); - SendMessage(hSliderPlay, TBM_SETPOS, TRUE, 0); - renderAnimation(0); - } -} - -void draw(HDC hdc) -{ - Graphics gf(hdc); - int half_interval = UI_INTERVAL / 2; - - // background - SolidBrush brush(backColor); - int back_y = half_interval + BTN_HEIGHT; - int back_height = back_y + BMP_MAX_LEN + UI_INTERVAL; - if (isViewChanged) - { - isViewChanged = false; - gf.FillRectangle(&brush, 0, back_y, WND_WIDTH, back_height); - } - - // image borderline - Pen pen(borderColor); - gf.DrawRectangle(&pen, anim.x - half_interval, anim.y - half_interval, anim.width + half_interval * 2, anim.height + half_interval * 2); - - // image - if (anim.image != NULL) - { - gf.DrawImage(anim.image, anim.x, anim.y, anim.width, anim.height); - } -} - -Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height) -{ - BITMAPINFO Info; - memset(&Info, 0, sizeof(Info)); - - Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - Info.bmiHeader.biWidth = width; - Info.bmiHeader.biHeight = height; - Info.bmiHeader.biPlanes = 1; - Info.bmiHeader.biBitCount = 32; - Info.bmiHeader.biCompression = BI_RGB; - Info.bmiHeader.biSizeImage = 0; //(((32 * width + 31) & ~31) / 8) * height; - - return new Gdiplus::Bitmap(&Info, data); -} - -void renderAnimation(UINT frameNum) -{ - if (isAnimNULL()) return; - if (anim.image != NULL) delete anim.image; - - curFrame = frameNum % getTotalFrame(); - - // render - UINT* resRender = renderRLottieAnimation(curFrame); - anim.image = CreateBitmap(resRender, animWidth, animHeight); - anim.image->RotateFlip(RotateNoneFlipY); - // call WM_PAINT message - InvalidateRect(mainWindow, &animRect, FALSE); -} - -void initUIControl(HWND hWnd) -{ - int half_ui_interval = UI_INTERVAL / 2; - - // button browse - int browse_x = UI_INTERVAL; - int browse_y = half_ui_interval; - CreateWindow(L"button", L"Browse", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, - browse_x, browse_y, BTN_WIDTH, BTN_HEIGHT, hWnd, (HMENU)BTN_BROWSE, hInst, NULL); - - // textbox FilePath - int textFile_x = browse_x + BTN_WIDTH + UI_INTERVAL; - int textFile_y = browse_y; - hTextFileToBeOpened = CreateWindowEx(0, L"static", L"No file selected.", WS_CHILD | WS_VISIBLE | ES_LEFT, - textFile_x, textFile_y, WND_WIDTH * 0.6, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); - - // image - anim.x = WND_WIDTH / 4; - anim.y = browse_y + BTN_HEIGHT + UI_INTERVAL * 2; - anim.width = BMP_MAX_LEN; - anim.height = anim.width; - - // animating range - SetRect(&animRect, - anim.x - UI_INTERVAL, - anim.y - UI_INTERVAL, - anim.x + anim.width + UI_INTERVAL * 2, - anim.y + anim.height + UI_INTERVAL * 2 - ); - - // background range - SetRect(&backRect, - 0, - anim.y - UI_INTERVAL, - WND_WIDTH, - anim.y + anim.height + UI_INTERVAL * 2 - ); - - // text Background Color - int textBC_x = WND_WIDTH / 20; - int textBC_y = anim.y + anim.height + UI_INTERVAL * 2; - CreateWindowEx(0, L"static", L"Background Color", WS_CHILD | WS_VISIBLE | ES_LEFT, - textBC_x, textBC_y, 120, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); - - // radio button - // white - int white_x = WND_WIDTH / 20; - int white_y = textBC_y + TEXT_HEIGHT + half_ui_interval; - CreateWindowEx(0, L"button", L"White", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, - white_x, white_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_WHITE, hInst, NULL); - - // black - int black_x = white_x + RDOBTN_WIDTH + half_ui_interval; - int black_y = white_y; - CreateWindowEx(0, L"button", L"Black", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, - black_x, black_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_BLACK, hInst, NULL); - - // red - int red_x = black_x + RDOBTN_WIDTH + half_ui_interval; - int red_y = white_y; - CreateWindowEx(0, L"button", L"Red", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, - red_x, red_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_RED, hInst, NULL); - - // green - int green_x = red_x + RDOBTN_WIDTH + half_ui_interval; - int green_y = white_y; - CreateWindowEx(0, L"button", L"Green", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, - green_x, green_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_GREEN, hInst, NULL); - - // blue - int blue_x = green_x + RDOBTN_WIDTH + half_ui_interval; - int blue_y = white_y; - CreateWindowEx(0, L"button", L"Blue", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, - blue_x, blue_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_BLUE, hInst, NULL); - - CheckRadioButton(hWnd, BTN_WHITE, BTN_BLUE, BTN_WHITE); - - // text Canvas Resize - int textCR_x = WND_WIDTH / 2; - int textCR_y = textBC_y; - CreateWindowEx(0, L"static", L"Canvas Resize", WS_CHILD | WS_VISIBLE | ES_LEFT, - textCR_x, textCR_y, 120, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); - - // slider Canvas Resize - int sliderCR_x = textCR_x; - int sliderCR_y = textCR_y + TEXT_HEIGHT + half_ui_interval; - hSliderCanvasResize = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD | WS_VISIBLE | TBS_FIXEDLENGTH | TBS_NOTICKS, - sliderCR_x, sliderCR_y, WND_WIDTH * 0.2, SLIDER_HEIGHT, hWnd, (HMENU)SLIDER_CANVAS_RESIZE, hInst, NULL); - - // init resize slider - UINT sizeSlider = anim.width / RESIZE_LENGTH; - SendMessage(hSliderCanvasResize, TBM_SETRANGE, FALSE, MAKELPARAM(0, sizeSlider)); - SendMessage(hSliderCanvasResize, TBM_SETPOS, TRUE, sizeSlider); - - // button play - int btnPlay_x = WND_WIDTH / 10; - int btnPlay_y = red_y + RDOBTN_HEIGHT + UI_INTERVAL * 2; - hBtnPlay = CreateWindow(L"button", L"Play", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, - btnPlay_x, btnPlay_y, BTN_WIDTH, BTN_HEIGHT, hWnd, (HMENU)BTN_PLAY, hInst, NULL); - - // slider play - int sliderPlay_x = btnPlay_x + BTN_WIDTH + UI_INTERVAL; - int sliderPlay_y = btnPlay_y; - hSliderPlay = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD | WS_VISIBLE | TBS_FIXEDLENGTH | TBS_NOTICKS, - sliderPlay_x, sliderPlay_y, WND_WIDTH * 0.6, SLIDER_HEIGHT, hWnd, (HMENU)SLIDER_PLAY, hInst, NULL); -} - -void resizeCanvas(HWND hWnd, int resizeValue) -{ - isViewChanged = true; - anim.x += resizeValue / 2; - anim.y += resizeValue / 2; - anim.width -= resizeValue; - anim.height -= resizeValue; - InvalidateRect(hWnd, &animRect, TRUE); -} - -void changeBackgroundColor(int r, int g, int b) -{ - isViewChanged = true; - backColor = Gdiplus::Color(r * 255, g * 255, b * 255); - if (r + g + b == 0) borderColor = Gdiplus::Color(255, 255, 255); - else borderColor = Gdiplus::Color(0, 0, 0); - setAnimationColor(r, g, b); - renderAnimation(curFrame); - InvalidateRect(mainWindow, &backRect, FALSE); -} \ No newline at end of file diff --git a/example/rlottiePlayer/rlottiePlayer.h b/example/rlottiePlayer/rlottiePlayer.h deleted file mode 100644 index 07e5fd2..0000000 --- a/example/rlottiePlayer/rlottiePlayer.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "resource.h" -#include "animation.h" -#include // OPENFILENAME -#include "atlconv.h" // String cast. (ex. LPWSTR <-> LPSTR) -#include -#include // slider handle - -// interval -#define UI_INTERVAL 20 - -// length -#define WND_WIDTH 1000 -#define WND_HEIGHT 800 -#define BMP_MAX_LEN 500 -#define BTN_WIDTH 100 -#define BTN_HEIGHT 30 -#define TEXT_HEIGHT 20 -#define SLIDER_HEIGHT 25 -#define RDOBTN_WIDTH 60 -#define RDOBTN_HEIGHT 20 -#define RESIZE_LENGTH 10 - -typedef struct RlottieBitmap -{ - Gdiplus::Bitmap* image = NULL; - int x = 0; - int y = 0; - unsigned int width = 0; - unsigned int height = 0; -}RlottieBitmap; \ No newline at end of file diff --git a/example/rlottiePlayer/rlottiePlayer.ico b/example/rlottiePlayer/rlottiePlayer.ico deleted file mode 100644 index b3ec03b..0000000 Binary files a/example/rlottiePlayer/rlottiePlayer.ico and /dev/null differ diff --git a/example/rlottiePlayer/rlottiePlayer.rc b/example/rlottiePlayer/rlottiePlayer.rc deleted file mode 100644 index 0c7935f..0000000 Binary files a/example/rlottiePlayer/rlottiePlayer.rc and /dev/null differ diff --git a/example/rlottiePlayer/rlottiePlayer.sln b/example/rlottiePlayer/rlottiePlayer.sln deleted file mode 100644 index d1c8f0d..0000000 --- a/example/rlottiePlayer/rlottiePlayer.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30503.244 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rlottiePlayer", "rlottiePlayer.vcxproj", "{CC7AD634-4D29-4D8E-997D-9727DABB44EE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x64.ActiveCfg = Debug|x64 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x64.Build.0 = Debug|x64 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x86.ActiveCfg = Debug|Win32 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x86.Build.0 = Debug|Win32 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x64.ActiveCfg = Release|x64 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x64.Build.0 = Release|x64 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x86.ActiveCfg = Release|Win32 - {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {57EEA15F-28FB-4C19-96B4-7B62BFA0CFE5} - EndGlobalSection -EndGlobal diff --git a/example/rlottiePlayer/rlottiePlayer.vcxproj b/example/rlottiePlayer/rlottiePlayer.vcxproj deleted file mode 100644 index 18e6533..0000000 --- a/example/rlottiePlayer/rlottiePlayer.vcxproj +++ /dev/null @@ -1,164 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {cc7ad634-4d29-4d8e-997d-9727dabb44ee} - rlottiePlayer - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - ..\..\inc;$(IncludePath) - - - false - - - - Level3 - true - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - Level3 - true - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - - - Windows - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;rlottie.lib;gdiplus.lib;%(AdditionalDependencies) - - - - - Level3 - true - true - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/rlottiePlayer/rlottiePlayer.vcxproj.filters b/example/rlottiePlayer/rlottiePlayer.vcxproj.filters deleted file mode 100644 index c8cf65b..0000000 --- a/example/rlottiePlayer/rlottiePlayer.vcxproj.filters +++ /dev/null @@ -1,55 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - - - Resource Files - - - - - Resource Files - - - Resource Files - - - \ No newline at end of file diff --git a/example/rlottiePlayer/rlottiePlayer.vcxproj.user b/example/rlottiePlayer/rlottiePlayer.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/example/rlottiePlayer/rlottiePlayer.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/example/rlottiePlayer/small.ico b/example/rlottiePlayer/small.ico deleted file mode 100644 index b3ec03b..0000000 Binary files a/example/rlottiePlayer/small.ico and /dev/null differ diff --git a/example/rlottiePlayer/targetver.h b/example/rlottiePlayer/targetver.h deleted file mode 100644 index bf75e08..0000000 --- a/example/rlottiePlayer/targetver.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -// // Including SDKDDKVer.h defines the highest available Windows platform. -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. -#include diff --git a/example/win32Player/Source.cpp b/example/win32Player/Source.cpp new file mode 100644 index 0000000..99ea876 --- /dev/null +++ b/example/win32Player/Source.cpp @@ -0,0 +1,60 @@ +#include "rlottie.h" +#include "animation.h" +using namespace rlottie; + +std::unique_ptr anim; +uint32_t *buffer; +size_t width, height; +size_t bytesPerLine; +uint32_t curColor = UINT32_MAX; + +void setAnimationSize(size_t w, size_t h) +{ + width = w; + height = h; + bytesPerLine = width * sizeof(uint32_t); + + if (buffer != NULL) freeAnimation(); + buffer = (uint32_t*)calloc(bytesPerLine * height, sizeof(uint32_t)); +} + +void setAnimation(char* path, size_t* w, size_t* h) +{ + anim = Animation::loadFromFile(path); + anim->size(*w, *h); + setAnimationSize(*w, *h); +} + +uint32_t* renderRLottieAnimation(uint32_t frameNum) +{ + Surface surface = Surface(buffer, width, height, bytesPerLine); + anim->renderSync(frameNum, surface); + // background color + for (int i = 0; i < height; i++) + for (int j = 0; j < width; ++j) + { + uint32_t* v = buffer + i * width + j; + if (*v == 0) *v = curColor; + } + return buffer; +} + +void setAnimationColor(int r, int g, int b) +{ + curColor = ((255 << 16) * r) + ((255 << 8) * g) + 255 * b; +} + +size_t getTotalFrame() +{ + return anim->totalFrame(); +} + +bool isAnimNULL() +{ + return anim == NULL; +} + +void freeAnimation() +{ + free(buffer); +} \ No newline at end of file diff --git a/example/win32Player/animation.h b/example/win32Player/animation.h new file mode 100644 index 0000000..483cb3f --- /dev/null +++ b/example/win32Player/animation.h @@ -0,0 +1,10 @@ +#pragma once +#include + +void setAnimation(char* path, size_t* w, size_t* h); +void setAnimationSize(size_t w, size_t h); +uint32_t* renderRLottieAnimation(uint32_t frameNum); +size_t getTotalFrame(); +bool isAnimNULL(); +void setAnimationColor(int r, int g, int b); +void freeAnimation(); \ No newline at end of file diff --git a/example/win32Player/framework.h b/example/win32Player/framework.h new file mode 100644 index 0000000..33a6be6 --- /dev/null +++ b/example/win32Player/framework.h @@ -0,0 +1,15 @@ +// header.h : include file for standard system include files, +// or project specific include files +// + +#pragma once + +#include "targetver.h" +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include +// C RunTime Header Files +#include +#include +#include +#include diff --git a/example/win32Player/resource.h b/example/win32Player/resource.h new file mode 100644 index 0000000..ac46939 --- /dev/null +++ b/example/win32Player/resource.h @@ -0,0 +1,40 @@ +//{{NO_DEPENDENCIES}} +// This is an include file generated by Microsoft Visual C++. +// It is being used in rlottiePlayer.rc. +// +#define IDC_MYICON 2 +#define IDD_RLOTTIEPLAYER_DIALOG 102 +#define IDS_APP_TITLE 103 +#define IDD_ABOUTBOX 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDI_RLOTTIEPLAYER 107 +#define IDI_SMALL 108 +#define IDC_RLOTTIEPLAYER 109 +#define IDR_MAINFRAME 128 +#define MAIN_WINDOW 130 +#define BTN_BROWSE 1004 +#define BTN_WHITE 1005 +#define BTN_BLACK 1006 +#define BTN_RED 1007 +#define BTN_GREEN 1008 +#define BTN_BLUE 1009 +#define SLIDER_CANVAS_RESIZE 1010 +#define BTN_PLAY 1011 +#define SLIDER_PLAY 1012 +#define TEXT_FILENAME 1013 +#define PICCTRL_RLOTTIE 1014 +#define TIMER_PLAY_ANIM 1015 +#define IDC_STATIC -1 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 131 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1017 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif diff --git a/example/win32Player/rlottie.dll b/example/win32Player/rlottie.dll new file mode 100644 index 0000000..296f70a Binary files /dev/null and b/example/win32Player/rlottie.dll differ diff --git a/example/win32Player/rlottie.lib b/example/win32Player/rlottie.lib new file mode 100644 index 0000000..2625916 Binary files /dev/null and b/example/win32Player/rlottie.lib differ diff --git a/example/win32Player/rlottiePlayer.cpp b/example/win32Player/rlottiePlayer.cpp new file mode 100644 index 0000000..b2d0431 --- /dev/null +++ b/example/win32Player/rlottiePlayer.cpp @@ -0,0 +1,521 @@ +// rlottiePlayer.cpp : Defines the entry point for the application. +// + + +#include "framework.h" +#include "rlottiePlayer.h" +using namespace Gdiplus; + +#define MAX_LOADSTRING 100 + +// Global Variables: +HINSTANCE hInst; // current instance +WCHAR szTitle[MAX_LOADSTRING]; // The title bar text +WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name +HWND mainWindow; // Main Window Instance +HWND hTextFileToBeOpened; // openDialog file path +HWND hBtnPlay; +HWND hSliderPlay, hSliderCanvasResize; +UINT curFrame = 0; +RlottieBitmap anim; // rendered Animation Bitmap +RECT animRect, backRect; +size_t animWidth, animHeight; +Gdiplus::Color backColor(255, 255, 255, 255); +Gdiplus::Color borderColor(255, 0, 0, 0); +bool isViewChanged = false; + +// Forward declarations of functions included in this code module: +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); +void openJSONFileDialog(HWND); +void initUIControl(HWND); +void dlgUICommand(HWND, WPARAM); +void resizeCanvas(HWND, int); +void changeBackgroundColor(int r, int g, int b); + +// Animation Rendering Functions +void draw(HDC); +Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height); +void renderAnimation(UINT); + +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPWSTR lpCmdLine, + _In_ int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + // initialize Gdiplus + Gdiplus::GdiplusStartupInput gdiplusStartUpInput; + ULONG_PTR gdiplustoken; + Gdiplus::GdiplusStartup(&gdiplustoken, &gdiplusStartUpInput, nullptr); + + // Initialize global strings + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_RLOTTIEPLAYER, szWindowClass, MAX_LOADSTRING); + MyRegisterClass(hInstance); + + // Perform application initialization: + if (!InitInstance(hInstance, nCmdShow)) + { + return FALSE; + } + + HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_RLOTTIEPLAYER)); + + MSG msg; + + // Main message loop: + while (GetMessage(&msg, nullptr, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + Gdiplus::GdiplusShutdown(gdiplustoken); + return (int)msg.wParam; +} + + + +// +// FUNCTION: MyRegisterClass() +// +// PURPOSE: Registers the window class. +// +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEXW wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_RLOTTIEPLAYER)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_RLOTTIEPLAYER); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassExW(&wcex); +} + +// +// FUNCTION: InitInstance(HINSTANCE, int) +// +// PURPOSE: Saves instance handle and creates main window +// +// COMMENTS: +// +// In this function, we save the instance handle in a global variable and +// create and display the main program window. +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + hInst = hInstance; // Store instance handle in our global variable + + DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; + mainWindow = CreateWindowEx(0, szWindowClass, szTitle, dwStyle, + CW_USEDEFAULT, CW_USEDEFAULT, WND_WIDTH, WND_HEIGHT, nullptr, nullptr, hInstance, nullptr); + + if (!mainWindow) + { + return FALSE; + } + + ShowWindow(mainWindow, nCmdShow); + UpdateWindow(mainWindow); + SetMenu(mainWindow, NULL); + + return TRUE; +} + +// +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) +// +// PURPOSE: Processes messages for the main window. +// +// WM_COMMAND - process the application menu +// WM_PAINT - Paint the main window +// WM_DESTROY - post a quit message and return +// +// +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + static bool isplay = false; + int wmId = LOWORD(wParam); + + switch (message) + { + case WM_CREATE: + { + initUIControl(hWnd); + break; + } + case WM_TIMER: + { + switch (wmId) + { + case TIMER_PLAY_ANIM: + { + renderAnimation(curFrame + 1); + SendMessage(hSliderPlay, TBM_SETPOS, TRUE, curFrame); + break; + } + default: + break; + } + break; + } + case WM_COMMAND: + { + // Parse the menu selections: + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + + case IDM_EXIT: + DestroyWindow(hWnd); + break; + + case BTN_BROWSE: + openJSONFileDialog(hWnd); + break; + + case BTN_PLAY: + { + LPWSTR textBtnPlay; + USES_CONVERSION; + if (isplay) + { + isplay = false; + textBtnPlay = A2W("Play"); + KillTimer(hWnd, TIMER_PLAY_ANIM); + } + else + { + isplay = true; + textBtnPlay = A2W("Pause"); + SetTimer(hWnd, TIMER_PLAY_ANIM, 10, NULL); + } + SetWindowText(hBtnPlay, textBtnPlay); + break; + } + + case WM_DROPFILES: + break; + case BTN_WHITE: + changeBackgroundColor(1, 1, 1); + break; + case BTN_BLACK: + changeBackgroundColor(0, 0, 0); + break; + case BTN_RED: + changeBackgroundColor(1, 0, 0); + break; + case BTN_GREEN: + changeBackgroundColor(0, 1, 0); + break; + case BTN_BLUE: + changeBackgroundColor(0, 0, 1); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + + case WM_HSCROLL: + { + if ((lParam != 0) && (reinterpret_cast(lParam) == hSliderPlay)) + { + UINT frameNum = SendDlgItemMessage(hWnd, SLIDER_PLAY, TBM_GETPOS, 0, 0); + renderAnimation(frameNum); + } + else if ((lParam != 0) && (reinterpret_cast(lParam) == hSliderCanvasResize)) + { + static int curSize = anim.width / RESIZE_LENGTH; + int newSize = SendDlgItemMessage(hWnd, SLIDER_CANVAS_RESIZE, TBM_GETPOS, 0, 0); + resizeCanvas(hWnd, (curSize - newSize) * RESIZE_LENGTH); + curSize = newSize; + } + break; + } + + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + draw(hdc); + EndPaint(hWnd, &ps); + } + break; + case WM_CTLCOLORSTATIC: + { + static HBRUSH hBrushEdit = CreateSolidBrush(RGB(255, 255, 255)); + return (LRESULT)hBrushEdit; + } + + case WM_DESTROY: + freeAnimation(); + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +// Message handler for about box. +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} + +void openJSONFileDialog(HWND hDlg) +{ + OPENFILENAME ofn; // common dialog box structure + TCHAR szFile[260] = { 0 }; // if using TCHAR macros + + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hDlg; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = _T("JSON\0*.json\0"); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + isViewChanged = true; + if (GetOpenFileName(&ofn)) + { + isViewChanged = true; + SetWindowText(hTextFileToBeOpened, ofn.lpstrFile); + // LPWSTR(w_char*) -> LPSTR(char*) + USES_CONVERSION; + LPSTR path = W2A(ofn.lpstrFile); + + setAnimation(path, &animWidth, &animHeight); + // init play slider + SendMessage(hSliderPlay, TBM_SETRANGE, FALSE, MAKELPARAM(0, getTotalFrame())); + SendMessage(hSliderPlay, TBM_SETPOS, TRUE, 0); + renderAnimation(0); + } +} + +void draw(HDC hdc) +{ + Graphics gf(hdc); + int half_interval = UI_INTERVAL / 2; + + // background + SolidBrush brush(backColor); + int back_y = half_interval + BTN_HEIGHT; + int back_height = back_y + BMP_MAX_LEN + UI_INTERVAL; + if (isViewChanged) + { + isViewChanged = false; + gf.FillRectangle(&brush, 0, back_y, WND_WIDTH, back_height); + } + + // image borderline + Pen pen(borderColor); + gf.DrawRectangle(&pen, anim.x - half_interval, anim.y - half_interval, anim.width + half_interval * 2, anim.height + half_interval * 2); + + // image + if (anim.image != NULL) + { + gf.DrawImage(anim.image, anim.x, anim.y, anim.width, anim.height); + } +} + +Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height) +{ + BITMAPINFO Info; + memset(&Info, 0, sizeof(Info)); + + Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + Info.bmiHeader.biWidth = width; + Info.bmiHeader.biHeight = height; + Info.bmiHeader.biPlanes = 1; + Info.bmiHeader.biBitCount = 32; + Info.bmiHeader.biCompression = BI_RGB; + Info.bmiHeader.biSizeImage = 0; //(((32 * width + 31) & ~31) / 8) * height; + + return new Gdiplus::Bitmap(&Info, data); +} + +void renderAnimation(UINT frameNum) +{ + if (isAnimNULL()) return; + if (anim.image != NULL) delete anim.image; + + curFrame = frameNum % getTotalFrame(); + + // render + UINT* resRender = renderRLottieAnimation(curFrame); + anim.image = CreateBitmap(resRender, animWidth, animHeight); + anim.image->RotateFlip(RotateNoneFlipY); + // call WM_PAINT message + InvalidateRect(mainWindow, &animRect, FALSE); +} + +void initUIControl(HWND hWnd) +{ + int half_ui_interval = UI_INTERVAL / 2; + + // button browse + int browse_x = UI_INTERVAL; + int browse_y = half_ui_interval; + CreateWindow(L"button", L"Browse", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, + browse_x, browse_y, BTN_WIDTH, BTN_HEIGHT, hWnd, (HMENU)BTN_BROWSE, hInst, NULL); + + // textbox FilePath + int textFile_x = browse_x + BTN_WIDTH + UI_INTERVAL; + int textFile_y = browse_y; + hTextFileToBeOpened = CreateWindowEx(0, L"static", L"No file selected.", WS_CHILD | WS_VISIBLE | ES_LEFT, + textFile_x, textFile_y, WND_WIDTH * 0.6, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); + + // image + anim.x = WND_WIDTH / 4; + anim.y = browse_y + BTN_HEIGHT + UI_INTERVAL * 2; + anim.width = BMP_MAX_LEN; + anim.height = anim.width; + + // animating range + SetRect(&animRect, + anim.x - UI_INTERVAL, + anim.y - UI_INTERVAL, + anim.x + anim.width + UI_INTERVAL * 2, + anim.y + anim.height + UI_INTERVAL * 2 + ); + + // background range + SetRect(&backRect, + 0, + anim.y - UI_INTERVAL, + WND_WIDTH, + anim.y + anim.height + UI_INTERVAL * 2 + ); + + // text Background Color + int textBC_x = WND_WIDTH / 20; + int textBC_y = anim.y + anim.height + UI_INTERVAL * 2; + CreateWindowEx(0, L"static", L"Background Color", WS_CHILD | WS_VISIBLE | ES_LEFT, + textBC_x, textBC_y, 120, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); + + // radio button + // white + int white_x = WND_WIDTH / 20; + int white_y = textBC_y + TEXT_HEIGHT + half_ui_interval; + CreateWindowEx(0, L"button", L"White", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, + white_x, white_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_WHITE, hInst, NULL); + + // black + int black_x = white_x + RDOBTN_WIDTH + half_ui_interval; + int black_y = white_y; + CreateWindowEx(0, L"button", L"Black", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, + black_x, black_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_BLACK, hInst, NULL); + + // red + int red_x = black_x + RDOBTN_WIDTH + half_ui_interval; + int red_y = white_y; + CreateWindowEx(0, L"button", L"Red", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, + red_x, red_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_RED, hInst, NULL); + + // green + int green_x = red_x + RDOBTN_WIDTH + half_ui_interval; + int green_y = white_y; + CreateWindowEx(0, L"button", L"Green", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, + green_x, green_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_GREEN, hInst, NULL); + + // blue + int blue_x = green_x + RDOBTN_WIDTH + half_ui_interval; + int blue_y = white_y; + CreateWindowEx(0, L"button", L"Blue", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, + blue_x, blue_y, RDOBTN_WIDTH, RDOBTN_HEIGHT, hWnd, (HMENU)BTN_BLUE, hInst, NULL); + + CheckRadioButton(hWnd, BTN_WHITE, BTN_BLUE, BTN_WHITE); + + // text Canvas Resize + int textCR_x = WND_WIDTH / 2; + int textCR_y = textBC_y; + CreateWindowEx(0, L"static", L"Canvas Resize", WS_CHILD | WS_VISIBLE | ES_LEFT, + textCR_x, textCR_y, 120, TEXT_HEIGHT, hWnd, (HMENU)TEXT_FILENAME, hInst, 0); + + // slider Canvas Resize + int sliderCR_x = textCR_x; + int sliderCR_y = textCR_y + TEXT_HEIGHT + half_ui_interval; + hSliderCanvasResize = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD | WS_VISIBLE | TBS_FIXEDLENGTH | TBS_NOTICKS, + sliderCR_x, sliderCR_y, WND_WIDTH * 0.2, SLIDER_HEIGHT, hWnd, (HMENU)SLIDER_CANVAS_RESIZE, hInst, NULL); + + // init resize slider + UINT sizeSlider = anim.width / RESIZE_LENGTH; + SendMessage(hSliderCanvasResize, TBM_SETRANGE, FALSE, MAKELPARAM(0, sizeSlider)); + SendMessage(hSliderCanvasResize, TBM_SETPOS, TRUE, sizeSlider); + + // button play + int btnPlay_x = WND_WIDTH / 10; + int btnPlay_y = red_y + RDOBTN_HEIGHT + UI_INTERVAL * 2; + hBtnPlay = CreateWindow(L"button", L"Play", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, + btnPlay_x, btnPlay_y, BTN_WIDTH, BTN_HEIGHT, hWnd, (HMENU)BTN_PLAY, hInst, NULL); + + // slider play + int sliderPlay_x = btnPlay_x + BTN_WIDTH + UI_INTERVAL; + int sliderPlay_y = btnPlay_y; + hSliderPlay = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD | WS_VISIBLE | TBS_FIXEDLENGTH | TBS_NOTICKS, + sliderPlay_x, sliderPlay_y, WND_WIDTH * 0.6, SLIDER_HEIGHT, hWnd, (HMENU)SLIDER_PLAY, hInst, NULL); +} + +void resizeCanvas(HWND hWnd, int resizeValue) +{ + isViewChanged = true; + anim.x += resizeValue / 2; + anim.y += resizeValue / 2; + anim.width -= resizeValue; + anim.height -= resizeValue; + InvalidateRect(hWnd, &animRect, TRUE); +} + +void changeBackgroundColor(int r, int g, int b) +{ + isViewChanged = true; + backColor = Gdiplus::Color(r * 255, g * 255, b * 255); + if (r + g + b == 0) borderColor = Gdiplus::Color(255, 255, 255); + else borderColor = Gdiplus::Color(0, 0, 0); + setAnimationColor(r, g, b); + renderAnimation(curFrame); + InvalidateRect(mainWindow, &backRect, FALSE); +} \ No newline at end of file diff --git a/example/win32Player/rlottiePlayer.h b/example/win32Player/rlottiePlayer.h new file mode 100644 index 0000000..07e5fd2 --- /dev/null +++ b/example/win32Player/rlottiePlayer.h @@ -0,0 +1,32 @@ +#pragma once + +#include "resource.h" +#include "animation.h" +#include // OPENFILENAME +#include "atlconv.h" // String cast. (ex. LPWSTR <-> LPSTR) +#include +#include // slider handle + +// interval +#define UI_INTERVAL 20 + +// length +#define WND_WIDTH 1000 +#define WND_HEIGHT 800 +#define BMP_MAX_LEN 500 +#define BTN_WIDTH 100 +#define BTN_HEIGHT 30 +#define TEXT_HEIGHT 20 +#define SLIDER_HEIGHT 25 +#define RDOBTN_WIDTH 60 +#define RDOBTN_HEIGHT 20 +#define RESIZE_LENGTH 10 + +typedef struct RlottieBitmap +{ + Gdiplus::Bitmap* image = NULL; + int x = 0; + int y = 0; + unsigned int width = 0; + unsigned int height = 0; +}RlottieBitmap; \ No newline at end of file diff --git a/example/win32Player/rlottiePlayer.ico b/example/win32Player/rlottiePlayer.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/example/win32Player/rlottiePlayer.ico differ diff --git a/example/win32Player/rlottiePlayer.rc b/example/win32Player/rlottiePlayer.rc new file mode 100644 index 0000000..0c7935f Binary files /dev/null and b/example/win32Player/rlottiePlayer.rc differ diff --git a/example/win32Player/rlottiePlayer.sln b/example/win32Player/rlottiePlayer.sln new file mode 100644 index 0000000..d1c8f0d --- /dev/null +++ b/example/win32Player/rlottiePlayer.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30503.244 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rlottiePlayer", "rlottiePlayer.vcxproj", "{CC7AD634-4D29-4D8E-997D-9727DABB44EE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x64.ActiveCfg = Debug|x64 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x64.Build.0 = Debug|x64 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x86.ActiveCfg = Debug|Win32 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Debug|x86.Build.0 = Debug|Win32 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x64.ActiveCfg = Release|x64 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x64.Build.0 = Release|x64 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x86.ActiveCfg = Release|Win32 + {CC7AD634-4D29-4D8E-997D-9727DABB44EE}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {57EEA15F-28FB-4C19-96B4-7B62BFA0CFE5} + EndGlobalSection +EndGlobal diff --git a/example/win32Player/rlottiePlayer.vcxproj b/example/win32Player/rlottiePlayer.vcxproj new file mode 100644 index 0000000..18e6533 --- /dev/null +++ b/example/win32Player/rlottiePlayer.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {cc7ad634-4d29-4d8e-997d-9727dabb44ee} + rlottiePlayer + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + ..\..\inc;$(IncludePath) + + + false + + + + Level3 + true + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + true + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;rlottie.lib;gdiplus.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/example/win32Player/rlottiePlayer.vcxproj.filters b/example/win32Player/rlottiePlayer.vcxproj.filters new file mode 100644 index 0000000..c8cf65b --- /dev/null +++ b/example/win32Player/rlottiePlayer.vcxproj.filters @@ -0,0 +1,55 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + + + Resource Files + + + + + Resource Files + + + Resource Files + + + \ No newline at end of file diff --git a/example/win32Player/rlottiePlayer.vcxproj.user b/example/win32Player/rlottiePlayer.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/example/win32Player/rlottiePlayer.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/example/win32Player/small.ico b/example/win32Player/small.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/example/win32Player/small.ico differ diff --git a/example/win32Player/targetver.h b/example/win32Player/targetver.h new file mode 100644 index 0000000..bf75e08 --- /dev/null +++ b/example/win32Player/targetver.h @@ -0,0 +1,6 @@ +#pragma once + +// // Including SDKDDKVer.h defines the highest available Windows platform. +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. +#include