From 2fcb2878fc1284c008bb7a784c4d46296f960dd4 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Sat, 12 Feb 2022 09:50:58 +0000 Subject: [PATCH] canvas pane: optional shadow; use cell flags --- apps/image_editor.cpp | 4 ++-- apps/script_console.cpp | 11 ++++++++++- desktop/gui.cpp | 29 +++++++++++++++++++++++------ desktop/os.header | 2 ++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/apps/image_editor.cpp b/apps/image_editor.cpp index c7def0d..a3e2530 100644 --- a/apps/image_editor.cpp +++ b/apps/image_editor.cpp @@ -887,8 +887,8 @@ void InstanceCreate(EsMessage *message) { EsWindowSetIcon(instance->window, ES_ICON_MULTIMEDIA_PHOTO_MANAGER); - EsCanvasPane *canvasPane = EsCanvasPaneCreate(instance->window, ES_CELL_FILL, ES_STYLE_PANEL_WINDOW_BACKGROUND); - instance->canvas = EsCustomElementCreate(canvasPane, ES_CELL_FILL | ES_ELEMENT_FOCUSABLE); + EsCanvasPane *canvasPane = EsCanvasPaneCreate(instance->window, ES_CELL_FILL | ES_CANVAS_PANE_SHOW_SHADOW, ES_STYLE_PANEL_WINDOW_BACKGROUND); + instance->canvas = EsCustomElementCreate(canvasPane, ES_CELL_CENTER | ES_ELEMENT_FOCUSABLE); instance->canvas->messageUser = CanvasMessage; EsElementFocus(instance->canvas, false); diff --git a/apps/script_console.cpp b/apps/script_console.cpp index 389d606..602db2f 100644 --- a/apps/script_console.cpp +++ b/apps/script_console.cpp @@ -654,6 +654,14 @@ const EsStyle styleList = { }, }; +const EsStyle styleImageViewerPane = { + .metrics = { + .mask = ES_THEME_METRICS_CLIP_ENABLED | ES_THEME_METRICS_MAXIMUM_HEIGHT, + .clipEnabled = true, + .maximumHeight = 400, + }, +}; + void AddREPLResult(ExecutionContext *context, EsElement *parent, Node *type, Value value) { // TODO Truncating/scrolling/collapsing/saving/copying output. // TODO Letting scripts register custom views for structs. @@ -688,7 +696,8 @@ void AddREPLResult(ExecutionContext *context, EsElement *parent, Node *type, Val if ((valueBytes > sizeof(pngSignature) && 0 == EsMemoryCompare(&pngSignature, valueText, sizeof(pngSignature))) || (valueBytes > sizeof(jpgSignature) && 0 == EsMemoryCompare(&jpgSignature, valueText, sizeof(jpgSignature)))) { - EsImageDisplay *display = EsImageDisplayCreate(parent, ES_CELL_H_FILL); + EsCanvasPane *canvasPane = EsCanvasPaneCreate(parent, ES_CELL_H_FILL, EsStyleIntern(&styleImageViewerPane)); + EsImageDisplay *display = EsImageDisplayCreate(canvasPane, ES_CELL_H_LEFT | ES_CELL_V_TOP); EsImageDisplayLoadFromMemory(display, valueText, valueBytes); } else if (EsUTF8IsValid(valueText, valueBytes)) { char *buffer = EsStringAllocateAndFormat(&bytes, "\u201C%s\u201D", valueBytes, valueText); diff --git a/desktop/gui.cpp b/desktop/gui.cpp index 8f34a5d..7ed4270 100644 --- a/desktop/gui.cpp +++ b/desktop/gui.cpp @@ -3943,12 +3943,26 @@ int ProcessCanvasPaneMessage(EsElement *element, EsMessage *message) { if (pane->panY < 0) pane->panY = 0; if (pane->panY > height - Height(bounds) / pane->zoom) pane->panY = height - Height(bounds) / pane->zoom; - if (width * pane->zoom <= Width(bounds) || pane->center) { + bool widthFits = width * pane->zoom <= Width(bounds); + bool heightFits = height * pane->zoom <= Height(bounds); + + if (pane->center) { pane->panX = width / 2 - Width(bounds) / pane->zoom / 2; + pane->panY = height / 2 - Height(bounds) / pane->zoom / 2; } - if (height * pane->zoom <= Height(bounds) || pane->center) { - pane->panY = height / 2 - Height(bounds) / pane->zoom / 2; + if (widthFits) { + uint64_t cellH = canvas->flags & (ES_CELL_H_LEFT | ES_CELL_H_RIGHT); + if (cellH == ES_CELL_H_LEFT) pane->panX = 0; + if (cellH == ES_CELL_H_CENTER) pane->panX = width / 2 - Width(bounds) / pane->zoom / 2; + if (cellH == ES_CELL_H_RIGHT) pane->panX = width - Width(bounds) / pane->zoom; + } + + if (heightFits) { + uint64_t cellV = canvas->flags & (ES_CELL_V_TOP | ES_CELL_V_BOTTOM); + if (cellV == ES_CELL_V_TOP) pane->panY = 0; + if (cellV == ES_CELL_V_CENTER) pane->panY = height / 2 - Height(bounds) / pane->zoom / 2; + if (cellV == ES_CELL_V_BOTTOM) pane->panY = height - Height(bounds) / pane->zoom; } pane->scroll.position[0] = pane->panX; @@ -3964,9 +3978,12 @@ int ProcessCanvasPaneMessage(EsElement *element, EsMessage *message) { } else if (message->type == ES_MSG_PAINT) { EsElement *canvas = CanvasPaneGetCanvas(element); if (!canvas) return 0; - UIStyle *style = GetStyle(MakeStyleKey(ES_STYLE_CANVAS_SHADOW, 0), true); - EsRectangle shadow = ES_RECT_4PD(canvas->offsetX, canvas->offsetY, canvas->width, canvas->height); - style->PaintLayers(message->painter, shadow, THEME_CHILD_TYPE_ONLY, ES_FLAGS_DEFAULT); + + if (element->flags & ES_CANVAS_PANE_SHOW_SHADOW) { + UIStyle *style = GetStyle(MakeStyleKey(ES_STYLE_CANVAS_SHADOW, 0), true); + EsRectangle shadow = ES_RECT_4PD(canvas->offsetX, canvas->offsetY, canvas->width, canvas->height); + style->PaintLayers(message->painter, shadow, THEME_CHILD_TYPE_ONLY, ES_FLAGS_DEFAULT); + } } else if (message->type == ES_MSG_MOUSE_MIDDLE_DOWN) { pane->lastPanPoint = EsMouseGetPosition(pane); } else if (message->type == ES_MSG_MOUSE_MIDDLE_DRAG) { diff --git a/desktop/os.header b/desktop/os.header index f78fea5..e2d7ae2 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -777,6 +777,8 @@ define ES_LIST_VIEW_CHOOSE_ITEM_MIDDLE_CLICK (4) define ES_SHUTDOWN_ACTION_POWER_OFF (1) define ES_SHUTDOWN_ACTION_RESTART (2) +define ES_CANVAS_PANE_SHOW_SHADOW (1 << 0) + include desktop/icons.header enum EsFatalError {