|
|
@ -2,10 +2,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
|
|
|
class Example : public olc::PixelGameEngine |
|
|
|
struct Cursor{ |
|
|
|
|
|
|
|
int line=0; |
|
|
|
|
|
|
|
int pos=0; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IDE : public olc::PixelGameEngine |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
Example() |
|
|
|
std::vector<Cursor>cursors={{0,2}}; |
|
|
|
|
|
|
|
std::vector<std::string>document={{"Test"}}; |
|
|
|
|
|
|
|
float lastBlinkTime=0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IDE() |
|
|
|
{ |
|
|
|
{ |
|
|
|
sAppName = "PGEIDE"; |
|
|
|
sAppName = "PGEIDE"; |
|
|
|
} |
|
|
|
} |
|
|
@ -13,12 +22,73 @@ public: |
|
|
|
public: |
|
|
|
public: |
|
|
|
bool OnUserCreate() override |
|
|
|
bool OnUserCreate() override |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::cout<<"Created: "<<ScreenWidth()<<"x"<<ScreenHeight()<<std::endl; |
|
|
|
std::cout<<"Created IDE: "<<ScreenWidth()<<"x"<<ScreenHeight()<<std::endl; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (GetKey(RIGHT).bPressed){ |
|
|
|
|
|
|
|
if (cursors[0].pos<document[cursors[0].line].size()){ |
|
|
|
|
|
|
|
cursors[0].pos++; |
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (cursors[0].line<document.size()-1){ |
|
|
|
|
|
|
|
cursors[0].line++; |
|
|
|
|
|
|
|
cursors[0].pos=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(LEFT).bPressed){ |
|
|
|
|
|
|
|
if (cursors[0].pos>0){ |
|
|
|
|
|
|
|
cursors[0].pos--; |
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (cursors[0].line>0){ |
|
|
|
|
|
|
|
cursors[0].line--; |
|
|
|
|
|
|
|
cursors[0].pos=document[cursors[0].line].size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(DOWN).bPressed){ |
|
|
|
|
|
|
|
if (cursors[0].line<document.size()-1){ |
|
|
|
|
|
|
|
cursors[0].line++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(UP).bPressed){ |
|
|
|
|
|
|
|
if (cursors[0].line>0){ |
|
|
|
|
|
|
|
cursors[0].line--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(HOME).bPressed){ |
|
|
|
|
|
|
|
if(GetKey(CTRL).bHeld){ |
|
|
|
|
|
|
|
cursors[0].line=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cursors[0].pos=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(END).bPressed){ |
|
|
|
|
|
|
|
if(GetKey(CTRL).bHeld){ |
|
|
|
|
|
|
|
cursors[0].line=document.size()-1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cursors[0].pos=document[cursors[0].line].size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GetKey(ENTER).bPressed){ |
|
|
|
|
|
|
|
if(cursors[0].pos==0){ |
|
|
|
|
|
|
|
//Insert in front of line.
|
|
|
|
|
|
|
|
document.insert(document.begin()+cursors[0].line++,{{}}); |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
document.insert(document.begin()+cursors[0].line+1,document[cursors[0].line].substr(cursors[0].pos,document[cursors[0].line].size())); |
|
|
|
|
|
|
|
document[cursors[0].line]=document[cursors[0].line].substr(0,cursors[0].pos); |
|
|
|
|
|
|
|
cursors[0].pos=0; |
|
|
|
|
|
|
|
cursors[0].line++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int i=0; |
|
|
|
|
|
|
|
for (std::string&line:document){ |
|
|
|
|
|
|
|
DrawStringDecal({0,float(i)*10},line); |
|
|
|
|
|
|
|
if(cursors[0].line==i&&lastBlinkTime>0.5f){DrawStringDecal({float(cursors[0].pos)*8-2,float(i)*10+1},"|",GREY,{0.5,0.8});} |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastBlinkTime+=fElapsedTime; |
|
|
|
|
|
|
|
if (lastBlinkTime>1.f){ |
|
|
|
|
|
|
|
lastBlinkTime--; |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -32,15 +102,14 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
int main(int argc, char** argv) |
|
|
|
{
|
|
|
|
{
|
|
|
|
Example demo; |
|
|
|
IDE demo; |
|
|
|
rcode code; |
|
|
|
rcode code; |
|
|
|
if (argc==3){ |
|
|
|
if (argc==3){ |
|
|
|
code=demo.Construct(std::stoi(argv[1]), std::stoi(argv[2]), 1, 1); |
|
|
|
code=demo.Construct(std::stoi(argv[1]), std::stoi(argv[2]), 1, 1); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
code=demo.Construct(1920, 1080, 1, 1); |
|
|
|
code=demo.Construct(200, 200, 1, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
if (code!=FAIL){ |
|
|
|
if (code!=FAIL){ |
|
|
|
std::cout<<"Run"<<std::endl; |
|
|
|
|
|
|
|
demo.Start(); |
|
|
|
demo.Start(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|