Skip to content

Commit

Permalink
removed object box
Browse files Browse the repository at this point in the history
  • Loading branch information
karwler committed Jun 3, 2016
1 parent eeff73e commit f8f9368
Show file tree
Hide file tree
Showing 22 changed files with 215 additions and 366 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Used libraries are boost_filesystem, SDL2, SDL2_image, SDL2_ttf and SDL2_mixer.

The Qt project file is configured for Linux, Windows and OS X.
Note: When setting the output directory in Qt, don’t name it ‘build’ cause it might mess up the executable’s location.
The makefile is only made for Linux.
The makefile is made only for Linux.

##Linux
For simple build just use the makefile.
Expand All @@ -35,7 +35,8 @@ Boost is assumed to be located in /usr/local/include (headers) and /usr/local/li

##To do list
- add browser to playlist editor
- fix line edit
- fix in-list line edit
- add text scroll to line edit
- finish settings menu lists
- improve mouse wheel scrolling
- test audio system under linux and os x
Expand Down
2 changes: 1 addition & 1 deletion VertiRead.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source">
Expand Down
Binary file modified rsc/resource.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion src/engine/inputSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void InputSys::MouseWheelEvent(const SDL_MouseWheelEvent& wheel) {
}

void InputSys::TextEvent(const SDL_TextInputEvent& text) {
static_cast<LineEdit*>(captured)->AddText(text.text);
static_cast<LineEdit*>(captured)->Editor()->Add(text.text);
}

void InputSys::CheckShortcuts(const SDL_KeyboardEvent& key) {
Expand Down
28 changes: 2 additions & 26 deletions src/engine/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ void Scene::CheckObjectsClick(const vector<Object*>& objs, bool doubleclick) {
CheckTileBoxClick(box, doubleclick);
break;
}
else if (ObjectBox* box = dynamic_cast<ObjectBox*>(area)) {
CheckObjectBoxClick(box);
break;
}
else if (ReaderBox* box = dynamic_cast<ReaderBox*>(area)) {
CheckReaderBoxClick(box, doubleclick);
break;
Expand Down Expand Up @@ -159,26 +155,6 @@ void Scene::CheckTileBoxClick(TileBox* obj, bool doubleclick) {
}
}

void Scene::CheckObjectBoxClick(ObjectBox* obj) {
vec2i interval = obj->VisibleObjects();
for (int i=interval.x; i!=interval.y; i++) {
SDL_Rect crop;
Object* item = obj->getObject(i, &crop);

if (inRect(cropRect(item->getRect(), crop), InputSys::mousePos())) {
if (Button* but = dynamic_cast<Button*>(item)) {
but->OnClick();
break;
}
else if (Capturer* cap = dynamic_cast<Capturer*>(item)) {
cap->OnClick();
break;
}
}
delete item;
}
}

void Scene::CheckReaderBoxClick(ReaderBox* obj, bool doubleclick) {
vec2i mPos = InputSys::mousePos();
if (obj->showList()) { // check list buttons
Expand Down Expand Up @@ -224,7 +200,7 @@ void Scene::CheckPopupSimpleClick(PopupMessage* obj) {
void Scene::CheckPopupChoiceClick(PopupChoice* obj) {
if (inRect(obj->OkButton(), InputSys::mousePos())) {
if (PopupText* poptext = dynamic_cast<PopupText*>(obj))
program->Event_TextCaptureOk(poptext->Line()->Editor());
program->Event_TextCaptureOk(poptext->LEdit()->Editor());
}
else if (inRect(obj->CancelButton(), InputSys::mousePos()))
SetPopup(nullptr);
Expand Down Expand Up @@ -291,7 +267,7 @@ void Scene::SetPopup(Popup* box) {
popup = box;

if (PopupText* poptext = dynamic_cast<PopupText*>(box))
World::inputSys()->SetCapture(poptext->Line());
World::inputSys()->SetCapture(poptext->LEdit());
else
World::inputSys()->SetCapture(nullptr);

Expand Down
1 change: 0 additions & 1 deletion src/engine/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Scene {
bool CheckSliderClick(ScrollArea* obj);
void CheckListBoxClick(ListBox* obj, bool doubleclick);
void CheckTileBoxClick(TileBox* obj, bool doubleclick);
void CheckObjectBoxClick(ObjectBox* obj);
void CheckReaderBoxClick(ReaderBox* obj, bool doubleclick);
void CheckPopupSimpleClick(PopupMessage* obj);
void CheckPopupChoiceClick(PopupChoice* obj);
Expand Down
73 changes: 27 additions & 46 deletions src/engine/windowSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,15 @@ void WindowSys::PassDrawObject(Object* obj) {
DrawObject(box);
else if (TileBox* box = dynamic_cast<TileBox*>(obj))
DrawObject(box);
else if (ObjectBox* box = dynamic_cast<ObjectBox*>(obj))
DrawObject(box);
else if (ReaderBox* box = dynamic_cast<ReaderBox*>(obj))
DrawObject(box);
else if (LineEdit* edit = dynamic_cast<LineEdit*>(obj))
DrawObject(edit);
else if (KeyGetter* kget = dynamic_cast<KeyGetter*>(obj))
DrawObject(kget);
else if (Checkbox* cbox = dynamic_cast<Checkbox*>(obj))
DrawObject(cbox);
else
DrawRect(obj->getRect(), obj->color);
}

void WindowSys::DrawObject(const SDL_Rect& bg, EColor bgColor, const Text& text) {
DrawRect(bg, bgColor);

int len = text.size().x;
len = len+5 > bg.w ? len - bg.w +10 : 0; // use len as crop variable
DrawText(text, { 0, 0, len, 0 });
Expand All @@ -162,6 +154,8 @@ void WindowSys::DrawObject(ListBox* obj) {

DrawRect(rect, color);
DrawText(Text(items[i]->label, vec2i(rect.x+5, rect.y-crop.y), obj->ItemH(), 8), crop);

PassDrawItem(i, obj, rect, crop);
}
DrawRect(obj->Bar(), EColor::darkened);
DrawRect(obj->Slider(), EColor::highlighted);
Expand All @@ -184,19 +178,6 @@ void WindowSys::DrawObject(TileBox* obj) {
DrawRect(obj->Slider(), EColor::highlighted);
}

void WindowSys::DrawObject(ObjectBox* obj) {
vec2i interval = obj->VisibleObjects();
for (int i=interval.x; i<=interval.y; i++) {
SDL_Rect crop;
Object* item = obj->getObject(i, &crop);
SDL_Rect rect = item->getRect();
PassDrawObject(item);
delete item;
}
DrawRect(obj->Bar(), EColor::darkened);
DrawRect(obj->Slider(), EColor::highlighted);
}

void WindowSys::DrawObject(ReaderBox* obj) {
vec2i interval = obj->VisiblePictures();
for (int i=interval.x; i<=interval.y; i++) {
Expand All @@ -220,38 +201,38 @@ void WindowSys::DrawObject(ReaderBox* obj) {
}
}

void WindowSys::DrawObject(LineEdit* obj) {
DrawRect(obj->getRect(), obj->color);
DrawText(obj->getLabel());

vec2i crop;
Text txt = obj->getText(&crop);
DrawText(txt, {crop.x, 0, crop.y, 0});
void WindowSys::DrawObject(Popup* obj) {
DrawRect(obj->getRect(), EColor::darkened);
for (Object* it : obj->getObjects())
PassDrawObject(it);
}

SDL_Rect rect = obj->getRect();
txt.text.resize(obj->Editor()->CursorPos());
DrawRect({rect.x+txt.size().x, rect.y, 3, rect.h}, EColor::highlighted); // draw caret
void WindowSys::PassDrawItem(int id, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop) {
if (Checkbox* obj = dynamic_cast<Checkbox*>(parent->Item(id)))
DrawItem(obj, parent, rect, crop);
else if (LineEdit* obj = dynamic_cast<LineEdit*>(parent->Item(id)))
DrawItem(obj, parent, rect, crop);
else if (KeyGetter* obj = dynamic_cast<KeyGetter*>(parent->Item(id)))
DrawItem(obj, parent, rect, crop);
}

void WindowSys::DrawObject(KeyGetter* obj) {
DrawRect(obj->getRect(), obj->color);
DrawText(obj->getLabel());
DrawText(obj->getText());
void WindowSys::DrawItem(Checkbox* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop) {
int top = (crop.y < item->spacing) ? item->spacing - crop.y : crop.y;
int bot = (crop.h > item->spacing) ? crop.h - item->spacing : item->spacing;

DrawRect({ rect.x+rect.w-rect.h+item->spacing, rect.y-crop.y+top, rect.w-item->spacing*2, rect.h+crop.h-top-bot }, item->On() ? EColor::highlighted : EColor::darkened);
}

void WindowSys::DrawObject(Checkbox* obj) {
DrawRect(obj->getRect(), obj->color);
DrawText(obj->getText());
void WindowSys::DrawItem(LineEdit* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop) {
int offset = Text(item->label, 0, parent->ItemH(), 8).size().x;

EColor color;
SDL_Rect rect = obj->getCheckbox(&color);
DrawRect(rect, color);
DrawText(Text(item->Editor()->getText(), vec2i(rect.x+offset+5, rect.y-crop.y), parent->ItemH(), 8), crop);
}

void WindowSys::DrawObject(Popup* obj) {
DrawRect(obj->getRect(), EColor::darkened);
for (Object* it : obj->getObjects())
PassDrawObject(it);
void WindowSys::DrawItem(KeyGetter* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop) {
int offset = Text(item->label, 0, parent->ItemH(), 8).size().x;

DrawText(Text(item->KeyName(), vec2i(rect.x+offset+5, rect.y-crop.y), parent->ItemH(), 8), crop);
}

void WindowSys::DrawRect(const SDL_Rect& rect, EColor color) {
Expand Down
9 changes: 5 additions & 4 deletions src/engine/windowSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class WindowSys {
void DrawObject(const SDL_Rect& bg, EColor bgColor, const Text& text);
void DrawObject(ListBox* obj);
void DrawObject(TileBox* obj);
void DrawObject(ObjectBox* obj);
void DrawObject(ReaderBox* obj);
void DrawObject(LineEdit* obj);
void DrawObject(KeyGetter* obj);
void DrawObject(Checkbox* obj);
void DrawObject(Popup* obj);

void PassDrawItem(int id, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop={ 0, 0, 0, 0 });
void DrawItem(Checkbox* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop);
void DrawItem(LineEdit* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop);
void DrawItem(KeyGetter* item, ListBox* parent, const SDL_Rect& rect, const SDL_Rect& crop);

void DrawRect(const SDL_Rect& rect, EColor color);
void DrawImage(const Image& img, const SDL_Rect& crop = { 0, 0, 0, 0 });
Expand Down
35 changes: 19 additions & 16 deletions src/prog/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,20 @@ void Program::Event_Ok() {

// OTHER EVENTS

void Program::Event_TextCaptureOk(TextEdit* box) {
void Program::Event_TextCaptureOk(TextEdit* edit) {
if (curMenu == EMenu::playlists) {
if (!fs::exists(World::scene()->Settings().playlistParh() + box->getText())) {
Filer::SavePlaylist(Playlist(box->getText()));
if (!fs::exists(World::scene()->Settings().playlistParh() + edit->getText())) {
Filer::SavePlaylist(Playlist(edit->getText()));
Event_OpenPlaylistList();
}
else
World::scene()->SetPopup(new PopupMessage("File already exists."));
}
else if (curMenu == EMenu::plistEditor) {
if (editor->showSongs)
editor->RenameSong(box->getText());
editor->RenameSong(edit->getText());
else
editor->RenameBook(box->getText());
editor->RenameBook(edit->getText());
SwitchScene(editor);
}
World::inputSys()->SetCapture(nullptr);
Expand Down Expand Up @@ -404,11 +404,14 @@ void Program::SwitchScene(void* dat) const {
vec2i ancT(160, 0);
sizT = vec2i(res.x-160, 30);
EFix fixT = FIX_POS | FIX_EX | FIX_H;
vector<Object*> items = {
new LineEdit(Object(ancT, posT, sizT, fixT), "Library ", World::scene()->Settings().dirLib),
new LineEdit(Object(ancT, posT, sizT, fixT), "Playlists ", World::scene()->Settings().dirPlist)

ListBox* box = new ListBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background));
vector<ListItem*> items = {
new LineEdit(box, "Library ", World::scene()->Settings().dirLib),
new LineEdit(box, "Playlists ", World::scene()->Settings().dirPlist)
};
objects.push_back(new ObjectBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
box->Items(items);
objects.push_back(box);
focObject = objects.size()-1;
break; }
case EMenu::videoSets: {
Expand All @@ -419,10 +422,10 @@ void Program::SwitchScene(void* dat) const {
new ButtonText(Object(vec2i(0, 150), posT, sizT, FIX_POS | FIX_SIZ), &Program::Event_Back, "Back")
};

vector<Object*> items = {
vector<ListItem*> items = {
// something
};
objects.push_back(new ObjectBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
objects.push_back(new ListBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
focObject = objects.size()-1;
break; }
case EMenu::audioSets: {
Expand All @@ -433,10 +436,10 @@ void Program::SwitchScene(void* dat) const {
new ButtonText(Object(vec2i(0, 150), posT, sizT, FIX_POS | FIX_SIZ), &Program::Event_Back, "Back")
};

vector<Object*> items = {
vector<ListItem*> items = {
// something
};
objects.push_back(new ObjectBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
objects.push_back(new ListBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
focObject = objects.size()-1;
break; }
case EMenu::controlsSets: {
Expand All @@ -447,10 +450,10 @@ void Program::SwitchScene(void* dat) const {
new ButtonText(Object(vec2i(0, 150), posT, sizT, FIX_ALL), &Program::Event_Back, "Back")
};

vector<Object*> items = {
vector<ListItem*> items = {
// something
};
objects.push_back(new ObjectBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
objects.push_back(new ListBox(Object(vec2i(160, 0), posT, vec2i(res.x-160, res.y), FIX_POS | FIX_END, EColor::background), items));
focObject = objects.size()-1;
}
}
Expand All @@ -475,7 +478,7 @@ string Program::FindFittingPlaylist(const string& picPath) {
Playlist playlist = Filer::LoadPlaylist(file.filename().string());
for (const string& book : playlist.books)
if (book == name)
return file.filename().string();
return playlist.name;
}
return "";
}
2 changes: 1 addition & 1 deletion src/prog/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Program {
void Event_Ok();

// other events
void Event_TextCaptureOk(TextEdit* box);
void Event_TextCaptureOk(TextEdit* edit);
void Event_KeyCaptureOk(SDL_Scancode key);
void Event_SelectionSet(void* box);
void Event_ScreenMode();
Expand Down
Loading

0 comments on commit f8f9368

Please sign in to comment.