touchscreen support

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
parent 48b50da2c3
commit ecf5f876a0
  1. 38
      ChallengeLeaguePointSolver/ChampionsLeaguePointSolver.cpp
  2. BIN
      ChallengeLeaguePointSolver/ChampionsLeaguePointSolver.wasm
  3. BIN
      ChallengeLeaguePointSolver/ChampionsLeaguePointSolver.zip
  4. 75
      ChallengeLeaguePointSolver/index.html
  5. 10
      ChallengeLeaguePointSolver/olcPGEX_QuickGUI.h
  6. BIN
      ChallengeLeaguePointSolver/pixelGameEngine_wasm.o

@ -6,6 +6,8 @@ using namespace olc;
QuickGUI::TextBox*prevTextBox=nullptr; QuickGUI::TextBox*prevTextBox=nullptr;
QuickGUI::TextBox*activeBox=nullptr;
// Override base class with your custom functionality // Override base class with your custom functionality
class ChampionsLeaguePointSolver : public olc::PixelGameEngine class ChampionsLeaguePointSolver : public olc::PixelGameEngine
{ {
@ -217,6 +219,7 @@ class ChampionsLeaguePointSolver : public olc::PixelGameEngine
QuickGUI::Label*p2Label; QuickGUI::Label*p2Label;
QuickGUI::Label*p3Label; QuickGUI::Label*p3Label;
QuickGUI::Button*calculateButton; QuickGUI::Button*calculateButton;
std::array<QuickGUI::Button*,11>inputButtons;
int totalCalculationSteps=0; int totalCalculationSteps=0;
bool calculating=false; bool calculating=false;
@ -283,6 +286,19 @@ class ChampionsLeaguePointSolver : public olc::PixelGameEngine
p3Label=new QuickGUI::Label(gui,"P3",vf2d{4.f,2.f}+vf2d{192+42*2,0},{36,12}); p3Label=new QuickGUI::Label(gui,"P3",vf2d{4.f,2.f}+vf2d{192+42*2,0},{36,12});
calculateButton=new QuickGUI::Button(gui,"Calculate",{4,2},{100,16}); calculateButton=new QuickGUI::Button(gui,"Calculate",{4,2},{100,16});
for(int i=0;i<inputButtons.size();i++){
if(i==0){
inputButtons[i]=new QuickGUI::Button(gui,std::to_string(i),{2.f+(1%3)*50,ScreenHeight()-(4-9/3)*26.f},{48,24});
}else
if(i==10){
inputButtons[i]=new QuickGUI::Button(gui,"<--",{2.f+(2%3)*50,ScreenHeight()-(4-9/3)*26.f},{48,24});
}else{
inputButtons[i]=new QuickGUI::Button(gui,std::to_string(i),{2.f+((i-1)%3)*50,ScreenHeight()-(4-(i-1)/3)*26.f},{48,24});
}
inputButtons[i]->bVisible=false;
inputButtons[i]->Enable(false);
}
for(int i=0;i<5;i++){ for(int i=0;i<5;i++){
for(int j=0;j<5;j++){ for(int j=0;j<5;j++){
for(int k=0;k<5;k++){ for(int k=0;k<5;k++){
@ -327,14 +343,36 @@ class ChampionsLeaguePointSolver : public olc::PixelGameEngine
bestComboA={}; bestComboA={};
bestComboB={}; bestComboB={};
} }
QuickGUI::TextBox*prevActiveBox=activeBox;
gui.Update(this); gui.Update(this);
gui.Draw(this); gui.Draw(this);
if(highestEX!=0){ if(highestEX!=0){
DrawString({112,4},std::to_string(highestEX)+" EX",YELLOW); DrawString({112,4},std::to_string(highestEX)+" EX",YELLOW);
} }
if(!calculating){
if(prevActiveBox!=nullptr){
for(int i=0;i<inputButtons.size();i++){
inputButtons[i]->bVisible=true;
inputButtons[i]->Enable(true);
if(inputButtons[i]->bPressed){
if(i==10){
prevActiveBox->sText=prevActiveBox->sText.substr(0,std::max(0,int(prevActiveBox->sText.length())-1));
}else{
if(prevActiveBox->sText.length()<4){
prevActiveBox->sText+=inputButtons[i]->sText;
}
}
activeBox=prevActiveBox;
prevActiveBox->m_bTextEdit=true;
TextEntryEnable(true,prevActiveBox->sText);
}
}
}
}
if(calculating){ if(calculating){
activeBox=nullptr;
if(calculationStep<cases.size()){ if(calculationStep<cases.size()){
Evaluate(calculationStep,true); Evaluate(calculationStep,true);
}else{ }else{

@ -0,0 +1,75 @@
<!doctype html>
<html lang="en-us">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
html,body { width: 100%; height: 100%; }
body { font-family: arial; margin: 0; padding: 0; background: #000; }
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten_border { border: none; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; background-color: black; }
</style>
</head>
<body>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
};
</script>
<script async type="text/javascript" src="ChampionsLeaguePointSolver.js"></script>
<script type="text/javascript">
Module.canvas.addEventListener("resize", (e) => {
var viewWidth = e.detail.width;
var viewHeight = e.detail.width / Module._olc_WindowAspectRatio;
if(viewHeight > e.detail.height)
{
viewHeight = e.detail.height;
viewWidth = e.detail.height * Module._olc_WindowAspectRatio;
}
// update dom attributes
Module.canvas.setAttribute("width", viewWidth);
Module.canvas.setAttribute("height", viewHeight);
var top = (e.detail.height - viewHeight) / 2;
var left = (e.detail.width - viewWidth) / 2;
// update styles
Module.canvas.style.position = "fixed";
Module.canvas.style.top = top.toString() + "px";
Module.canvas.style.left = left.toString() + "px";
Module.canvas.style.width = "";
Module.canvas.style.height = "";
// trigger PGE update
Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight);
// ensure canvas has focus
Module.canvas.focus();
e.preventDefault();
});
</script>
</body>
</html>

@ -76,7 +76,6 @@
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
namespace olc::QuickGUI namespace olc::QuickGUI
{ {
class Manager; class Manager;
@ -216,7 +215,7 @@ namespace olc::QuickGUI
TextBox*tabNext=nullptr; TextBox*tabNext=nullptr;
TextBox*tabPrev=nullptr; TextBox*tabPrev=nullptr;
protected: public:
bool m_bTextEdit = false; bool m_bTextEdit = false;
}; };
@ -394,6 +393,8 @@ namespace olc::QuickGUI
#ifdef OLC_PGEX_QUICKGUI #ifdef OLC_PGEX_QUICKGUI
#undef OLC_PGEX_QUICKGUI #undef OLC_PGEX_QUICKGUI
extern olc::QuickGUI::TextBox*activeBox;
namespace olc::QuickGUI namespace olc::QuickGUI
{ {
@ -570,6 +571,7 @@ namespace olc::QuickGUI
if (bPressed && pge->IsTextEntryEnabled() && !m_bTextEdit) if (bPressed && pge->IsTextEntryEnabled() && !m_bTextEdit)
{ {
pge->TextEntryEnable(false); pge->TextEntryEnable(false);
activeBox=nullptr;
} }
@ -577,6 +579,7 @@ namespace olc::QuickGUI
{ {
TextBox::bBoxClicked=true; TextBox::bBoxClicked=true;
pge->TextEntryEnable(true, sText); pge->TextEntryEnable(true, sText);
activeBox=this;
m_bTextEdit = true; m_bTextEdit = true;
} }
@ -596,6 +599,7 @@ namespace olc::QuickGUI
if(!TextBox::bBoxClicked){ if(!TextBox::bBoxClicked){
sText = pge->TextEntryGetString(); sText = pge->TextEntryGetString();
pge->TextEntryEnable(false); pge->TextEntryEnable(false);
activeBox=nullptr;
} }
m_bTextEdit = false; m_bTextEdit = false;
} }
@ -608,6 +612,7 @@ namespace olc::QuickGUI
if(tabPrev!=nullptr){ if(tabPrev!=nullptr){
m_bTextEdit = false; m_bTextEdit = false;
pge->TextEntryEnable(true, tabPrev->sText); pge->TextEntryEnable(true, tabPrev->sText);
activeBox=tabPrev;
tabPrev->m_bTextEdit=true; tabPrev->m_bTextEdit=true;
TextBox::bBoxClicked=true; TextBox::bBoxClicked=true;
} }
@ -615,6 +620,7 @@ namespace olc::QuickGUI
if(tabNext!=nullptr){ if(tabNext!=nullptr){
m_bTextEdit = false; m_bTextEdit = false;
pge->TextEntryEnable(true, tabNext->sText); pge->TextEntryEnable(true, tabNext->sText);
activeBox=tabNext;
tabNext->m_bTextEdit=true; tabNext->m_bTextEdit=true;
TextBox::bBoxClicked=true; TextBox::bBoxClicked=true;
} }

Loading…
Cancel
Save