Skip to content

Commit 926cdac

Browse files
committed
update for new libchesto, rebuild with latest libs
1 parent ce3e3e2 commit 926cdac

16 files changed

Lines changed: 347 additions & 210 deletions

‎edit/main.cpp‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../libs/json/single_include/nlohmann/json.hpp"
77
#include <algorithm>
88

9+
using namespace Chesto;
910

1011
#if defined(__WIIU__)
1112
#include <sysapp/launch.h>
@@ -14,38 +15,42 @@
1415
int main(int argc, char* argv[])
1516
{
1617
// initialize main title screen
17-
MainDisplay* display = new MainDisplay();
18+
auto display = std::make_unique<MainDisplay>();
1819

1920
// the main input handler
20-
auto events = display->events;
21-
events->rapidFireRate = 6; // 2x faster directional key repeat
21+
display->events->rapidFireRate = 6; // 2x faster directional key repeat
2222

2323
std::string startPath = START_PATH;
2424

2525
// USAGE: vgedit [file to edit path] [callback path]
26-
if (argc > 1) {
26+
if (argc > 1)
27+
{
2728
// get the file path from the command line
2829
startPath = argv[1];
2930

3031
// if there's a callback path, store it for later
31-
if (argc > 2) {
32+
if (argc > 2)
33+
{
3234
display->callbackPath = argv[2];
3335
}
3436
}
3537

3638
// check if the args.json file exists
3739
std::ifstream argsFile("args.json");
38-
if (argsFile.good()) {
40+
if (argsFile.good())
41+
{
3942
// parse the args.json file
4043
std::string argsJson((std::istreambuf_iterator<char>(argsFile)), std::istreambuf_iterator<char>());
4144
auto args = nlohmann::json::parse(argsJson);
4245

4346
// check if the file path is specified
44-
if (args.contains("filename")) {
47+
if (args.contains("filename"))
48+
{
4549
startPath = args["filename"];
4650

4751
// if there's a callback path, store it for later
48-
if (args.contains("callback")) {
52+
if (args.contains("callback"))
53+
{
4954
display->callbackPath = args["callback"];
5055
}
5156

@@ -58,21 +63,23 @@ int main(int argc, char* argv[])
5863
if (startPath != START_PATH && !std::filesystem::is_directory(startPath))
5964
{
6065
// if the file doesn't exist, create it TODO: entire path?
61-
if (!std::filesystem::exists(startPath)) {
66+
if (!std::filesystem::exists(startPath))
67+
{
6268
std::ofstream file(startPath);
6369
file.close();
6470
}
6571

6672
display->openFile(false, &startPath);
67-
68-
} else {
73+
}
74+
else
75+
{
6976
// otherwise, open a file browser to the start path
70-
FileBrowser* fileBrowser = new FileBrowser(startPath.c_str());
71-
display->browser = fileBrowser;
72-
display->elements.push_back(fileBrowser);
77+
auto fileBrowser = std::make_unique<FileBrowser>(startPath.c_str());
78+
display->browser = fileBrowser.get();
79+
display->addNode(std::move(fileBrowser));
7380
}
7481

75-
display->mainLoop();
76-
77-
return 0;
82+
// main loop
83+
auto* displayPtr = display.release();
84+
return displayPtr->mainLoop();
7885
}

‎gui/EditorView.cpp‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
#include "../libs/chesto/src/EKeyboard.hpp"
21
#include "EditorView.hpp"
2+
#include "../libs/chesto/src/EKeyboard.hpp"
33
#include "MainDisplay.hpp"
44

5+
using namespace Chesto;
6+
57
EditorView::EditorView(Editor* editor)
68
{
79
// initialize the text view for the first time, using whatever's in the editor
8-
mainTextField = new TextInputElement(editor);
9-
mainTextField->x = 10;
10-
mainTextField->y = 70;
11-
this->elements.push_back(mainTextField);
10+
auto mainTextFieldPtr = std::make_unique<TextInputElement>(editor);
11+
mainTextFieldPtr->x = 10;
12+
mainTextFieldPtr->y = 70;
1213

1314
#if defined(_3DS) || defined(_3DS_MOCK)
14-
mainTextField->x += 40;
15-
mainTextField->y += SCREEN_HEIGHT;
15+
mainTextFieldPtr->x += 40;
16+
mainTextFieldPtr->y += SCREEN_HEIGHT;
1617
#endif
1718

19+
mainTextField = mainTextFieldPtr.get();
20+
this->addNode(std::move(mainTextFieldPtr));
21+
1822
this->editor = editor;
1923
this->text = editor->text;
2024

@@ -63,23 +67,24 @@ void EditorView::reset_bounds()
6367
float cursor_y = mainTextField->selectedYPos;
6468

6569
// if this boolean is set, adjust the textfield in the direction of the cursor
66-
if (keepCursorOnscreen) {
70+
if (keepCursorOnscreen)
71+
{
6772
#if defined(_3DS) || defined(_3DS_MOCK)
6873
if (cursor_y > SCREEN_HEIGHT - 150)
69-
mainTextField->y -= h/2;
74+
mainTextField->y -= h / 2;
7075
if (cursor_y < 50)
71-
mainTextField->y += h/2;
76+
mainTextField->y += h / 2;
7277
#else
7378
if (mainTextField->selectedPos == 0)
7479
mainTextField->y = 0;
7580

7681
bool blockKeyboardDraws = mainTextField->insertMode && !keyboard->immersiveMode;
7782

7883
if (cursor_y > (blockKeyboardDraws ? 200 : (SCREEN_HEIGHT - 100)))
79-
mainTextField->y -= h/2;
84+
mainTextField->y -= h / 2;
8085

81-
if (cursor_y < 50 && mainTextField->y < -1 * h/4)
82-
mainTextField->y += h/2;
86+
if (cursor_y < 50 && mainTextField->y < -1 * h / 4)
87+
mainTextField->y += h / 2;
8388
#endif
8489
}
8590
}
@@ -90,9 +95,9 @@ bool EditorView::copySelection()
9095

9196
if (copiedText)
9297
delete copiedText;
93-
98+
9499
int pos = mainTextField->selectedPos;
95-
int width = mainTextField->selectedWidth;
100+
int width = mainTextField->selectedWidth;
96101

97102
copiedText = new std::string(text->substr(pos, width));
98103
((MainDisplay*)RootDisplay::mainDisplay)->copiedText = copiedText;
@@ -106,7 +111,7 @@ bool EditorView::pasteSelection()
106111
copiedText = ((MainDisplay*)RootDisplay::mainDisplay)->copiedText;
107112
if (copiedText == NULL)
108113
return false;
109-
114+
110115
editor->appendHistory(copiedText->c_str(), mainTextField->selectedPos, false);
111116

112117
for (char& letter : *copiedText)

‎gui/EditorView.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "TextInputElement.hpp"
77
#include "Toolbar.hpp"
88

9-
class EKeyboard;
9+
using namespace Chesto;
10+
1011
class Toolbar;
1112

1213
class EditorView : public Element
@@ -19,10 +20,10 @@ class EditorView : public Element
1920
Toolbar* toolbar = NULL;
2021
std::string* copiedText = NULL;
2122

22-
std::string* text = NULL;
23+
std::string* text = NULL;
2324

2425
// set to false when scrolling away with touch controls
25-
bool keepCursorOnscreen = true;
26+
bool keepCursorOnscreen = true;
2627

2728
// the big, main text field for the editor
2829
TextInputElement* mainTextField;

0 commit comments

Comments
 (0)