merge gui_display.* into gui.*

This commit is contained in:
Gwenhael Le Moine 2024-04-14 20:32:44 +02:00
parent edf1fcb06b
commit e0a789eef4
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 84 additions and 98 deletions

View file

@ -16,7 +16,6 @@ dist/hpemu: src/bus.o \
src/main.o \
src/opcodes.o \
src/gui_buttons.o \
src/gui_display.o \
src/files.o \
src/ports.o \
src/rpl.o \

View file

@ -317,7 +317,81 @@ void button_draw_all( Button* buttons )
}
}
bool gui_refresh()
void SDL__display_show()
{
SDL_SetRenderDrawColor( renderer, colors.faceplate.r, colors.faceplate.g, colors.faceplate.b, colors.faceplate.a );
SDL_RenderClear( renderer );
if ( shouldRender == true ) {
shouldRender = false;
int pitch, w, h;
Uint32* pixels;
int access;
Uint32 format;
if ( SDL_QueryTexture( texTarget, &format, &access, &w, &h ) != 0 )
printf( "error\n" );
if ( SDL_LockTexture( texTarget, NULL, ( void** )&pixels, &pitch ) != 0 )
printf( "SDL_LockTexture: %s.\n", SDL_GetError() );
SDL_PixelFormat* pixelFormat = SDL_AllocFormat( format );
// do stuff
for ( int y = 0; y < LCD_HEIGHT; y++ ) {
for ( int x = 0; x < LCD_WIDTH; x++ ) {
int R = 0;
int G = 0;
int B = 0;
byte hp48pixel = lcdScreenGS[ x + y * LCD_WIDTH ];
if ( hp48pixel == '\0' ) {
R = colors.lcd_pixoff.r;
G = colors.lcd_pixoff.g;
B = colors.lcd_pixoff.b;
} else if ( hp48pixel == '\1' ) {
R = colors.lcd_pixgray1.r;
G = colors.lcd_pixgray1.g;
B = colors.lcd_pixgray1.b;
} else if ( hp48pixel == '\2' ) {
R = colors.lcd_pixgray2.r;
G = colors.lcd_pixgray2.g;
B = colors.lcd_pixgray2.b;
} else if ( hp48pixel == '\3' ) {
R = colors.lcd_pixon.r;
G = colors.lcd_pixon.g;
B = colors.lcd_pixon.b;
}
// Now you want to format the color to a correct format that SDL
// can use. Basically we convert our RGB color to a hex-like BGR
// color.
Uint32 color = SDL_MapRGB( pixelFormat, R, G, B );
// Before setting the color, we need to know where we have to
// place it.
Uint32 pixelPosition = y * ( pitch / sizeof( unsigned int ) ) + x;
pixels[ pixelPosition ] = color;
}
}
SDL_UnlockTexture( texTarget );
}
// Show rendered to texture
SDL_Rect r1 = { 0, 0, LCD_WIDTH, LCD_HEIGHT };
SDL_Rect r2 = { LCD_X * UI_SCALE, LCD_Y * UI_SCALE, LCD_WIDTH * UI_SCALE, LCD_HEIGHT * UI_SCALE };
SDL_RenderCopyEx( renderer, texTarget, &r1, &r2, 0, NULL, SDL_FLIP_NONE );
button_draw_all( calc_buttons );
SDL_RenderPresent( renderer );
}
bool gui_events()
{
SDL_Event event;
@ -604,8 +678,8 @@ bool gui_refresh()
case SDL_SCANCODE_J:
release_VAR();
break;
case SDL_SCANCODE_K:
case SDL_SCANCODE_UP:
case SDL_SCANCODE_K:
case SDL_SCANCODE_UP:
release_UP();
break;
case SDL_SCANCODE_L:
@ -621,15 +695,15 @@ bool gui_refresh()
release_EVAL();
break;
case SDL_SCANCODE_P:
case SDL_SCANCODE_LEFT:
case SDL_SCANCODE_LEFT:
release_LEFT();
break;
case SDL_SCANCODE_Q:
case SDL_SCANCODE_DOWN:
case SDL_SCANCODE_DOWN:
release_DOWN();
break;
case SDL_SCANCODE_R:
case SDL_SCANCODE_RIGHT:
case SDL_SCANCODE_RIGHT:
release_RIGHT();
break;
case SDL_SCANCODE_S:

View file

@ -90,7 +90,9 @@ extern bool SDL_ready;
extern void button_draw_all( /*BITMAP *bmp,*/ Button* buttons );
extern bool gui_refresh();
extern void SDL__display_show( void );
extern bool gui_events();
extern void gui_init( void );
extern void gui_exit( void );
#endif

View file

@ -1,82 +0,0 @@
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "display.h"
#include "gui.h"
#include "gui_buttons.h"
void SDL__display_show()
{
SDL_SetRenderDrawColor( renderer, colors.faceplate.r, colors.faceplate.g, colors.faceplate.b, colors.faceplate.a );
SDL_RenderClear( renderer );
if ( shouldRender == true ) {
shouldRender = false;
int pitch, w, h;
Uint32* pixels;
int access;
Uint32 format;
if ( SDL_QueryTexture( texTarget, &format, &access, &w, &h ) != 0 )
printf( "error\n" );
if ( SDL_LockTexture( texTarget, NULL, ( void** )&pixels, &pitch ) != 0 )
printf( "SDL_LockTexture: %s.\n", SDL_GetError() );
SDL_PixelFormat* pixelFormat = SDL_AllocFormat( format );
// do stuff
for ( int y = 0; y < LCD_HEIGHT; y++ ) {
for ( int x = 0; x < LCD_WIDTH; x++ ) {
int R = 0;
int G = 0;
int B = 0;
byte hp48pixel = lcdScreenGS[ x + y * LCD_WIDTH ];
if ( hp48pixel == '\0' ) {
R = colors.lcd_pixoff.r;
G = colors.lcd_pixoff.g;
B = colors.lcd_pixoff.b;
} else if ( hp48pixel == '\1' ) {
R = colors.lcd_pixgray1.r;
G = colors.lcd_pixgray1.g;
B = colors.lcd_pixgray1.b;
} else if ( hp48pixel == '\2' ) {
R = colors.lcd_pixgray2.r;
G = colors.lcd_pixgray2.g;
B = colors.lcd_pixgray2.b;
} else if ( hp48pixel == '\3' ) {
R = colors.lcd_pixon.r;
G = colors.lcd_pixon.g;
B = colors.lcd_pixon.b;
}
// Now you want to format the color to a correct format that SDL
// can use. Basically we convert our RGB color to a hex-like BGR
// color.
Uint32 color = SDL_MapRGB( pixelFormat, R, G, B );
// Before setting the color, we need to know where we have to
// place it.
Uint32 pixelPosition = y * ( pitch / sizeof( unsigned int ) ) + x;
pixels[ pixelPosition ] = color;
}
}
SDL_UnlockTexture( texTarget );
}
// Show rendered to texture
SDL_Rect r1 = { 0, 0, LCD_WIDTH, LCD_HEIGHT };
SDL_Rect r2 = { LCD_X * UI_SCALE, LCD_Y * UI_SCALE, LCD_WIDTH * UI_SCALE, LCD_HEIGHT * UI_SCALE };
SDL_RenderCopyEx( renderer, texTarget, &r1, &r2, 0, NULL, SDL_FLIP_NONE );
button_draw_all( calc_buttons );
SDL_RenderPresent( renderer );
}

View file

@ -1,6 +0,0 @@
#ifndef __GUI_DISPLAY_H
#define __GUI_DISPLAY_H
extern void SDL__display_show( void );
#endif

View file

@ -7,7 +7,6 @@
#include "emulator.h"
#include "gui.h"
#include "display.h"
#include "gui_display.h"
unsigned int currentTime;
@ -38,7 +37,7 @@ static inline void mainloop()
SDL__display_show();
}
if ( !gui_refresh() )
if ( !gui_events() )
return;
}