fmt
This commit is contained in:
parent
bb4ed43b8a
commit
9a1350aff2
4 changed files with 270 additions and 269 deletions
3
Makefile
3
Makefile
|
@ -17,3 +17,6 @@ nuke:
|
|||
cd draw2d && make nuke
|
||||
cd postscript && make nuke
|
||||
cd wingui && make nuke
|
||||
|
||||
fmt:
|
||||
gofmt -w draw2d postscript wingui cmd
|
||||
|
|
|
@ -56,12 +56,12 @@ func TestDrawCubicCurve(gc draw2d.GraphicContext) {
|
|||
}
|
||||
|
||||
var (
|
||||
mh uint32
|
||||
wndBufferHeader uint32
|
||||
wndBuffer wingui.BITMAP
|
||||
hdcWndBuffer uint32
|
||||
ppvBits *image.RGBAColor
|
||||
backBuffer *image.RGBA
|
||||
mh uint32
|
||||
wndBufferHeader uint32
|
||||
wndBuffer wingui.BITMAP
|
||||
hdcWndBuffer uint32
|
||||
ppvBits *image.RGBAColor
|
||||
backBuffer *image.RGBA
|
||||
postscriptContent string
|
||||
)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
|||
|
||||
switch msg {
|
||||
case wingui.WM_CREATE:
|
||||
hdc := wingui.GetDC(hwnd);
|
||||
hdc := wingui.GetDC(hwnd)
|
||||
wndBufferHeader = wingui.CreateCompatibleBitmap(hdc, 600, 800)
|
||||
wingui.GetObject(wndBufferHeader, unsafe.Sizeof(wndBuffer), uintptr(unsafe.Pointer(&wndBuffer)))
|
||||
hdcWndBuffer = wingui.CreateCompatibleDC(hdc)
|
||||
|
@ -81,7 +81,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
|||
bmp_header.Size = uint32(unsafe.Sizeof(bmp_header))
|
||||
bmp_header.Width = 600
|
||||
bmp_header.Height = 800
|
||||
bmp_header.SizeImage = 0// the api says this must be 0 for BI_RGB images
|
||||
bmp_header.SizeImage = 0 // the api says this must be 0 for BI_RGB images
|
||||
bmp_header.Compression = wingui.BI_RGB
|
||||
bmp_header.BitCount = 32
|
||||
bmp_header.Planes = 1
|
||||
|
@ -101,7 +101,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
|||
hdcWndBuffer = wingui.CreateCompatibleDC(hdc)
|
||||
wingui.SelectObject(hdcWndBuffer, wndBufferHeader)
|
||||
|
||||
pixel := (*[600*800]image.RGBAColor)(unsafe.Pointer(ppvBits))
|
||||
pixel := (*[600 * 800]image.RGBAColor)(unsafe.Pointer(ppvBits))
|
||||
pixelSlice := pixel[:]
|
||||
backBuffer = &image.RGBA{pixelSlice, 600, image.Rect(0, 0, 600, 800)}
|
||||
fmt.Println("Create windows")
|
||||
|
@ -123,7 +123,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
|||
reader := strings.NewReader(postscriptContent)
|
||||
interpreter.Execute(reader)
|
||||
gc.Restore()
|
||||
wingui.BitBlt(hdc, 0, 0 , int(wndBuffer.Width), int(wndBuffer.Height), hdcWndBuffer, 0, 0, wingui.SRCCOPY);
|
||||
wingui.BitBlt(hdc, 0, 0, int(wndBuffer.Width), int(wndBuffer.Height), hdcWndBuffer, 0, 0, wingui.SRCCOPY)
|
||||
wingui.EndPaint(hwnd, &ps)
|
||||
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
||||
case wingui.WM_CLOSE:
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
"freetype-go.googlecode.com/hg/freetype/raster"
|
||||
)
|
||||
|
||||
type Painter interface{
|
||||
type Painter interface {
|
||||
raster.Painter
|
||||
SetColor(color image.Color)
|
||||
}
|
||||
|
||||
type ImageGraphicContext struct {
|
||||
img draw.Image
|
||||
img draw.Image
|
||||
painter Painter
|
||||
fillRasterizer *raster.Rasterizer
|
||||
strokeRasterizer *raster.Rasterizer
|
||||
|
|
104
wingui/wingdi.go
104
wingui/wingdi.go
|
@ -6,7 +6,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
|
||||
WM_PAINT = 15
|
||||
|
||||
BI_RGB = 0
|
||||
|
@ -17,71 +16,70 @@ const (
|
|||
SRCCOPY = 0xCC0020
|
||||
)
|
||||
|
||||
type RECT struct{
|
||||
Left int32
|
||||
Top int32
|
||||
Right int32
|
||||
type RECT struct {
|
||||
Left int32
|
||||
Top int32
|
||||
Right int32
|
||||
Bottom int32
|
||||
}
|
||||
|
||||
type PAINTSTRUCT struct{
|
||||
HDC uint32
|
||||
Erase int32 // bool
|
||||
RcPaint RECT
|
||||
Restore int32 // bool
|
||||
IncUpdate int32 // bool
|
||||
rgbReserved [32]byte
|
||||
type PAINTSTRUCT struct {
|
||||
HDC uint32
|
||||
Erase int32 // bool
|
||||
RcPaint RECT
|
||||
Restore int32 // bool
|
||||
IncUpdate int32 // bool
|
||||
rgbReserved [32]byte
|
||||
}
|
||||
|
||||
type BITMAP struct{
|
||||
Type int32
|
||||
Width int32
|
||||
Height int32
|
||||
WidthBytes int32
|
||||
Planes uint16
|
||||
BitsPixel uint16
|
||||
Bits * byte
|
||||
type BITMAP struct {
|
||||
Type int32
|
||||
Width int32
|
||||
Height int32
|
||||
WidthBytes int32
|
||||
Planes uint16
|
||||
BitsPixel uint16
|
||||
Bits *byte
|
||||
}
|
||||
|
||||
type BITMAPINFOHEADER struct{
|
||||
Size uint32
|
||||
Width int32
|
||||
Height int32
|
||||
Planes uint16
|
||||
BitCount uint16
|
||||
Compression uint32
|
||||
SizeImage uint32
|
||||
XPelsPerMeter int32
|
||||
YPelsPerMeter int32
|
||||
ClrUsed uint32
|
||||
ClrImportant uint32
|
||||
type BITMAPINFOHEADER struct {
|
||||
Size uint32
|
||||
Width int32
|
||||
Height int32
|
||||
Planes uint16
|
||||
BitCount uint16
|
||||
Compression uint32
|
||||
SizeImage uint32
|
||||
XPelsPerMeter int32
|
||||
YPelsPerMeter int32
|
||||
ClrUsed uint32
|
||||
ClrImportant uint32
|
||||
}
|
||||
|
||||
type BITMAPINFO struct{
|
||||
Header BITMAPINFOHEADER
|
||||
Colors [1]RGBQUAD
|
||||
type BITMAPINFO struct {
|
||||
Header BITMAPINFOHEADER
|
||||
Colors [1]RGBQUAD
|
||||
}
|
||||
|
||||
type RGBQUAD struct{
|
||||
Blue byte
|
||||
Green byte
|
||||
Red byte
|
||||
Reserved byte
|
||||
type RGBQUAD struct {
|
||||
Blue byte
|
||||
Green byte
|
||||
Red byte
|
||||
Reserved byte
|
||||
}
|
||||
|
||||
var (
|
||||
modgdi32 = loadDll("gdi32.dll")
|
||||
|
||||
procGetDC = getSysProcAddr(moduser32, "GetDC")
|
||||
procCreateCompatibleDC = getSysProcAddr(modgdi32, "CreateCompatibleDC")
|
||||
procGetObject = getSysProcAddr(modgdi32, "GetObjectW")
|
||||
procSelectObject = getSysProcAddr(modgdi32, "SelectObject")
|
||||
procBeginPaint = getSysProcAddr(moduser32, "BeginPaint")
|
||||
procEndPaint = getSysProcAddr(moduser32, "EndPaint")
|
||||
procGetDC = getSysProcAddr(moduser32, "GetDC")
|
||||
procCreateCompatibleDC = getSysProcAddr(modgdi32, "CreateCompatibleDC")
|
||||
procGetObject = getSysProcAddr(modgdi32, "GetObjectW")
|
||||
procSelectObject = getSysProcAddr(modgdi32, "SelectObject")
|
||||
procBeginPaint = getSysProcAddr(moduser32, "BeginPaint")
|
||||
procEndPaint = getSysProcAddr(moduser32, "EndPaint")
|
||||
procCreateCompatibleBitmap = getSysProcAddr(modgdi32, "CreateCompatibleBitmap")
|
||||
procCreateDIBSection = getSysProcAddr(modgdi32, "CreateDIBSection")
|
||||
procBitBlt = getSysProcAddr(modgdi32, "BitBlt")
|
||||
|
||||
procCreateDIBSection = getSysProcAddr(modgdi32, "CreateDIBSection")
|
||||
procBitBlt = getSysProcAddr(modgdi32, "BitBlt")
|
||||
)
|
||||
|
||||
func GetDC(hwnd uint32) (hdc uint32) {
|
||||
|
@ -102,7 +100,7 @@ func GetObject(hgdiobj uint32, cbBuffer int, object uintptr) (size uint32) {
|
|||
return size
|
||||
}
|
||||
|
||||
func SelectObject(hdc uint32, hgdiobj uint32) (uint32) {
|
||||
func SelectObject(hdc uint32, hgdiobj uint32) uint32 {
|
||||
r0, _, _ := syscall.Syscall(procSelectObject, 2, uintptr(hdc), uintptr(hgdiobj), 0)
|
||||
return uint32(r0)
|
||||
}
|
||||
|
@ -118,17 +116,17 @@ func EndPaint(hwnd uint32, ps *PAINTSTRUCT) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func CreateCompatibleBitmap(hdc uint32, width ,height int) ( hbitmap uint32) {
|
||||
func CreateCompatibleBitmap(hdc uint32, width, height int) (hbitmap uint32) {
|
||||
r0, _, _ := syscall.Syscall(procCreateCompatibleBitmap, 3, uintptr(hdc), uintptr(width), uintptr(height))
|
||||
return uint32(r0)
|
||||
}
|
||||
|
||||
func CreateDIBSection(hdc uint32, pbmi *BITMAPINFO , iUsage uint, ppvBits uintptr, hSection uint32, dwOffset uint32) ( hbitmap uint32) {
|
||||
func CreateDIBSection(hdc uint32, pbmi *BITMAPINFO, iUsage uint, ppvBits uintptr, hSection uint32, dwOffset uint32) (hbitmap uint32) {
|
||||
r0, _, _ := syscall.Syscall6(procCreateDIBSection, 6, uintptr(hdc), uintptr(unsafe.Pointer(pbmi)), uintptr(iUsage), ppvBits, uintptr(hSection), uintptr(dwOffset))
|
||||
return uint32(r0)
|
||||
}
|
||||
|
||||
func BitBlt(hdc uint32, nXDest, nYDest, nWidth, nHeight int, hdcSrc uint32, nXSrc, nYSrc int, dwRop uint32) ( bool) {
|
||||
func BitBlt(hdc uint32, nXDest, nYDest, nWidth, nHeight int, hdcSrc uint32, nXSrc, nYSrc int, dwRop uint32) bool {
|
||||
r0, _, _ := syscall.Syscall9(procBitBlt, 9, uintptr(hdc), uintptr(nXDest), uintptr(nYDest), uintptr(nWidth), uintptr(nHeight), uintptr(hdcSrc), uintptr(nXSrc), uintptr(nYSrc), uintptr(dwRop))
|
||||
return r0 != 0
|
||||
}
|
Loading…
Reference in a new issue