Skip to content

Commit

Permalink
Add Zooming Feature in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauchia committed Aug 16, 2024
1 parent 86887d4 commit b9a3daa
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 43 deletions.
152 changes: 110 additions & 42 deletions lib/gui/src/mainScr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "mainScr.hpp"
#include "core/lv_obj.h"
#include "core/lv_obj_pos.h"
#include "globalGuiDef.h"
#include "globalMapsDef.h"
Expand Down Expand Up @@ -40,6 +41,8 @@ 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 @@ -273,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 @@ -290,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 @@ -442,15 +413,31 @@ 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(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_add_flag(btnFullScreen, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(btnZoomOut, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(btnZoomIn, LV_OBJ_FLAG_HIDDEN);
}
else
{
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_HIDDEN);
lv_obj_invalidate(btnFullScreen);
lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(btnZoomIn, LV_OBJ_FLAG_HIDDEN);
}
//lv_obj_invalidate(btnFullScreen);
}

/**
Expand All @@ -465,14 +452,18 @@ void fullScreenEvent(lv_event_t *event)
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(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);
Expand All @@ -488,6 +479,56 @@ void fullScreenEvent(lv_event_t *event)
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 @@ -634,22 +675,49 @@ void createMainScr()
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(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_add_flag(btnFullScreen, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(btnZoomOut, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(btnZoomIn, LV_OBJ_FLAG_HIDDEN);
}
else
{
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_event_cb(btnFullScreen, fullScreenEvent, LV_EVENT_CLICKED, NULL);

lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(btnZoomIn, LV_OBJ_FLAG_HIDDEN);
}

// 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, toolBarEvent, LV_EVENT_CLICKED, 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
6 changes: 5 additions & 1 deletion lib/gui/src/mainScr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ extern lv_obj_t *satTrackTile;
*
*/
extern lv_obj_t *btnFullScreen;
extern lv_obj_t *btnZoomIn;
extern lv_obj_t *btnZoomOut;
extern int toolBarOffset;
extern int toolBarSpace;

Expand Down Expand Up @@ -98,7 +100,7 @@ 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();
Expand All @@ -107,6 +109,8 @@ 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

0 comments on commit b9a3daa

Please sign in to comment.