mirror of https://gitlab.com/nakst/essence
refactoring
This commit is contained in:
parent
78f3c2a77f
commit
7bbbbf7e57
|
@ -24,6 +24,7 @@
|
|||
#include <emmintrin.h>
|
||||
|
||||
#define SHARED_COMMON_WANT_ALL
|
||||
#define SHARED_MATH_WANT_ALL
|
||||
#include <shared/ini.h>
|
||||
#include <shared/avl_tree.cpp>
|
||||
#include <shared/heap.cpp>
|
||||
|
@ -1130,8 +1131,7 @@ EsMessage *EsMessageReceive() {
|
|||
APIInstance *apiInstance = (APIInstance *) instance->_private;
|
||||
|
||||
if (message.message.tabOperation.error == ES_SUCCESS) {
|
||||
EsRectangle bounds = EsElementGetWindowBounds(instance->window->toolbarSwitcher);
|
||||
EsAnnouncementShow(instance->window, ES_FLAGS_DEFAULT, (bounds.l + bounds.r) / 2, bounds.b, INTERFACE_STRING(FileRenameSuccess));
|
||||
EsAnnouncementShow(instance->window, ES_FLAGS_DEFAULT, -1, -1, INTERFACE_STRING(FileRenameSuccess));
|
||||
} else {
|
||||
char buffer[512];
|
||||
const char *errorMessage = interfaceString_FileSaveErrorUnknown;
|
||||
|
@ -1363,11 +1363,10 @@ void EsInstanceSaveComplete(EsMessage *message, bool success) {
|
|||
|
||||
if (success) {
|
||||
EsInstanceSetModified(instance, false);
|
||||
EsRectangle bounds = EsElementGetWindowBounds(instance->window->toolbarSwitcher);
|
||||
size_t messageBytes;
|
||||
char *message = EsStringAllocateAndFormat(&messageBytes, "Saved to %s", // TODO Localization.
|
||||
apiInstance->startupInformation->filePathBytes, apiInstance->startupInformation->filePath);
|
||||
EsAnnouncementShow(instance->window, ES_FLAGS_DEFAULT, (bounds.l + bounds.r) / 2, bounds.b, message, messageBytes);
|
||||
EsAnnouncementShow(instance->window, ES_FLAGS_DEFAULT, -1, -1, message, messageBytes);
|
||||
EsHeapFree(message);
|
||||
EsCommandSetDisabled(&apiInstance->commandShowInFileManager, false);
|
||||
|
||||
|
|
|
@ -3869,6 +3869,12 @@ int AnnouncementMessage(EsElement *element, EsMessage *message) {
|
|||
void EsAnnouncementShow(EsWindow *parent, uint64_t flags, int32_t x, int32_t y, const char *text, ptrdiff_t textBytes) {
|
||||
(void) flags;
|
||||
|
||||
if (x == -1 && y == -1) {
|
||||
EsRectangle bounds = EsElementGetWindowBounds((EsElement *) parent->toolbarSwitcher ?: parent);
|
||||
x = (bounds.l + bounds.r) / 2;
|
||||
y = bounds.t + 40 * theming.scale;
|
||||
}
|
||||
|
||||
EsWindow *window = EsWindowCreate(nullptr, ES_WINDOW_TIP);
|
||||
if (!window) return;
|
||||
window->messageUser = AnnouncementMessage;
|
||||
|
@ -3878,7 +3884,7 @@ void EsAnnouncementShow(EsWindow *parent, uint64_t flags, int32_t x, int32_t y,
|
|||
int32_t height = display ? display->GetHeight(width) : 0;
|
||||
|
||||
EsRectangle parentBounds = {};
|
||||
if (parent) parentBounds = EsWindowGetBounds(parent);
|
||||
if (parent) parentBounds = EsWindowGetBounds(parent);
|
||||
EsRectangle bounds = ES_RECT_4PD(x - width / 2 + parentBounds.l, y - height + parentBounds.t, width, height);
|
||||
EsSyscall(ES_SYSCALL_WINDOW_SET_PROPERTY, window->handle, 0x00, 0, ES_WINDOW_PROPERTY_ALPHA);
|
||||
EsSyscall(ES_SYSCALL_WINDOW_MOVE, window->handle, (uintptr_t) &bounds, 0, ES_WINDOW_MOVE_ADJUST_TO_FIT_SCREEN | ES_WINDOW_MOVE_ALWAYS_ON_TOP);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// TODO Fix glitches.
|
||||
// TODO RAST_REPEAT_NORMAL is wrong with negative values.
|
||||
|
||||
#ifdef IN_DESIGNER
|
||||
#if defined(IN_DESIGNER) && !defined(DESIGNER2)
|
||||
#define RAST_ARRAY(x) x *
|
||||
#define RAST_ARRAY_ADD arrput
|
||||
#define RAST_ARRAY_CLEAR arrclear
|
||||
|
|
|
@ -380,7 +380,7 @@ void ThemeFillRectangle(EsPainter *painter, EsRectangle bounds, ThemePaintData p
|
|||
if (!THEME_RECT_VALID(bounds)) return;
|
||||
|
||||
if (paint.type == THEME_PAINT_SOLID) {
|
||||
#ifndef IN_DESIGNER
|
||||
#if !defined(IN_DESIGNER) || defined(DESIGNER2)
|
||||
_DrawBlock(painter->target->stride, bits, bounds, paint.solid->color, painter->target->fullAlpha);
|
||||
#else
|
||||
uint32_t color = paint.solid->color;
|
||||
|
|
|
@ -120,6 +120,7 @@ void KRegisterAsyncTask(KAsyncTaskCallback callback, EsGeneric argument, bool ne
|
|||
#define SHARED_DEFINITIONS_ONLY
|
||||
#endif
|
||||
|
||||
#define SHARED_MATH_WANT_BASIC_UTILITIES
|
||||
#include <shared/unicode.cpp>
|
||||
#include <shared/math.cpp>
|
||||
#include <shared/linked_list.cpp>
|
||||
|
|
|
@ -1,26 +1,8 @@
|
|||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
#define SHARED_COMMON_WANT_RECTANGLES
|
||||
#define SHARED_COMMON_WANT_RENDERING
|
||||
#define SHARED_COMMON_WANT_STRINGS
|
||||
#define SHARED_COMMON_WANT_MEMORY
|
||||
#define SHARED_COMMON_WANT_AUDIO
|
||||
#define SHARED_COMMON_WANT_PRINTING
|
||||
#define SHARED_COMMON_WANT_TIMING
|
||||
#define SHARED_COMMON_WANT_RANDOM
|
||||
#define SHARED_COMMON_WANT_ALGORITHMS
|
||||
#define SHARED_COMMON_WANT_MISCELLANEOUS
|
||||
#define SHARED_COMMON_WANT_SYNC
|
||||
#define SHARED_COMMON_WANT_BYTE_SWAP
|
||||
#define SHARED_COMMON_WANT_CSTDLIB
|
||||
#define SHARED_COMMON_WANT_BUFFERS
|
||||
#define SHARED_COMMON_WANT_AUDIO
|
||||
#endif
|
||||
|
||||
/////////////////////////////////
|
||||
// EsRectangle utility functions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_RECTANGLES
|
||||
#if defined(SHARED_COMMON_WANT_RECTANGLES) || defined(SHARED_COMMON_WANT_ALL)
|
||||
|
||||
struct Corners8 { int8_t tl, tr, bl, br; };
|
||||
struct Corners32 { int32_t tl, tr, bl, br; };
|
||||
|
@ -39,7 +21,9 @@ inline int Height(EsRectangle rectangle) {
|
|||
}
|
||||
|
||||
EsRectangle Translate(EsRectangle rectangle, int x, int y) {
|
||||
return EsRectangleAdd(rectangle, ES_RECT_2(x, y));
|
||||
rectangle.l += x, rectangle.r += x;
|
||||
rectangle.t += y, rectangle.b += y;
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
bool EsRectangleClip(EsRectangle parent, EsRectangle rectangle, EsRectangle *output) {
|
||||
|
@ -53,7 +37,7 @@ bool EsRectangleClip(EsRectangle parent, EsRectangle rectangle, EsRectangle *out
|
|||
intersection.r = current.r < rectangle.r ? current.r : rectangle.r;
|
||||
intersection.b = current.b < rectangle.b ? current.b : rectangle.b;
|
||||
} else {
|
||||
intersection = ES_RECT_4(0, 0, 0, 0);
|
||||
intersection = {};
|
||||
}
|
||||
|
||||
if (output) {
|
||||
|
@ -63,6 +47,10 @@ bool EsRectangleClip(EsRectangle parent, EsRectangle rectangle, EsRectangle *out
|
|||
return intersection.l < intersection.r && intersection.t < intersection.b;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
EsRectangle EsRectangleAddBorder(EsRectangle rectangle, EsRectangle border) {
|
||||
rectangle.l += border.l;
|
||||
rectangle.r -= border.r;
|
||||
|
@ -165,7 +153,7 @@ EsRectangle EsRectangleCut(EsRectangle a, int32_t amount, char side) {
|
|||
// Rendering.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_RENDERING
|
||||
#if defined(SHARED_COMMON_WANT_RENDERING) || defined(SHARED_COMMON_WANT_ALL)
|
||||
|
||||
ES_FUNCTION_OPTIMISE_O3
|
||||
void BlendPixel(uint32_t *destinationPixel, uint32_t modified, bool fullAlpha) {
|
||||
|
@ -209,6 +197,41 @@ void BlendPixel(uint32_t *destinationPixel, uint32_t modified, bool fullAlpha) {
|
|||
*destinationPixel = result;
|
||||
}
|
||||
|
||||
void _DrawBlock(uintptr_t stride, void *bits, EsRectangle bounds, uint32_t color, bool fullAlpha) {
|
||||
stride /= 4;
|
||||
uint32_t *lineStart = (uint32_t *) bits + bounds.t * stride + bounds.l;
|
||||
|
||||
__m128i color4 = _mm_set_epi32(color, color, color, color);
|
||||
|
||||
for (int i = 0; i < bounds.b - bounds.t; i++, lineStart += stride) {
|
||||
uint32_t *destination = lineStart;
|
||||
int j = bounds.r - bounds.l;
|
||||
|
||||
if ((color & 0xFF000000) != 0xFF000000) {
|
||||
do {
|
||||
BlendPixel(destination, color, fullAlpha);
|
||||
destination++;
|
||||
} while (--j);
|
||||
} else {
|
||||
while (j >= 4) {
|
||||
_mm_storeu_si128((__m128i *) destination, color4);
|
||||
destination += 4;
|
||||
j -= 4;
|
||||
}
|
||||
|
||||
while (j > 0) {
|
||||
*destination = color;
|
||||
destination++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
uint32_t EsColorBlend(uint32_t under, uint32_t over, bool fullAlpha) {
|
||||
BlendPixel(&under, over, fullAlpha);
|
||||
return under;
|
||||
|
@ -280,37 +303,6 @@ void EsDrawClear(EsPainter *painter, EsRectangle bounds) {
|
|||
}
|
||||
}
|
||||
|
||||
void _DrawBlock(uintptr_t stride, void *bits, EsRectangle bounds, uint32_t color, bool fullAlpha) {
|
||||
stride /= 4;
|
||||
uint32_t *lineStart = (uint32_t *) bits + bounds.t * stride + bounds.l;
|
||||
|
||||
__m128i color4 = _mm_set_epi32(color, color, color, color);
|
||||
|
||||
for (int i = 0; i < bounds.b - bounds.t; i++, lineStart += stride) {
|
||||
uint32_t *destination = lineStart;
|
||||
int j = bounds.r - bounds.l;
|
||||
|
||||
if ((color & 0xFF000000) != 0xFF000000) {
|
||||
do {
|
||||
BlendPixel(destination, color, fullAlpha);
|
||||
destination++;
|
||||
} while (--j);
|
||||
} else {
|
||||
while (j >= 4) {
|
||||
_mm_storeu_si128((__m128i *) destination, color4);
|
||||
destination += 4;
|
||||
j -= 4;
|
||||
}
|
||||
|
||||
while (j > 0) {
|
||||
*destination = color;
|
||||
destination++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EsDrawBlock(EsPainter *painter, EsRectangle bounds, uint32_t color) {
|
||||
if (!(color & 0xFF000000)) {
|
||||
return;
|
||||
|
@ -478,7 +470,7 @@ void EsDrawPaintTarget(EsPainter *painter, EsPaintTarget *source, EsRectangle de
|
|||
// String utility functions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_STRINGS
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
size_t EsCStringLength(const char *string) {
|
||||
if (!string) {
|
||||
|
@ -1256,7 +1248,7 @@ double EsDoubleParse(const char *nptr, ptrdiff_t maxBytes, char **endptr) {
|
|||
// Memory utility functions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_MEMORY
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
void EsMemoryCopy(void *_destination, const void *_source, size_t bytes) {
|
||||
// TODO Prevent this from being optimised out in the kernel.
|
||||
|
@ -1393,7 +1385,7 @@ void EsMemoryFill(void *from, void *to, uint8_t byte) {
|
|||
// Printing.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_PRINTING
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
#ifdef USE_STB_SPRINTF
|
||||
#define STB_SPRINTF_IMPLEMENTATION
|
||||
|
@ -1447,7 +1439,7 @@ void EsPrintHelloWorld() {
|
|||
// Timing utility functions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_TIMING
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
#ifdef KERNEL
|
||||
|
||||
|
@ -1486,7 +1478,7 @@ int __tsi = 1;
|
|||
// Random number generator.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_RANDOM
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
struct RNGState {
|
||||
uint64_t s[4];
|
||||
|
@ -1556,7 +1548,7 @@ uint8_t EsRandomU8() {
|
|||
// Standard algorithms.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_ALGORITHMS
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
void EsSortWithSwapCallback(void *_base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, EsGeneric),
|
||||
EsGeneric argument, void (*swap)(const void *, const void *, EsGeneric)) {
|
||||
|
@ -1604,7 +1596,7 @@ void EsSort(void *_base, size_t nmemb, size_t size, int (*compar)(const void *,
|
|||
// Miscellaneous.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_MISCELLANEOUS
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
void EnterDebugger() {
|
||||
// Do nothing.
|
||||
|
@ -1722,7 +1714,7 @@ void LoadImage(const void *path, ptrdiff_t pathBytes, void *destination, int des
|
|||
// Synchronisation.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_SYNC
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
void EsSpinlockAcquire(EsSpinlock *spinlock) {
|
||||
__sync_synchronize();
|
||||
|
@ -1812,7 +1804,7 @@ void EsMutexDestroy(EsMutex *mutex) {
|
|||
// Byte swapping.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_BYTE_SWAP
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
uint16_t ByteSwap16(uint16_t x) {
|
||||
return (x << 8) | (x >> 8);
|
||||
|
@ -1839,7 +1831,7 @@ uint32_t SwapBigEndian32(uint32_t x) {
|
|||
// C standard library.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_CSTDLIB
|
||||
#ifdef SHARED_COMMON_WANT_ALL
|
||||
|
||||
void *EsCRTmemset(void *s, int c, size_t n) {
|
||||
uint8_t *s8 = (uint8_t *) s;
|
||||
|
@ -2550,7 +2542,7 @@ int EsCRTvsnprintf(char *buffer, size_t bufferSize, const char *format, va_list
|
|||
// Memory buffers.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_COMMON_WANT_BUFFERS
|
||||
#if defined(SHARED_COMMON_WANT_BUFFERS) || defined(SHARED_COMMON_WANT_ALL)
|
||||
|
||||
const void *EsBufferRead(EsBuffer *buffer, size_t readBytes) {
|
||||
if (!readBytes && buffer->position == buffer->bytes) {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Basic utilities.
|
||||
/////////////////////////////////
|
||||
|
||||
#if defined(SHARED_MATH_WANT_BASIC_UTILITIES) || defined(SHARED_MATH_WANT_ALL)
|
||||
|
||||
template <class T>
|
||||
T RoundDown(T value, T divisor) {
|
||||
value /= divisor;
|
||||
|
@ -80,11 +82,13 @@ inline int64_t AbsoluteInteger64(int64_t a) {
|
|||
return a > 0 ? a : -a;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////
|
||||
// Interpolation.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifndef KERNEL
|
||||
#if defined(SHARED_MATH_WANT_INTERPOLATION) || defined(SHARED_MATH_WANT_ALL)
|
||||
|
||||
float LinearMap(float inFrom, float inTo, float outFrom, float outTo, float value) {
|
||||
float raw = (value - inFrom) / (inTo - inFrom);
|
||||
|
@ -95,6 +99,36 @@ float LinearInterpolate(float from, float to, float progress) {
|
|||
return from + progress * (to - from);
|
||||
}
|
||||
|
||||
float RubberBand(float original, float target) {
|
||||
float sign = SignFloat(original - target);
|
||||
float distance = AbsoluteFloat(original - target);
|
||||
float amount = EsCRTlog2f(distance);
|
||||
return target + sign * amount * 2.0f;
|
||||
}
|
||||
|
||||
float GammaInterpolate(float from, float to, float progress) {
|
||||
from = from * from;
|
||||
to = to * to;
|
||||
return EsCRTsqrtf(from + progress * (to - from));
|
||||
}
|
||||
|
||||
double SmoothAnimationTime(double progress) {
|
||||
if (progress > 1) return 1;
|
||||
progress -= 1;
|
||||
return 1 + progress * progress * progress;
|
||||
}
|
||||
|
||||
double SmoothAnimationTimeSharp(double progress) {
|
||||
if (progress > 1) return 1;
|
||||
progress -= 1;
|
||||
double progressSquared = progress * progress;
|
||||
return 1 + progressSquared * progressSquared * progress;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_MATH_WANT_ALL
|
||||
|
||||
EsRectangle EsRectangleLinearInterpolate(EsRectangle from, EsRectangle to, float progress) {
|
||||
return ES_RECT_4(LinearInterpolate(from.l, to.l, progress), LinearInterpolate(from.r, to.r, progress),
|
||||
LinearInterpolate(from.t, to.t, progress), LinearInterpolate(from.b, to.b, progress));
|
||||
|
@ -119,38 +153,14 @@ uint32_t EsColorInterpolate(uint32_t from, uint32_t to, float progress) {
|
|||
| (uint32_t) (LinearInterpolate(fa, ta, progress) * 255.0f) << 24;
|
||||
}
|
||||
|
||||
float RubberBand(float original, float target) {
|
||||
float sign = SignFloat(original - target);
|
||||
float distance = AbsoluteFloat(original - target);
|
||||
float amount = EsCRTlog2f(distance);
|
||||
return target + sign * amount * 2.0f;
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
float GammaInterpolate(float from, float to, float progress) {
|
||||
from = from * from;
|
||||
to = to * to;
|
||||
return EsCRTsqrtf(from + progress * (to - from));
|
||||
}
|
||||
#endif
|
||||
|
||||
double SmoothAnimationTime(double progress) {
|
||||
if (progress > 1) return 1;
|
||||
progress -= 1;
|
||||
return 1 + progress * progress * progress;
|
||||
}
|
||||
|
||||
double SmoothAnimationTimeSharp(double progress) {
|
||||
if (progress > 1) return 1;
|
||||
progress -= 1;
|
||||
double progressSquared = progress * progress;
|
||||
return 1 + progressSquared * progressSquared * progress;
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// HSV colors.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_MATH_WANT_ALL
|
||||
|
||||
uint32_t EsColorConvertToRGB(float h, float s, float v) {
|
||||
float r = 0, g = 0, b = 0;
|
||||
|
||||
|
@ -204,10 +214,14 @@ bool EsColorIsLight(uint32_t color) {
|
|||
return brightness >= 180.0f;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////
|
||||
// Standard mathematical functions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_MATH_WANT_ALL
|
||||
|
||||
union ConvertFloatInteger {
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
@ -869,10 +883,14 @@ bool EsCRTisnanf(float x) {
|
|||
#undef D
|
||||
#undef F
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////
|
||||
// High precision floats.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_MATH_WANT_ALL
|
||||
|
||||
#define MANTISSA_BITS (256)
|
||||
#include <x86intrin.h>
|
||||
|
||||
|
@ -1502,10 +1520,14 @@ void BigFloatInitialise() {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////
|
||||
// Calculating expressions.
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef SHARED_MATH_WANT_ALL
|
||||
|
||||
namespace Calculator {
|
||||
enum ValueType : uint8_t {
|
||||
VALUE_ERROR,
|
||||
|
|
|
@ -1406,6 +1406,7 @@ void DoCommand(const char *l) {
|
|||
|
||||
while ((entry = readdir(directory))) {
|
||||
if (0 == strcmp(entry->d_name, "nanosvg.h")) continue;
|
||||
if (0 == strcmp(entry->d_name, "hsluv.h")) continue;
|
||||
if (0 == strcmp(entry->d_name, "stb_ds.h")) continue;
|
||||
if (0 == strcmp(entry->d_name, "stb_image.h")) continue;
|
||||
if (0 == strcmp(entry->d_name, "stb_sprintf.h")) continue;
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#define UI_IMPLEMENTATION
|
||||
#define ES_CRT_WITHOUT_PREFIX
|
||||
#define EsPainter _EsPainter
|
||||
#define EsPaintTarget _EsPaintTarget
|
||||
#include "luigi.h"
|
||||
#undef EsPaintTarget
|
||||
#undef EsPainter
|
||||
#ifndef OS_ESSENCE
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#include "hsluv.h"
|
||||
|
||||
|
@ -34,20 +39,59 @@
|
|||
#define ES_TEXT_ELLIPSIS (1 << 6)
|
||||
#define ES_TEXT_WRAP (1 << 7)
|
||||
|
||||
#define ES_FONT_SANS (0xFFFF)
|
||||
#define ES_FONT_SERIF (0xFFFE)
|
||||
#define ES_FONT_MONOSPACED (0xFFFD)
|
||||
#define ES_FONT_SANS (0xFFFF)
|
||||
#define ES_FONT_SERIF (0xFFFE)
|
||||
#define ES_FONT_MONOSPACED (0xFFFD)
|
||||
|
||||
#define ES_FUNCTION_OPTIMISE_O2 __attribute__((optimize("-O2")))
|
||||
#define ES_FUNCTION_OPTIMISE_O3 __attribute__((optimize("-O3")))
|
||||
|
||||
#define ES_INFINITY INFINITY
|
||||
|
||||
#define EsAssert assert
|
||||
#define EsCRTacosf acosf
|
||||
#define EsCRTatan2f atan2f
|
||||
#define EsCRTceilf ceilf
|
||||
#define EsCRTcosf cosf
|
||||
#define EsCRTfabsf fabsf
|
||||
#define EsCRTfloorf floorf
|
||||
#define EsCRTfmodf fmodf
|
||||
#define EsCRTisnanf isnan
|
||||
#define EsCRTlog2f log2f
|
||||
#define EsCRTsinf sinf
|
||||
#define EsCRTsqrtf sqrtf
|
||||
#define EsHeap void
|
||||
#define EsHeapAllocate(a, b, c) calloc(1, (a))
|
||||
#define EsHeapFree(a, b, c) free((a))
|
||||
#define EsMemoryZero(a, b) memset((a), 0, (b))
|
||||
#define EsMemoryCopy memcpy
|
||||
#define EsMemoryCopyReverse memmove
|
||||
#define EsMemoryZero(a, b) memset((a), 0, (b))
|
||||
#define EsPanic(...) UI_ASSERT(false)
|
||||
|
||||
#define ES_MEMORY_MOVE_BACKWARDS -
|
||||
|
||||
#define SHARED_COMMON_WANT_BUFFERS
|
||||
|
||||
struct EsRectangle {
|
||||
int32_t l, r, t, b;
|
||||
};
|
||||
|
||||
struct EsBuffer {
|
||||
union { const uint8_t *in; uint8_t *out; };
|
||||
size_t position, bytes;
|
||||
bool error;
|
||||
void *context;
|
||||
};
|
||||
|
||||
void *EsHeapAllocate(size_t bytes, bool zero, EsHeap *heap = nullptr) {
|
||||
(void) heap;
|
||||
return zero ? calloc(1, bytes) : malloc(bytes);
|
||||
}
|
||||
|
||||
void EsHeapFree(void *pointer, size_t bytes = 0, EsHeap *heap = nullptr) {
|
||||
(void) heap;
|
||||
(void) bytes;
|
||||
free(pointer);
|
||||
}
|
||||
|
||||
void *EsHeapReallocate(void *oldAddress, size_t newAllocationSize, bool zeroNewSpace, EsHeap *) {
|
||||
UI_ASSERT(!zeroNewSpace);
|
||||
return realloc(oldAddress, newAllocationSize);
|
||||
|
@ -69,6 +113,17 @@ void EsMemoryMove(void *_start, void *_end, intptr_t amount, bool zeroEmptySpace
|
|||
|
||||
#endif
|
||||
|
||||
struct EsPaintTarget {
|
||||
void *bits;
|
||||
uint32_t width, height, stride;
|
||||
bool fullAlpha, readOnly;
|
||||
};
|
||||
|
||||
struct EsPainter {
|
||||
EsRectangle clip;
|
||||
EsPaintTarget *target;
|
||||
};
|
||||
|
||||
const char *cursorStrings[] = {
|
||||
"Normal",
|
||||
"Text",
|
||||
|
@ -101,53 +156,19 @@ const char *cursorStrings[] = {
|
|||
"Blank",
|
||||
};
|
||||
|
||||
void BlendPixel(uint32_t *destinationPixel, uint32_t modified, bool fullAlpha) {
|
||||
if ((modified & 0xFF000000) == 0xFF000000) {
|
||||
*destinationPixel = modified;
|
||||
} else if ((modified & 0xFF000000) == 0x00000000) {
|
||||
} else if ((*destinationPixel & 0xFF000000) != 0xFF000000 && fullAlpha) {
|
||||
uint32_t original = *destinationPixel;
|
||||
uint32_t alpha1 = (modified & 0xFF000000) >> 24;
|
||||
uint32_t alpha2 = 255 - alpha1;
|
||||
uint32_t alphaD = (original & 0xFF000000) >> 24;
|
||||
uint32_t alphaD2 = alphaD * alpha2;
|
||||
uint32_t alphaOut = alpha1 + (alphaD2 >> 8);
|
||||
#define IN_DESIGNER
|
||||
#define DESIGNER2
|
||||
|
||||
if (alphaOut) {
|
||||
uint32_t m2 = alphaD2 / alphaOut;
|
||||
uint32_t m1 = (alpha1 << 8) / alphaOut;
|
||||
if (m2 == 0x100) m2--;
|
||||
if (m1 == 0x100) m1--;
|
||||
uint32_t r2 = m2 * ((original & 0x000000FF) >> 0);
|
||||
uint32_t g2 = m2 * ((original & 0x0000FF00) >> 8);
|
||||
uint32_t b2 = m2 * ((original & 0x00FF0000) >> 16);
|
||||
uint32_t r1 = m1 * ((modified & 0x000000FF) >> 0);
|
||||
uint32_t g1 = m1 * ((modified & 0x0000FF00) >> 8);
|
||||
uint32_t b1 = m1 * ((modified & 0x00FF0000) >> 16);
|
||||
uint32_t result = (alphaOut << 24)
|
||||
| (0x00FF0000 & ((b1 + b2) << 8))
|
||||
| (0x0000FF00 & ((g1 + g2) << 0))
|
||||
| (0x000000FF & ((r1 + r2) >> 8));
|
||||
*destinationPixel = result;
|
||||
}
|
||||
} else {
|
||||
uint32_t original = *destinationPixel;
|
||||
uint32_t alpha1 = (modified & 0xFF000000) >> 24;
|
||||
uint32_t alpha2 = 255 - alpha1;
|
||||
uint32_t r2 = alpha2 * ((original & 0x000000FF) >> 0);
|
||||
uint32_t g2 = alpha2 * ((original & 0x0000FF00) >> 8);
|
||||
uint32_t b2 = alpha2 * ((original & 0x00FF0000) >> 16);
|
||||
uint32_t r1 = alpha1 * ((modified & 0x000000FF) >> 0);
|
||||
uint32_t g1 = alpha1 * ((modified & 0x0000FF00) >> 8);
|
||||
uint32_t b1 = alpha1 * ((modified & 0x00FF0000) >> 16);
|
||||
uint32_t result = 0xFF000000 | (0x00FF0000 & ((b1 + b2) << 8))
|
||||
| (0x0000FF00 & ((g1 + g2) << 0))
|
||||
| (0x000000FF & ((r1 + r2) >> 8));
|
||||
*destinationPixel = result;
|
||||
}
|
||||
}
|
||||
#define SHARED_COMMON_WANT_RECTANGLES
|
||||
#define SHARED_COMMON_WANT_RENDERING
|
||||
#include "../shared/common.cpp"
|
||||
#define SHARED_MATH_WANT_BASIC_UTILITIES
|
||||
#define SHARED_MATH_WANT_INTERPOLATION
|
||||
#include "../shared/math.cpp"
|
||||
|
||||
#include "../shared/array.cpp"
|
||||
#include "../desktop/renderer.cpp"
|
||||
#include "../desktop/theme.cpp"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -1210,10 +1231,10 @@ void InspectorPopulate() {
|
|||
sprintf(cPropertyName, "layers_%d_mode", i);
|
||||
UILabelCreate(0, 0, "Mode:", -1);
|
||||
UIPanelCreate(0, UI_ELEMENT_PARENT_PUSH | UI_PANEL_HORIZONTAL);
|
||||
InspectorAddRadioSwitch(object, "Background", cPropertyName, 0);
|
||||
InspectorAddRadioSwitch(object, "Shadow", cPropertyName, 1);
|
||||
InspectorAddRadioSwitch(object, "Content", cPropertyName, 2);
|
||||
InspectorAddRadioSwitch(object, "Overlay", cPropertyName, 3);
|
||||
InspectorAddRadioSwitch(object, "Background", cPropertyName, THEME_LAYER_MODE_BACKGROUND);
|
||||
InspectorAddRadioSwitch(object, "Shadow", cPropertyName, THEME_LAYER_MODE_SHADOW);
|
||||
InspectorAddRadioSwitch(object, "Content", cPropertyName, THEME_LAYER_MODE_CONTENT);
|
||||
InspectorAddRadioSwitch(object, "Overlay", cPropertyName, THEME_LAYER_MODE_OVERLAY);
|
||||
InspectorBind(&UIButtonCreate(0, UI_BUTTON_SMALL, "X", 1)->e, object->id, cPropertyName, INSPECTOR_REMOVE_BUTTON);
|
||||
UIParentPop();
|
||||
UIParentPop();
|
||||
|
|
Loading…
Reference in New Issue