def drawTdo(self): turtle = KfTurtle() bitmap = TBitmap() if self.plant == None: return if self.tdo == None: return # set up clipping bitmap bitmap = delphi_compatability.TBitmap().Create() bitmap.Width = kTdoSize bitmap.Height = kTdoSize bitmap.Canvas.Brush.Color = delphi_compatability.clWhite bitmap.Canvas.Rectangle(0, 0, bitmap.Width, bitmap.Height) # set up turtle turtle = uturtle.KfTurtle.defaultStartUsing() try: turtle.drawingSurface.pane = bitmap.Canvas turtle.setDrawOptionsForDrawingTdoOnly() # must be after pane and draw options set turtle.reset() turtle.xyz(self.position.X, self.position.Y, 0) try: turtle.push() turtle.rotateY(self.rotateAngle) turtle.drawingSurface.recordingStart() self.tdo.draw(turtle, self.scale, "", "", 0, 0) turtle.drawingSurface.recordingStop() turtle.drawingSurface.recordingDraw() turtle.drawingSurface.clearTriangles() turtle.pop() except Exception, e: usupport.messageForExceptionType(e, "PdTdoParameterPanel.drawTdo") bitmap.free ubmpsupport.copyBitmapToCanvasWithGlobalPalette(bitmap, self.Canvas, self.tdoRect)
def gridDrawCell(self, Sender, Col, Row, Rect, State): plant = PdPlant() textDrawRect = TRect() textToDraw = "" self.grid.Canvas.Brush.Color = delphi_compatability.clWhite self.grid.Canvas.Pen.Width = 1 if (self.plants.Count > 0) and (Row == 0): self.grid.Canvas.Pen.Color = delphi_compatability.clSilver else: self.grid.Canvas.Pen.Color = delphi_compatability.clWhite self.grid.Canvas.Rectangle(Rect.left, Rect.top, Rect.right, Rect.bottom) if Row == 1: if self.plants.Count <= 0: return textToDraw = IntToStr(self.ages[Col]) if usupport.rWidth(Rect) > 50: # 50 is fixed size textToDraw = textToDraw + " days" textDrawRect.Left = Rect.left + usupport.rWidth(Rect) / 2 - self.grid.Canvas.TextWidth(textToDraw) / 2 textDrawRect.Top = Rect.top + usupport.rHeight(Rect) / 2 - self.grid.Canvas.TextHeight("0") / 2 self.grid.Canvas.TextOut(textDrawRect.Left, textDrawRect.Top, textToDraw) return plant = None plant = self.plantForIndex(Col) if plant == None: return if not plant.previewCacheUpToDate: # draw plant # draw gray solid box to show delay for drawing plant cache self.grid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsSolid self.grid.Canvas.Brush.Color = delphi_compatability.clSilver self.grid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.grid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom) plant.drawPreviewIntoCache(Point(self.grid.DefaultColWidth, self.grid.DefaultRowHeight), uplant.kDontConsiderDomainScale, umain.kDrawNow) plant.previewCache.Transparent = false ubmpsupport.copyBitmapToCanvasWithGlobalPalette(plant.previewCache, self.grid.Canvas, Rect) # draw selection rectangle self.grid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsClear self.grid.Canvas.Pen.Width = 2 if plant == self.selectedPlant: self.grid.Canvas.Pen.Color = udomain.domain.options.firstSelectionRectangleColor else: self.grid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.grid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom)
def fillRectWithColor(self, aRect, aColor): bitmap = TBitmap() bitmap = delphi_compatability.TBitmap().Create() try: try: bitmap.Width = usupport.rWidth(aRect) bitmap.Height = usupport.rHeight(aRect) except: bitmap.Width = 1 bitmap.Height = 1 ubmpsupport.setPixelFormatBasedOnScreenForBitmap(bitmap) bitmap.Canvas.Brush.Color = aColor bitmap.Canvas.FillRect(Rect(0, 0, bitmap.Width, bitmap.Height)) ubmpsupport.copyBitmapToCanvasWithGlobalPalette(bitmap, self.Canvas, aRect) finally: bitmap.free
def fillRectWithColor(self, aRect, aColor): bitmap = TBitmap() bitmap = delphi_compatability.TBitmap().Create() try: try: bitmap.Width = usupport.rWidth(aRect) bitmap.Height = usupport.rHeight(aRect) except: bitmap.Width = 1 bitmap.Height = 1 ubmpsupport.setPixelFormatBasedOnScreenForBitmap(bitmap) bitmap.Canvas.Brush.Color = aColor bitmap.Canvas.FillRect(Rect(0, 0, bitmap.Width, bitmap.Height)) ubmpsupport.copyBitmapToCanvasWithGlobalPalette( bitmap, self.Canvas, aRect) finally: bitmap.free
def drawTdo(self): turtle = KfTurtle() bitmap = TBitmap() if self.plant == None: return if self.tdo == None: return # set up clipping bitmap bitmap = delphi_compatability.TBitmap().Create() bitmap.Width = kTdoSize bitmap.Height = kTdoSize bitmap.Canvas.Brush.Color = delphi_compatability.clWhite bitmap.Canvas.Rectangle(0, 0, bitmap.Width, bitmap.Height) # set up turtle turtle = uturtle.KfTurtle.defaultStartUsing() try: turtle.drawingSurface.pane = bitmap.Canvas turtle.setDrawOptionsForDrawingTdoOnly() # must be after pane and draw options set turtle.reset() turtle.xyz(self.position.X, self.position.Y, 0) try: turtle.push() turtle.rotateY(self.rotateAngle) turtle.drawingSurface.recordingStart() self.tdo.draw(turtle, self.scale, "", "", 0, 0) turtle.drawingSurface.recordingStop() turtle.drawingSurface.recordingDraw() turtle.drawingSurface.clearTriangles() turtle.pop() except Exception, e: usupport.messageForExceptionType( e, "PdTdoParameterPanel.drawTdo") bitmap.free ubmpsupport.copyBitmapToCanvasWithGlobalPalette( bitmap, self.Canvas, self.tdoRect)
def paint(self): fullRect = TRect() minRect = TRect() maxRect = TRect() minText = "" maxText = "" percentText = "" i = 0 partType = 0 topPos = 0 labelTexts = [0] * (range(0, utravers.kStatisticsPartTypeLast + 1) + 1) hasStuff = false fullRect = self.GetClientRect() self.Canvas.Font = self.Font if self.textHeight == 0: self.calculateTextDimensions() if self.plant != None: # v2.0 + ' (% of total)' percentText = "Statistics for " + self.plant.getName() else: # v2.0 percentText = "(no plants selected)" self.percentRect.Top = fullRect.Top + uppanel.kTopBottomGap self.percentRect.Bottom = self.percentRect.Top + self.textHeight self.percentRect.Left = fullRect.Left + uppanel.kLeftRightGap # v2.0 bold font self.Canvas.Font.Style = [UNRESOLVED.fsBold, ] self.percentRect.Right = self.percentRect.Left + self.Canvas.TextWidth(percentText) self.Canvas.Font.Style = [] for i in range(0, utravers.kStatisticsPartTypeLast + 1): labelTexts[i] = self.labelStringForPartType(i) topPos = self.percentRect.Bottom + uppanel.kBetweenGap self.maxLabelWidth = 0 for i in range(0, utravers.kStatisticsPartTypeLast + 1): self.labelRects[i] = Rect(0, 0, 0, 0) for i in range(0, utravers.kStatisticsPartTypeLast + 1): self.labelRects[i].Left = uppanel.kLeftRightGap self.labelRects[i].Right = self.labelRects[i].Left + self.Canvas.TextWidth(labelTexts[i]) if self.labelRects[i].Right - self.labelRects[i].Left > self.maxLabelWidth: self.maxLabelWidth = self.labelRects[i].Right - self.labelRects[i].Left self.labelRects[i].Top = topPos if labelTexts[i] == "": self.labelRects[i].Bottom = self.labelRects[i].Top else: self.labelRects[i].Bottom = self.labelRects[i].Top + self.textHeight topPos = topPos + (self.labelRects[i].Bottom - self.labelRects[i].Top) if self.labelRects[i].Right - self.labelRects[i].Left > self.maxLabelWidth: self.maxLabelWidth = self.labelRects[i].Right - self.labelRects[i].Left for i in range(0, utravers.kStatisticsPartTypeLast + 1): # set all label widths equal to largest, so can right-justify them self.labelRects[i].Right = self.labelRects[i].Left + self.maxLabelWidth self.graphRect.Left = uppanel.kLeftRightGap + self.maxLabelWidth + uppanel.kBetweenGap self.graphRect.Right = fullRect.Right - uppanel.kLeftRightGap self.graphRect.Top = self.percentRect.Bottom + uppanel.kBetweenGap self.graphRect.Bottom = fullRect.Bottom - uppanel.kTopBottomGap - self.textHeight - uppanel.kBetweenGap minText = "0" minRect.Left = self.graphRect.Left minRect.Right = minRect.Left + self.Canvas.TextWidth(minText) minRect.Top = self.graphRect.Bottom minRect.Bottom = minRect.Top + self.textHeight maxText = "100 %" maxRect = minRect maxRect.Right = self.graphRect.Right maxRect.Left = maxRect.Right - self.Canvas.TextWidth(maxText) self.drawBitmap.Canvas.Brush.Color = UNRESOLVED.clBtnFace # v1.4 self.drawBitmap.Canvas.Pen.Color = UNRESOLVED.clBtnFace self.drawBitmap.Canvas.Rectangle(0, 0, self.drawBitmap.Width, self.drawBitmap.Height) for i in range(0, utravers.kStatisticsPartTypeLast + 1): if self.labelRects[i].Bottom <= self.graphRect.Bottom: partType = self.partTypeForIndex(i) hasStuff = (self.statistics.liveBiomass_pctMPB[partType] + self.statistics.deadBiomass_pctMPB[partType] > 0) or (self.statistics.count[partType] > 0) self.drawTextLabel(labelTexts[i], self.labelRects[i], hasStuff, false, false) if self.plant != None: self.drawGraph() self.drawBitmap.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsClear if self.plant != None: self.drawBitmap.Canvas.Pen.Color = UNRESOLVED.clBtnText else: self.drawBitmap.Canvas.Pen.Color = UNRESOLVED.clBtnFace self.drawBitmap.Canvas.Rectangle(self.graphRect.Left, self.graphRect.Top, self.graphRect.Right, self.graphRect.Bottom) # v2.0 top label in bold self.Canvas.Font.Style = [UNRESOLVED.fsBold, ] self.drawTextLabel(percentText, self.percentRect, (self.plant != None), false, false) self.Canvas.Font.Style = [] if self.plant != None: self.drawTextLabel(minText, minRect, true, false, false) self.drawTextLabel(maxText, maxRect, true, false, false) if self.drawBitmap.Width > 0: ubmpsupport.copyBitmapToCanvasWithGlobalPalette(self.drawBitmap, self.Canvas, Rect(0, 0, 0, 0))
def plantsDrawGridDrawCell(self, Sender, Col, Row, Rect, State): generation = PdGeneration() plant = PdPlant() textDrawRect = TRect() try: self.plantsDrawGrid.Canvas.Font = self.plantsDrawGrid.Font self.plantsDrawGrid.Canvas.Font.Color = delphi_compatability.clBlack if Col == 0: #if (row = selectedRow) and (generations.count > 0) then #plantsDrawGrid.canvas.brush.color := clBlue #else self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Pen.Color = self.plantsDrawGrid.Canvas.Brush.Color self.plantsDrawGrid.Canvas.Rectangle(Rect.left, Rect.top, Rect.right, Rect.bottom) if Row > self.generations.Count - 1: return #if row = selectedRow then #plantsDrawGrid.canvas.font.color := clWhite; textDrawRect.Left = Rect.left + usupport.rWidth(Rect) / 2 - self.plantsDrawGrid.Canvas.TextWidth(IntToStr(Row + 1)) / 2 textDrawRect.Top = Rect.top + usupport.rHeight(Rect) / 2 - self.plantsDrawGrid.Canvas.TextHeight("0") / 2 self.plantsDrawGrid.Canvas.TextOut(textDrawRect.Left, textDrawRect.Top, IntToStr(Row + 1)) return else: self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Pen.Width = 1 self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Rectangle(Rect.left, Rect.top, Rect.right, Rect.bottom) generation = None generation = self.generationForIndex(Row) if generation == None: return plant = None plant = generation.plantForIndex(Col - 1) if plant == None: return if not plant.previewCacheUpToDate: # draw plant # draw gray solid box to show delay for drawing plant cache self.plantsDrawGrid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsSolid self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clSilver self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.plantsDrawGrid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom) # draw plant preview cache plant.fixedPreviewScale = false plant.fixedDrawPosition = false plant.drawPreviewIntoCache(Point(self.plantsDrawGrid.DefaultColWidth, self.plantsDrawGrid.DefaultRowHeight), uplant.kDontConsiderDomainScale, umain.kDrawNow) plant.previewCache.Transparent = false ubmpsupport.copyBitmapToCanvasWithGlobalPalette(plant.previewCache, self.plantsDrawGrid.Canvas, Rect) # draw selection rectangle self.plantsDrawGrid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsClear self.plantsDrawGrid.Canvas.Pen.Width = 2 if (Col == self.lightUpCell.X) and (Row == self.lightUpCell.Y): self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clAqua elif Row == self.selectedRow: if plant == generation.firstSelectedPlant(): self.plantsDrawGrid.Canvas.Pen.Color = udomain.domain.options.firstSelectionRectangleColor elif plant == generation.secondSelectedPlant(): self.plantsDrawGrid.Canvas.Pen.Color = udomain.domain.options.multiSelectionRectangleColor else: self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver else: self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.plantsDrawGrid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom) if plant == generation.firstParent: # draw parent indicator self.plantsDrawGrid.Canvas.TextOut(Rect.left + 4, Rect.top + 2, "p1") elif plant == generation.secondParent: self.plantsDrawGrid.Canvas.TextOut(Rect.left + 4, Rect.top + 2, "p2") finally: ucursor.cursor_stopWait()