mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
keyboard
This commit is contained in:
parent
d793dc93ab
commit
a409bc6200
@ -1,6 +1,9 @@
|
|||||||
package UI
|
package UI
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/draw"
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
"github.com/cuu/gogame/color"
|
"github.com/cuu/gogame/color"
|
||||||
)
|
)
|
||||||
//sysgo/UI/keyboard_keys.layout
|
//sysgo/UI/keyboard_keys.layout
|
||||||
@ -19,6 +22,15 @@ func NewKeyboardIcon() *KeyboardIcon {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *KeyboardIcon) Draw() {
|
||||||
|
|
||||||
|
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||||
|
|
||||||
|
surface.Blit(self.Parent.GetCanvasHWND(),self.ImgSurf,rect_,nil)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type KeyboardSelector struct {
|
type KeyboardSelector struct {
|
||||||
PageSelector
|
PageSelector
|
||||||
Parent *Keyboard
|
Parent *Keyboard
|
||||||
@ -35,14 +47,51 @@ func (self *KeyboardSelector) Draw() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Keyboard {
|
type Keyboard struct {
|
||||||
Page
|
Page
|
||||||
|
|
||||||
SectionNumbers int
|
SectionNumbers int
|
||||||
SectionIndex int
|
SectionIndex int
|
||||||
Icons map[string]UI.IconItemInterface
|
Icons map[string]IconItemInterface
|
||||||
|
|
||||||
KeyboardLayoutFile string ///sysgo/UI/keyboard_keys.layout
|
KeyboardLayoutFile string ///sysgo/UI/keyboard_keys.layout
|
||||||
|
|
||||||
|
LeftOrRight int
|
||||||
|
|
||||||
|
RowIndex int
|
||||||
|
|
||||||
|
Textarea *Textarea
|
||||||
|
Selector *KeyboardSelector
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewKeyboard() *Keyboard {
|
||||||
|
p := &Keyboard{}
|
||||||
|
|
||||||
|
p.SectionNumbers = 3
|
||||||
|
p.SectionIndex = 1
|
||||||
|
|
||||||
|
p.Icons = make( map[string]IconItemInterface )
|
||||||
|
|
||||||
|
p.LeftOrRight = 1
|
||||||
|
|
||||||
|
p.RowIndex = 0
|
||||||
|
|
||||||
|
p.FootMsg = [5]string{"Nav.","ABC","Done","Backspace","Enter"}
|
||||||
|
|
||||||
|
return p
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Keyboard) ReadLayoutFile( fname string) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
LayoutIndex := 0
|
||||||
|
|
||||||
|
content ,err := ReadLines(fname)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
48
sysgo/UI/text_item.go
Normal file
48
sysgo/UI/text_item.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
|
"github.com/cuu/gogame/color"
|
||||||
|
"github.com/cuu/gogame/font"
|
||||||
|
"github.com/cuu/gogame/draw"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
type TextItem struct {
|
||||||
|
IconItem
|
||||||
|
Str string
|
||||||
|
Color *color.Color
|
||||||
|
FontObj *ttf.Font
|
||||||
|
Bold bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTextItem() *TextItem {
|
||||||
|
p := &TextItem{}
|
||||||
|
p.Color = &color.Color{83,83,83,255}
|
||||||
|
p.MyType = ICON_TYPES["LETTER"]
|
||||||
|
p.Bold = false
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *TextItem) Draw() {
|
||||||
|
font.SetBold(self.FontObj,self.Bold)
|
||||||
|
|
||||||
|
my_text := font.Render(self.FontObj,self.Str,true,self.Color,nil)
|
||||||
|
|
||||||
|
if surface.GetWidth(my_text) != self.Width {
|
||||||
|
self.Width = surface.GetWidth(my_text)
|
||||||
|
}
|
||||||
|
|
||||||
|
if surface.GetHeight(my_text) != self.Height {
|
||||||
|
self.Height = surface.GetHeight(my_text)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||||
|
surface.Blit(self.Parent.GetCanvasHWND(),my_text,rect_,nil)
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,17 @@
|
|||||||
package UI
|
package UI
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
"github.com/veandco/go-sdl2/ttf"
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
"github.com/cuu/gogame/color"
|
"github.com/cuu/gogame/color"
|
||||||
|
"github.com/cuu/gogame/draw"
|
||||||
|
"github.com/cuu/gogame/font"
|
||||||
|
"github.com/cuu/gogame/rect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Textarea struct {
|
type Textarea struct {
|
||||||
@ -79,7 +86,6 @@ func (self *Textarea) AppendAndBlitText(alphabet string) {
|
|||||||
if self.TextFull == false {
|
if self.TextFull == false {
|
||||||
|
|
||||||
if self.TextIndex <= len(self.MyWords) {
|
if self.TextIndex <= len(self.MyWords) {
|
||||||
m = append(m[:idx], append([]string{"U"}, m[idx:]...)...)
|
|
||||||
self.MyWords = append(self.MyWords[:self.TextIndex],
|
self.MyWords = append(self.MyWords[:self.TextIndex],
|
||||||
append([]string{alphabet},self.MyWords[self.TextIndex:]...)...)
|
append([]string{alphabet},self.MyWords[self.TextIndex:]...)...)
|
||||||
|
|
||||||
@ -96,12 +102,131 @@ func (self *Textarea) AppendAndBlitText(alphabet string) {
|
|||||||
func (self *Textarea) BuildBlitText() {
|
func (self *Textarea) BuildBlitText() {
|
||||||
blit_rows := make([][]string,0)
|
blit_rows := make([][]string,0)
|
||||||
|
|
||||||
w := 0
|
w := 0
|
||||||
xmargin := 5
|
// xmargin := 5
|
||||||
endmargin :=15
|
endmargin :=15
|
||||||
x := self.PosX + xmargin
|
|
||||||
linenumber := 0
|
linenumber := 0
|
||||||
cursor_row := 0
|
cursor_row := 0
|
||||||
|
|
||||||
|
|
||||||
|
for i,v := range self.MyWords {
|
||||||
|
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||||
|
t_width := surface.GetWidth(t)
|
||||||
|
w+=t_width
|
||||||
|
|
||||||
|
if linenumber < len(blit_rows) {
|
||||||
|
blit_rows[linenumber] = append(blit_rows[linenumber],v)
|
||||||
|
}else {
|
||||||
|
blit_rows = append(blit_rows,[]string{v})
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == self.TextIndex - 1 {
|
||||||
|
cursor_row = linenumber
|
||||||
|
}
|
||||||
|
|
||||||
|
if w + t_width >= self.Width - endmargin {
|
||||||
|
w = 0
|
||||||
|
linenumber += 1
|
||||||
|
blit_rows = append(blit_rows,[]string{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(blit_rows) == 1 {
|
||||||
|
self.BlitWords = blit_rows[0]
|
||||||
|
self.BlitIndex = self.TextIndex
|
||||||
|
}else if len(blit_rows) == 2 || cursor_row < 2 {
|
||||||
|
self.BlitWords = append(blit_rows[0], blit_rows[1]...)
|
||||||
|
self.BlitIndex = self.TextIndex
|
||||||
|
|
||||||
|
}else {
|
||||||
|
self.BlitWords = append(blit_rows[cursor_row-1], blit_rows[cursor_row]...)
|
||||||
|
self.BlitIndex = self.TextIndex
|
||||||
|
|
||||||
|
for i,v := range blit_rows {
|
||||||
|
if i == cursor_row - 1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
self.BlitIndex -= len(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Textarea) BlitText() {
|
||||||
|
//blit every single word into surface and calc the width ,check multi line
|
||||||
|
self.BuildBlitText()
|
||||||
|
|
||||||
|
w := 0
|
||||||
|
xmargin := 5
|
||||||
|
endmargin := 15
|
||||||
|
|
||||||
|
x := self.PosX + xmargin
|
||||||
|
y := self.PosY
|
||||||
|
|
||||||
|
linenumber := 0
|
||||||
|
|
||||||
|
if len(self.MyWords) > self.TextLimit {
|
||||||
|
self.TextFull = true
|
||||||
|
}else {
|
||||||
|
self.TextFull = false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _,v := range self.BlitWords {
|
||||||
|
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||||
|
w += surface.GetWidth(t)
|
||||||
|
|
||||||
|
if w >= self.Width - endmargin && linenumber == 0 {
|
||||||
|
linenumber += 1
|
||||||
|
x = self.PosX + xmargin
|
||||||
|
y = self.PosY + surface.GetHeight(t) * linenumber
|
||||||
|
w = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
rect_ := rect.Rect(x,y,0,0)
|
||||||
|
surface.Blit(self.CanvasHWND,t,&rect_,nil)
|
||||||
|
x += surface.GetWidth(t)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Textarea) Cursor() {
|
||||||
|
w := 0
|
||||||
|
xmargin := 5
|
||||||
|
endmargin := 15
|
||||||
|
x := self.PosX+xmargin
|
||||||
|
y := self.PosY
|
||||||
|
linenumber := 0
|
||||||
|
|
||||||
|
for _,v := range self.BlitWords[:self.BlitIndex] {
|
||||||
|
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||||
|
w += surface.GetWidth(t)
|
||||||
|
|
||||||
|
if w >= self.Width - endmargin && linenumber == 0 {
|
||||||
|
x = self.PosX + xmargin
|
||||||
|
y = self.PosY + surface.GetHeight(t)
|
||||||
|
w = 0
|
||||||
|
linenumber +=1
|
||||||
|
}
|
||||||
|
|
||||||
|
if w >= self.Width - endmargin*3 && linenumber > 0 {
|
||||||
|
x += surface.GetWidth(t)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
x += surface.GetWidth(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
c_t := font.Render(self.FontObj,"_",true,&color.Color{0,0,0,255},nil)
|
||||||
|
rect_ := rect.Rect(x+1,y-2,0,0)
|
||||||
|
surface.Blit(self.CanvasHWND,c_t,&rect_,nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Textarea) Draw() {
|
||||||
|
|
||||||
|
rect_:= rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
|
||||||
|
|
||||||
|
draw.AARoundRect(self.CanvasHWND,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||||
|
|
||||||
|
self.BlitText()
|
||||||
|
self.Cursor()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user