From 7647f870a66448e6062507b56bd11353b521910f Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 24 Mar 2024 13:39:40 +0100 Subject: [PATCH] added LEFT_LABELS config param --- config.py | 1 + renderer.py | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index d5b5c46..ee8b3c5 100644 --- a/config.py +++ b/config.py @@ -23,6 +23,7 @@ class Config: VALUES_GAP = 5 ARROW_LABEL_DISTANCE = 5 FORCE_DESCS_ON_SIDE = False + LEFT_LABELS = False WIDTH = 1200 HEIGHT = 800 diff --git a/renderer.py b/renderer.py index 399cd36..22d5ab8 100644 --- a/renderer.py +++ b/renderer.py @@ -31,7 +31,12 @@ class Renderer: def render(self, schema: InstructionSetSchema) -> None: self.surf.fill(self.config.BACKGROUND_COLOR) - self.drawStructure(schema.structures["main"], schema.structures, self.margins[3], self.margins[0]) + mainStruct: Structure = schema.structures["main"] + ox = self.margins[3] + if self.config.LEFT_LABELS: + ox = self.config.WIDTH - self.margins[3] - mainStruct.bits * self.config.BIT_WIDTH + + self.drawStructure(schema.structures["main"], schema.structures, ox, self.margins[0]) if self.display: name = os.path.basename(schema.path) @@ -76,12 +81,20 @@ class Renderer: pygame.draw.line(self.surf, borderCol, [bitX, bitsY], [bitX, bitsY + bitH]) ranges = struct.getSortedRanges() + if self.config.LEFT_LABELS: + ranges.reverse() if self.config.FORCE_DESCS_ON_SIDE: - descX = self.margins[3] + structures["main"].bits * bitW + if self.config.LEFT_LABELS: + descX = self.config.WIDTH - self.margins[3] - structures["main"].bits * bitW + else: + descX = self.margins[3] + structures["main"].bits * bitW else: - descX = ox + max(0, (struct.bits-12) * bitW) + if self.config.LEFT_LABELS: + descX = ox + struct.bits * bitW + else: + descX = ox descY = bitsY + bitH * 2 @@ -128,10 +141,16 @@ class Renderer: bitH = self.config.BIT_HEIGHT arrowMargin = self.config.ARROW_MARGIN + if endX > startX: + endX -= arrowMargin + + else: + endX += arrowMargin + pygame.draw.lines(self.surf, self.config.LINK_COLOR, False, [ [startX, startY + bitH*1.5], [startX, endY + bitH/2], - [endX - arrowMargin, endY + bitH/2] + [endX, endY + bitH/2] ]) def drawDescription(self, @@ -145,7 +164,10 @@ class Renderer: bitW = self.config.BIT_WIDTH bitH = self.config.BIT_HEIGHT - descX = max(descX, rStartX + rWidth/2 + bitW) + if self.config.LEFT_LABELS: + descX = min(descX, rStartX + rWidth/2 - bitW) + else: + descX = max(descX, rStartX + rWidth/2 + bitW) self.drawUnderbracket(rStartX, rStartX + rWidth, rStartY) @@ -153,12 +175,17 @@ class Renderer: self.drawLink(midX, rStartY, descX, descY) descTxt = self.font.render(range_.description, True, self.config.TEXT_COLOR) - self.surf.blit(descTxt, [descX, descY + (bitH - descTxt.get_height())/2]) + txtX = descX + + if self.config.LEFT_LABELS: + txtX -= descTxt.get_width() + + self.surf.blit(descTxt, [txtX, descY + (bitH - descTxt.get_height())/2]) descY += descTxt.get_height() if range_.values is not None and range_.dependsOn is None: - descX, descY = self.drawValues(range_.values, descX, descY) + txtX, descY = self.drawValues(range_.values, txtX, descY) descY += self.config.DESCRIPTION_MARGIN