Skip to content

Commit

Permalink
Merge pull request #181 from jgauchia/180-map-screen-full-screen-mode
Browse files Browse the repository at this point in the history
Add full screen feature to map screen
  • Loading branch information
jgauchia authored Aug 16, 2024
2 parents af26644 + 96c4ed7 commit 3a3c8e4
Show file tree
Hide file tree
Showing 15 changed files with 757 additions and 78 deletions.
254 changes: 211 additions & 43 deletions lib/gui/src/mainScr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@
*/

#include "mainScr.hpp"
#include "core/lv_obj.h"
#include "core/lv_obj_pos.h"
#include "globalGuiDef.h"
#include "globalMapsDef.h"
#include "settings.hpp"
#include "tft.hpp"


bool isMainScreen = false; // Flag to indicate main screen is selected
bool isScrolled = true; // Flag to indicate when tileview was scrolled
bool isReady = false; // Flag to indicate when tileview scroll was finished
bool redrawMap = true; // Flag to indicate when needs to redraw Map
uint8_t activeTile = 0; // Current active tile
bool isMainScreen = false; // Flag to indicate main screen is selected
bool isScrolled = true; // Flag to indicate when tileview was scrolled
bool isReady = false; // Flag to indicate when tileview scroll was finished
bool redrawMap = true; // Flag to indicate when needs to redraw Map
uint8_t activeTile = 0; // Current active tile

#ifdef LARGE_SCREEN
int toolBarOffset = 100;
int toolBarSpace = 60;
#endif
#ifndef LARGE_SCREEN
int toolBarOffset = 80;
int toolBarSpace = 50;
#endif

lv_obj_t *compassHeading;
lv_obj_t *compassImg;
Expand All @@ -26,6 +40,9 @@ lv_obj_t *compassTile;
lv_obj_t *navTile;
lv_obj_t *mapTile;
lv_obj_t *satTrackTile;
lv_obj_t *btnFullScreen;
lv_obj_t *btnZoomIn;
lv_obj_t *btnZoomOut;

/**
* @brief Update compass screen event
Expand Down Expand Up @@ -154,13 +171,23 @@ void getActTile(lv_event_t *event)
if (activeTile == MAP)
{
createMapScrSprites();
lv_obj_add_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
if (isMapFullScreen)
{
lv_obj_add_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(notifyBarHour, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(notifyBarIcons, LV_OBJ_FLAG_HIDDEN);
}
}
else
{
lv_obj_clear_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
if (isMapFullScreen)
{
lv_obj_clear_flag(notifyBarHour,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(notifyBarIcons, LV_OBJ_FLAG_HIDDEN);
}
}
}
else
Expand All @@ -184,6 +211,12 @@ void scrollTile(lv_event_t *event)
isReady = false;
redrawMap = false;

if (isMapFullScreen)
{
lv_obj_clear_flag(notifyBarHour,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(notifyBarIcons, LV_OBJ_FLAG_HIDDEN);
}

deleteMapScrSprites();
deleteSatInfoSprites();
}
Expand Down Expand Up @@ -243,11 +276,11 @@ void updateMainScreen(lv_timer_t *t)
}

/**
* @brief Update zoom value
* @brief Map Gesture Event
*
* @param event
*/
void getZoomValue(lv_event_t *event)
void gestureEvent(lv_event_t *event)
{
lv_obj_t *screen = (lv_obj_t *)lv_event_get_current_target(event);
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
Expand All @@ -260,40 +293,8 @@ void getZoomValue(lv_event_t *event)
case LV_DIR_RIGHT:
break;
case LV_DIR_TOP:
if (!isVectorMap)
{
if (zoom >= minZoom && zoom < maxZoom)
zoom++;
}
else
{
zoom--;
isPosMoved = true;
if (zoom < 1)
{
zoom = 1;
isPosMoved = false;
}
}
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
break;
case LV_DIR_BOTTOM:
if (!isVectorMap)
{
if (zoom <= maxZoom && zoom > minZoom)
zoom--;
}
else
{
zoom++;
isPosMoved = true;
if (zoom > MAX_ZOOM)
{
zoom = MAX_ZOOM;
isPosMoved = false;
}
}
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
break;
}
}
Expand Down Expand Up @@ -402,6 +403,131 @@ void updateSatTrack(lv_event_t *event)
#endif
}

/**
* @brief Tool Bar Event
*
* @param event
*/
void toolBarEvent(lv_event_t *event)
{
showToolBar = !showToolBar;

if (!isMapFullScreen)
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT - toolBarOffset);
lv_obj_set_pos(btnZoomOut, 10 , MAP_HEIGHT - (toolBarOffset + toolBarSpace));
lv_obj_set_pos(btnZoomIn, 10, MAP_HEIGHT - (toolBarOffset + (2 * toolBarSpace)));
}
else
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT_FULL - (toolBarOffset + 24));
lv_obj_set_pos(btnZoomOut, 10, MAP_HEIGHT_FULL - (toolBarOffset + toolBarSpace + 24));
lv_obj_set_pos(btnZoomIn,10, MAP_HEIGHT_FULL - (toolBarOffset + (2 * toolBarSpace) + 24));
}

if (!showToolBar)
{
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
}
else
{
lv_obj_add_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
}
}

/**
* @brief Full Screen Event Toolbar
*
* @param event
*/
void fullScreenEvent(lv_event_t *event)
{
isMapFullScreen = !isMapFullScreen;

if (!isMapFullScreen)
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT - toolBarOffset);
lv_obj_set_pos(btnZoomOut, 10, MAP_HEIGHT - (toolBarOffset + toolBarSpace));
lv_obj_set_pos(btnZoomIn, 10, MAP_HEIGHT - (toolBarOffset + (2 * toolBarSpace)));
lv_obj_clear_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(notifyBarHour, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(notifyBarIcons, LV_OBJ_FLAG_HIDDEN);
}
else
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT_FULL - (toolBarOffset + 24));
lv_obj_set_pos(btnZoomOut, 10, MAP_HEIGHT_FULL - (toolBarOffset + toolBarSpace + 24));
lv_obj_set_pos(btnZoomIn, 10, MAP_HEIGHT_FULL - (toolBarOffset + (2 * toolBarSpace) + 24));
lv_obj_add_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(notifyBarHour, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(notifyBarIcons, LV_OBJ_FLAG_HIDDEN);
}

deleteMapScrSprites();
createMapScrSprites();

redrawMap = true;

lv_obj_invalidate(tilesScreen);
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
}

/**
* @brief Zoom In Event Toolbar
*
* @param event
*/
void zoomInEvent(lv_event_t *event)
{
if (!isVectorMap)
{
if (zoom >= minZoom && zoom < maxZoom)
zoom++;
}
else
{
zoom--;
isPosMoved = true;
if (zoom < 1)
{
zoom = 1;
isPosMoved = false;
}
}
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
}

/**
* @brief Zoom Out Event Toolbar
*
* @param event
*/
void zoomOutEvent(lv_event_t *event)
{
if (!isVectorMap)
{
if (zoom <= maxZoom && zoom > minZoom)
zoom--;
}
else
{
zoom++;
isPosMoved = true;
if (zoom > MAX_ZOOM)
{
zoom = MAX_ZOOM;
isPosMoved = false;
}
}
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
}

/**
* @brief Create Main Screen
*
Expand Down Expand Up @@ -544,11 +670,53 @@ void createMainScr()
lv_obj_add_event_cb(speedLabel, updateCompassScr, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(editScreenBtn, editScreen, LV_EVENT_ALL, NULL);

// Map Tile
// Map Tile Toolbar
btnFullScreen = lv_btn_create(mapTile);
lv_obj_remove_style_all(btnFullScreen);
lv_obj_set_size(btnFullScreen, 48, 48);
lv_obj_add_event_cb(btnFullScreen, fullScreenEvent, LV_EVENT_CLICKED, NULL);

btnZoomOut = lv_btn_create(mapTile);
lv_obj_remove_style_all(btnZoomOut);
lv_obj_set_size(btnZoomOut, 48, 48);
lv_obj_add_event_cb(btnZoomOut, zoomOutEvent, LV_EVENT_CLICKED, NULL);


btnZoomIn = lv_btn_create(mapTile);
lv_obj_remove_style_all(btnZoomIn);
lv_obj_set_size(btnZoomIn, 48, 48);
lv_obj_add_event_cb(btnZoomIn, zoomInEvent, LV_EVENT_CLICKED, NULL);

if (!isMapFullScreen)
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT - toolBarOffset);
lv_obj_set_pos(btnZoomOut, 10, MAP_HEIGHT - (toolBarOffset + toolBarSpace));
lv_obj_set_pos(btnZoomIn, 10, MAP_HEIGHT - ( toolBarOffset + (2 * toolBarSpace)));
}
else
{
lv_obj_set_pos(btnFullScreen, 10, MAP_HEIGHT_FULL - (toolBarOffset + 24));
lv_obj_set_pos(btnZoomOut, 10, MAP_HEIGHT_FULL - (toolBarOffset + toolBarSpace + 24));
lv_obj_set_pos(btnZoomIn, 10, MAP_HEIGHT_FULL - (toolBarOffset + (2 * toolBarSpace) + 24));
}

if (!showToolBar)
{
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
}
else
{
lv_obj_add_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
}

// Map Tile Events
lv_obj_add_event_cb(mapTile, updateMap, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(mainScreen, getZoomValue, LV_EVENT_GESTURE, NULL);
lv_obj_add_event_cb(mapTile, gestureEvent, LV_EVENT_GESTURE, NULL);
lv_obj_add_event_cb(mapTile, toolBarEvent, LV_EVENT_LONG_PRESSED, NULL);

// Navigation Tile
// TODO
Expand Down
16 changes: 15 additions & 1 deletion lib/gui/src/mainScr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ extern lv_obj_t *navTile;
extern lv_obj_t *mapTile;
extern lv_obj_t *satTrackTile;

/**
* @brief Map Toolbar Buttons
*
*/
extern lv_obj_t *btnFullScreen;
extern lv_obj_t *btnZoomIn;
extern lv_obj_t *btnZoomOut;
extern int toolBarOffset;
extern int toolBarSpace;

/**
* @brief Compass Tile screen objects
*
Expand Down Expand Up @@ -90,13 +100,17 @@ void scrollTile(lv_event_t *event);
void generateRenderMap();
void generateVectorMap();
void updateMainScreen(lv_timer_t *t);
void getZoomValue(lv_event_t *event);
void gestureEvent(lv_event_t *event);
void deleteMapScrSprites();
void createMapScrSprites();
void drawMapWidgets();
void updateMap(lv_event_t *event);
void activeGnssEvent(lv_event_t *event);
void updateSatTrack(lv_event_t *event);
void toolBarEvent(lv_event_t *event);
void fullScreenEvent(lv_event_t *event);
void zoomOutEvent(lv_event_t *event);
void zoomInEvent(lv_event_t *event);

void createMainScr();

Expand Down
Loading

0 comments on commit 3a3c8e4

Please sign in to comment.