mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
image: Remove image.DrawFilledRect (#142)
This commit is contained in:
parent
580effba8e
commit
85279e8422
@ -26,6 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
imageEmpty *ebiten.Image
|
||||||
imageGameBG *ebiten.Image
|
imageGameBG *ebiten.Image
|
||||||
imageWindows *ebiten.Image
|
imageWindows *ebiten.Image
|
||||||
imageGameover *ebiten.Image
|
imageGameover *ebiten.Image
|
||||||
@ -67,6 +68,12 @@ func linesTextBoxPosition() (x, y int) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
|
// Empty
|
||||||
|
imageEmpty, err = ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
imageEmpty.Fill(color.White)
|
||||||
// Background
|
// Background
|
||||||
imageGameBG, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterLinear)
|
imageGameBG, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterLinear)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,7 +128,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func drawWindow(r *ebiten.Image, x, y, width, height int) error {
|
func drawWindow(r *ebiten.Image, x, y, width, height int) error {
|
||||||
return r.DrawFilledRect(x, y, width, height, color.NRGBA{0, 0, 0, 0xc0})
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
w, h := imageEmpty.Size()
|
||||||
|
op.GeoM.Scale(float64(width)/float64(w), float64(height)/float64(h))
|
||||||
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
|
op.ColorM.Scale(0, 0, 0, 0.75)
|
||||||
|
return r.DrawImage(imageEmpty, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff}
|
var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff}
|
||||||
|
@ -128,11 +128,18 @@ func updateInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pianoImage *ebiten.Image
|
var (
|
||||||
|
imagePiano *ebiten.Image
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
pianoImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
imageEmpty, err := ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
imageEmpty.Fill(color.White)
|
||||||
|
imagePiano, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -142,8 +149,13 @@ func init() {
|
|||||||
for i, k := range whiteKeys {
|
for i, k := range whiteKeys {
|
||||||
x := i*width + 36
|
x := i*width + 36
|
||||||
height := 112
|
height := 112
|
||||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.White)
|
op := &ebiten.DrawImageOptions{}
|
||||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.Black)
|
w, h := imageEmpty.Size()
|
||||||
|
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
|
||||||
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
|
op.ColorM.Scale(1, 1, 1, 1)
|
||||||
|
imagePiano.DrawImage(imageEmpty, op)
|
||||||
|
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
|
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
|
||||||
@ -153,8 +165,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
x := i*width + 24
|
x := i*width + 24
|
||||||
height := 64
|
height := 64
|
||||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.Black)
|
op := &ebiten.DrawImageOptions{}
|
||||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.White)
|
w, h := imageEmpty.Size()
|
||||||
|
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
|
||||||
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
|
op.ColorM.Scale(0, 0, 0, 1)
|
||||||
|
imagePiano.DrawImage(imageEmpty, op)
|
||||||
|
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +185,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
|
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
|
||||||
screen.DrawImage(pianoImage, nil)
|
screen.DrawImage(imagePiano, nil)
|
||||||
|
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright 2015 Hajime Hoshi
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
|
||||||
"github.com/hajimehoshi/ebiten/exp/shape"
|
|
||||||
"image/color"
|
|
||||||
"log"
|
|
||||||
//"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 320
|
|
||||||
screenHeight = 240
|
|
||||||
)
|
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
|
||||||
for i := 0; i < 6; i++ {
|
|
||||||
screen.DrawRect(2*i, 2*i, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
|
||||||
}
|
|
||||||
screen.DrawFilledRect(10, 10, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
|
||||||
screen.DrawFilledRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
|
||||||
screen.DrawLine(130, 0, 140, 100, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
|
||||||
screen.DrawLine(140, 0, 150, 100, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
|
||||||
|
|
||||||
shape.DrawEllipse(screen, 0, 0, 200, 200, color.NRGBA{0x80, 0xff, 0x80, 0x80})
|
|
||||||
//shape.DrawArc(screen, 0, 0, 50, 50, 0, math.Pi/2, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Shapes (Ebiten Demo)"); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
5
image.go
5
image.go
@ -116,11 +116,6 @@ func (i *Image) DrawRect(x, y, width, height int, clr color.Color) error {
|
|||||||
return i.DrawLines(&rectsAsLines{&rect{x, y, width, height, clr}})
|
return i.DrawLines(&rectsAsLines{&rect{x, y, width, height, clr}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawFilledRect draws a filled rectangle.
|
|
||||||
func (i *Image) DrawFilledRect(x, y, width, height int, clr color.Color) error {
|
|
||||||
return i.DrawFilledRects(&rect{x, y, width, height, clr})
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawFilledRects draws filled rectangles on the image.
|
// DrawFilledRects draws filled rectangles on the image.
|
||||||
func (i *Image) DrawFilledRects(rects Rects) (err error) {
|
func (i *Image) DrawFilledRects(rects Rects) (err error) {
|
||||||
i.pixels = nil
|
i.pixels = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user