Compare commits

...

2 Commits

Author SHA1 Message Date
sigonasr2, Sig, Sigo 06995639ab Start backspace functionality and handle all keys displayed 2 years ago
sigonasr2, Sig, Sigo 8c2c6e551a Keyboard functionality 2 years ago
  1. 2
      C++ProjectTemplate.js
  2. BIN
      C++ProjectTemplate.wasm
  3. 50
      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;
@ -96,7 +108,41 @@ public:
return true;
}
void GetAnyKeyPress(olc::Key pressed)override{
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){
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