-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpwindow.go
228 lines (181 loc) · 5.55 KB
/
xpwindow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package main
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type IXPWindow interface {
Draw(*ebiten.Image)
GetRect() Rect
SetPosition(float64, float64)
GetPosition() (float64, float64)
SetActive(bool)
GetHWND() int
OnLButtonDown()
OnLButtonUp()
OnClose()
OnMove()
OnMouseMove()
GetText() string
}
type XPWindow struct {
xpScreen *WinXPScreen
game *Game
posX, posY, width, height float64
title string
active bool
closeButtonHover bool
closeButtonDown bool
hWnd int
captionFrameImage *ebiten.Image
leftFrameImage *ebiten.Image
rightFrameImage *ebiten.Image
bottomFrameImage *ebiten.Image
//closeButtonImage *ebiten.Image
//closeGlyphImage *ebiten.Image
font *Font
}
func (wnd *XPWindow) GetText() string {
return wnd.title
}
func (wnd *XPWindow) Draw(screen *ebiten.Image) {
x := wnd.posX
y := wnd.posY
width := wnd.width
height := wnd.height
g := wnd.game
captionBarState := 1
if wnd.xpScreen.activeWindow == wnd {
captionBarState = 0
}
g.DrawStatedNineGrid(screen, wnd.captionFrameImage, captionBarState, 2, 1.0, NineGridInfo{Right: 35, Top: 9, Left: 28, Bottom: 17}, x, y, width, height)
g.DrawStatedNineGrid(screen, wnd.leftFrameImage, captionBarState, 2, 1.0, NineGridInfo{Right: 2, Top: 0, Left: 2, Bottom: 0}, x, y+30, 4, height-30-5)
g.DrawStatedNineGrid(screen, wnd.rightFrameImage, captionBarState, 2, 1.0, NineGridInfo{Right: 2, Top: 0, Left: 2, Bottom: 0}, x+width-4, y+30, 4, height-30-5)
g.DrawStatedNineGrid(screen, wnd.bottomFrameImage, captionBarState, 2, 1.0, NineGridInfo{Right: 5, Top: 2, Left: 5, Bottom: 2}, x, y+height-5, width, 5)
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(x+6, y+8)
// screen.DrawImage(xpNotepadIcon, op)
/*
closeBtnState := 0
if wnd.closeButtonDown {
closeBtnState = 2
} else if wnd.closeButtonHover {
closeBtnState = 1
}
*/
//g.DrawWinXPCloseButton(screen, wnd.xpScreen.activeWindow != wnd, closeBtnState, x+width-25, y+5, 21, 21)
fontRenderer := g.fontRenderer
fontRenderer.PushState()
fontRenderer.Reset()
fontRenderer.SetTextColor(color.White)
fontRenderer.SetScale(2.0)
fontRenderer.SetFont(wnd.font)
textDim := fontRenderer.GetStringDimensions(wnd.title)
fontRenderer.DrawTextAt(screen, wnd.title, Vec2f{x + 28, y + (30-textDim.Y)/2})
fontRenderer.PopState()
ebitenutil.DrawRect(screen, x+4, y+30, width-4-4, height-30-5, color.RGBA{236, 233, 216, 255})
}
func (wnd *XPWindow) GetHWND() int {
return wnd.hWnd
}
func (wnd *XPWindow) GetRect() Rect {
return Rect{int(wnd.posX), int(wnd.posY), int(wnd.posX + wnd.width), int(wnd.posY + wnd.height)}
}
func (wnd *XPWindow) SetPosition(x float64, y float64) {
wnd.posX = x
wnd.posY = y
}
func (wnd *XPWindow) GetPosition() (x float64, y float64) {
return wnd.posX, wnd.posY
}
func (wnd *XPWindow) OnMove() {
}
func (wnd *XPWindow) SetActive(status bool) {
wnd.active = status
}
func (wnd *XPWindow) OnMouseMove() {
curX, curY := ebiten.CursorPosition()
ncPosX := curX - int(wnd.posX)
ncPosY := curY - int(wnd.posY)
if ncPosX >= int(wnd.width)-5-21 && ncPosY >= 5 &&
ncPosX < int(wnd.width)-5 && ncPosY < 30-5 {
wnd.closeButtonHover = true
return
} else {
wnd.closeButtonHover = false
}
}
func (wnd *XPWindow) OnLButtonDown() {
curX, curY := ebiten.CursorPosition()
ncPosX := curX - int(wnd.posX)
ncPosY := curY - int(wnd.posY)
if ncPosX >= int(wnd.width)-5-21 && ncPosY >= 5 &&
ncPosX < int(wnd.width)-5 && ncPosY < 30-5 {
wnd.closeButtonDown = true
return
}
if ncPosX >= 0 && ncPosY >= 0 &&
ncPosX <= int(wnd.width) && ncPosY <= 30 {
windowGrab = wnd
wnd.OnMove()
}
}
func (wnd *XPWindow) OnLButtonUp() {
if wnd.closeButtonDown {
wnd.OnClose()
wnd.closeButtonDown = false
}
}
func (wnd *XPWindow) OnClose() {
wnd.DestroyWindow()
}
func (wnd *XPWindow) DestroyWindow() {
wnd.OnDestroy()
a := &wnd.xpScreen.windows
for i := len(*a) - 1; i >= 0; i-- {
if (*a)[i].GetHWND() == wnd.hWnd {
*a = append((*a)[:i], (*a)[i+1:]...)
break
}
}
}
func (wnd *XPWindow) OnDestroy() {
}
func InitXPWindow(wnd *XPWindow, xps *WinXPScreen, title string, x float64, y float64, width float64, height float64) {
resMan := ResourceManager_GetInstance()
wnd.captionFrameImage = resMan.LoadImage("assets/computer/frame_caption.png")
wnd.leftFrameImage = resMan.LoadImage("assets/computer/frame_left.png")
wnd.rightFrameImage = resMan.LoadImage("assets/computer/frame_right.png")
wnd.bottomFrameImage = resMan.LoadImage("assets/computer/frame_bottom.png")
wnd.font = resMan.LoadFontJSON("font/font_fantasy.json")
wnd.hWnd = xps.hwndCounter
xps.hwndCounter++
wnd.xpScreen = xps
wnd.game = xps.game
wnd.posX = x
wnd.posY = y
if x == cwUseDefault {
wnd.posX = float64(xps.cwDefX)
wnd.posY = float64(xps.cwDefY)
if xps.cwDefY+int(height) < screenHeight {
xps.cwDefY += 10
}
xps.cwDefX += 10
if xps.cwDefX >= screenWidth {
xps.cwDefX = 0
xps.cwDefY = 0
}
} else {
wnd.posX = x
wnd.posY = y
}
wnd.width = width
wnd.height = height
wnd.title = title
xps.SetActiveWindow(wnd)
}
func NewXPWindow(xps *WinXPScreen, title string, x float64, y float64, width float64, height float64) *XPWindow {
s := new(XPWindow)
InitXPWindow(s, xps, title, x, y, width, height)
return s
}