-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petr Laštovička
committed
Apr 25, 2022
1 parent
e04e030
commit 1892f9f
Showing
12 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "app.hpp" | ||
|
||
namespace cz::lastaapps::vimxel { | ||
int App::run(vector<string> args) { | ||
display::Display().draw(); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef APP_H | ||
#define APP_H | ||
#include <vector> | ||
#include <string> | ||
#include "display/display.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel { | ||
|
||
class App final { | ||
public: | ||
int run(vector<string> args); | ||
private: | ||
// Storage engine | ||
// NCurses Init | ||
// Table | ||
// Display | ||
// Vim | ||
}; | ||
|
||
|
||
} // namespace cz::lastaapps::vimxel | ||
|
||
#endif |
45 changes: 45 additions & 0 deletions
45
Semestralni_prace/src/cz/lastaapps/vimxel/display/contentDrawer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "contentDrawer.hpp" | ||
|
||
namespace cz::lastaapps::vimxel::display { | ||
|
||
ContentDrawer::ContentDrawer( | ||
WINDOW* w, | ||
const size_t colW, const size_t rowH, | ||
shared_ptr<CellContract> ptr) | ||
: Drawer(w), mColWidth(colW), mRowHeight(rowH), mCntr(ptr) { init(); } | ||
|
||
ContentDrawer::ContentDrawer( | ||
WINDOW* w, | ||
const size_t colW, const size_t rowH, | ||
table::Coordinates pos, table::Coordinates viewPort, shared_ptr<CellContract> ptr) | ||
: Drawer(w, pos, viewPort), mColWidth(colW), mRowHeight(rowH), mCntr(ptr) { init(); } | ||
|
||
ContentDrawer::~ContentDrawer() { | ||
mCntr->unregisterCallback(); | ||
} | ||
void ContentDrawer::init() { | ||
mCntr->registerCallback( | ||
[this](const Coordinates& coord) { renderItem(coord); }); | ||
} | ||
void ContentDrawer::draw() { | ||
} | ||
inline Coordinates ContentDrawer::getCellsCount() const { | ||
return Coordinates(mWinSize.x() / mColWidth, mWinSize.y() / mRowHeight); | ||
} | ||
inline void ContentDrawer::renderItem(const Coordinates& coord) { | ||
const Coordinates point = getRealPoint(coord); | ||
const string content = mCntr -> getDataAt(coord); | ||
const bool selected = isSelected(coord); | ||
if (selected) wattron(mWin, A_STANDOUT); | ||
mvwprintw(mWin, point.y(), point.x(), "%.*s", (int)mColWidth, content.c_str()); | ||
wattroff(mWin, A_STANDOUT); | ||
} | ||
inline bool ContentDrawer::isSelected(const Coordinates& coord) { | ||
return mPos.x() == coord.x() && mPos.y() == coord.y(); | ||
} | ||
Coordinates ContentDrawer::getRealPoint(const Coordinates& coord) { | ||
const Coordinates diff = coord - mViewPort; | ||
return Coordinates(diff.x() * mColWidth, diff.y() * mRowHeight); | ||
} | ||
|
||
} // namespace cz::lastaapps::vimxel::display |
36 changes: 36 additions & 0 deletions
36
Semestralni_prace/src/cz/lastaapps/vimxel/display/contentDrawer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef CONTENT_DRAWER_H | ||
#define CONTENT_DRAWER_H | ||
#include <ncurses.h> | ||
#include <memory> | ||
|
||
#include "../table/coordinate.hpp" | ||
#include "../table/cellContract.hpp" | ||
#include "drawer.hpp" | ||
using namespace std; | ||
using namespace cz::lastaapps::vimxel; | ||
using namespace cz::lastaapps::vimxel::table; | ||
namespace cz::lastaapps::vimxel::display { | ||
class ContentDrawer final : public Drawer { | ||
const size_t mColWidth, mRowHeight; | ||
const shared_ptr<CellContract> mCntr; | ||
Coordinates cellCount = getCellsCount(); | ||
|
||
public: | ||
ContentDrawer(WINDOW * w, const size_t colW, const size_t rowH, shared_ptr<CellContract> cnt); | ||
ContentDrawer( | ||
WINDOW* w, | ||
const size_t colW, const size_t rowH, | ||
table::Coordinates pos, table::Coordinates viewPort, | ||
shared_ptr<CellContract> cnt); | ||
~ContentDrawer(); | ||
void draw() override; | ||
|
||
private: | ||
void init(); | ||
inline Coordinates getCellsCount() const; | ||
inline void renderItem(const Coordinates &coord); | ||
inline bool isSelected(const Coordinates &coord); | ||
Coordinates getRealPoint(const Coordinates& coord); | ||
}; | ||
} // namespace cz::lastaapps::vimxel::display | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
#include "display/display.hpp" | ||
#include "app.hpp" | ||
#include <vector> | ||
#include <string> | ||
using namespace std; | ||
|
||
int main(void) { | ||
cz::lastaapps::vimxel::display::Display().draw(); | ||
int main(int cnt, char** args) { | ||
vector<string> normal; | ||
for (int i = 0; i < cnt; i++) { | ||
normal.emplace_back(string(args[i])); | ||
} | ||
cz::lastaapps::vimxel::App().run(normal); | ||
return 0; | ||
} |
14 changes: 14 additions & 0 deletions
14
Semestralni_prace/src/cz/lastaapps/vimxel/table/cellContract.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "cellContract.hpp" | ||
|
||
|
||
namespace cz::lastaapps::vimxel::table { | ||
void CellContract::dataUpdatedAt(const Coordinates & coord) { | ||
mCallback(coord); | ||
} | ||
void CellContract::registerCallback(Callback c) { | ||
mCallback = c; | ||
} | ||
void CellContract::unregisterCallback() { | ||
mCallback = Callback(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Semestralni_prace/src/cz/lastaapps/vimxel/table/cellContract.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef CELL_CONTRACT_H | ||
#define CELL_CONTRACT_H | ||
#include "coordinate.hpp" | ||
#include <functional> | ||
#include <list> | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::table { | ||
class CellContract { | ||
using Callback = function<void(const Coordinates&)>; | ||
Callback mCallback; | ||
public: | ||
virtual ~CellContract() {}; | ||
virtual string getDataAt(const Coordinates & coord) const = 0; | ||
void dataUpdatedAt(const Coordinates & coord); | ||
void registerCallback(Callback); | ||
void unregisterCallback(); | ||
}; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters