cursor shadow setting

This commit is contained in:
nakst 2021-08-23 22:52:06 +01:00
parent fc013e8485
commit 7163761f39
10 changed files with 74 additions and 25 deletions

View File

@ -87,6 +87,7 @@ struct EsFileStore {
struct GlobalData {
int32_t clickChainTimeoutMs;
bool swapLeftAndRightButtons;
bool showCursorShadow;
};
struct ThreadLocalStorage {
@ -1131,6 +1132,7 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
api.global->clickChainTimeoutMs = EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("click_chain_timeout_ms"));
api.global->swapLeftAndRightButtons = EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("swap_left_and_right_buttons"));
api.global->showCursorShadow = EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("show_cursor_shadow"));
} else {
EsHandle initialMountPointsBuffer = EsSyscall(ES_SYSCALL_PROCESS_GET_CREATION_ARGUMENT, ES_CURRENT_PROCESS, CREATION_ARGUMENT_INITIAL_MOUNT_POINTS, 0, 0);
size_t initialMountPointCount = EsConstantBufferGetSize(initialMountPointsBuffer) / sizeof(EsMountPoint);

View File

@ -6330,11 +6330,12 @@ bool UISetCursor(EsWindow *window) {
}
bool _xor = cursorStyle == ES_CURSOR_TEXT;
bool shadow = !_xor && api.global->showCursorShadow;
return EsSyscall(ES_SYSCALL_WINDOW_SET_CURSOR, window->handle,
(uintptr_t) theming.cursors.bits + x * 4 + y * theming.cursors.stride,
((0xFF & ox) << 0) | ((0xFF & oy) << 8) | ((0xFF & w) << 16) | ((0xFF & h) << 24),
theming.cursors.stride | (cursorStyle << 24) | ((uint32_t) _xor << 31));
theming.cursors.stride | ((uint32_t) _xor << 31) | ((uint32_t) shadow << 30));
}
void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, ProcessMessageTiming *timing) {

View File

@ -72,8 +72,8 @@ const EsStyle styleSettingsTable = {
const EsStyle styleSettingsCheckboxGroup = {
.metrics = {
.mask = ES_THEME_METRICS_GAP_MAJOR | ES_THEME_METRICS_GAP_MINOR,
.gapMajor = 3,
.gapMinor = 3,
.gapMajor = 0,
.gapMinor = 0,
},
};
@ -328,7 +328,7 @@ void SettingsPageMouse(EsElement *element, SettingsPage *page) {
SettingsAddCheckbox(table, INTERFACE_STRING(DesktopSettingsMouseSwapLeftAndRightButtons), 'B',
"general", "swap_left_and_right_buttons", &api.global->swapLeftAndRightButtons);
SettingsAddCheckbox(table, INTERFACE_STRING(DesktopSettingsMouseShowShadow), 'W',
"general", "show_cursor_shadow", nullptr); // TODO.
"general", "show_cursor_shadow", &api.global->showCursorShadow);
SettingsAddCheckbox(table, INTERFACE_STRING(DesktopSettingsMouseLocateCursorOnCtrl), 'L',
"general", "locate_cursor_on_ctrl", nullptr);

View File

@ -1,5 +1,7 @@
#ifndef IMPLEMENTATION
#define CURSOR_SHADOW_OFFSET (1)
struct Surface : EsPaintTarget {
bool Resize(size_t newResX, size_t newResY, uint32_t clearColor = 0, bool copyOldBits = false);
void Copy(Surface *source, EsPoint destinationPoint, EsRectangle sourceRegion, bool addToModifiedRegion);
@ -8,6 +10,7 @@ struct Surface : EsPaintTarget {
void Blur(EsRectangle region, EsRectangle clip);
void SetBits(K_USER_BUFFER const void *bits, uintptr_t stride, EsRectangle region);
void Scroll(EsRectangle region, ptrdiff_t delta, bool vertical);
void CreateCursorShadow(Surface *source);
EsRectangle modifiedRegion;
};
@ -230,7 +233,7 @@ void Surface::Scroll(EsRectangle region, ptrdiff_t delta, bool vertical) {
#define C3(p) ((p & 0xFF000000) >> 0x18)
__attribute__((optimize("-O2")))
void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint16_t *kernel, uintptr_t repeat) {
void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint16_t *k, uintptr_t repeat) {
if (width <= 3 || height <= 3) {
return;
}
@ -243,12 +246,9 @@ void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint1
for (int i = 0; i < width; i++, u++, v++) {
if (i + 3 < width) g = *v;
*u = (((C0(a) * kernel[0] + C0(b) * kernel[1] + C0(c) * kernel[2] + C0(d) * kernel[3] + C0(e)
* kernel[4] + C0(f) * kernel[5] + C0(g) * kernel[6]) >> 8) << 0x00)
+ (((C1(a) * kernel[0] + C1(b) * kernel[1] + C1(c) * kernel[2] + C1(d) * kernel[3] + C1(e)
* kernel[4] + C1(f) * kernel[5] + C1(g) * kernel[6]) >> 8) << 0x08)
+ (((C2(a) * kernel[0] + C2(b) * kernel[1] + C2(c) * kernel[2] + C2(d) * kernel[3] + C2(e)
* kernel[4] + C2(f) * kernel[5] + C2(g) * kernel[6]) >> 8) << 0x10)
*u = (((C0(a) * k[0] + C0(b) * k[1] + C0(c) * k[2] + C0(d) * k[3] + C0(e) * k[4] + C0(f) * k[5] + C0(g) * k[6]) >> 8) << 0x00)
+ (((C1(a) * k[0] + C1(b) * k[1] + C1(c) * k[2] + C1(d) * k[3] + C1(e) * k[4] + C1(f) * k[5] + C1(g) * k[6]) >> 8) << 0x08)
+ (((C2(a) * k[0] + C2(b) * k[1] + C2(c) * k[2] + C2(d) * k[3] + C2(e) * k[4] + C2(f) * k[5] + C2(g) * k[6]) >> 8) << 0x10)
+ (C3(d) << 0x18);
a = b, b = c, c = d, d = e, e = f, f = g;
}
@ -263,12 +263,9 @@ void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint1
for (int i = 0; i < height; i++, u += stride, v += stride) {
if (i + 3 < height) g = *v;
*u = (((C0(a) * kernel[0] + C0(b) * kernel[1] + C0(c) * kernel[2] + C0(d) * kernel[3] + C0(e)
* kernel[4] + C0(f) * kernel[5] + C0(g) * kernel[6]) >> 8) << 0x00)
+ (((C1(a) * kernel[0] + C1(b) * kernel[1] + C1(c) * kernel[2] + C1(d) * kernel[3] + C1(e)
* kernel[4] + C1(f) * kernel[5] + C1(g) * kernel[6]) >> 8) << 0x08)
+ (((C2(a) * kernel[0] + C2(b) * kernel[1] + C2(c) * kernel[2] + C2(d) * kernel[3] + C2(e)
* kernel[4] + C2(f) * kernel[5] + C2(g) * kernel[6]) >> 8) << 0x10)
*u = (((C0(a) * k[0] + C0(b) * k[1] + C0(c) * k[2] + C0(d) * k[3] + C0(e) * k[4] + C0(f) * k[5] + C0(g) * k[6]) >> 8) << 0x00)
+ (((C1(a) * k[0] + C1(b) * k[1] + C1(c) * k[2] + C1(d) * k[3] + C1(e) * k[4] + C1(f) * k[5] + C1(g) * k[6]) >> 8) << 0x08)
+ (((C2(a) * k[0] + C2(b) * k[1] + C2(c) * k[2] + C2(d) * k[3] + C2(e) * k[4] + C2(f) * k[5] + C2(g) * k[6]) >> 8) << 0x10)
+ (C3(d) << 0x18);
a = b, b = c, c = d, d = e, e = f, f = g;
}
@ -472,6 +469,45 @@ void Surface::Draw(Surface *source, EsRectangle destinationRegion, int sourceX,
EsDrawBitmap(&painter, destinationRegion, (uint32_t *) sourceBits, source->stride, alpha);
}
void Surface::CreateCursorShadow(Surface *temporary) {
const uint32_t kernel[] = { 14, 43, 82, 43, 14 };
uint32_t *bits1 = (uint32_t *) bits;
uint32_t *bits2 = (uint32_t *) temporary->bits;
for (int32_t i = 0; i < (int32_t) height; i++) {
for (int32_t j = 0; j < (int32_t) width; j++) {
uint32_t s = 0;
for (int32_t k = 0; k < 5; k++) {
int32_t l = j + k - 2;
if (l >= 0 && l < (int32_t) width) {
s += ((bits1[i * stride / 4 + l] & 0xFF000000) >> 24) * kernel[k];
}
}
bits2[i * temporary->stride / 4 + j] = s;
}
}
for (int32_t i = 0; i < (int32_t) height - CURSOR_SHADOW_OFFSET; i++) {
for (int32_t j = 0; j < (int32_t) width - CURSOR_SHADOW_OFFSET; j++) {
uint32_t s = 0;
for (int32_t k = 0; k < 5; k++) {
int32_t l = i + k - 2;
if (l >= 0 && l < (int32_t) height) {
s += bits2[l * temporary->stride / 4 + j] * kernel[k];
}
}
uint32_t *out = &bits1[(i + CURSOR_SHADOW_OFFSET) * stride / 4 + (j + CURSOR_SHADOW_OFFSET)];
*out = EsColorBlend((s >> 16) << 24, *out, true);
}
}
}
void GraphicsUpdateScreen32(K_USER_BUFFER const uint8_t *_source, uint32_t sourceWidth, uint32_t sourceHeight, uint32_t sourceStride,
uint32_t destinationX, uint32_t destinationY,
uint32_t screenWidth, uint32_t screenHeight, uint32_t stride, volatile uint8_t *pixel) {

View File

@ -1070,17 +1070,26 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_WINDOW_SET_CURSOR) {
}
bool changedCursor = false;
bool different = argument1 != windowManager.cursorID || windowManager.cursorShadow != !!(argument3 & (1 << 30));
if (!window->closed && argument1 != windowManager.cursorID && !windowManager.eyedropping && (windowManager.hoverWindow == window || !windowManager.hoverWindow)) {
if (!window->closed && different && !windowManager.eyedropping && (windowManager.hoverWindow == window || !windowManager.hoverWindow)) {
windowManager.cursorID = argument1;
windowManager.cursorImageOffsetX = (int8_t) ((argument2 >> 0) & 0xFF);
windowManager.cursorImageOffsetY = (int8_t) ((argument2 >> 8) & 0xFF);
windowManager.cursorXOR = argument3 >> 31;
windowManager.cursorXOR = argument3 & (1 << 31);
windowManager.cursorShadow = argument3 & (1 << 30);
if (windowManager.cursorSurface.Resize(imageWidth, imageHeight)) {
windowManager.cursorSwap.Resize(imageWidth, imageHeight);
windowManager.cursorSurface.SetBits((K_USER_BUFFER const void *) argument1, argument3 & 0xFFFFFF,
ES_RECT_4(0, windowManager.cursorSurface.width, 0, windowManager.cursorSurface.height));
int width = imageWidth + CURSOR_SHADOW_OFFSET;
int height = imageHeight + CURSOR_SHADOW_OFFSET;
if (windowManager.cursorSurface.Resize(width, height)
&& windowManager.cursorSwap.Resize(width, height)
&& windowManager.cursorTemporary.Resize(width, height)) {
windowManager.cursorSurface.SetBits((K_USER_BUFFER const void *) argument1, argument3 & 0xFFFFFF, ES_RECT_2S(imageWidth, imageHeight));
if (windowManager.cursorShadow) {
windowManager.cursorSurface.CreateCursorShadow(&windowManager.cursorTemporary);
}
}
windowManager.changedCursorImage = true;

View File

@ -99,10 +99,10 @@ struct WindowManager {
int cursorXPrecise, cursorYPrecise; // Scaled up by a factor of 10.
unsigned lastButtons;
Surface cursorSurface, cursorSwap;
Surface cursorSurface, cursorSwap, cursorTemporary;
int cursorImageOffsetX, cursorImageOffsetY;
uintptr_t cursorID;
bool cursorXOR;
bool cursorXOR, cursorShadow;
bool changedCursorImage;
// Keyboard:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -8,6 +8,7 @@ settings_path=0:/Settings
default_user_documents_path=0:/
installation_state=0
click_chain_timeout_ms=500
show_cursor_shadow=1
[ui]
; User interface settings that are accessible by all applications.

Binary file not shown.

Binary file not shown.