use reference more instead of pointer

pull/23/head
JuanJakobo 2022-07-20 14:59:32 +02:00
parent f0fe9004d1
commit 15bfe04c09
8 changed files with 50 additions and 44 deletions

View File

@ -16,13 +16,13 @@
using std::string;
using std::vector;
ListView::ListView(const irect *contentRect, int page) : _contentRect(contentRect), _shownPage(page)
ListView::ListView(const irect &contentRect, int page) : _contentRect(contentRect), _shownPage(page)
{
_entries.clear();
_footerHeight = _contentRect->h / 10;
_footerHeight = _contentRect.h / 15;
_footerFontHeight = 0.3 * _footerHeight;
_entryFontHeight = 30; //0.2 * _footerFontHeight;//entrySize; //TODO how much?
_entryFontHeight = contentRect.h/45;
_footerFont = OpenFont("LiberationMono", _footerFontHeight, 1);
_entryFont = OpenFont("LiberationMono", _entryFontHeight, 1);
@ -30,11 +30,17 @@ ListView::ListView(const irect *contentRect, int page) : _contentRect(contentRec
SetFont(_entryFont, BLACK);
_pageIcon = iRect(_contentRect->w - 100, _contentRect->h - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
_firstPageButton = iRect(_contentRect->x, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
_prevPageButton = iRect(_contentRect->x + 150, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
_nextPageButton = iRect(_contentRect->x + 300, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
_lastPageButton = iRect(_contentRect->x + 450, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
int footerWidth = contentRect.w/20;
_pageIcon = iRect(_contentRect.w - footerWidth*2, _contentRect.h + _contentRect.y - _footerHeight, contentRect.w/10, _footerHeight, ALIGN_CENTER);
_firstPageButton = iRect(_contentRect.x, _contentRect.h + _contentRect.y - _footerHeight, contentRect.w/8, _footerHeight, ALIGN_CENTER);
_prevPageButton = iRect(_contentRect.x + footerWidth*3, _contentRect.h + _contentRect.y - _footerHeight, contentRect.w/8, _footerHeight, ALIGN_CENTER);
_nextPageButton = iRect(_contentRect.x + footerWidth*6, _contentRect.h + _contentRect.y - _footerHeight, contentRect.w/8, _footerHeight, ALIGN_CENTER);
_lastPageButton = iRect(_contentRect.x + footerWidth*9, _contentRect.h + _contentRect.y - _footerHeight, contentRect.w/8, _footerHeight, ALIGN_CENTER);
}
ListView::~ListView()
@ -46,22 +52,22 @@ ListView::~ListView()
void ListView::draw()
{
FillAreaRect(_contentRect, WHITE);
FillAreaRect(&_contentRect, WHITE);
drawEntries();
drawFooter();
PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h);
PartialUpdate(_contentRect.x, _contentRect.y, _contentRect.w, _contentRect.h);
}
void ListView::reDrawCurrentEntry()
{
FillAreaRect(_entries.at(_selectedEntry)->getPosition(), WHITE);
FillAreaRect(&_entries.at(_selectedEntry)->getPosition(), WHITE);
_entries.at(_selectedEntry)->draw(_entryFont, _entryFontBold, _entryFontHeight);
updateEntry(_selectedEntry);
}
void ListView::invertCurrentEntryColor()
{
InvertAreaBW(_entries.at(_selectedEntry)->getPosition()->x, _entries.at(_selectedEntry)->getPosition()->y, _entries.at(_selectedEntry)->getPosition()->w, _entries.at(_selectedEntry)->getPosition()->h);
InvertAreaBW(_entries.at(_selectedEntry)->getPosition().x, _entries.at(_selectedEntry)->getPosition().y, _entries.at(_selectedEntry)->getPosition().w, _entries.at(_selectedEntry)->getPosition().h);
updateEntry(_selectedEntry);
}
@ -96,7 +102,7 @@ bool ListView::checkIfEntryClicked(int x, int y)
{
for (unsigned int i = 0; i < _entries.size(); i++)
{
if (_entries.at(i)->getPage() == _shownPage && IsInRect(x, y, _entries.at(i)->getPosition()) == 1)
if (_entries.at(i)->getPage() == _shownPage && IsInRect(x, y, &_entries.at(i)->getPosition()) == 1)
{
_selectedEntry = i;
return true;
@ -125,7 +131,7 @@ void ListView::drawFooter()
void ListView::updateEntry(int entryID)
{
PartialUpdate(_entries.at(entryID)->getPosition()->x, _entries.at(entryID)->getPosition()->y, _entries.at(entryID)->getPosition()->w, _entries.at(entryID)->getPosition()->h);
PartialUpdate(_entries.at(entryID)->getPosition().x, _entries.at(entryID)->getPosition().y, _entries.at(entryID)->getPosition().w, _entries.at(entryID)->getPosition().h);
}
void ListView::actualizePage(int pageToShow)
@ -141,9 +147,9 @@ void ListView::actualizePage(int pageToShow)
else
{
_shownPage = pageToShow;
FillArea(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h, WHITE);
FillArea(_contentRect.x, _contentRect.y, _contentRect.w, _contentRect.h, WHITE);
drawEntries();
drawFooter();
PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h);
PartialUpdate(_contentRect.x, _contentRect.y, _contentRect.w, _contentRect.h);
}
}

View File

@ -25,13 +25,10 @@ public:
* @param ContentRect area of the screen where the list view is placed
* @param Items items that shall be shown in the listview
*/
ListView(const irect *contentRect, int page);
ListView(const irect &contentRect, int page);
virtual ~ListView();
virtual Entry *getCurrentEntry() = 0;
virtual Entry *getEntry(int entryID) = 0;
int getShownPage(){return _shownPage;};
/**
@ -80,7 +77,7 @@ protected:
int _footerHeight;
int _footerFontHeight;
int _entryFontHeight;
const irect *_contentRect;
const irect _contentRect;
std::vector<std::shared_ptr<ListViewEntry>> _entries;
ifont *_footerFont;
ifont *_entryFont;

View File

@ -25,7 +25,7 @@ public:
virtual ~ListViewEntry(){};
irect *getPosition() { return &_position; }
irect &getPosition() { return _position; }
int getPage() const { return _page; }
/**
@ -36,8 +36,6 @@ public:
* @param fontHeight height of the font
*/
virtual void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) = 0;
virtual Entry* get() = 0;
protected:
int _page;

View File

@ -14,17 +14,17 @@
using std::string;
LoginView *LoginView::_loginViewStatic;
std::unique_ptr<LoginView> LoginView::_loginViewStatic;
LoginView::LoginView(const irect *contentRect) : _contentRect(contentRect)
LoginView::LoginView(const irect &contentRect) : _contentRect(contentRect)
{
_loginViewStatic = this;
_loginViewStatic = std::unique_ptr<LoginView>(this);
int contentHeight = contentRect->h / 2;
int contentWidth = _contentRect->w * 0.9;
int contentHeight = contentRect.h / 2;
int contentWidth = _contentRect.w * 0.9;
int beginY = 0.4 * contentHeight;
int beginX = (_contentRect->w - contentWidth) / 2;
int beginX = (_contentRect.w - contentWidth) / 2;
int contents = contentHeight / 7;
@ -32,7 +32,7 @@ LoginView::LoginView(const irect *contentRect) : _contentRect(contentRect)
_loginFont = OpenFont("LiberationMono", _loginFontHeight, FONT_STD);
SetFont(_loginFont, BLACK);
FillAreaRect(_contentRect, WHITE);
FillAreaRect(&_contentRect, WHITE);
_urlButton = iRect(beginX, beginY, contentWidth, contents, ALIGN_CENTER);
DrawTextRect(_urlButton.x, _urlButton.y - _loginFontHeight - _loginFontHeight/2, _urlButton.w, _urlButton.h, "Server address:", ALIGN_LEFT);
@ -142,4 +142,4 @@ void LoginView::keyboardHandler(char *text)
DrawTextRect2(&_passwordButton, pass.c_str());
}
}
}

View File

@ -12,6 +12,7 @@
#include "inkview.h"
#include <string>
#include <memory>
enum KeyboardTarget
{
@ -30,7 +31,7 @@ public:
*
* @param contentRect area where the loginscreen shall be drawn
*/
LoginView(const irect *contentRect);
LoginView(const irect &contentRect);
~LoginView();
@ -48,10 +49,10 @@ public:
std::string getURL() { return _url; };
private:
static LoginView *_loginViewStatic;
static std::unique_ptr<LoginView> _loginViewStatic;
int _loginFontHeight;
ifont *_loginFont;
const irect *_contentRect;
const irect _contentRect;
irect _urlButton;
irect _loginButton;
irect _usernameButton;

View File

@ -14,10 +14,11 @@
using std::vector;
WebDAVView::WebDAVView(const irect *contentRect, const vector<WebDAVItem> &items, int page) : ListView(contentRect, page)
WebDAVView::WebDAVView(const irect &contentRect, const vector<WebDAVItem> &items, int page) : ListView(contentRect, page)
{
//TODO add line above!
auto pageHeight = 0;
auto contentHeight = _contentRect->h - _footerHeight;
auto contentHeight = _contentRect.h - _footerHeight;
auto entrycount = items.size();
_entries.reserve(entrycount);
@ -25,13 +26,17 @@ WebDAVView::WebDAVView(const irect *contentRect, const vector<WebDAVItem> &items
auto i = 0;
while (i < entrycount)
{
auto entrySize = TextRectHeight(contentRect->w, items.at(i).title.c_str(), 0) + 2.5 * _entryFontHeight;
auto entrySize = TextRectHeight(contentRect.w, items.at(i).title.c_str(), 0) + 2.5 * _entryFontHeight;
if(items.at(i).type == IFILE)
{
entrySize += _entryFontHeight;
}
if ((pageHeight + entrySize) > contentHeight)
{
pageHeight = 0;
_page++;
}
irect rect = iRect(_contentRect->x, _contentRect->y + pageHeight, _contentRect->w, entrySize, 0);
irect rect = iRect(_contentRect.x, _contentRect.y + pageHeight, _contentRect.w, entrySize, 0);
_entries.emplace_back(std::unique_ptr<WebDAVViewEntry>(new WebDAVViewEntry(_page, rect, items.at(i))));

View File

@ -26,11 +26,10 @@ public:
* @param Items items that shall be shown in the listview
* @param page page that is shown, default is 1
*/
WebDAVView(const irect *contentRect, const std::vector<WebDAVItem> &items, int page = 1);
WebDAVView(const irect &contentRect, const std::vector<WebDAVItem> &items, int page = 1);
//TODO make other pointer...
WebDAVItem *getCurrentEntry() { return getEntry(_selectedEntry); };
WebDAVItem &getCurrentEntry() { return getEntry(_selectedEntry); };
WebDAVItem *getEntry(int entryID) { return std::dynamic_pointer_cast<WebDAVViewEntry>(_entries.at(entryID))->get(); };
WebDAVItem &getEntry(int entryID) { return std::dynamic_pointer_cast<WebDAVViewEntry>(_entries.at(entryID))->get(); };
};
#endif

View File

@ -33,7 +33,7 @@ public:
*/
void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) override;
WebDAVItem *get() override { return &_entry; };
WebDAVItem &get() { return _entry; };
private:
WebDAVItem _entry;