Signed integer representation
This commit is contained in:
parent
a47445f494
commit
0ce136585b
23
draw.go
23
draw.go
@ -147,6 +147,8 @@ func drawHexadecimal (xOffset, yOffset int, number uint64) {
|
|||||||
application.SetColor(xOffset, yOffset, stone.ColorBlue)
|
application.SetColor(xOffset, yOffset, stone.ColorBlue)
|
||||||
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
|
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
|
||||||
|
|
||||||
|
number = drawSign(xOffset, yOffset, number)
|
||||||
|
|
||||||
for x := 0; x < 16; x ++ {
|
for x := 0; x < 16; x ++ {
|
||||||
bitOffset -= 4
|
bitOffset -= 4
|
||||||
|
|
||||||
@ -181,6 +183,8 @@ func drawDecimal (xOffset, yOffset int, number uint64) {
|
|||||||
application.SetColor(xOffset, yOffset, stone.ColorBlue)
|
application.SetColor(xOffset, yOffset, stone.ColorBlue)
|
||||||
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
|
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
|
||||||
|
|
||||||
|
number = drawSign(xOffset, yOffset, number)
|
||||||
|
|
||||||
for x := 0; x < 20; x ++ {
|
for x := 0; x < 20; x ++ {
|
||||||
trueX := x + xOffset + 5
|
trueX := x + xOffset + 5
|
||||||
character := rune((number / divisor) % 10) + '0'
|
character := rune((number / divisor) % 10) + '0'
|
||||||
@ -230,3 +234,22 @@ func drawOctal (xOffset, yOffset int, number uint64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func drawSign (xOffset, yOffset int, number uint64) (alteredNumber uint64) {
|
||||||
|
alteredNumber = number
|
||||||
|
|
||||||
|
if showSigned {
|
||||||
|
if int64(alteredNumber) >= 0 {
|
||||||
|
application.SetRune(xOffset + 3, yOffset, '+')
|
||||||
|
application.SetColor (
|
||||||
|
xOffset + 3, yOffset, stone.ColorGreen)
|
||||||
|
} else {
|
||||||
|
application.SetRune(xOffset + 3, yOffset, '-')
|
||||||
|
application.SetColor (
|
||||||
|
xOffset + 3, yOffset, stone.ColorRed)
|
||||||
|
alteredNumber = uint64(int64(number) * -1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
18
main.go
18
main.go
@ -15,7 +15,8 @@ var application = &stone.Application { }
|
|||||||
var expressionRoot Expression
|
var expressionRoot Expression
|
||||||
var inputBuffer stone.DamageBuffer
|
var inputBuffer stone.DamageBuffer
|
||||||
var showLeftColumn bool
|
var showLeftColumn bool
|
||||||
var showEndResult bool
|
var showEndResult bool = true
|
||||||
|
var showSigned bool = true
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
application.SetTitle("MathPan")
|
application.SetTitle("MathPan")
|
||||||
@ -81,11 +82,6 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
|
|||||||
redraw()
|
redraw()
|
||||||
application.Draw()
|
application.Draw()
|
||||||
|
|
||||||
case stone.KeyTab:
|
|
||||||
showEndResult = !showEndResult
|
|
||||||
redraw()
|
|
||||||
application.Draw()
|
|
||||||
|
|
||||||
case stone.KeyDelete:
|
case stone.KeyDelete:
|
||||||
if selectedExpression == nil { break }
|
if selectedExpression == nil { break }
|
||||||
parent := selectedExpression.Parent()
|
parent := selectedExpression.Parent()
|
||||||
@ -211,6 +207,16 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
|
|||||||
|
|
||||||
redraw()
|
redraw()
|
||||||
application.Draw()
|
application.Draw()
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
showSigned = !showSigned
|
||||||
|
redraw()
|
||||||
|
application.Draw()
|
||||||
|
|
||||||
|
case stone.KeyTab:
|
||||||
|
showEndResult = !showEndResult
|
||||||
|
redraw()
|
||||||
|
application.Draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user