From 84c036f8a352f675a8ede5260bc5ba884726d8d3 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Mon, 14 Dec 2020 11:40:19 +0100 Subject: [PATCH] removed unused functions for text colorizing --- d2core/d2gui/common.go | 27 --------------------------- d2core/d2gui/layout.go | 12 ++++++------ d2core/d2term/terminal.go | 36 ++++++------------------------------ 3 files changed, 12 insertions(+), 63 deletions(-) diff --git a/d2core/d2gui/common.go b/d2core/d2gui/common.go index f81bb4e6..02dd2094 100644 --- a/d2core/d2gui/common.go +++ b/d2core/d2gui/common.go @@ -1,8 +1,6 @@ package d2gui import ( - "image/color" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" ) @@ -37,28 +35,3 @@ func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, fram func half(n int) int { return n / 2 } - -func rgbaColor(rgba uint32) color.RGBA { - result := color.RGBA{} - a, b, g, r := 0, 1, 2, 3 - byteWidth := 8 - byteMask := 0xff - - for idx := 0; idx < 4; idx++ { - shift := idx * byteWidth - component := uint8(rgba>>shift) & uint8(byteMask) - - switch idx { - case a: - result.A = component - case b: - result.B = component - case g: - result.G = component - case r: - result.R = component - } - } - - return result -} diff --git a/d2core/d2gui/layout.go b/d2core/d2gui/layout.go index 43125acf..44c7f7a0 100644 --- a/d2core/d2gui/layout.go +++ b/d2core/d2gui/layout.go @@ -248,16 +248,16 @@ func (l *Layout) renderEntryDebug(entry *layoutEntry, target d2interface.Surface target.PushTranslation(entry.x, entry.y) defer target.Pop() - drawColor := rgbaColor(white) + drawColor := d2util.Color(white) switch entry.widget.(type) { case *Layout: - drawColor = rgbaColor(magenta) + drawColor = d2util.Color(magenta) case *SpacerStatic, *SpacerDynamic: - drawColor = rgbaColor(grey2) + drawColor = d2util.Color(grey2) case *Label: - drawColor = rgbaColor(green) + drawColor = d2util.Color(green) case *Button: - drawColor = rgbaColor(yellow) + drawColor = d2util.Color(yellow) } target.DrawLine(entry.width, 0, drawColor) @@ -487,7 +487,7 @@ func (l *Layout) createButton(renderer d2interface.Renderer, text string, return nil, loadErr } - textColor := rgbaColor(grey) + textColor := d2util.Color(grey) textWidth, textHeight := font.GetTextMetrics(text) textX := half(buttonWidth) - half(textWidth) textY := half(buttonHeight) - half(textHeight) + config.textOffset diff --git a/d2core/d2term/terminal.go b/d2core/d2term/terminal.go index f83a5089..c7d4eea1 100644 --- a/d2core/d2term/terminal.go +++ b/d2core/d2term/terminal.go @@ -14,6 +14,7 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" ) const ( @@ -491,39 +492,14 @@ func parseCommand(command string) []string { return params } -func rgbaColor(rgba uint32) color.RGBA { - result := color.RGBA{} - a, b, g, r := 0, 1, 2, 3 - byteWidth := 8 - byteMask := 0xff - - for idx := 0; idx < 4; idx++ { - shift := idx * byteWidth - component := uint8(rgba>>shift) & uint8(byteMask) - - switch idx { - case a: - result.A = component - case b: - result.B = component - case g: - result.G = component - case r: - result.R = component - } - } - - return result -} - func createTerminal() (*terminal, error) { terminal := &terminal{ lineCount: termRowCount, - bgColor: rgbaColor(darkGrey), - fgColor: rgbaColor(lightGrey), - infoColor: rgbaColor(lightBlue), - warningColor: rgbaColor(yellow), - errorColor: rgbaColor(red), + bgColor: d2util.Color(darkGrey), + fgColor: d2util.Color(lightGrey), + infoColor: d2util.Color(lightBlue), + warningColor: d2util.Color(yellow), + errorColor: d2util.Color(red), actions: make(map[string]termActionEntry), }