added LEFT_LABELS config param

This commit is contained in:
Louis Heredero 2024-03-24 13:39:40 +01:00
parent 75d145096d
commit 7647f870a6
2 changed files with 35 additions and 7 deletions

View File

@ -23,6 +23,7 @@ class Config:
VALUES_GAP = 5 VALUES_GAP = 5
ARROW_LABEL_DISTANCE = 5 ARROW_LABEL_DISTANCE = 5
FORCE_DESCS_ON_SIDE = False FORCE_DESCS_ON_SIDE = False
LEFT_LABELS = False
WIDTH = 1200 WIDTH = 1200
HEIGHT = 800 HEIGHT = 800

View File

@ -31,7 +31,12 @@ class Renderer:
def render(self, schema: InstructionSetSchema) -> None: def render(self, schema: InstructionSetSchema) -> None:
self.surf.fill(self.config.BACKGROUND_COLOR) 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: if self.display:
name = os.path.basename(schema.path) name = os.path.basename(schema.path)
@ -76,12 +81,20 @@ class Renderer:
pygame.draw.line(self.surf, borderCol, [bitX, bitsY], [bitX, bitsY + bitH]) pygame.draw.line(self.surf, borderCol, [bitX, bitsY], [bitX, bitsY + bitH])
ranges = struct.getSortedRanges() ranges = struct.getSortedRanges()
if self.config.LEFT_LABELS:
ranges.reverse()
if self.config.FORCE_DESCS_ON_SIDE: 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: 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 descY = bitsY + bitH * 2
@ -128,10 +141,16 @@ class Renderer:
bitH = self.config.BIT_HEIGHT bitH = self.config.BIT_HEIGHT
arrowMargin = self.config.ARROW_MARGIN arrowMargin = self.config.ARROW_MARGIN
if endX > startX:
endX -= arrowMargin
else:
endX += arrowMargin
pygame.draw.lines(self.surf, self.config.LINK_COLOR, False, [ pygame.draw.lines(self.surf, self.config.LINK_COLOR, False, [
[startX, startY + bitH*1.5], [startX, startY + bitH*1.5],
[startX, endY + bitH/2], [startX, endY + bitH/2],
[endX - arrowMargin, endY + bitH/2] [endX, endY + bitH/2]
]) ])
def drawDescription(self, def drawDescription(self,
@ -145,7 +164,10 @@ class Renderer:
bitW = self.config.BIT_WIDTH bitW = self.config.BIT_WIDTH
bitH = self.config.BIT_HEIGHT 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) self.drawUnderbracket(rStartX, rStartX + rWidth, rStartY)
@ -153,12 +175,17 @@ class Renderer:
self.drawLink(midX, rStartY, descX, descY) self.drawLink(midX, rStartY, descX, descY)
descTxt = self.font.render(range_.description, True, self.config.TEXT_COLOR) 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() descY += descTxt.get_height()
if range_.values is not None and range_.dependsOn is None: 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 descY += self.config.DESCRIPTION_MARGIN