Merge branch 'fz-dev' into dev

This commit is contained in:
MX 2022-10-26 21:57:53 +03:00
commit 56b9361bc0
No known key found for this signature in database
GPG Key ID: 6C4C311DFD4B4AB5
7 changed files with 112 additions and 17 deletions

View File

@ -391,16 +391,39 @@ void canvas_set_bitmap_mode(Canvas* canvas, bool alpha) {
void canvas_set_orientation(Canvas* canvas, CanvasOrientation orientation) {
furi_assert(canvas);
if(canvas->orientation != orientation) {
canvas->orientation = orientation;
if(canvas->orientation == CanvasOrientationHorizontal) {
switch(orientation) {
case CanvasOrientationHorizontal:
if(canvas->orientation == CanvasOrientationVertical ||
canvas->orientation == CanvasOrientationVerticalFlip) {
FURI_SWAP(canvas->width, canvas->height);
}
u8g2_SetDisplayRotation(&canvas->fb, U8G2_R0);
} else if(canvas->orientation == CanvasOrientationVertical) {
break;
case CanvasOrientationHorizontalFlip:
if(canvas->orientation == CanvasOrientationVertical ||
canvas->orientation == CanvasOrientationVerticalFlip) {
FURI_SWAP(canvas->width, canvas->height);
}
u8g2_SetDisplayRotation(&canvas->fb, U8G2_R2);
break;
case CanvasOrientationVertical:
if(canvas->orientation == CanvasOrientationHorizontal ||
canvas->orientation == CanvasOrientationHorizontalFlip) {
FURI_SWAP(canvas->width, canvas->height);
};
u8g2_SetDisplayRotation(&canvas->fb, U8G2_R3);
} else {
break;
case CanvasOrientationVerticalFlip:
if(canvas->orientation == CanvasOrientationHorizontal ||
canvas->orientation == CanvasOrientationHorizontalFlip) {
FURI_SWAP(canvas->width, canvas->height);
}
u8g2_SetDisplayRotation(&canvas->fb, U8G2_R1);
break;
default:
furi_assert(0);
}
canvas->orientation = orientation;
}
}

View File

@ -43,7 +43,9 @@ typedef enum {
/** Canvas Orientation */
typedef enum {
CanvasOrientationHorizontal,
CanvasOrientationHorizontalFlip,
CanvasOrientationVertical,
CanvasOrientationVerticalFlip,
} CanvasOrientation;
/** Font Direction */

View File

@ -322,7 +322,9 @@ void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) {
furi_check(layer < GuiLayerMAX);
// Only fullscreen supports Vertical orientation for now
furi_assert(
(layer == GuiLayerFullscreen) || (view_port->orientation != ViewPortOrientationVertical));
(layer == GuiLayerFullscreen) ||
((view_port->orientation != ViewPortOrientationVertical) &&
(view_port->orientation != ViewPortOrientationVerticalFlip)));
gui_lock(gui);
// Verify that view port is not yet added

View File

@ -25,7 +25,9 @@ extern "C" {
typedef enum {
ViewOrientationHorizontal,
ViewOrientationHorizontalFlip,
ViewOrientationVertical,
ViewOrientationVerticalFlip,
} ViewOrientation;
/** View, anonymous type */

View File

@ -331,10 +331,16 @@ void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* vie
view_dispatcher->current_view = view;
// Dispatch view enter event
if(view_dispatcher->current_view) {
if(view->orientation == ViewOrientationVertical)
if(view->orientation == ViewOrientationVertical) {
view_port_set_orientation(view_dispatcher->view_port, ViewPortOrientationVertical);
else if(view->orientation == ViewOrientationHorizontal)
} else if(view->orientation == ViewOrientationVerticalFlip) {
view_port_set_orientation(view_dispatcher->view_port, ViewPortOrientationVerticalFlip);
} else if(view->orientation == ViewOrientationHorizontal) {
view_port_set_orientation(view_dispatcher->view_port, ViewPortOrientationHorizontal);
} else if(view->orientation == ViewOrientationHorizontalFlip) {
view_port_set_orientation(
view_dispatcher->view_port, ViewPortOrientationHorizontalFlip);
}
view_enter(view_dispatcher->current_view);
view_port_enabled_set(view_dispatcher->view_port, true);
view_port_update(view_dispatcher->view_port);

View File

@ -7,7 +7,7 @@
// TODO add mutex to view_port ops
static void view_port_rotate_buttons(InputEvent* event) {
static void view_port_remap_buttons_vertical(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyRight;
@ -26,14 +26,61 @@ static void view_port_rotate_buttons(InputEvent* event) {
}
}
static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas* canvas) {
if(view_port->orientation == ViewPortOrientationHorizontal) {
canvas_set_orientation(canvas, CanvasOrientationHorizontal);
} else if(view_port->orientation == ViewPortOrientationVertical) {
canvas_set_orientation(canvas, CanvasOrientationVertical);
static void view_port_remap_buttons_vertical_flip(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyLeft;
break;
case InputKeyDown:
event->key = InputKeyRight;
break;
case InputKeyRight:
event->key = InputKeyUp;
break;
case InputKeyLeft:
event->key = InputKeyDown;
break;
default:
break;
}
}
static void view_port_remap_buttons_horizontal_flip(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyDown;
break;
case InputKeyDown:
event->key = InputKeyUp;
break;
case InputKeyRight:
event->key = InputKeyLeft;
break;
case InputKeyLeft:
event->key = InputKeyRight;
break;
default:
break;
}
}
static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas* canvas) {
switch(view_port->orientation) {
case ViewPortOrientationHorizontalFlip:
canvas_set_orientation(canvas, CanvasOrientationHorizontalFlip);
break;
case ViewPortOrientationVertical:
canvas_set_orientation(canvas, CanvasOrientationVertical);
break;
case ViewPortOrientationVerticalFlip:
canvas_set_orientation(canvas, CanvasOrientationVerticalFlip);
break;
default:
canvas_set_orientation(canvas, CanvasOrientationHorizontal);
break;
};
}
ViewPort* view_port_alloc() {
ViewPort* view_port = malloc(sizeof(ViewPort));
view_port->orientation = ViewPortOrientationHorizontal;
@ -122,8 +169,19 @@ void view_port_input(ViewPort* view_port, InputEvent* event) {
furi_check(view_port->gui);
if(view_port->input_callback) {
if(view_port_get_orientation(view_port) == ViewPortOrientationVertical) {
view_port_rotate_buttons(event);
ViewPortOrientation orientation = view_port_get_orientation(view_port);
switch(orientation) {
case ViewPortOrientationHorizontalFlip:
view_port_remap_buttons_horizontal_flip(event);
break;
case ViewPortOrientationVertical:
view_port_remap_buttons_vertical(event);
break;
case ViewPortOrientationVerticalFlip:
view_port_remap_buttons_vertical_flip(event);
break;
default:
break;
}
view_port->input_callback(event, view_port->input_callback_context);
}

View File

@ -16,7 +16,9 @@ typedef struct ViewPort ViewPort;
typedef enum {
ViewPortOrientationHorizontal,
ViewPortOrientationHorizontalFlip,
ViewPortOrientationVertical,
ViewPortOrientationVerticalFlip,
} ViewPortOrientation;
/** ViewPort Draw callback