Start backspace functionality and handle all keys displayed

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2, Sig, Sigo 2 years ago
parent 8c2c6e551a
commit 06995639ab
  1. 2
      C++ProjectTemplate.js
  2. BIN
      C++ProjectTemplate.wasm
  3. 47
      main.cpp

File diff suppressed because one or more lines are too long

Binary file not shown.

@ -7,11 +7,23 @@ struct Cursor{
int pos=0;
};
struct PrintKey{
char normal;
char shift;
};
class IDE : public olc::PixelGameEngine
{
public:
std::vector<Cursor>cursors={{0,2}};
std::vector<std::string>document={{"Test"}};
std::map<Key,PrintKey>PRINTABLE={
{K0,{')'}},{K1,{'!'}},{K2,{'@'}},{K3,{'#'}},{K4,{'$'}},{K5,{'%'}},{K6,{'^'}},{K7,{'&'}},{K8,{'*'}},{K9,{'('}},
{SPACE,{' ',' '}},
{NP_MUL,{'*','*'}},{NP_DIV,{'/','/'}},{NP_ADD,{'+','+'}},{NP_SUB,{'-','-'}},{NP_DECIMAL,{'.','.'}},{PERIOD,{'.','>'}},
{EQUALS,{'=','+'}},{COMMA,{',','<'}},{MINUS,{'-','_'}},
{OEM_1,{';',':'}},{OEM_2,{'/','?'}},{OEM_3,{'`','~'}},{OEM_4,{'[','{'}},{OEM_5,{' '}},{OEM_6,{']','}'}},{OEM_7,{'\'','"'}},{OEM_8,{'\\','|'}}
};
float lastBlinkTime=0;
IDE()
@ -82,7 +94,7 @@ public:
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});}
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;
@ -97,8 +109,39 @@ public:
}
void GetAnyKeyPress(olc::Key k)override{
lastBlinkTime=0.5f;
if (k==BACK){
if (cursors[0].pos==0){
if (cursors[0].line>0){
cursors[0].pos=document[cursors[0].line-1].size();
document[cursors[0].line-1].append(document[cursors[0].line]);
document[cursors[0].line--].clear();
}
} else {
}
} else
if (k>=A&&k<=Z){
document[cursors[0].line].insert(cursors[0].pos,std::string(1,Z-k));
if (GetKey(SHIFT).bHeld){
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,k-1+'A'));
} else {
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,k-1+'a'));
}
} else
if (k>=K0&&k<=K9){
if (GetKey(SHIFT).bHeld){
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,PRINTABLE[k].normal));
} else {
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,k-K0+'0'));
}
} else {
if (PRINTABLE.find(k)!=PRINTABLE.end()){
if (GetKey(SHIFT).bHeld){
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,PRINTABLE[k].shift));
} else {
document[cursors[0].line].insert(cursors[0].pos++,std::string(1,PRINTABLE[k].normal));
}
}
}
}
};

Loading…
Cancel
Save