NMEA2000-Code weiterbearbeitet

This commit is contained in:
2025-02-07 19:48:32 +01:00
parent a0638c76e5
commit bdbd168123
8 changed files with 259 additions and 72 deletions

View File

@@ -1,3 +1,4 @@
import os
import cairo
import math
from .page import Page
@@ -6,11 +7,50 @@ class ApparentWind(Page):
def __init__(self, pageno, cfg, boatdata):
super().__init__(pageno, cfg, boatdata)
self.buttonlabel[1] = 'MODE'
self.mode = 'L' # (W)ind (L)ens
self.symbol = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "front.png"))
def draw(self, ctx):
def handle_key(self, buttonid):
if buttonid == 1:
if self.mode == 'W':
self.mode = 'L'
else:
self.mode = 'W'
return True
return False
def draw_wind(self, ctx):
# Name
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(60)
ctx.set_font_size(40)
ctx.move_to(20, 100)
ctx.show_text("Apparent Wind")
def draw_lens(self, ctx):
ctx.save()
ctx.set_source_surface(self.symbol, 140, 30)
ctx.paint()
ctx.restore()
ctx.set_line_width(2)
# Analoginstrument
cx = 200
cy = 150
r = 135
ctx.arc(cx, cy, r, math.radians(110), math.radians(250))
ctx.stroke()
ctx.arc(cx, cy, r, math.radians(-70), math.radians(70))
ctx.stroke()
# Windstärke als Digitalwert
ctx.select_font_face("DSEG7 Classic")
ctx.set_font_size(40)
self.draw_text_center(ctx, cx, cy + 80, "14.3", fix1=True)
def draw(self, ctx):
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
if self.mode == 'W':
self.draw_wind(ctx)
else:
self.draw_lens(ctx)

View File

@@ -167,36 +167,67 @@ class Page():
ctx.fill()
ctx.set_source_rgb(0, 0, 0)
def draw_text_center(self, ctx, x, y, content, rotate=False, baseline=False, fill=False):
ext = ctx.text_extents(content)
def draw_text_center(self, ctx, x, y, content, rotate=False, baseline=False, fill=False, fix1=False):
"""
Korrektur für DSEG7: Die Breite der 1 ist gleich 0.289 * Breite der anderen Ziffern
Da der Leerraum bei der Ausgabe mit berücksichtigt wird, muß die tatsächliche
Ausgabeposition links von der Mitte sein um (1 - 0.289) * Breite (=0.711)
Zusätzlich muß der Abstand zwischen der 1 und dem nachfolgenden Zeichen berücksichtigt
werden
"""
if fix1 and content[0] == '1':
print("Fix1")
ext1 = ctx.text_extents('1')
w1 = 0.289 * ext1.width
dx = ext1.width - w1
ext = ctx.text_extents(content[1:])
else:
ext = ctx.text_extents(content)
if fill:
ctx.set_source_rgb(*self.bgcolor)
xf = x + ext.x_bearing - 2
yf = y + ext.height / 2 + ext.y_bearing - 2
wf = ext.width + 4
if fix1:
wf += w1
hf = ext.height + 4
ctx.rectangle(xf, yf, wf, hf)
ctx.fill()
ctx.set_source_rgb(*self.fgcolor)
if rotate:
w = ext[2]
if fix1 and content[0] == '1':
w += w1
x = x - dx
if baseline:
ctx.move_to(x - ext[3] / 2.0, y)
ctx.move_to(x - w / 2.0, y)
else:
ctx.move_to(x - ext[3] / 2.0, y + ext[2] / 2.0)
ctx.move_to(x - w / 2.0, y + ext[2] / 2.0)
ctx.save()
ctx.rotate(1.5 * math.pi)
ctx.show_text(content)
ctx.restore()
else:
w = ext.width
if fix1 and content[0] == '1':
w += w1
x = x - dx
if baseline:
ctx.move_to(x - ext[2] / 2.0, y)
ctx.move_to(x - w / 2.0, y)
else:
ctx.move_to(x - ext[2] / 2.0, y + ext[3] / 2.0)
ctx.move_to(x - w / 2.0, y + ext[3] / 2.0)
ctx.show_text(content)
ctx.stroke()
def draw_text_ralign(self, ctx, x, y, content):
ext = ctx.text_extents(content)
ctx.move_to(x - ext[2], y)
def draw_text_ralign(self, ctx, x, y, content, fix1=False):
if fix1 and content[0] == '1':
w1 = ctx.text_extents('1')[2] * 0.289
ext = ctx.text_extents(content[1:])
w = ext[2] + w1
x = x - dx
else:
ext = ctx.text_extents(content)
w = ext[2]
ctx.move_to(x - w, y)
ctx.show_text(content)
ctx.stroke()