Update drag drawing mouse style

Signed-off-by: xing-jiangpan <xingjiangpan2@huawei.com>
Change-Id: I7a4ed08b48fb9edc5d34ec8a0a3b50dbb6d1a180
This commit is contained in:
xing-jiangpan 2023-09-28 02:52:49 +00:00
parent f8f1deb439
commit 82dc95203b
8 changed files with 88 additions and 26 deletions

14
etc/drag_icon/BUILD.gn Executable file → Normal file
View File

@ -48,8 +48,15 @@ ohos_prebuilt_etc("drawing_image_Forbid_One_Drag") {
relative_install_dir = "device_status/drag_icon"
}
ohos_prebuilt_etc("drawing_image_Mouse_Drag") {
source = "src/Mouse_Drag.svg"
ohos_prebuilt_etc("drawing_image_Mouse_Drag_Default") {
source = "src/Mouse_Drag_Default.svg"
part_name = "${device_status_part_name}"
subsystem_name = "${device_status_subsystem_name}"
relative_install_dir = "device_status/drag_icon"
}
ohos_prebuilt_etc("drawing_image_Mouse_Drag_Cursor_Circle") {
source = "src/Mouse_Drag_Cursor_Circle.png"
part_name = "${device_status_part_name}"
subsystem_name = "${device_status_subsystem_name}"
relative_install_dir = "device_status/drag_icon"
@ -69,7 +76,8 @@ group("device_status_drag_icon") {
":drawing_image_Default_Drag",
":drawing_image_Forbid_Drag",
":drawing_image_Forbid_One_Drag",
":drawing_image_Mouse_Drag",
":drawing_image_Mouse_Drag_Cursor_Circle",
":drawing_image_Mouse_Drag_Default",
":drawing_image_Move_Drag",
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -795,18 +795,13 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Failed_Mouse, T
if (g_deviceMouseId < 0) {
ASSERT_TRUE(g_deviceMouseId < 0);
} else {
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), nullptr);
ASSERT_EQ(ret, RET_ERR);
ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
ASSERT_EQ(ret, RET_ERR);
}
}

View File

@ -57,6 +57,9 @@ public:
DrawMouseIconModifier() = default;
~DrawMouseIconModifier() = default;
void Draw(Rosen::RSDrawingContext &context) const override;
private:
void OnDraw(std::shared_ptr<Media::PixelMap> pixelMap, int32_t pointerStyleId) const;
};
class DrawDynamicEffectModifier : public Rosen::RSContentStyleModifier {
@ -86,6 +89,8 @@ struct DrawingInfo {
int32_t pixelMapY { -1 };
int32_t displayX { -1 };
int32_t displayY { -1 };
int32_t mouseWidth { 0 };
int32_t mouseHeight { 0 };
int32_t rootNodeWidth { -1 };
int32_t rootNodeHeight { -1 };
float scalingValue { 0.0 };

View File

@ -16,7 +16,6 @@
#include "drag_data_manager.h"
#include "hitrace_meter.h"
#include "pointer_style.h"
#include "devicestatus_define.h"
#include "drag_data.h"

View File

@ -28,8 +28,10 @@
#include "image_source.h"
#include "image_type.h"
#include "image_utils.h"
#include "input_manager.h"
#include "parameters.h"
#include "pointer_event.h"
#include "pointer_style.h"
#include "render/rs_filter.h"
#include "string_ex.h"
#include "transaction/rs_interfaces.h"
@ -81,7 +83,13 @@ constexpr float BLUR_SIGMA_SCALE { 0.57735f };
constexpr float RADIUS_VP { 23.0f };
constexpr float DEFAULT_SATURATION { 1.05f };
constexpr float DEFAULT_BRIGHTNESS { 1.05f };
constexpr float INCREASE_RATIO { 1.22f };
constexpr int32_t DEFAULT_MOUSE_SIZE { 1 };
constexpr int32_t DEFAULT_COLOR_VALUE { 0 };
constexpr int32_t INVALID_COLOR_VALUE { -1 };
constexpr int32_t GLOBAL_WINDOW_ID { -1 };
constexpr int32_t MOUSE_DRAG_CURSOR_CIRCLE_STYLE { 41 };
constexpr int32_t CURSOR_CIRCLE_MIDDLE { 2 };
const std::string DEVICE_TYPE_DEFAULT { "default" };
const std::string DEVICE_TYPE_PHONE { "phone" };
const std::string THREAD_NAME { "AnimationEventRunner" };
@ -90,7 +98,8 @@ const std::string COPY_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy
const std::string DEFAULT_DRAG_PATH { "/system/etc/device_status/drag_icon/Default_Drag.svg" };
const std::string FORBID_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_Drag.svg" };
const std::string FORBID_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_One_Drag.svg" };
const std::string MOUSE_DRAG_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag.svg" };
const std::string MOUSE_DRAG_DEFAULT_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Default.svg" };
const std::string MOUSE_DRAG_CURSOR_CIRCLE_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Cursor_Circle.png" };
const std::string MOVE_DRAG_PATH { "/system/etc/device_status/drag_icon/Move_Drag.svg" };
#ifdef __aarch64__
const std::string DRAG_ANIMATION_EXTENSION_SO_PATH { "/system/lib64/drag_drop_ext/libdrag_drop_ext.z.so" };
@ -304,8 +313,8 @@ int32_t DragDrawing::UpdateShadowPic(const ShadowInfo &shadowInfo)
return RET_ERR;
}
int32_t adjustSize = (SVG_WIDTH + TWELVE_SIZE) * scalingValue;
g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + adjustSize;
g_drawingInfo.rootNodeHeight = g_drawingInfo.pixelMap->GetHeight() + adjustSize;
g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + g_drawingInfo.mouseWidth + adjustSize;
g_drawingInfo.rootNodeHeight = g_drawingInfo.pixelMap->GetHeight() + g_drawingInfo.mouseHeight + adjustSize;
CHKPR(g_drawingInfo.rootNode, RET_ERR);
g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
@ -378,6 +387,8 @@ void DragDrawing::DestroyDragWindow()
g_drawingInfo.pixelMapY = -1;
g_drawingInfo.displayX = -1;
g_drawingInfo.displayY = -1;
g_drawingInfo.mouseWidth = 0;
g_drawingInfo.mouseHeight = 0;
g_drawingInfo.rootNodeWidth = -1;
g_drawingInfo.rootNodeHeight = -1;
g_drawingInfo.pixelMap = nullptr;
@ -1194,7 +1205,7 @@ float DragDrawing::RadiusVp2Sigma(float radiusVp, float dipScale)
return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f;
}
DragDrawing::~DragDrawing()
DragDrawing::~DragDrawing()
{
if (dragExtHandle_ != nullptr) {
dlclose(dragExtHandle_);
@ -1236,8 +1247,8 @@ void DrawSVGModifier::Draw(Rosen::RSDrawingContext& context) const
rosenImage->SetImageRepeat(0);
dragStyleNode->SetBgImage(rosenImage);
adjustSize = (SVG_WIDTH + TWELVE_SIZE) * scalingValue;
g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + adjustSize;
g_drawingInfo.rootNodeHeight = g_drawingInfo.pixelMap->GetHeight() + adjustSize;
g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + g_drawingInfo.mouseWidth + adjustSize;
g_drawingInfo.rootNodeHeight = g_drawingInfo.pixelMap->GetHeight() + g_drawingInfo.mouseHeight + adjustSize;
CHKPV(g_drawingInfo.rootNode);
g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
@ -1275,19 +1286,47 @@ void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
{
CALL_DEBUG_ENTER;
std::string imagePath = MOUSE_DRAG_PATH;
std::string imagePath;
MMI::PointerStyle pointerStyle;
int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle);
if (ret != RET_OK) {
FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
return;
}
int32_t pointerStyleId = pointerStyle.id;
if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
imagePath = MOUSE_DRAG_CURSOR_CIRCLE_PATH;
} else {
imagePath = MOUSE_DRAG_DEFAULT_PATH;
}
Media::SourceOptions opts;
opts.formatHint = "image/svg+xml";
uint32_t errCode = 0;
auto imageSource = Media::ImageSource::CreateImageSource(imagePath, opts, errCode);
CHKPV(imageSource);
int32_t pointerSize = pointerStyle.size;
if (pointerSize < DEFAULT_MOUSE_SIZE) {
FI_HILOGD("Invalid pointerSize:%{public}d", pointerSize);
pointerSize = DEFAULT_MOUSE_SIZE;
}
Media::DecodeOptions decodeOpts;
decodeOpts.desiredSize = {
.width = DEVICE_INDEPENDENT_PIXEL * GetScaling(),
.height = DEVICE_INDEPENDENT_PIXEL * GetScaling()
.width = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling(),
.height = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling()
};
int32_t pointerColor = pointerStyle.color;
if (pointerColor != INVALID_COLOR_VALUE) {
decodeOpts.SVGOpts.fillColor = {.isValidColor = true, .color = pointerColor};
}
std::shared_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode);
CHKPV(pixelMap);
OnDraw(pixelMap, pointerStyleId);
}
void DrawMouseIconModifier::OnDraw(std::shared_ptr<Media::PixelMap> pixelMap, int32_t pointerStyleId) const
{
CALL_DEBUG_ENTER;
CHKPV(pixelMap);
if (!CheckNodesValid()) {
FI_HILOGE("Check nodes valid failed");
return;
@ -1295,18 +1334,36 @@ void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
CHKPV(mouseIconNode);
int32_t adjustSize = TWELVE_SIZE * GetScaling();
mouseIconNode->SetBounds(-g_drawingInfo.pixelMapX, -g_drawingInfo.pixelMapY + adjustSize,
pixelMap->GetWidth(), pixelMap->GetHeight());
mouseIconNode->SetFrame(-g_drawingInfo.pixelMapX, -g_drawingInfo.pixelMapY + adjustSize,
pixelMap->GetWidth(), pixelMap->GetHeight());
mouseIconNode->SetBgImageWidth(decodeOpts.desiredSize.width);
mouseIconNode->SetBgImageHeight(decodeOpts.desiredSize.height);
if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
int32_t positionX = -g_drawingInfo.pixelMapX - (pixelMap->GetWidth() / CURSOR_CIRCLE_MIDDLE);
int32_t positionY = -g_drawingInfo.pixelMapY + adjustSize - (pixelMap->GetHeight() / CURSOR_CIRCLE_MIDDLE);
mouseIconNode->SetBounds(positionX, positionY, pixelMap->GetWidth(), pixelMap->GetHeight());
mouseIconNode->SetFrame(positionX, positionY, pixelMap->GetWidth(), pixelMap->GetHeight());
} else {
mouseIconNode->SetBounds(-g_drawingInfo.pixelMapX, -g_drawingInfo.pixelMapY + adjustSize,
pixelMap->GetWidth(), pixelMap->GetHeight());
mouseIconNode->SetFrame(-g_drawingInfo.pixelMapX, -g_drawingInfo.pixelMapY + adjustSize,
pixelMap->GetWidth(), pixelMap->GetHeight());
}
mouseIconNode->SetBgImageWidth(pixelMap->GetWidth());
mouseIconNode->SetBgImageHeight(pixelMap->GetHeight());
mouseIconNode->SetBgImagePositionX(0);
mouseIconNode->SetBgImagePositionY(0);
auto rosenImage = std::make_shared<Rosen::RSImage>();
rosenImage->SetPixelMap(pixelMap);
rosenImage->SetImageRepeat(0);
mouseIconNode->SetBgImage(rosenImage);
g_drawingInfo.mouseWidth = pixelMap->GetWidth();
g_drawingInfo.mouseHeight = pixelMap->GetHeight();
adjustSize = (SVG_WIDTH + TWELVE_SIZE) * GetScaling();
g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + pixelMap->GetWidth() + adjustSize;
g_drawingInfo.rootNodeHeight = g_drawingInfo.pixelMap->GetHeight() + pixelMap->GetHeight() + adjustSize;
CHKPV(g_drawingInfo.rootNode);
g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight);
CHKPV(g_drawingInfo.surfaceNode);
g_drawingInfo.surfaceNode->SetBoundsWidth(g_drawingInfo.rootNodeWidth);
g_drawingInfo.surfaceNode->SetBoundsHeight(g_drawingInfo.rootNodeHeight);
Rosen::RSTransaction::FlushImplicitTransaction();
}

View File

@ -17,9 +17,7 @@
#include "extra_data.h"
#include "hitrace_meter.h"
#include "input_manager.h"
#include "pixel_map.h"
#include "pointer_style.h"
#include "udmf_client.h"
#include "unified_types.h"