Fix input on linux

This commit is contained in:
j3d1 2018-11-06 09:04:43 +01:00
parent f3037a06ce
commit 8c38903445
4 changed files with 33 additions and 36 deletions

View file

@ -3,9 +3,9 @@
#define _HAL_H_
#define I_LEFT 0
#define I_RIGHT 0
#define I_UP 0
#define I_DOWN 0
#define I_RIGHT 1
#define I_UP 2
#define I_DOWN 3
void debug(const char* str);

View file

@ -3,7 +3,7 @@
#include "node.h"
#include "gfx/canvas.h"
char peng[] = {'_','_','_','_','_',0};
char peng[] = {' ', ' ', ' ', ' ', ' ', 0};
int j = 0;
@ -11,19 +11,16 @@ void fooValue::render(canvas& c){
for(int i = 0; i<32; i++)
c.draw(0,i);
for(int i = 0; i<c.getWidth(); i++)
c.draw(i,31-i%32);
for(int i = 0; i<c.getWidth(); i++)
c.draw(i,31-(i+16)%32);
c.print(5 , 10, title_);
peng[0]=input[0]?' ':'#';
peng[1]=input[1]?' ':'#';
peng[2]=input[2]?' ':'#';
peng[3]=input[3]?' ':'#';
peng[0] = input[0] ? 'L' : ' ';
peng[1] = input[1] ? 'R' : ' ';
peng[2] = input[2] ? 'U' : ' ';
peng[3] = input[3] ? 'D' : ' ';
j++;
j%=26;
peng[4] = 'a'+j;
j %= 10;
peng[4] = 'A' + j;
c.print(5 , 20, peng);
}
@ -38,6 +35,6 @@ void menu::render(canvas& c){
for(int i = 0; i<32;i++)
c.draw(0,i);
for(int i = 0; i<32 && i<c.getWidth();i++)
c.draw((i%c.getWidth()),i);
c.print(5, 10, title_);
}

View file

@ -10,9 +10,9 @@ void layout::render() {
for (int j = 0; j < allocated_; j++) {
node *node_ptr;
if (node_ptr = slots[j].content) {
slots[j].canvas_->clear();
node_ptr->render(*slots[j].canvas_);
screen_.draw(slots[j].pos_, 0, *slots[j].canvas_);
}
}
}

View file

@ -6,9 +6,9 @@
//Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
#include <cstdio>
SDL_Window* window = NULL;
SDL_Window *window = nullptr;
SDL_Event event;
SDL_Renderer *renderer;
@ -26,14 +26,8 @@ void hal_init(){
exit(1);
}
*/
int i;
SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
}
@ -50,7 +44,8 @@ void hal_render() {
bool quit = false;
while (!quit) {
if (SDL_WaitEvent(&event)) {
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
@ -91,8 +86,13 @@ void hal_render() {
quit = true;
break;
}
} else {
SDL_Delay(10);
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
render();
SDL_RenderPresent(renderer);
}