func newWindow(title string, width int, height int, control Control) *window { widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) ctitle := togstr(title) defer freegstr(ctitle) w := &window{ widget: widget, wc: (*C.GtkContainer)(unsafe.Pointer(widget)), bin: (*C.GtkBin)(unsafe.Pointer(widget)), window: (*C.GtkWindow)(unsafe.Pointer(widget)), closing: newEvent(), } C.gtk_window_set_title(w.window, ctitle) g_signal_connect( C.gpointer(unsafe.Pointer(w.window)), "delete-event", C.GCallback(C.windowClosing), C.gpointer(unsafe.Pointer(w))) C.gtk_window_resize(w.window, C.gint(width), C.gint(height)) w.container = newContainer(control) w.container.setParent(&controlParent{w.wc}) // for dialogs; otherwise, they will be modal to all windows, not just this one w.group = C.gtk_window_group_new() C.gtk_window_group_add_window(w.group, w.window) return w }
// WindowNew is a wrapper around gtk_window_new(). func WindowNew(t WindowType) (*Window, error) { c := C.gtk_window_new(C.GtkWindowType(t)) if c == nil { return nil, nilPtrErr } return wrapWindow(wrapObject(unsafe.Pointer(c))), nil }
func NewWindow(tp WindowType) *Window { ret := C.gtk_window_new(C.GtkWindowType(tp)) if ret == nil { return nil } return ToWindow(unsafe.Pointer(ret)) }
func startGui(width, height int, title string, port int) { C.gtk_init(nil, nil) //gtk.Init(nil) window := C.window window = C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) C.gtk_window_set_title(C.to_GtkWindow(window), C.to_gcharptr(C.CString(title))) C.connect_destroy(window) vbox := C.gtk_hbox_new(0, 1) C.webview = C._new_webkit() C.gtk_container_add(C.to_GtkContainer(vbox), C.webview) C.loadUri(C.webview, C.to_gcharptr(C.CString(fmt.Sprintf("http://127.0.0.1:%d", port)))) C.gtk_container_add(C.to_GtkContainer(window), vbox) C.gtk_widget_set_size_request(window, C.gint(width), C.gint(height)) C.gtk_widget_show(vbox) C.gtk_widget_show(window) //Window.ShowAll() C.gtk_widget_show(C.webview) /* This only matters if proxy is stupid! proxy := os.Getenv("HTTP_PROXY") if len(proxy) > 0 { ptr := C.CString(uri) C.proxyshit(ptr) C.free(ptr) } */ C.gtk_main() //gtk.GtkMain() }
func CreateWindow(title string, width int, height int) unsafe.Pointer { Logger.Println("CreateWindow") // Create window. window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) // Default size. C.gtk_window_set_default_size(C.ToGtkWindow(window), C.gint(width), C.gint(height)) // Center. C.gtk_window_set_position(C.ToGtkWindow(window), C.GTK_WIN_POS_CENTER) // Title. csTitle := C.CString(title) defer C.free(unsafe.Pointer(csTitle)) C.gtk_window_set_title(C.ToGtkWindow(window), (*C.gchar)(csTitle)) // TODO: focus // g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL); // CEF requires a container. Embedding browser in a top // level window fails. vbox := C.gtk_vbox_new(0, 0) C.gtk_container_add(C.ToGtkContainer(window), vbox) // Show. C.gtk_widget_show_all(window) return unsafe.Pointer(vbox) }
// Create new window func NewWindow(wtype GtkWindowType, properties map[string]interface{}) (w *Window) { w = &Window{} o := C.gtk_window_new(C.GtkWindowType(wtype)) w.Container = NewContainer(unsafe.Pointer(o)) w.object = C.to_GtkWindow(unsafe.Pointer(o)) return w }
func (window *GTKWindow) Create(width uint, height uint, title string) bool { C.gtk_init(nil, nil) gtk_window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) C.gtk_window_set_title((*C.GtkWindow)(unsafe.Pointer(gtk_window)), (*C.gchar)(C.CString(title))) f := func() { window.destroy = true } r := func() { window.render = true } //g_signal_connect (G_OBJECT (canvas), "expose-event", G_CALLBACK (expose_cb), NULL); C.GtkSetEvent((*C.gpointer)(unsafe.Pointer(gtk_window)), C.CString("destroy"), unsafe.Pointer(&f)) C.GtkSetEvent((*C.gpointer)(unsafe.Pointer(gtk_window)), C.CString("expose-event"), unsafe.Pointer(&r)) C.gtk_widget_show(gtk_window) return true }
func Window(t GtkWindowType) *GtkWindow { return &GtkWindow{GtkWidget{ C.gtk_window_new(C.GtkWindowType(t))}} }
func gtk_window_new() *C.GtkWidget { return C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) }
func FromLua(code string) map[string]unsafe.Pointer { lua := lgo.NewLua() bindings := make(map[string]unsafe.Pointer) processActorArgs := func(actor *C.ClutterActor, args map[interface{}]interface{}) unsafe.Pointer { pointer := unsafe.Pointer(actor) var minFilter, magFilter *C.ClutterScalingFilter var scaleX C.gdouble = 1.0 var scaleY C.gdouble = 1.0 var translationX, translationY, translationZ C.gfloat for k, v := range args { switch key := k.(type) { case string: switch key { case "id": bindings[v.(string)] = pointer case "bgcolor", "background_color": C.clutter_actor_set_background_color(actor, NewColorFromString(v.(string))) case "clip_rect": clip := (*C.ClutterRect)(v.(unsafe.Pointer)) C.clutter_actor_set_clip(actor, C.gfloat(clip.origin.x), C.gfloat(clip.origin.y), C.gfloat(clip.size.width), C.gfloat(clip.size.height)) case "content": C.clutter_actor_set_content(actor, (*C.ClutterContent)(v.(unsafe.Pointer))) case "content_gravity": switch v.(string) { case "top-left": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP_LEFT) case "top": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP) case "top-right": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP_RIGHT) case "left": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_LEFT) case "center": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_CENTER) case "right": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RIGHT) case "bottom-left": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM_LEFT) case "bottom": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM) case "bottom-right": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM_RIGHT) case "resize-fill": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RESIZE_FILL) case "resize-aspect": C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT) default: log.Fatalf("unknown content gravity: %s", v.(string)) } case "content_repeat": switch v.(string) { case "none": C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_NONE) case "x", "x-axis": C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_X_AXIS) case "y", "y-axis": C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_Y_AXIS) case "both": C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_BOTH) default: log.Fatalf("unknown content repeat: %s", v.(string)) } case "x", "fixed_x": C.clutter_actor_set_x(actor, C.gfloat(v.(float64))) case "y", "fixed_y": C.clutter_actor_set_y(actor, C.gfloat(v.(float64))) case "height": C.clutter_actor_set_height(actor, C.gfloat(v.(float64))) case "layout", "layout_manager": C.clutter_actor_set_layout_manager(actor, (*C.ClutterLayoutManager)(v.(unsafe.Pointer))) case "mag_filter", "magnification_filter": magFilter = (*C.ClutterScalingFilter)(v.(unsafe.Pointer)) C.clutter_actor_set_content_scaling_filters(actor, *minFilter, *magFilter) case "margin_bottom": C.clutter_actor_set_margin_bottom(actor, C.gfloat(v.(float64))) case "margin_left": C.clutter_actor_set_margin_left(actor, C.gfloat(v.(float64))) case "margin_right": C.clutter_actor_set_margin_right(actor, C.gfloat(v.(float64))) case "margin_top": C.clutter_actor_set_margin_top(actor, C.gfloat(v.(float64))) //TODO min height //TODO min width case "min_filter", "minification_filter": minFilter = (*C.ClutterScalingFilter)(v.(unsafe.Pointer)) C.clutter_actor_set_content_scaling_filters(actor, *minFilter, *magFilter) case "name": C.clutter_actor_set_name(actor, toGStr(v.(string))) //TODO natural height //TODO natural width case "offscreen_redirect": switch v.(string) { case "auto", "automatic-for-opacity": C.clutter_actor_set_offscreen_redirect(actor, C.CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY) case "always": C.clutter_actor_set_offscreen_redirect(actor, C.CLUTTER_OFFSCREEN_REDIRECT_ALWAYS) default: log.Fatalf("unknown offscreen redirect option: %s", v.(string)) } case "opacity": C.clutter_actor_set_opacity(actor, C.guint8(uint8(v.(float64)))) case "pivot_point": point := (*C.ClutterPoint)(v.(unsafe.Pointer)) C.clutter_actor_set_pivot_point(actor, C.gfloat(point.x), C.gfloat(point.y)) case "pivot_point_z": C.clutter_actor_set_pivot_point_z(actor, C.gfloat(v.(float64))) case "position": point := (*C.ClutterPoint)(v.(unsafe.Pointer)) C.clutter_actor_set_position(actor, C.gfloat(point.x), C.gfloat(point.y)) case "reactive": b := C.FALSE if v.(bool) { b = C.TRUE } C.clutter_actor_set_reactive(actor, C.gboolean(b)) case "request_mode": switch v.(string) { case "height", "height_for_width": C.clutter_actor_set_request_mode(actor, C.CLUTTER_REQUEST_HEIGHT_FOR_WIDTH) case "width", "width_for_height": C.clutter_actor_set_request_mode(actor, C.CLUTTER_REQUEST_WIDTH_FOR_HEIGHT) default: log.Fatalf("unknown request mode: %s", v.(string)) } case "rotation_angle_x": C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_X_AXIS, C.gdouble(v.(float64))) case "rotation_angle_y": C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_Y_AXIS, C.gdouble(v.(float64))) case "rotation_angle_z": C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_Z_AXIS, C.gdouble(v.(float64))) case "scale_x": scaleX = C.gdouble(v.(float64)) C.clutter_actor_set_scale(actor, scaleX, scaleY) case "scale_y": scaleY = C.gdouble(v.(float64)) C.clutter_actor_set_scale(actor, scaleX, scaleY) case "scale_z": C.clutter_actor_set_scale_z(actor, C.gdouble(v.(float64))) case "size": size := (*C.ClutterSize)(v.(unsafe.Pointer)) C.clutter_actor_set_size(actor, C.gfloat(size.width), C.gfloat(size.height)) case "text_direction", "text_dir": switch v.(string) { case "default": C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_DEFAULT) case "left", "left-to-right", "ltr": C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_LTR) case "right", "right-to-left", "rtl": C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_RTL) default: log.Fatalf("unknown text direction: %s", v.(string)) } //TODO transform case "translation_x": translationX = C.gfloat(v.(float64)) C.clutter_actor_set_translation(actor, translationX, translationY, translationZ) case "translation_y": translationY = C.gfloat(v.(float64)) C.clutter_actor_set_translation(actor, translationX, translationY, translationZ) case "translation_z": translationZ = C.gfloat(v.(float64)) C.clutter_actor_set_translation(actor, translationX, translationY, translationZ) case "visible": if v.(bool) { C.clutter_actor_show(actor) } else { C.clutter_actor_hide(actor) } case "width": C.clutter_actor_set_width(actor, C.gfloat(v.(float64))) case "x_align": switch v.(string) { case "fill": C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_FILL) case "start": C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_START) case "center": C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_CENTER) case "end": C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_END) default: log.Fatalf("unknown x align: %s", v.(string)) } case "x_expand": b := C.FALSE if v.(bool) { b = C.TRUE } C.clutter_actor_set_x_expand(actor, C.gboolean(b)) case "y_align": switch v.(string) { case "fill": C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_FILL) case "start": C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_START) case "center": C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_CENTER) case "end": C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_END) default: log.Fatalf("unknown y align: %s", v.(string)) } case "y_expand": b := C.FALSE if v.(bool) { b = C.TRUE } C.clutter_actor_set_y_expand(actor, C.gboolean(b)) case "z", "z_position": C.clutter_actor_set_z_position(actor, C.gfloat(v.(float64))) } case float64: switch value := v.(type) { case unsafe.Pointer: //TODO add tests if IsActor(value) { // actor child C.clutter_actor_add_child(actor, (*C.ClutterActor)(value)) } else if IsAction(value) { // action C.clutter_actor_add_action(actor, (*C.ClutterAction)(value)) } else if IsConstraint(value) { // constraint C.clutter_actor_add_constraint(actor, (*C.ClutterConstraint)(value)) } else if IsEffect(value) { // effect C.clutter_actor_add_effect(actor, (*C.ClutterEffect)(value)) } else { log.Fatalf("unknown subelement type") } } } } return pointer } processBoxArgs := func(box *C.ClutterLayoutManager, args map[string]interface{}) { //TODO } lua.RegisterFunctions(map[string]interface{}{ // actors "Actor": func(args map[interface{}]interface{}) unsafe.Pointer { actor := C.clutter_actor_new() return processActorArgs(actor, args) }, "Stage": func(args map[interface{}]interface{}) unsafe.Pointer { window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) embed := C.gtk_clutter_embed_new() C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(window)), embed) actor := C.gtk_clutter_embed_get_stage((*C.GtkClutterEmbed)(unsafe.Pointer(embed))) C.clutter_actor_show(actor) C.gtk_widget_show_all((*C.GtkWidget)(unsafe.Pointer(window))) pointer := processActorArgs(actor, args) stage := (*C.ClutterStage)(unsafe.Pointer(actor)) for k, v := range args { //TODO other properties switch key := k.(type) { case string: switch key { case "title": C.clutter_stage_set_title(stage, toGStr(v.(string))) } } } return pointer }, "Text": func(args map[interface{}]interface{}) unsafe.Pointer { actor := C.clutter_text_new() pointer := processActorArgs(actor, args) text := (*C.ClutterText)(unsafe.Pointer(actor)) for k, v := range args { //TODO other properties switch key := k.(type) { case string: switch key { case "text": C.clutter_text_set_text(text, toGStr(v.(string))) case "use_markup": b := C.FALSE if v.(bool) { b = C.TRUE } C.clutter_text_set_use_markup(text, C.gboolean(b)) case "markup": C.clutter_text_set_markup(text, toGStr(v.(string))) case "color": C.clutter_text_set_color(text, NewColorFromString(v.(string))) } case float64: } } return pointer }, // data structures "Point": func(args []float64) unsafe.Pointer { var point C.ClutterPoint point.x = C.float(args[0]) point.y = C.float(args[1]) return unsafe.Pointer(&point) }, "Size": func(args []float64) unsafe.Pointer { var size C.ClutterSize size.width = C.float(args[0]) size.height = C.float(args[1]) return unsafe.Pointer(&size) }, "Rect": func(args []float64) unsafe.Pointer { var rect C.ClutterRect var point C.ClutterPoint var size C.ClutterSize point.x = C.float(args[0]) point.y = C.float(args[1]) size.width = C.float(args[2]) size.height = C.float(args[3]) rect.origin = point rect.size = size return unsafe.Pointer(&rect) }, // contents "Image": func(args []string) unsafe.Pointer { //TODO set data image := C.clutter_image_new() return unsafe.Pointer(image) }, // layouts "Box": func(args map[string]interface{}) unsafe.Pointer { box := C.clutter_box_layout_new() processBoxArgs(box, args) return unsafe.Pointer(box) }, "HBox": func(args map[string]interface{}) unsafe.Pointer { box := C.clutter_box_layout_new() C.clutter_box_layout_set_orientation((*C.ClutterBoxLayout)(unsafe.Pointer(box)), C.CLUTTER_ORIENTATION_HORIZONTAL) processBoxArgs(box, args) return unsafe.Pointer(box) }, "VBox": func(args map[string]interface{}) unsafe.Pointer { box := C.clutter_box_layout_new() C.clutter_box_layout_set_orientation((*C.ClutterBoxLayout)(unsafe.Pointer(box)), C.CLUTTER_ORIENTATION_VERTICAL) processBoxArgs(box, args) return unsafe.Pointer(box) }, // effects "Blur": func(args map[string]interface{}) unsafe.Pointer { effect := C.clutter_blur_effect_new() return unsafe.Pointer(effect) }, // constraints "Align": func(args map[string]interface{}) unsafe.Pointer { constraint := C.clutter_align_constraint_new(nil, C.CLUTTER_ALIGN_X_AXIS, 0) align := (*C.ClutterAlignConstraint)(unsafe.Pointer(constraint)) for key, v := range args { switch key { case "source": C.clutter_align_constraint_set_source(align, (*C.ClutterActor)(bindings[v.(string)])) case "axis": switch v.(string) { case "x", "X": C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_X_AXIS) case "y", "Y": C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_Y_AXIS) case "both", "BOTH", "Both": C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_BOTH) } case "factor": C.clutter_align_constraint_set_factor(align, C.gfloat(v.(float64))) } } return unsafe.Pointer(constraint) }, }) lua.RunString(code) return bindings }
func main() { // init gtk var argc C.int C.gtk_init(&argc, nil) // root window win := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) connect(win, "destroy", func() { // quit gtk when window is closed C.gtk_main_quit() }) // root grid grid := C.gtk_grid_new() C.gtk_container_add(asContainer(win), grid) // webview container pages := C.gtk_notebook_new() C.gtk_grid_attach(asGrid(grid), pages, 0, 0, 1, 1) C.gtk_widget_set_vexpand(pages, C.gtk_true()) C.gtk_widget_set_hexpand(pages, C.gtk_true()) C.gtk_notebook_set_tab_pos(asNotebook(pages), C.GTK_POS_LEFT) // new view constructor var newView func() *View newView = func() *View { view := NewView() label := C.gtk_label_new(nil) C.gtk_label_set_use_markup(asLabel(label), C.gtk_true()) C.gtk_misc_set_alignment(asMisc(label), 0, 0.5) C.gtk_notebook_append_page(asNotebook(pages), view.Widget, label) // new view is requested connect(view.View, "create", func() *C.GtkWidget { return newView().Widget }) // set tab label to page title connect(view.View, "notify::title", func() { var title string // trim long title for _, r := range fromGStr(C.webkit_web_view_get_title(view.View)) { if len(title) > 32 { break } title += string(r) } C.gtk_label_set_markup(asLabel(label), toGStr(fmt.Sprintf(`<span font="10">%s</span>`, title))) }) return view } // first view view := newView() C.webkit_web_view_load_uri(view.View, toGStr("http://www.bilibili.tv")) // show window and run C.gtk_widget_show_all(win) C.gtk_main() }
func gtk_window_new(t int) GtkWidget { return GtkWidget(C.gtk_window_new(C.int(t))) }
// Returns C pointer func NewWindow(t WindowType) *Window { w := new(Window) w.SetPtr(glib.Pointer(C.gtk_window_new(C.GtkWindowType(t)))) return w }