Merge branch 'sbinet-github-imports'

This commit is contained in:
Laurent Le Goff 2015-04-17 11:17:23 +02:00
commit 3d2a09c9e2
43 changed files with 941 additions and 921 deletions

View File

@ -1,7 +1,7 @@
#include $(GOROOT)/src/Make.inc
all: install
all: install test
install:
cd draw2d && go install
@ -15,6 +15,16 @@ build:
cd postscript && go build
# cd wingui && make build
test:
#cd cmd && go build draw2dgl.go
cd cmd && go build gettingStarted.go
cd cmd && go build testandroid.go
cd cmd && go build testdraw2d.go
cd cmd && go build testgopher.go
cd cmd && go build testimage.go
cd cmd && go build testpostscript.go
#cd cmd && go build testX11draw.go
clean:
cd draw2d && go clean
# cd draw2dgl && make clean

8
README
View File

@ -11,14 +11,14 @@ Some algorithm have been translated from http://www.antigrain.com project ([http
Once you have Go installed, to install draw2d:
* First see the installation procedure of [http://code.google.com/p/freetype-go/ freetype-go]
* goinstall draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d
* `go get github.com/llgcode/draw2d/draw2d`
a good starting point is the [http://code.google.com/p/draw2d/wiki/GettingStarted getting started]
a good starting point is the [http://github.com/llgcode/draw2d/wiki/GettingStarted getting started]
=== [http://code.google.com/p/draw2d/wiki/Samples Samples] ===
=== [http://github.com/llgcode/draw2d/wiki/Samples Samples] ===
Sample images generated by draw2d (inspired by [http://cairographics.org/samples/ cairo samples]):
there's already some bugs please refer to [http://code.google.com/p/draw2d/issues/list issue tracking]
there's already some bugs please refer to [http://github.com/llgcode/draw2d/issues issue tracking]
[http://draw2d.googlecode.com/svn/wiki/test_results/TestPath.png]
[http://draw2d.googlecode.com/svn/wiki/test_results/TestDrawArc.png]

View File

@ -18,8 +18,6 @@
package main
import (
"code.google.com/p/draw2d/draw2dgl"
"code.google.com/p/draw2d/postscript"
"gl"
"glut"
"io/ioutil"
@ -28,6 +26,9 @@ import (
"os"
"strings"
"time"
"github.com/llgcode/draw2d/draw2dgl"
"github.com/llgcode/draw2d/postscript"
)
var postscriptContent string

View File

@ -6,12 +6,12 @@ package main
import (
"bufio"
"fmt"
"image"
"image/png"
"log"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/png"
"github.com/llgcode/draw2d/draw2d"
)
func saveToPngFile(filePath string, m image.Image) {

View File

@ -1,12 +1,13 @@
package main
import (
"code.google.com/p/draw2d/draw2d"
"exp/gui"
"exp/gui/x11"
"fmt"
"image"
"math"
"github.com/llgcode/draw2d/draw2d"
)
func main() {

View File

@ -3,14 +3,14 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/color"
"image/png"
"log"
"math"
"os"
"github.com/llgcode/draw2d/draw2d"
)
const (

View File

@ -6,14 +6,14 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/color"
"image/png"
"log"
"math"
"os"
"github.com/llgcode/draw2d/draw2d"
)
const (

View File

@ -3,14 +3,14 @@ package main
import (
"bufio"
"fmt"
"image"
"image/color"
"image/png"
"log"
"math"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/color"
"image/png"
"github.com/llgcode/draw2d/draw2d"
)
const (

View File

@ -2,7 +2,6 @@ package main
import (
"bufio"
"code.google.com/p/draw2d/draw2d"
"fmt"
"image"
"image/draw"
@ -10,6 +9,8 @@ import (
"log"
"math"
"os"
"github.com/llgcode/draw2d/draw2d"
)
func saveToPngFile(filePath string, m image.Image) {

View File

@ -2,8 +2,6 @@ package main
import (
"bufio"
"code.google.com/p/draw2d/draw2d"
"code.google.com/p/draw2d/postscript"
"fmt"
"image"
"image/png"
@ -11,6 +9,9 @@ import (
"log"
"os"
"strings"
"github.com/llgcode/draw2d/draw2d"
"github.com/llgcode/draw2d/postscript"
)
func saveToPngFile(filePath string, m image.Image) {

View File

@ -4,8 +4,9 @@
package draw2d
import (
"code.google.com/p/freetype-go/freetype/raster"
"math"
"code.google.com/p/freetype-go/freetype/raster"
)
func arc(t VertexConverter, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64) {

View File

@ -1,6 +1,6 @@
package main
import "code.google.com/p/draw2d/draw2d/curve"
import "github.com/llgcode/draw2d/draw2d/curve"
import "testing"
import __os__ "os"
import __regexp__ "regexp"

View File

@ -24,7 +24,7 @@ func SegmentArc(t LineTracer, x, y, rx, ry, start, angle, scale float64) {
if (angle < end-da/4) != clockWise {
curX = x + math.Cos(end)*rx
curY = y + math.Sin(end)*ry
break;
break
}
curX = x + math.Cos(angle)*rx
curY = y + math.Sin(angle)*ry

View File

@ -2,7 +2,6 @@ package curve
import (
"bufio"
"code.google.com/p/draw2d/draw2d/raster"
"fmt"
"image"
"image/color"
@ -11,6 +10,8 @@ import (
"log"
"os"
"testing"
"github.com/llgcode/draw2d/draw2d/raster"
)
var (

View File

@ -4,10 +4,11 @@
package draw2d
import (
"code.google.com/p/freetype-go/freetype/truetype"
"io/ioutil"
"log"
"path"
"code.google.com/p/freetype-go/freetype/truetype"
)
var (

View File

@ -4,14 +4,15 @@
package draw2d
import (
"code.google.com/p/freetype-go/freetype/raster"
"code.google.com/p/freetype-go/freetype/truetype"
"errors"
"image"
"image/color"
"image/draw"
"log"
"math"
"code.google.com/p/freetype-go/freetype/raster"
"code.google.com/p/freetype-go/freetype/truetype"
)
type Painter interface {

View File

@ -2,14 +2,15 @@ package raster
import (
"bufio"
"code.google.com/p/draw2d/draw2d/curve"
"code.google.com/p/freetype-go/freetype/raster"
"image"
"image/color"
"image/png"
"log"
"os"
"testing"
"code.google.com/p/freetype-go/freetype/raster"
"github.com/llgcode/draw2d/draw2d/curve"
)
var flattening_threshold float64 = 0.5

View File

@ -4,9 +4,10 @@
package draw2d
import (
"code.google.com/p/freetype-go/freetype/truetype"
"image"
"image/color"
"code.google.com/p/freetype-go/freetype/truetype"
)
type StackGraphicContext struct {

View File

@ -4,8 +4,9 @@
package draw2d
import (
"code.google.com/p/freetype-go/freetype/raster"
"math"
"code.google.com/p/freetype-go/freetype/raster"
)
type MatrixTransform [6]float64

View File

@ -1,12 +1,13 @@
package draw2dgl
import (
"code.google.com/p/draw2d/draw2d"
"code.google.com/p/freetype-go/freetype/raster"
"gl"
"image"
"image/color"
"image/draw"
"code.google.com/p/freetype-go/freetype/raster"
"github.com/llgcode/draw2d/draw2d"
//"log"
)

View File

@ -3,14 +3,14 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/draw"
"image/png"
"log"
"math"
"os"
"github.com/llgcode/draw2d/draw2d"
)
func saveToPngFile(filePath string, m image.Image) {
@ -36,7 +36,7 @@ func saveToPngFile(filePath string, m image.Image) {
func main() {
file, err := os.Open("android.png")
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
defer file.Close()
a, _, err := image.Decode(file)
@ -44,13 +44,13 @@ func main() {
//load go icon image
file2, err := os.Open("go.png")
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
defer file2.Close()
g, _, err := image.Decode(file2)
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
ar := a.Bounds()
@ -58,7 +58,7 @@ func main() {
i := image.NewRGBA(image.Rect(0, 0, w, h))
draw.Draw(i, ar, a, ar.Min, draw.Src)
tr := draw2d.NewRotationMatrix(x*(math.Pi / 180.0))
tr := draw2d.NewRotationMatrix(x * (math.Pi / 180.0))
draw2d.DrawImage(g, i, tr, draw.Over, draw2d.LinearFilter)
saveToPngFile("Test2.png", i)
}

View File

@ -4,11 +4,12 @@
package postscript
import (
"code.google.com/p/draw2d/draw2d"
"io"
"log"
"os"
"strconv"
"github.com/llgcode/draw2d/draw2d"
)
type Interpreter struct {
@ -44,7 +45,7 @@ func NewDictionary(prealloc int) Dictionary {
return make(Dictionary, prealloc)
}
func (interpreter *Interpreter) SetGraphicContext(gc draw2d.GraphicContext) {
func (interpreter *Interpreter) SetGraphicContext(gc draw2d.GraphicContext) {
interpreter.gc = gc
}

View File

@ -3,8 +3,6 @@
package postscript
import ()
//int array array -> Create array of length int
func array(interpreter *Interpreter) {
interpreter.Push(make([]Value, interpreter.PopInt()))

View File

@ -5,10 +5,11 @@
package postscript
import (
"code.google.com/p/draw2d/draw2d"
"image/color"
"log"
"math"
"github.com/llgcode/draw2d/draw2d"
)
//Path Construction Operators
@ -198,7 +199,7 @@ func setcmybcolor(interpreter *Interpreter) {
}
func setdash(interpreter *Interpreter) {
interpreter.PopInt() // offset
interpreter.PopInt() // offset
interpreter.PopArray() // dash
//log.Printf("setdash not yet implemented dash: %v, offset: %d \n", dash, offset)
}

View File

@ -4,10 +4,6 @@
// Miscellaneous Operators
package postscript
import (
//"log"
)
//proc bind proc Replace operator names in proc with operators; perform idiom recognition
func bind(interpreter *Interpreter) {
pdef := interpreter.PopProcedureDefinition()

View File

@ -7,109 +7,109 @@
package wingui
import (
"syscall"
"unsafe"
"syscall"
"unsafe"
)
type Wndclassex struct {
Size uint32
Style uint32
WndProc uintptr
ClsExtra int32
WndExtra int32
Instance syscall.Handle
Icon syscall.Handle
Cursor syscall.Handle
Background syscall.Handle
MenuName *uint16
ClassName *uint16
IconSm syscall.Handle
Size uint32
Style uint32
WndProc uintptr
ClsExtra int32
WndExtra int32
Instance syscall.Handle
Icon syscall.Handle
Cursor syscall.Handle
Background syscall.Handle
MenuName *uint16
ClassName *uint16
IconSm syscall.Handle
}
type Point struct {
X uintptr
Y uintptr
X uintptr
Y uintptr
}
type Msg struct {
Hwnd syscall.Handle
Message uint32
Wparam uintptr
Lparam uintptr
Time uint32
Pt Point
Hwnd syscall.Handle
Message uint32
Wparam uintptr
Lparam uintptr
Time uint32
Pt Point
}
const (
// Window styles
WS_OVERLAPPED = 0
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_MINIMIZE = 0x20000000
WS_VISIBLE = 0x10000000
WS_DISABLED = 0x8000000
WS_CLIPSIBLINGS = 0x4000000
WS_CLIPCHILDREN = 0x2000000
WS_MAXIMIZE = 0x1000000
WS_CAPTION = WS_BORDER | WS_DLGFRAME
WS_BORDER = 0x800000
WS_DLGFRAME = 0x400000
WS_VSCROLL = 0x200000
WS_HSCROLL = 0x100000
WS_SYSMENU = 0x80000
WS_THICKFRAME = 0x40000
WS_GROUP = 0x20000
WS_TABSTOP = 0x10000
WS_MINIMIZEBOX = 0x20000
WS_MAXIMIZEBOX = 0x10000
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
// Common Window Styles
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
// Window styles
WS_OVERLAPPED = 0
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_MINIMIZE = 0x20000000
WS_VISIBLE = 0x10000000
WS_DISABLED = 0x8000000
WS_CLIPSIBLINGS = 0x4000000
WS_CLIPCHILDREN = 0x2000000
WS_MAXIMIZE = 0x1000000
WS_CAPTION = WS_BORDER | WS_DLGFRAME
WS_BORDER = 0x800000
WS_DLGFRAME = 0x400000
WS_VSCROLL = 0x200000
WS_HSCROLL = 0x100000
WS_SYSMENU = 0x80000
WS_THICKFRAME = 0x40000
WS_GROUP = 0x20000
WS_TABSTOP = 0x10000
WS_MINIMIZEBOX = 0x20000
WS_MAXIMIZEBOX = 0x10000
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
// Common Window Styles
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
WS_EX_CLIENTEDGE = 0x200
WS_EX_CLIENTEDGE = 0x200
// Some windows messages
WM_CREATE = 1
WM_DESTROY = 2
WM_CLOSE = 16
WM_COMMAND = 273
// Some windows messages
WM_CREATE = 1
WM_DESTROY = 2
WM_CLOSE = 16
WM_COMMAND = 273
// Some button control styles
BS_DEFPUSHBUTTON = 1
// Some button control styles
BS_DEFPUSHBUTTON = 1
// Some color constants
COLOR_WINDOW = 5
COLOR_BTNFACE = 15
// Some color constants
COLOR_WINDOW = 5
COLOR_BTNFACE = 15
// Default window position
CW_USEDEFAULT = 0x80000000 - 0x100000000
// Default window position
CW_USEDEFAULT = 0x80000000 - 0x100000000
// Show window default style
SW_SHOWDEFAULT = 10
// Show window default style
SW_SHOWDEFAULT = 10
)
var (
// Some globally known cursors
IDC_ARROW = MakeIntResource(32512)
IDC_IBEAM = MakeIntResource(32513)
IDC_WAIT = MakeIntResource(32514)
IDC_CROSS = MakeIntResource(32515)
// Some globally known cursors
IDC_ARROW = MakeIntResource(32512)
IDC_IBEAM = MakeIntResource(32513)
IDC_WAIT = MakeIntResource(32514)
IDC_CROSS = MakeIntResource(32515)
// Some globally known icons
IDI_APPLICATION = MakeIntResource(32512)
IDI_HAND = MakeIntResource(32513)
IDI_QUESTION = MakeIntResource(32514)
IDI_EXCLAMATION = MakeIntResource(32515)
IDI_ASTERISK = MakeIntResource(32516)
IDI_WINLOGO = MakeIntResource(32517)
IDI_WARNING = IDI_EXCLAMATION
IDI_ERROR = IDI_HAND
IDI_INFORMATION = IDI_ASTERISK
// Some globally known icons
IDI_APPLICATION = MakeIntResource(32512)
IDI_HAND = MakeIntResource(32513)
IDI_QUESTION = MakeIntResource(32514)
IDI_EXCLAMATION = MakeIntResource(32515)
IDI_ASTERISK = MakeIntResource(32516)
IDI_WINLOGO = MakeIntResource(32517)
IDI_WARNING = IDI_EXCLAMATION
IDI_ERROR = IDI_HAND
IDI_INFORMATION = IDI_ASTERISK
)
//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) = GetModuleHandleW
@ -130,5 +130,5 @@ var (
//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) = user32.PostMessageW
func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id)))
return (*uint16)(unsafe.Pointer(uintptr(id)))
}

View File

@ -8,27 +8,27 @@ import (
const (
WM_PAINT = 15
BI_RGB = 0
BI_RGB = 0
BI_BITFIELDS = 3
DIB_PAL_COLORS = 1
DIB_RGB_COLORS = 0
BLACKNESS = 0x42
DSTINVERT = 0x550009
MERGECOPY = 0xC000CA
MERGEPAINT = 0xBB0226
NOTSRCCOPY = 0x330008
BLACKNESS = 0x42
DSTINVERT = 0x550009
MERGECOPY = 0xC000CA
MERGEPAINT = 0xBB0226
NOTSRCCOPY = 0x330008
NOTSRCERASE = 0x1100A6
PATCOPY = 0xF00021
PATINVERT = 0x5A0049
PATPAINT = 0xFB0A09
SRCAND = 0x8800C6
SRCCOPY = 0xCC0020
SRCERASE = 0x440328
SRCINVERT = 0x660046
SRCPAINT = 0xEE0086
WHITENESS = 0xFF0062
PATCOPY = 0xF00021
PATINVERT = 0x5A0049
PATPAINT = 0xFB0A09
SRCAND = 0x8800C6
SRCCOPY = 0xCC0020
SRCERASE = 0x440328
SRCINVERT = 0x660046
SRCPAINT = 0xEE0086
WHITENESS = 0xFF0062
)
type RECT struct {
@ -120,7 +120,7 @@ func SelectObject(hdc syscall.Handle, hgdiobj syscall.Handle) syscall.Handle {
return syscall.Handle(r0)
}
func BeginPaint(hwnd syscall.Handle, ps *PAINTSTRUCT) (hdc syscall.Handle){
func BeginPaint(hwnd syscall.Handle, ps *PAINTSTRUCT) (hdc syscall.Handle) {
r0, _, _ := syscall.Syscall(procBeginPaint.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(ps)), 0)
hdc = syscall.Handle(r0)
return

View File

@ -1,151 +1,152 @@
package main
import (
"fmt"
"os"
"syscall"
"unsafe"
. "code.google.com/p/draw2d/wingui"
"fmt"
"os"
"syscall"
"unsafe"
. "github.com/llgcode/draw2d/wingui"
)
// some help functions
func abortf(format string, a ...interface{}) {
fmt.Fprintf(os.Stdout, format, a...)
os.Exit(1)
fmt.Fprintf(os.Stdout, format, a...)
os.Exit(1)
}
func abortErrNo(funcname string, err error) {
errno, _ := err.(syscall.Errno)
abortf("%s failed: %d %s\n", funcname, uint32(errno), err)
errno, _ := err.(syscall.Errno)
abortf("%s failed: %d %s\n", funcname, uint32(errno), err)
}
// global vars
var (
mh syscall.Handle
bh syscall.Handle
mh syscall.Handle
bh syscall.Handle
)
// WinProc called by windows to notify us of all windows events we might be interested in.
func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
_ = make([]int, 100000)
switch msg {
case WM_CREATE:
var e error
// CreateWindowEx
bh, e = CreateWindowEx(
0,
syscall.StringToUTF16Ptr("button"),
syscall.StringToUTF16Ptr("Quit"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
75, 70, 140, 25,
hwnd, 1, mh, 0)
if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("button handle is %x\n", bh)
rc = DefWindowProc(hwnd, msg, wparam, lparam)
case WM_COMMAND:
switch syscall.Handle(lparam) {
case bh:
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
if e != nil {
abortErrNo("PostMessage", e)
}
default:
rc = DefWindowProc(hwnd, msg, wparam, lparam)
}
case WM_CLOSE:
DestroyWindow(hwnd)
case WM_DESTROY:
PostQuitMessage(0)
default:
rc = DefWindowProc(hwnd, msg, wparam, lparam)
}
//fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc)
return
_ = make([]int, 100000)
switch msg {
case WM_CREATE:
var e error
// CreateWindowEx
bh, e = CreateWindowEx(
0,
syscall.StringToUTF16Ptr("button"),
syscall.StringToUTF16Ptr("Quit"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
75, 70, 140, 25,
hwnd, 1, mh, 0)
if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("button handle is %x\n", bh)
rc = DefWindowProc(hwnd, msg, wparam, lparam)
case WM_COMMAND:
switch syscall.Handle(lparam) {
case bh:
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
if e != nil {
abortErrNo("PostMessage", e)
}
default:
rc = DefWindowProc(hwnd, msg, wparam, lparam)
}
case WM_CLOSE:
DestroyWindow(hwnd)
case WM_DESTROY:
PostQuitMessage(0)
default:
rc = DefWindowProc(hwnd, msg, wparam, lparam)
}
//fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc)
return
}
func rungui() int {
var e error
var e error
// GetModuleHandle
mh, e = GetModuleHandle(nil)
if e != nil {
abortErrNo("GetModuleHandle", e)
}
// GetModuleHandle
mh, e = GetModuleHandle(nil)
if e != nil {
abortErrNo("GetModuleHandle", e)
}
// Get icon we're going to use.
myicon, e := LoadIcon(0, IDI_APPLICATION)
if e != nil {
abortErrNo("LoadIcon", e)
}
// Get icon we're going to use.
myicon, e := LoadIcon(0, IDI_APPLICATION)
if e != nil {
abortErrNo("LoadIcon", e)
}
// Get cursor we're going to use.
mycursor, e := LoadCursor(0, IDC_ARROW)
if e != nil {
abortErrNo("LoadCursor", e)
}
// Get cursor we're going to use.
mycursor, e := LoadCursor(0, IDC_ARROW)
if e != nil {
abortErrNo("LoadCursor", e)
}
// Create callback
wproc := syscall.NewCallback(WndProc)
// Create callback
wproc := syscall.NewCallback(WndProc)
// RegisterClassEx
wcname := syscall.StringToUTF16Ptr("myWindowClass")
var wc Wndclassex
wc.Size = uint32(unsafe.Sizeof(wc))
wc.WndProc = wproc
wc.Instance = mh
wc.Icon = myicon
wc.Cursor = mycursor
wc.Background = COLOR_BTNFACE + 1
wc.MenuName = nil
wc.ClassName = wcname
wc.IconSm = myicon
if _, e := RegisterClassEx(&wc); e != nil {
abortErrNo("RegisterClassEx", e)
}
// RegisterClassEx
wcname := syscall.StringToUTF16Ptr("myWindowClass")
var wc Wndclassex
wc.Size = uint32(unsafe.Sizeof(wc))
wc.WndProc = wproc
wc.Instance = mh
wc.Icon = myicon
wc.Cursor = mycursor
wc.Background = COLOR_BTNFACE + 1
wc.MenuName = nil
wc.ClassName = wcname
wc.IconSm = myicon
if _, e := RegisterClassEx(&wc); e != nil {
abortErrNo("RegisterClassEx", e)
}
// CreateWindowEx
wh, e := CreateWindowEx(
WS_EX_CLIENTEDGE,
wcname,
syscall.StringToUTF16Ptr("My window"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
0, 0, mh, 0)
if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("main window handle is %x\n", wh)
// CreateWindowEx
wh, e := CreateWindowEx(
WS_EX_CLIENTEDGE,
wcname,
syscall.StringToUTF16Ptr("My window"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
0, 0, mh, 0)
if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("main window handle is %x\n", wh)
// ShowWindow
ShowWindow(wh, SW_SHOWDEFAULT)
// ShowWindow
ShowWindow(wh, SW_SHOWDEFAULT)
// UpdateWindow
if e := UpdateWindow(wh); e != nil {
abortErrNo("UpdateWindow", e)
}
// UpdateWindow
if e := UpdateWindow(wh); e != nil {
abortErrNo("UpdateWindow", e)
}
// Process all windows messages until WM_QUIT.
var m Msg
for {
r, e := GetMessage(&m, 0, 0, 0)
if e != nil {
abortErrNo("GetMessage", e)
}
if r == 0 {
// WM_QUIT received -> get out
break
}
TranslateMessage(&m)
DispatchMessage(&m)
}
return int(m.Wparam)
// Process all windows messages until WM_QUIT.
var m Msg
for {
r, e := GetMessage(&m, 0, 0, 0)
if e != nil {
abortErrNo("GetMessage", e)
}
if r == 0 {
// WM_QUIT received -> get out
break
}
TranslateMessage(&m)
DispatchMessage(&m)
}
return int(m.Wparam)
}
func main() {
rc := rungui()
os.Exit(rc)
rc := rungui()
os.Exit(rc)
}

View File

@ -5,18 +5,19 @@
package main
import (
"code.google.com/p/draw2d/draw2d"
"code.google.com/p/draw2d/wingui"
"code.google.com/p/draw2d/postscript"
"fmt"
"image"
"io/ioutil"
"image/color"
"strings"
"io/ioutil"
"os"
"strings"
"syscall"
"time"
"unsafe"
"github.com/llgcode/draw2d/draw2d"
"github.com/llgcode/draw2d/postscript"
"github.com/llgcode/draw2d/wingui"
)
// some help functions
@ -56,7 +57,7 @@ func TestDrawCubicCurve(gc draw2d.GraphicContext) {
gc.Stroke()
}
func DrawTiger(gc draw2d.GraphicContext){
func DrawTiger(gc draw2d.GraphicContext) {
if postscriptContent == "" {
src, err := os.OpenFile("../../resource/postscript/tiger.ps", 0, 0)
if err != nil {
@ -73,12 +74,12 @@ func DrawTiger(gc draw2d.GraphicContext){
}
var (
mh syscall.Handle
hdcWndBuffer syscall.Handle
wndBufferHeader syscall.Handle
mh syscall.Handle
hdcWndBuffer syscall.Handle
wndBufferHeader syscall.Handle
wndBuffer wingui.BITMAP
ppvBits *uint8
backBuffer *image.RGBA
ppvBits *uint8
backBuffer *image.RGBA
postscriptContent string
)
@ -119,7 +120,7 @@ func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintpt
pixel := (*[600 * 800 * 4]uint8)(unsafe.Pointer(ppvBits))
pixelSlice := pixel[:]
backBuffer = &image.RGBA{pixelSlice, 4*600, image.Rect(0, 0, 600, 800)}
backBuffer = &image.RGBA{pixelSlice, 4 * 600, image.Rect(0, 0, 600, 800)}
fmt.Println("Create windows")
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
case wingui.WM_COMMAND:
@ -134,7 +135,7 @@ func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintpt
gc := draw2d.NewGraphicContext(backBuffer)
/*gc.SetFillColor(color.RGBA{0xFF, 0xFF, 0xFF, 0xFF})
gc.Clear()*/
for i := 0; i < len(backBuffer.Pix); i+=1 {
for i := 0; i < len(backBuffer.Pix); i += 1 {
backBuffer.Pix[i] = 0xff
}
gc.Save()
@ -143,7 +144,7 @@ func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintpt
gc.Restore()
// back buf in
var tmp uint8
for i := 0; i < len(backBuffer.Pix); i+=4 {
for i := 0; i < len(backBuffer.Pix); i += 4 {
tmp = backBuffer.Pix[i]
backBuffer.Pix[i] = backBuffer.Pix[i+2]
backBuffer.Pix[i+2] = tmp

View File

@ -8,185 +8,185 @@ import "unsafe"
import "syscall"
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
moduser32 = syscall.NewLazyDLL("user32.dll")
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
moduser32 = syscall.NewLazyDLL("user32.dll")
procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
procRegisterClassExW = moduser32.NewProc("RegisterClassExW")
procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
procDefWindowProcW = moduser32.NewProc("DefWindowProcW")
procDestroyWindow = moduser32.NewProc("DestroyWindow")
procPostQuitMessage = moduser32.NewProc("PostQuitMessage")
procShowWindow = moduser32.NewProc("ShowWindow")
procUpdateWindow = moduser32.NewProc("UpdateWindow")
procGetMessageW = moduser32.NewProc("GetMessageW")
procTranslateMessage = moduser32.NewProc("TranslateMessage")
procDispatchMessageW = moduser32.NewProc("DispatchMessageW")
procLoadIconW = moduser32.NewProc("LoadIconW")
procLoadCursorW = moduser32.NewProc("LoadCursorW")
procSetCursor = moduser32.NewProc("SetCursor")
procSendMessageW = moduser32.NewProc("SendMessageW")
procPostMessageW = moduser32.NewProc("PostMessageW")
procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
procRegisterClassExW = moduser32.NewProc("RegisterClassExW")
procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
procDefWindowProcW = moduser32.NewProc("DefWindowProcW")
procDestroyWindow = moduser32.NewProc("DestroyWindow")
procPostQuitMessage = moduser32.NewProc("PostQuitMessage")
procShowWindow = moduser32.NewProc("ShowWindow")
procUpdateWindow = moduser32.NewProc("UpdateWindow")
procGetMessageW = moduser32.NewProc("GetMessageW")
procTranslateMessage = moduser32.NewProc("TranslateMessage")
procDispatchMessageW = moduser32.NewProc("DispatchMessageW")
procLoadIconW = moduser32.NewProc("LoadIconW")
procLoadCursorW = moduser32.NewProc("LoadCursorW")
procSetCursor = moduser32.NewProc("SetCursor")
procSendMessageW = moduser32.NewProc("SendMessageW")
procPostMessageW = moduser32.NewProc("PostMessageW")
)
func GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
handle = syscall.Handle(r0)
if handle == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
handle = syscall.Handle(r0)
if handle == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) {
r0, _, e1 := syscall.Syscall(procRegisterClassExW.Addr(), 1, uintptr(unsafe.Pointer(wndclass)), 0, 0)
atom = uint16(r0)
if atom == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall(procRegisterClassExW.Addr(), 1, uintptr(unsafe.Pointer(wndclass)), 0, 0)
atom = uint16(r0)
if atom == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall12(procCreateWindowExW.Addr(), 12, uintptr(exstyle), uintptr(unsafe.Pointer(classname)), uintptr(unsafe.Pointer(windowname)), uintptr(style), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(wndparent), uintptr(menu), uintptr(instance), uintptr(param))
hwnd = syscall.Handle(r0)
if hwnd == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall12(procCreateWindowExW.Addr(), 12, uintptr(exstyle), uintptr(unsafe.Pointer(classname)), uintptr(unsafe.Pointer(windowname)), uintptr(style), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(wndparent), uintptr(menu), uintptr(instance), uintptr(param))
hwnd = syscall.Handle(r0)
if hwnd == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = uintptr(r0)
return
r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = uintptr(r0)
return
}
func DestroyWindow(hwnd syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func PostQuitMessage(exitcode int32) {
syscall.Syscall(procPostQuitMessage.Addr(), 1, uintptr(exitcode), 0, 0)
return
syscall.Syscall(procPostQuitMessage.Addr(), 1, uintptr(exitcode), 0, 0)
return
}
func ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) {
r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0)
wasvisible = bool(r0 != 0)
return
r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0)
wasvisible = bool(r0 != 0)
return
}
func UpdateWindow(hwnd syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
ret = int32(r0)
if ret == -1 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
ret = int32(r0)
if ret == -1 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func TranslateMessage(msg *Msg) (done bool) {
r0, _, _ := syscall.Syscall(procTranslateMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
done = bool(r0 != 0)
return
r0, _, _ := syscall.Syscall(procTranslateMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
done = bool(r0 != 0)
return
}
func DispatchMessage(msg *Msg) (ret int32) {
r0, _, _ := syscall.Syscall(procDispatchMessageW.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
ret = int32(r0)
return
r0, _, _ := syscall.Syscall(procDispatchMessageW.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
ret = int32(r0)
return
}
func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
icon = syscall.Handle(r0)
if icon == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
icon = syscall.Handle(r0)
if icon == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
cursor = syscall.Handle(r0)
if cursor == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
cursor = syscall.Handle(r0)
if cursor == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
precursor = syscall.Handle(r0)
if precursor == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
precursor = syscall.Handle(r0)
if precursor == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = uintptr(r0)
return
r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = uintptr(r0)
return
}
func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) {
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}