1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
void ODFAEGCreator::actionPerformed(Button* button) {
if (button->getText() == "Create") {
appliname = ta->getText();
std::ofstream applis("applis");
applis<<appliname<<std::endl;
applis.close();
applitype = dpList->getSelectedItem();
path = fdTexturePath->getAppiDir() + "/" + appliname;
const char* lcars = appliname.c_str();
char* ucars = new char[appliname.size()];
for (unsigned int i = 0; i < appliname.length(); i++) {
ucars[i] = std::toupper(lcars[i]);
}
std::string majAppliname (ucars, appliname.length());
delete ucars;
ucars = new char[appliname.size()];
for (unsigned int i = 0; i < appliname.length(); i++) {
ucars[i] = std::tolower(lcars[i]);
}
minAppliname = std::string(ucars, appliname.length());
if(!mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
std::cerr<<"Failed to create application directory!";
wApplicationNew->setVisible(false);
if (applitype == "Normal") {
std::ofstream header(path+"/"+minAppliname+".hpp");
std::cerr << "Error: " << strerror(errno);
header<<"#ifndef "<<majAppliname<<"_HPP"<<std::endl;
header<<"#define "<<majAppliname<<"_HPP"<<std::endl;
header<<"#include \"/usr/local/include/odfaeg/Core/application.h\""<<std::endl;
header<<"class "<<appliname<<" : public odfaeg::core::Application {"<<std::endl;
header<<" public : "<<std::endl;
header<<" "<<appliname<<"(sf::VideoMode vm, std::string title);"<<std::endl;
header<<" void onLoad();"<<std::endl;
header<<" void onInit();"<<std::endl;
header<<" void onRender(odfaeg::graphic::RenderComponentManager* cm);"<<std::endl;
header<<" void onDisplay(odfaeg::graphic::RenderWindow* window);"<<std::endl;
header<<" void onUpdate (odfaeg::graphic::RenderWindow*, sf::Event& event);"<<std::endl;
header<<" void onExec ();"<<std::endl;
header<<"};"<<std::endl;
header<<"#endif"<<std::endl;
header.close();
std::ofstream source(path+"/"+minAppliname+".cpp");
source<<"#include \""+path+"/"+minAppliname+".hpp\""<<std::endl;
source<<"using namespace odfaeg::graphic;"<<std::endl;
source<<appliname<<"::"<<appliname<<"(sf::VideoMode vm, std::string title) : "<<std::endl;
source<<"Application (vm, title, sf::Style::Resize|sf::Style::Close, sf::ContextSettings(0, 0, 0, 3, 0)) {"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onLoad() {"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onInit() {"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onRender(RenderComponentManager *cm) {"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onDisplay(RenderWindow* window) {"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onUpdate (RenderWindow* window, sf::Event& event) {"<<std::endl;
source<<" if (&getRenderWindow() == window && event.type == sf::Event::Closed) {"<<std::endl;
source<<" stop();"<<std::endl;
source<<" }"<<std::endl;
source<<"}"<<std::endl;
source<<"void "<<appliname<<"::onExec () {"<<std::endl;
source<<"}"<<std::endl;
source.close();
std::string width = taWidth->getText();
std::string height = taHeight->getText();
std::ofstream main(path+"/main.cpp");
main<<"#include \""<<minAppliname<<".hpp\""<<std::endl;
main<<"int main(int argc, char* argv[]) {"<<std::endl;
main<<" "<<appliname<<" app(sf::VideoMode("<<width<<","<<height<<"),\""<<appliname<<"\");"<<std::endl;
main<<" return app.exec();"<<std::endl;
main<<"}"<<std::endl;
main.close();
}
}
if (button->getText() == "New texture") {
fdTexturePath->setVisible(true);
fdTexturePath->setEventContextActivated(true);
}
} |
Partager