//
// Created by chenjinyi on 2024/10/29.
//

#ifndef _ASP_DISPLAY_H
#define _ASP_DISPLAY_H
#include "AspPlayer.h"
#include "AspClientDefine.h"
#include "AspSharedPtr.h"

namespace wuying {
namespace asp {

enum AspAction {
    ACTION_UP,
    ACTION_DOWN
};

struct AspResolution {
    int32_t x;
    int32_t y;
    uint32_t width;
    uint32_t height;
};

enum ASPTouchAction {
    ASP_TOUCH_ACTION_DOWN = 1,
    ASP_TOUCH_ACTION_UP,
    ASP_TOUCH_ACTION_MOVE,
    ASP_TOUCH_ACTION_POINTER_DOWN,
    ASP_TOUCH_ACTION_POINTER_UP,
    ASP_TOUCH_ACTION_UNIVERSAL
};

struct AspTouchEvent {
    uint8_t  trackingId;
    uint32_t xpos;
    uint32_t ypos;
    uint32_t pressure;
    ASPTouchAction action;
};

enum AspMouseButtonMask {
    ASP_MOUSE_BUTTON_MASK_L = (1 << 0),
    ASP_MOUSE_BUTTON_MASK_M = (1 << 1),
    ASP_MOUSE_BUTTON_MASK_R = (1 << 2),
    ASP_MOUSE_BUTTON_MASK_F = (1 << 3),
    ASP_MOUSE_BUTTON_MASK_B = (1 << 4),

    ASP_MOUSE_BUTTON_MASK = 0x1f
};

enum AspMouseButton {
    ASP_MOUSE_BUTTON_INVALID,
    ASP_MOUSE_BUTTON_LEFT,
    ASP_MOUSE_BUTTON_MIDDLE,
    ASP_MOUSE_BUTTON_RIGHT,
    ASP_MOUSE_BUTTON_UP,
    ASP_MOUSE_BUTTON_DOWN,
    ASP_MOUSE_BUTTON_SIDE_FORWARD,
    ASP_MOUSE_BUTTON_SIDE_BACK,

    ASP_MOUSE_BUTTON_ENUM_END
};

typedef std::function<void()> ReleaseBuffer;
typedef std::function<void()> FrameDrawCompleteCallback;

struct AspImageFrame {
    uint32_t frameId;
    void* buffer;
    uint32_t width;
    uint32_t height;
    AspImageFormat format;
    ReleaseBuffer releaseBuffer;
    FrameDrawCompleteCallback callback;
};

class ASP_CLIENT_SDK_API IAspDisplayCallback : public AspRefCounted {
public:
    virtual void onImageFrameReady(AspImageFrame &frame) = 0;
};

class ASP_CLIENT_SDK_API AspDisplay : public AspRefCounted {
public:
    virtual void setResolution(int32_t x, int32_t y, uint32_t width, uint32_t height) = 0;
    virtual AspResolution& getResolution() = 0;
    virtual void setDpi(uint16_t dpi) = 0;

    virtual void sendMouseMove(uint32_t x, uint32_t y, uint32_t buttonState) = 0;
    virtual void sendMouseMoveDelta(int32_t dx, int32_t dy, uint32_t button_state) = 0;
    virtual void sendMouseClick(AspAction action, uint32_t button, uint32_t buttonState) = 0;
    virtual void sendMouseWheel(int32_t deltaX, int32_t deltaY, uint32_t buttonState) = 0;
  
    virtual void sendKeyEvent(AspAction action, int scancode) = 0;
    virtual void setKeyboardLockModifiers(uint32_t modifiers) = 0;

    virtual void sendTouchEvent(std::vector<AspTouchEvent>& events) = 0;
};
}
}


#endif //_ASP_DISPLAY_H
