Fix input on linux
This commit is contained in:
parent
f3037a06ce
commit
8c38903445
4 changed files with 33 additions and 36 deletions
|
@ -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);
|
||||
|
|
|
@ -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_);
|
||||
}
|
||||
|
|
|
@ -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_);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,34 +6,28 @@
|
|||
|
||||
//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;
|
||||
|
||||
void hal_init(){
|
||||
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
|
||||
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
|
||||
void hal_init() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* //Create window
|
||||
window = SDL_CreateWindow( "SDL Tutorial", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS );
|
||||
if( window == NULL ) {
|
||||
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
int i;
|
||||
/* //Create window
|
||||
window = SDL_CreateWindow( "SDL Tutorial", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS );
|
||||
if( window == NULL ) {
|
||||
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue