ui rewrite
This commit is contained in:
parent
dad0aefa78
commit
07c3d31d38
4 changed files with 265 additions and 168 deletions
6
Makefile
6
Makefile
|
|
@ -1,9 +1,9 @@
|
|||
CC = gcc
|
||||
CXX = g++
|
||||
|
||||
CPPFLAGS = -g
|
||||
CFLAGS = -g
|
||||
LDFLAGS = -g
|
||||
CPPFLAGS = -g #-O3 -ffast-math
|
||||
CFLAGS = -g #-O3 -ffast-math
|
||||
LDFLAGS = -g #-O3 -ffast-math
|
||||
LDLIBS = -lfltk -lcurl -lfltk_images
|
||||
|
||||
|
||||
|
|
|
|||
354
src/main.cpp
354
src/main.cpp
|
|
@ -1,255 +1,289 @@
|
|||
#include <FL/Enumerations.H>
|
||||
#include <FL/Fl_Group.H>
|
||||
#include <FL/Fl_Widget.H>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "testcpp.hpp"
|
||||
#include "curlwrap.hpp"
|
||||
#include "images.h"
|
||||
#include "summarymanager.hpp"
|
||||
#include "testcpp.hpp"
|
||||
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/Fl_Box.H>
|
||||
#include <FL/Fl_Multi_Browser.H>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Box.H>
|
||||
#include <FL/Fl_Button.H>
|
||||
#include <FL/Fl_PNG_Image.H>
|
||||
#include <FL/fl_ask.H>
|
||||
#include <FL/Fl_Flex.H>
|
||||
#include <FL/Fl_Multi_Browser.H>
|
||||
#include <FL/Fl_PNG_Image.H>
|
||||
#include <FL/Fl_Tile.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/fl_ask.H>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Person {
|
||||
std::string year;
|
||||
std::string name;
|
||||
std::string year;
|
||||
std::string name;
|
||||
|
||||
Person(std::string& y, std::string& n) : year(y), name(n) {}
|
||||
std::string toString() const {
|
||||
return "{(Person): " + year + ", " + name + "}";
|
||||
}
|
||||
Person(std::string &y, std::string &n) : year(y), name(n) {}
|
||||
std::string toString() const {
|
||||
return "{(Person): " + year + ", " + name + "}";
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Person& e) {
|
||||
//os << "{(Person): " << e.year << ", " << e.name << "}";
|
||||
os << e.toString();
|
||||
return os;
|
||||
std::ostream &operator<<(std::ostream &os, const Person &e) {
|
||||
// os << "{(Person): " << e.year << ", " << e.name << "}";
|
||||
os << e.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
struct BasicEntry {
|
||||
Person A;
|
||||
Person B;
|
||||
Person A;
|
||||
Person B;
|
||||
|
||||
std::string matchlink;
|
||||
std::string matchlink;
|
||||
|
||||
int Apercent;
|
||||
int Bpercent;
|
||||
|
||||
std::string toString() const {
|
||||
return "{(BasicEntry): " + A.toString() + ", " + B.toString() + ", " + matchlink + + ", " + std::to_string(Apercent) + "%, " + std::to_string(Bpercent) + "%}";
|
||||
}
|
||||
int Apercent;
|
||||
int Bpercent;
|
||||
|
||||
std::string toString() const {
|
||||
return "{(BasicEntry): " + A.toString() + ", " + B.toString() + ", " + matchlink + +", " +
|
||||
std::to_string(Apercent) + "%, " + std::to_string(Bpercent) + "%}";
|
||||
}
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& os, const BasicEntry& e) {
|
||||
//os << "{(BasicEntry): " << e.A << ", " << e.B << ", " << e.matchlink << "}";
|
||||
os << e.toString();
|
||||
return os;
|
||||
std::ostream &operator<<(std::ostream &os, const BasicEntry &e) {
|
||||
// os << "{(BasicEntry): " << e.A << ", " << e.B << ", " << e.matchlink << "}";
|
||||
os << e.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Selected {
|
||||
Fl_Multi_Browser& browser;
|
||||
Selected(Fl_Multi_Browser& browser_in) : browser(browser_in) {}
|
||||
Fl_Multi_Browser &browser;
|
||||
Selected(Fl_Multi_Browser &browser_in) : browser(browser_in) {}
|
||||
};
|
||||
|
||||
void show_callback(Fl_Widget *w, void * data) {
|
||||
Selected * rdata = (Selected *) data;
|
||||
void show_callback(Fl_Widget *w, void *data) {
|
||||
Selected *rdata = (Selected *)data;
|
||||
|
||||
auto s = rdata->browser.size() + 1;
|
||||
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
if (rdata->browser.selected(i)) {
|
||||
fl_alert("%s", rdata->browser.text(i));
|
||||
}
|
||||
}
|
||||
auto s = rdata->browser.size() + 1;
|
||||
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
if (rdata->browser.selected(i)) {
|
||||
fl_alert("%s", rdata->browser.text(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<BasicEntry> MakeEntires(std::string filename) {
|
||||
|
||||
std::vector<BasicEntry> out;
|
||||
std::vector<BasicEntry> out;
|
||||
|
||||
std::ifstream matches(filename);
|
||||
std::ifstream matches(filename);
|
||||
|
||||
if (!matches.is_open()) {
|
||||
std::cout << "Err reading " <<filename << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (!matches.is_open()) {
|
||||
std::cout << "Err reading " << filename << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::string line;
|
||||
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
|
||||
size_t linenum = 1; // One indexed like devtools
|
||||
while(std::getline(matches, line)) {
|
||||
if (linenum < 15) {
|
||||
size_t linenum = 1; // One indexed like devtools
|
||||
while (std::getline(matches, line)) {
|
||||
if (linenum < 15) {
|
||||
|
||||
} else {
|
||||
if ( (linenum - 15) % 3 == 0) {
|
||||
line1 = line;
|
||||
if (line == "</td></tr></tbody></table>" || line == "</TABLE>" ) break;
|
||||
} else if ( (linenum - 15) % 3 == 1) {
|
||||
line2 = line;
|
||||
} else {
|
||||
if ((linenum - 15) % 3 == 0) {
|
||||
line1 = line;
|
||||
if (line == "</td></tr></tbody></table>" || line == "</TABLE>")
|
||||
break;
|
||||
} else if ((linenum - 15) % 3 == 1) {
|
||||
line2 = line;
|
||||
|
||||
// std::cout << "Debug: L1: " << line1 << std::endl;
|
||||
// std::cout << "Debug: L2: " << line2 << std::endl;
|
||||
// std::cout << "Debug: L1: " << line1 << std::endl;
|
||||
// std::cout << "Debug: L2: " << line2 << std::endl;
|
||||
|
||||
auto firstquote = line1.find("\"");
|
||||
// printf("fq: %ld\n", firstquote);
|
||||
auto secondquote = line1.find("\"", firstquote + 1);
|
||||
// printf("sq: %ld\n", secondquote);
|
||||
auto matchlink = line1.substr(firstquote + 1, secondquote - (firstquote + 1));
|
||||
|
||||
auto firstquote = line1.find("\"");
|
||||
// printf("fq: %ld\n", firstquote);
|
||||
auto secondquote = line1.find("\"", firstquote+1);
|
||||
// printf("sq: %ld\n", secondquote);
|
||||
auto matchlink = line1.substr(firstquote+1, secondquote - (firstquote+1));
|
||||
auto firstslash = line1.find("/", secondquote + 1);
|
||||
auto secondslash = line1.find("/", firstslash + 1);
|
||||
auto thirdslash = line1.find("/", secondslash + 1);
|
||||
|
||||
auto firstslash = line1.find("/", secondquote+ 1);
|
||||
auto secondslash = line1.find("/", firstslash+1);
|
||||
auto thirdslash = line1.find("/", secondslash+1);
|
||||
auto firstpar = line1.find("(", thirdslash + 1);
|
||||
auto secondpar = line1.find(")", firstpar + 1);
|
||||
|
||||
auto firstpar = line1.find("(", thirdslash+1);
|
||||
auto secondpar = line1.find(")", firstpar+1);
|
||||
auto p1class = line1.substr(firstslash + 1, secondslash - firstslash - 1);
|
||||
auto p1name = line1.substr(secondslash + 1, thirdslash - secondslash - 1);
|
||||
|
||||
auto p1class = line1.substr(firstslash+1, secondslash - firstslash - 1);
|
||||
auto p1name = line1.substr(secondslash+1, thirdslash - secondslash -1);
|
||||
auto p1match = line1.substr(firstpar + 1, secondpar - firstpar - 2);
|
||||
|
||||
auto p1match = line1.substr(firstpar+1, secondpar - firstpar - 2);
|
||||
std::cout << p1match << std::endl;
|
||||
|
||||
std::cout << p1match << std::endl;
|
||||
firstquote = line2.find("\"");
|
||||
secondquote = line2.find("\"", firstquote + 1);
|
||||
firstslash = line2.find("/", secondquote + 1);
|
||||
secondslash = line2.find("/", firstslash + 1);
|
||||
thirdslash = line2.find("/", secondslash + 1);
|
||||
firstpar = line2.find("(", thirdslash + 1);
|
||||
secondpar = line2.find(")", firstpar + 1);
|
||||
|
||||
firstquote = line2.find("\"");
|
||||
secondquote = line2.find("\"", firstquote+1);
|
||||
firstslash = line2.find("/", secondquote+1);
|
||||
secondslash = line2.find("/", firstslash+1);
|
||||
thirdslash = line2.find("/", secondslash+1);
|
||||
firstpar = line2.find("(", thirdslash+1);
|
||||
secondpar = line2.find(")", firstpar+1);
|
||||
auto p2class = line2.substr(firstslash + 1, secondslash - (firstslash + 1));
|
||||
auto p2name = line2.substr(secondslash + 1, thirdslash - (secondslash + 1));
|
||||
|
||||
auto p2match = line2.substr(firstpar + 1, secondpar - firstpar - 2);
|
||||
std::cout << p2match << std::endl;
|
||||
|
||||
auto p2class = line2.substr(firstslash+1, secondslash - (firstslash+1));
|
||||
auto p2name = line2.substr(secondslash+1, thirdslash - (secondslash+1));
|
||||
auto p1 = Person(p1class, p1name);
|
||||
|
||||
auto p2match = line2.substr(firstpar+1, secondpar - firstpar - 2);
|
||||
std::cout << p2match << std::endl;
|
||||
auto p2 = Person(p2class, p2name);
|
||||
|
||||
auto p1 = Person(p1class, p1name);
|
||||
BasicEntry finent = {.A = p1,
|
||||
.B = p2,
|
||||
.matchlink = matchlink,
|
||||
.Apercent = std::stoi(p1match),
|
||||
.Bpercent = std::stoi(p2match)};
|
||||
|
||||
auto p2 = Person(p2class, p2name);
|
||||
|
||||
BasicEntry finent = {.A = p1, .B = p2, .matchlink = matchlink, .Apercent = std::stoi(p1match), .Bpercent = std::stoi(p2match) };
|
||||
|
||||
out.push_back(finent);
|
||||
|
||||
}
|
||||
}
|
||||
linenum++;
|
||||
|
||||
}
|
||||
return out;
|
||||
out.push_back(finent);
|
||||
}
|
||||
}
|
||||
linenum++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
struct State {
|
||||
std::vector<BasicEntry> entries;
|
||||
std::vector<BasicEntry> entries;
|
||||
};
|
||||
|
||||
|
||||
void changelayout(Fl_Widget * w, void * meow) {
|
||||
std::pair<Fl_Flex&, Fl_Multi_Browser&> * in = (std::pair<Fl_Flex&, Fl_Multi_Browser&>* ) meow;
|
||||
in->second.show();
|
||||
// in->second.parent()->redraw();
|
||||
// in->first.window()->redraw();
|
||||
//in->first.init_sizes();
|
||||
in->first.layout();
|
||||
//in->first.redraw();
|
||||
void changelayout(Fl_Widget *w, void *meow) {
|
||||
std::pair<Fl_Flex &, SummaryManager &> *in = (std::pair<Fl_Flex &, SummaryManager &> *)meow;
|
||||
in->second.show();
|
||||
// in->second.parent()->redraw();
|
||||
// in->first.window()->redraw();
|
||||
// in->first.init_sizes();
|
||||
in->first.layout();
|
||||
in->second.redraw();
|
||||
// in->first.redraw();
|
||||
}
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
if (argc < 2) {
|
||||
std::cout << "Not enough args" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
struct Topbar : Fl_Group {
|
||||
|
||||
Fl_PNG_Image inspectIcon;
|
||||
|
||||
State s;
|
||||
s.entries = MakeEntires(argv[1]);
|
||||
Fl_Box *titleText;
|
||||
Fl_Button *inspect;
|
||||
|
||||
Topbar(int x, int y, int w, int h)
|
||||
: Fl_Group(x, y, w, h),
|
||||
inspectIcon("Inspect", icon_inspect_file_png, icon_inspect_file_png_len) {
|
||||
|
||||
titleText = new Fl_Box(0, 0, 100, 50, "MossMan");
|
||||
titleText->labelsize(36);
|
||||
titleText->labelfont(FL_TIMES | FL_BOLD);
|
||||
titleText->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT);
|
||||
inspect = new Fl_Button(950, 0, 50, 50);
|
||||
resizable(titleText);
|
||||
|
||||
for (auto e : s.entries) {
|
||||
std::cout << e << std::endl;
|
||||
}
|
||||
inspect->image(inspectIcon);
|
||||
inspect->tooltip("Inspect Entr(ies)");
|
||||
|
||||
end();
|
||||
}
|
||||
};
|
||||
|
||||
Fl::scheme("base");
|
||||
auto window = std::make_unique<Fl_Window>(300, 300, 300, 300, "MossMan :D");
|
||||
struct MainGui : Fl_Window {
|
||||
Topbar *topbar;
|
||||
|
||||
auto group = std::make_unique<Fl_Group>(0,0,300,300);
|
||||
auto group2 = std::make_unique<Fl_Group>(0, 0, 300, 50);
|
||||
auto box = std::make_unique<Fl_Box>(0,0,100,50,"MossMan");
|
||||
box->labelsize(36);
|
||||
box->labelfont(FL_TIMES | FL_BOLD);
|
||||
box->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT);
|
||||
auto button = std::make_unique<Fl_Button>(250, 0, 50, 50);
|
||||
auto button2 = std::make_unique<Fl_Button>(200,0, 50, 50);
|
||||
group2->resizable(*box);
|
||||
group2->end();
|
||||
Fl_Tile *tilebox;
|
||||
Fl_Multi_Browser *list;
|
||||
SummaryManager *summaryEditor;
|
||||
MainGui() : Fl_Window(0, 0, 1000, 750, "MossMan :3") {
|
||||
topbar = new Topbar(0, 0, 1000, 50);
|
||||
|
||||
tilebox = new Fl_Tile(0, 50, 1000, 700); // parent is maingui, will be freed at decon
|
||||
list = new Fl_Multi_Browser(0, 50, 150, 700);
|
||||
summaryEditor = new SummaryManager(150, 50, 850, 700);
|
||||
|
||||
auto group3 = std::make_unique<Fl_Flex>(0,51,300, 250, Fl_Flex::HORIZONTAL);
|
||||
// auto browser = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
||||
// auto browser2 = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
||||
auto browser = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
||||
auto browser2 = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
||||
browser2->hide();
|
||||
group3->end();
|
||||
std::pair<Fl_Flex&, Fl_Multi_Browser&> saved(*group3, *browser2);
|
||||
button2->callback(changelayout,&saved);
|
||||
tilebox->end();
|
||||
|
||||
auto icon = std::make_unique<Fl_PNG_Image>("Inspect", icon_inspect_file_png, icon_inspect_file_png_len);
|
||||
button->image(*icon);
|
||||
button->tooltip("Inspect Entr(ies)");
|
||||
end();
|
||||
|
||||
resizable(tilebox);
|
||||
}
|
||||
};
|
||||
|
||||
for (auto e : s.entries) {
|
||||
auto h = ((e.A.year + "/" + e.A.name) + " and " + (e.B.year + "/" + e.B.name) + " (" + std::to_string(e.Apercent) + "%, " + std::to_string(e.Bpercent) + "%)");
|
||||
browser->add(h.c_str());
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
std::cout << "Not enough args" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
State s;
|
||||
s.entries = MakeEntires(argv[1]);
|
||||
|
||||
group->resizable(*group3);
|
||||
group->end();
|
||||
for (auto e : s.entries) {
|
||||
std::cout << e << std::endl;
|
||||
}
|
||||
|
||||
Fl::scheme("base");
|
||||
// auto window = std::make_unique<Fl_Window>(300, 300, 300, 300, "MossMan :D");
|
||||
|
||||
window->resizable(*group);
|
||||
window->end();
|
||||
// auto group = std::make_unique<Fl_Group>(0,0,300,300);
|
||||
// auto group2 = std::make_unique<Fl_Group>(0, 0, 300, 50);
|
||||
// auto box = std::make_unique<Fl_Box>(0,0,100,50,"MossMan");
|
||||
// box->labelsize(36);
|
||||
// box->labelfont(FL_TIMES | FL_BOLD);
|
||||
// box->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT);
|
||||
// auto button = std::make_unique<Fl_Button>(250, 0, 50, 50);
|
||||
// auto button2 = std::make_unique<Fl_Button>(200,0, 50, 50);
|
||||
// group2->resizable(*box);
|
||||
// group2->end();
|
||||
|
||||
// auto group3 = std::make_unique<Fl_Flex>(0,51,300, 250, Fl_Flex::HORIZONTAL);
|
||||
// // auto browser = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
||||
// // auto browser2 = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
||||
// auto browser = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
||||
// auto tabs = std::make_unique<SummaryManager>(0,0,300,300);
|
||||
// //auto browser2 = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
||||
// tabs->hide();
|
||||
// group3->end();
|
||||
// std::pair<Fl_Flex&, SummaryManager&> saved(*group3, *tabs);
|
||||
// button2->callback(changelayout,&saved);
|
||||
|
||||
// auto icon = std::make_unique<Fl_PNG_Image>("Inspect", icon_inspect_file_png,
|
||||
// icon_inspect_file_png_len); button->image(*icon); button->tooltip("Inspect Entr(ies)");
|
||||
|
||||
// for (auto e : s.entries) {
|
||||
// auto h = ((e.A.year + "/" + e.A.name) + " and " + (e.B.year + "/" + e.B.name) + " (" +
|
||||
// std::to_string(e.Apercent) + "%, " + std::to_string(e.Bpercent) + "%)");
|
||||
// browser->add(h.c_str());
|
||||
// }
|
||||
|
||||
// group->resizable(*group3);
|
||||
// group->end();
|
||||
|
||||
Selected callbackdata(*browser);
|
||||
// window->resizable(*group);
|
||||
// window->end();
|
||||
|
||||
button->callback(show_callback, (void*) &callbackdata);
|
||||
// MainGui x;
|
||||
|
||||
window->show();
|
||||
// Selected callbackdata(*browser);
|
||||
|
||||
// button->callback(show_callback, (void*) &callbackdata);
|
||||
|
||||
// window->show();
|
||||
|
||||
MainGui x;
|
||||
x.show();
|
||||
|
||||
return Fl::run();
|
||||
return Fl::run();
|
||||
}
|
||||
|
|
|
|||
45
src/summarymanager.cpp
Normal file
45
src/summarymanager.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "summarymanager.hpp"
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Button.H>
|
||||
#include <FL/Fl_Tabs.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
SummaryManager::SummaryManager(int x, int y, int w, int h)
|
||||
: Fl_Group(x, y, w, h), tabs(x, y, w, h) {
|
||||
|
||||
Fl_Group *grp1 = new Fl_Group(x, y + 30, w, h - 30, "Tab1");
|
||||
{
|
||||
Fl_Window *win1 = new Fl_Window(x, y + 30, w, h - 30, "Tab1W");
|
||||
std::cout << "here" << std::endl;
|
||||
{
|
||||
auto butt = new Fl_Button(0, 0, 100, 200, "test");
|
||||
}
|
||||
win1->end();
|
||||
auto butt = new Fl_Button(0, 30, 100, 200, "nyaaa");
|
||||
}
|
||||
grp1->end();
|
||||
// Fl_Group *grp2 = new Fl_Group(20, 30, 280, 170, "Tab2");
|
||||
// {
|
||||
// }
|
||||
// grp2->end();
|
||||
// Fl_Group *grp3 = new Fl_Group(20, 30, 280, 170, "Tab3");
|
||||
// {
|
||||
// }
|
||||
// grp3->end();
|
||||
// Fl_Group *grp4 = new Fl_Group(20, 30, 280, 170, "Tab4");
|
||||
// {
|
||||
// }
|
||||
// grp4->end();
|
||||
// Fl_Group *grp5 = new Fl_Group(20, 30, 280, 170, "Tab5");
|
||||
// {
|
||||
// }
|
||||
// grp5->end();
|
||||
tabs.end();
|
||||
tabs.handle_overflow(Fl_Tabs::OVERFLOW_DRAG);
|
||||
|
||||
tabs.resizable(grp1);
|
||||
|
||||
end();
|
||||
}
|
||||
18
src/summarymanager.hpp
Normal file
18
src/summarymanager.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef SUMMARYMANAGER_HEADER
|
||||
#define SUMMARYMANAGER_HEADER
|
||||
|
||||
#include <FL/Fl_Button.H>
|
||||
#include <FL/Fl_Group.H>
|
||||
#include <FL/Fl_Tabs.H>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct SummaryManager : Fl_Group {
|
||||
SummaryManager(int x, int y, int w, int h);
|
||||
Fl_Tabs tabs;
|
||||
std::vector<Fl_Button*> items;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue