Skip to content

Commit

Permalink
Merge pull request #39 from olivierbutler/main
Browse files Browse the repository at this point in the history
Add "check for update" feature
  • Loading branch information
rwellinger authored Feb 5, 2024
2 parents 42866a8 + 7108f03 commit 2836ca0
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ file(GLOB OPUSFILE_PREFIX "${LIBACFUTILS}/opus/opusfile-${PLAT_LONG}")
file(GLOB LIBOGG_PREFIX "${LIBACFUTILS}/opus/libogg-${PLAT_LONG}/install")
file(GLOB OPENSSL_PREFIX "${LIBACFUTILS}/ssl/openssl-${PLAT_LONG}")
file(GLOB ICONV_PREFIX "${LIBACFUTILS}/libiconv/libiconv-${PLAT_LONG}")
file(GLOB CURL_PREFIX "${LIBACFUTILS}/curl/libcurl-${PLAT_LONG}")

file(GLOB SRC *.c)
file(GLOB HDR *.h)
Expand Down Expand Up @@ -78,6 +79,7 @@ include_directories(bp PUBLIC
"${CAIRO_PREFIX}/include/cairo"
"${FREETYPE_PREFIX}/include/freetype2"
"${GLEW_PREFIX}/include"
"${CURL_PREFIX}/include"
)

# Compiler flags
Expand All @@ -92,6 +94,7 @@ endif()
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
add_definitions(-DDEBUG)
add_definitions(-DCURL_STATICLIB)
add_definitions(-DGLEW_BUILD=GLEW_STATIC -DGLEW_MX)
add_definitions(-DPCRE2_CODE_UNIT_WIDTH=8 -DPCRE2_STATIC)
add_definitions(-DLIBXML_STATIC)
Expand Down
1 change: 0 additions & 1 deletion src/bp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,6 @@ bp_init(void) {
logMsg(BP_INFO_LOG "acf override file found in %s : using it ", acf_override_file);
bp_ls.outline = acf_outline_read(acf_override_file);
} else {
//logMsg(BP_INFO_LOG "acf override file NOT found: using original file %s ", my_path);
bp_ls.outline = acf_outline_read(my_path);
}
free(acf_override_file);
Expand Down
154 changes: 141 additions & 13 deletions src/bp_cam.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <png.h>

#include "text_rendering.h"

#include <XPLMCamera.h>
#include <XPLMGraphics.h>
#include <XPLMInstance.h>
Expand Down Expand Up @@ -81,6 +83,15 @@
#define PREDICTION_DRAWING_PHASE xplm_Phase_Window
#define PREDICTION_DRAWING_PHASE_BEFORE 1

#if IBM
#define BOTTOM_MSG_FONT "Aileron\\Aileron-Regular.otf"
#else /* !IBM */
#define BOTTOM_MSG_FONT "Aileron/Aileron-Regular.otf"
#endif /* !IBM */
#define BOTTOM_MSG_FONT_SIZE 21

enum { MARGIN_SIZE = 10 };

static vect3_t cam_pos;
static double cam_height;
static double cam_hdg;
Expand Down Expand Up @@ -180,6 +191,19 @@ static button_t buttons[] = {
static int button_hit = -1, button_lit = -1;
static bool_t cam_inited = B_FALSE;

static struct {
char *msg;
int timeout;
uint64_t end;
int width;
int height;
GLuint texture;
uint8_t *bytes;
} bottom_msg = { NULL, 0, 0, 0, 0, 0, NULL };

static FT_Library ft;
static FT_Face face;

bool_t
load_icon(button_t *btn) {
char *filename;
Expand Down Expand Up @@ -466,7 +490,6 @@ draw_segment(const seg_t *seg) {
// -seg->start_pos.y, &info), ==, xplm_ProbeHitTerrain);
if (XPLMProbeTerrainXYZ(probe, seg->start_pos.x, 0,
-seg->start_pos.y, &info) != xplm_ProbeHitTerrain) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return ;
}
Expand All @@ -476,7 +499,6 @@ draw_segment(const seg_t *seg) {
// -seg->end_pos.y, &info), ==, xplm_ProbeHitTerrain);
if (XPLMProbeTerrainXYZ(probe, seg->end_pos.x, 0,
-seg->end_pos.y, &info) != xplm_ProbeHitTerrain) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return ;
}
Expand Down Expand Up @@ -537,7 +559,6 @@ draw_segment(const seg_t *seg) {

if (XPLMProbeTerrainXYZ(probe, p1.x, 0, -p1.y,
&info) != xplm_ProbeHitTerrain) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return ;
}
Expand Down Expand Up @@ -683,7 +704,6 @@ draw_prediction(XPLMDrawingPhase phase, int before, void *refcon) {

if (XPLMProbeTerrainXYZ(probe, seg->end_pos.x, 0,
-seg->end_pos.y, &info)) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return (1);
}
Expand Down Expand Up @@ -715,9 +735,8 @@ draw_prediction(XPLMDrawingPhase phase, int before, void *refcon) {
// -cursor_world_pos.y, &info), ==, xplm_ProbeHitTerrain);
if (XPLMProbeTerrainXYZ(probe, cursor_world_pos.x, 0,
-cursor_world_pos.y, &info)) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return (1);
XPLMDestroyProbe(probe);
return (1);
}
draw_acf_symbol(VECT3(cursor_world_pos.x, info.locationY,
cursor_world_pos.y), cursor_hdg, RED_TUPLE);
Expand All @@ -728,9 +747,8 @@ draw_prediction(XPLMDrawingPhase phase, int before, void *refcon) {
// -seg->end_pos.y, &info), ==, xplm_ProbeHitTerrain);
if (XPLMProbeTerrainXYZ(probe, seg->end_pos.x, 0,
-seg->end_pos.y, &info)) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return (1);
XPLMDestroyProbe(probe);
return (1);
}
draw_acf_symbol(VECT3(seg->end_pos.x, info.locationY,
seg->end_pos.y), seg->end_hdg, GREEN_TUPLE);
Expand All @@ -741,9 +759,8 @@ draw_prediction(XPLMDrawingPhase phase, int before, void *refcon) {
// -cursor_world_pos.y, &info), ==, xplm_ProbeHitTerrain);
if (XPLMProbeTerrainXYZ(probe, cursor_world_pos.x, 0,
-cursor_world_pos.y, &info)) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return (1);
XPLMDestroyProbe(probe);
return (1);
}
di.structSize = sizeof(di);
di.x = cursor_world_pos.x;
Expand Down Expand Up @@ -851,6 +868,10 @@ fake_win_draw(XPLMWindowID inWindowID, void *inRefcon) {
draw_icon(btn, w - btn->w * scale, h_off - btn->h * scale,
scale, i == button_hit, i == button_lit);
}

if (bottom_msg.msg != NULL) {
draw_bottom_msg(w,h);
}
}

static int
Expand Down Expand Up @@ -1106,6 +1127,8 @@ bp_cam_start(void) {
char icao[8] = {0};
char *cam_obj_path;
char airline[1024] = {0};
char bottom_msg[256] = {0};
char *updateAvailable;

if (cam_inited || !bp_init())
return (B_FALSE);
Expand Down Expand Up @@ -1214,6 +1237,12 @@ bp_cam_start(void) {
}
cam_inited = B_TRUE;

updateAvailable = getPluginUpdateStatus();
if (updateAvailable != NULL) {
snprintf(bottom_msg, sizeof(bottom_msg), "New version of BetterPushBack available: %s", updateAvailable);
init_bottom_msg(bottom_msg);
}

return (B_TRUE);
}

Expand Down Expand Up @@ -1260,10 +1289,109 @@ bp_cam_stop(void) {

pop_fov_values();

clear_bottom_msg();

return (B_TRUE);
}

bool_t
bp_cam_is_running(void) {
return (cam_inited);
}

void
init_bottom_msg(char *msg)
{
FT_Error err;
char *filename;
int tex_w, tex_h;
uint8_t *tex_bytes;

if ((err = FT_Init_FreeType(&ft)) != 0) {
logMsg("Error initializing FreeType library: %s",
ft_err2str(err));
return ;
}

filename = mkpathname(bp_plugindir, "data", "fonts", BOTTOM_MSG_FONT,
NULL);
if ((err = FT_New_Face(ft, filename, 0, &face)) != 0) {
logMsg("Error loading init_msg font %s: %s", filename,
ft_err2str(err));
VERIFY(FT_Done_FreeType(ft) == 0);
free(filename);
return ;
}
free(filename);

clear_bottom_msg();

if (strlen(msg) == 0 ) {
return;
}
if (!get_text_block_size(msg, face, BOTTOM_MSG_FONT_SIZE,
&bottom_msg.width, &bottom_msg.height)) {
return;
}

tex_w = bottom_msg.width + 2 * MARGIN_SIZE;
tex_h = bottom_msg.height + 2 * MARGIN_SIZE;
tex_bytes = calloc(tex_w * tex_h * 4, 1);

/* fill with a black, semi-transparent background */
for (int i = 0; i < tex_w * tex_h; i++)
tex_bytes[i * 4 + 3] = (uint8_t)(255 * 0.67);

if (!render_text_block(msg, face, BOTTOM_MSG_FONT_SIZE,
MARGIN_SIZE, MARGIN_SIZE + BOTTOM_MSG_FONT_SIZE,
255, 255, 255, tex_bytes, tex_w, tex_h)) {
free(tex_bytes);
return;
}

bottom_msg.msg = msg;
bottom_msg.bytes = tex_bytes;



glGenTextures(1, &bottom_msg.texture);
glBindTexture(GL_TEXTURE_2D, bottom_msg.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, bottom_msg.bytes);

}


void
clear_bottom_msg(void)
{
if (bottom_msg.msg != NULL) {
glDeleteTextures(1, &bottom_msg.texture);
free(bottom_msg.bytes);
memset(&bottom_msg, 0, sizeof (bottom_msg));
}
}

void
draw_bottom_msg(int screen_x, int screen_y) {

UNUSED(screen_y);

glBindTexture(GL_TEXTURE_2D, bottom_msg.texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex2f((screen_x - bottom_msg.width) / 2 - MARGIN_SIZE, 0);
glTexCoord2f(0.0, 0.0);
glVertex2f((screen_x - bottom_msg.width) / 2 - MARGIN_SIZE,
bottom_msg.height + 2 * MARGIN_SIZE);
glTexCoord2f(1.0, 0.0);
glVertex2f((screen_x + bottom_msg.width) / 2 + MARGIN_SIZE,
bottom_msg.height + 2 * MARGIN_SIZE);
glTexCoord2f(1.0, 1.0);
glVertex2f((screen_x + bottom_msg.width) / 2 + MARGIN_SIZE, 0);
glEnd();
}
6 changes: 6 additions & 0 deletions src/bp_cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void unload_buttons(void);
void nil_win_key(XPLMWindowID inWindowID, char inKey, XPLMKeyFlags inFlags,
char inVirtualKey, void *inRefcon, int losingFocus);

void draw_bottom_msg(int screen_x, int screen_y);

void clear_bottom_msg(void);

void init_bottom_msg(char *msg);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/cab_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ cam_ctl(XPLMCameraPosition_t *pos, int losing_control, void *refcon)

if (XPLMProbeTerrainXYZ(probe, bp_ls.tug->pos.pos.x, 0,
-bp_ls.tug->pos.pos.y, &info)) {
//logMsg(BP_WARN_LOG "XPLMProbeTerrainXYZ != xplm_ProbeHitTerrain continuing anyway");
XPLMDestroyProbe(probe);
return (1);
XPLMDestroyProbe(probe);
return (1);
}

/* Must be upright, no driving on ceilings! */
Expand Down
Loading

0 comments on commit 2836ca0

Please sign in to comment.