refactor
This commit is contained in:
parent
e75c38df20
commit
5e099ea6db
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <pins.h>
|
||||
#include <font.h>
|
||||
#include <render.h>
|
||||
#include <component.h>
|
||||
#include <configs.h>
|
||||
#include <string>
|
||||
|
|
|
@ -35,5 +35,7 @@ static inline SDL_Rect operator+(const SDL_Rect &A, const SDL_Rect &B) {
|
|||
|
||||
void draw_thicker_line(SDL_Renderer *renderer, const SDL_Point *point, int n);
|
||||
void draw_surrounding_line(SDL_Renderer *renderer, SDL_Rect r, int gap);
|
||||
void draw_str(SDL_Renderer *renderer, const char *str, int x, int y, uint32_t fg);
|
||||
void draw_str(SDL_Renderer *renderer, const char *str, int x, int y, uint32_t fg, uint32_t bg);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <nvboard.h>
|
||||
#include <render.h>
|
||||
|
||||
#define BTNC_X 520
|
||||
#define BTNC_Y 250
|
||||
|
@ -24,24 +23,19 @@ static void init_render_local(SDL_Renderer *renderer) {
|
|||
|
||||
// draw indices for each button
|
||||
const char *str = "CUDLR";
|
||||
char buf[2] = "?";
|
||||
for (int i = 0; i < 5; i ++) {
|
||||
SDL_Texture *t = ch2texture(renderer, str[i], 0xffffff, BOARD_BG_COLOR);
|
||||
SDL_Point p = Point(btn_rects[i].x, btn_rects[i].y) + Point(BTNC_WIDTH + 2, BTNC_HEIGHT / 2)
|
||||
- Point(0, CH_HEIGHT / 2);
|
||||
SDL_Rect r = Rect(p, CH_WIDTH, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
buf[0] = str[i];
|
||||
draw_str(renderer, buf, p.x, p.y, 0xffffff, BOARD_BG_COLOR);
|
||||
}
|
||||
|
||||
// draw the title
|
||||
// draw label
|
||||
str = "Button Pad";
|
||||
SDL_Texture *t = str2texture(renderer, str, 0xffffff, BOARD_BG_COLOR);
|
||||
int w0 = CH_WIDTH * strlen(str);
|
||||
SDL_Point p = Point(btn_rects[3].x, btn_rects[1].y) - Point(0, gap) - Point(0, CH_HEIGHT / 2)
|
||||
+ Point(w / 2, 0) - Point(w0 / 2, 0);
|
||||
SDL_Rect r = Rect(p, w0, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
+ Point(w / 2, 0) - Point(CH_WIDTH * strlen(str) / 2, 0);
|
||||
draw_str(renderer, str, p.x, p.y, 0xffffff, BOARD_BG_COLOR);
|
||||
}
|
||||
|
||||
void init_button(SDL_Renderer *renderer) {
|
||||
|
|
17
src/led.cpp
17
src/led.cpp
|
@ -1,5 +1,4 @@
|
|||
#include <nvboard.h>
|
||||
#include <render.h>
|
||||
|
||||
#define LED_X 60 + (4/2)
|
||||
#define LED_Y 360
|
||||
|
@ -39,23 +38,15 @@ static void init_render_local(SDL_Renderer *renderer) {
|
|||
for (int i = 0; i < 16; i ++) {
|
||||
char buf[8];
|
||||
int n = snprintf(buf, 8, "%d", i);
|
||||
SDL_Texture *t = str2texture(renderer, buf, 0xffffff, (21 << 16) | (153 << 8) | 120);
|
||||
int w_texture = CH_WIDTH * n;
|
||||
SDL_Rect r = Rect(p0 - Point(w_texture / 2, 0), w_texture, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
draw_str(renderer, buf, p0.x - CH_WIDTH * n / 2, p0.y, 0xffffff);
|
||||
p0.x -= LED_WIDTH + LED_SEP;
|
||||
}
|
||||
|
||||
// draw the title
|
||||
// draw label
|
||||
const char *str = "LED";
|
||||
SDL_Texture *t = str2texture(renderer, str, 0xffffff, BOARD_BG_COLOR);
|
||||
int w0 = CH_WIDTH * strlen(str);
|
||||
p0 = Point(LED_X, LED_Y) - Point(gap2 + 4, 0) + Point(0, LED_HEIGHT / 2)
|
||||
- Point(0, CH_HEIGHT / 2) - Point(w0, 0);
|
||||
r = Rect(p0, w0, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
- Point(0, CH_HEIGHT / 2) - Point(CH_WIDTH * strlen(str), 0);
|
||||
draw_str(renderer, str, p0.x, p0.y, 0xffffff);
|
||||
}
|
||||
|
||||
void init_led(SDL_Renderer *renderer) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <nvboard.h>
|
||||
#include <render.h>
|
||||
|
||||
static std::string nvboard_home;
|
||||
static SDL_Texture *tfpga_background;
|
||||
|
@ -58,6 +57,22 @@ void draw_surrounding_line(SDL_Renderer *renderer, SDL_Rect r,
|
|||
draw_thicker_line(renderer, p, 9);
|
||||
}
|
||||
|
||||
static void draw_str_internal(SDL_Renderer *renderer, SDL_Texture *t, const char *str, int x, int y) {
|
||||
SDL_Rect r = Rect(x, y, CH_WIDTH * strlen(str), CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
}
|
||||
|
||||
void draw_str(SDL_Renderer *renderer, const char *str, int x, int y, uint32_t fg) {
|
||||
SDL_Texture *t = str2texture(renderer, str, fg);
|
||||
draw_str_internal(renderer, t, str, x, y);
|
||||
}
|
||||
|
||||
void draw_str(SDL_Renderer *renderer, const char *str, int x, int y, uint32_t fg, uint32_t bg) {
|
||||
SDL_Texture *t = str2texture(renderer, str, fg, bg);
|
||||
draw_str_internal(renderer, t, str, x, y);
|
||||
}
|
||||
|
||||
|
||||
void init_render(SDL_Renderer *renderer) {
|
||||
nvboard_home = getenv("NVBOARD_HOME");
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <nvboard.h>
|
||||
#include <render.h>
|
||||
|
||||
#define SEG_X 60
|
||||
#define SEG_Y 225
|
||||
|
@ -101,23 +100,18 @@ static void init_render_local(SDL_Renderer *renderer) {
|
|||
// draw indices of each 7-seg display
|
||||
SDL_Point p = Point(SEG_X, SEG_Y) + Point(SEG_TOT_WIDTH, SEG_TOT_HEIGHT) + Point(0, gap)
|
||||
- Point(SEG_TOT_WIDTH / 8 / 2, 0) - Point(CH_WIDTH / 2, CH_HEIGHT / 2);
|
||||
char buf[2] = "?";
|
||||
for (int i = 0; i < 8; i ++) {
|
||||
SDL_Texture *t = ch2texture(renderer, '0' + i, 0xffffff, BOARD_BG_COLOR);
|
||||
SDL_Rect r = Rect(p, CH_WIDTH, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
buf[0] = '0' + i;
|
||||
draw_str(renderer, buf, p.x, p.y, 0xffffff, BOARD_BG_COLOR);
|
||||
p = p - Point(SEG_TOT_WIDTH / 8, 0);
|
||||
}
|
||||
|
||||
// draw the title
|
||||
// draw label
|
||||
const char *str = "Seven Segment Display";
|
||||
SDL_Texture *t = str2texture(renderer, str, 0xffffff, BOARD_BG_COLOR);
|
||||
int w = CH_WIDTH * strlen(str);
|
||||
p = Point(SEG_X, SEG_Y) - Point(0, gap) - Point(0, CH_HEIGHT / 2)
|
||||
+ Point(SEG_TOT_WIDTH / 2, 0) - Point(w / 2, 0);
|
||||
SDL_Rect r = Rect(p, w, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
+ Point(SEG_TOT_WIDTH / 2, 0) - Point(CH_WIDTH * strlen(str) / 2, 0);
|
||||
draw_str(renderer, str, p.x, p.y, 0xffffff, BOARD_BG_COLOR);
|
||||
}
|
||||
|
||||
void init_segs7(SDL_Renderer *renderer) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <nvboard.h>
|
||||
#include <render.h>
|
||||
|
||||
#define SWITCH_X 60
|
||||
#define SWITCH_Y 400
|
||||
|
@ -27,15 +26,11 @@ static void init_render_local(SDL_Renderer *renderer) {
|
|||
p[1] = p[1] + Point(w_group4, 0);
|
||||
}
|
||||
|
||||
// draw the title
|
||||
// draw label
|
||||
const char *str = "SW";
|
||||
SDL_Texture *t = str2texture(renderer, str, 0xffffff, BOARD_BG_COLOR);
|
||||
int w0 = CH_WIDTH * strlen(str);
|
||||
SDL_Point p0 = Point(SWITCH_X, SWITCH_Y) - Point(gap2 + 4, 0) + Point(0, SWITCH_HEIGHT / 2)
|
||||
- Point(0, CH_HEIGHT / 2) - Point(w0, 0);
|
||||
SDL_Rect r = Rect(p0, w0, CH_HEIGHT);
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_DestroyTexture(t);
|
||||
- Point(0, CH_HEIGHT / 2) - Point(CH_WIDTH * strlen(str), 0);
|
||||
draw_str(renderer, str, p0.x, p0.y, 0xffffff);
|
||||
}
|
||||
|
||||
void init_switch(SDL_Renderer *renderer) {
|
||||
|
|
14
src/vga.cpp
14
src/vga.cpp
|
@ -108,7 +108,21 @@ void vga_set_clk_cycle(int cycle) {
|
|||
vga_clk_cycle_minus_1 = cycle - 1;
|
||||
}
|
||||
|
||||
static void init_render_local(SDL_Renderer *renderer) {
|
||||
// draw line
|
||||
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0);
|
||||
SDL_Point p[3];
|
||||
p[0] = Point(0, WINDOW_HEIGHT / 2) + Point(30, 0) - Point(0, CH_HEIGHT);
|
||||
p[1] = p[0] - Point(16, 0);
|
||||
p[2] = Point(p[1].x, WINDOW_HEIGHT / 2);
|
||||
draw_thicker_line(renderer, p, 3);
|
||||
|
||||
// draw label
|
||||
draw_str(renderer, "VGA", p[0].x + 4, p[0].y - CH_HEIGHT / 2, 0xffffff);
|
||||
}
|
||||
|
||||
void init_vga(SDL_Renderer *renderer) {
|
||||
init_render_local(renderer);
|
||||
vga = new VGA(renderer, 1, 0, VGA_TYPE);
|
||||
SDL_Rect *rect_ptr = new SDL_Rect;
|
||||
*rect_ptr = (SDL_Rect){0, WINDOW_HEIGHT / 2, VGA_DEFAULT_WIDTH, VGA_DEFAULT_HEIGHT};
|
||||
|
|
Loading…
Reference in New Issue