From 8feaa1c439bbce90c7fb8ce9f63baa650a005a05 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 21 Aug 2014 18:23:51 -0400 Subject: [PATCH] Finished the Area.Repaint() test and fixed found bugs. There's some weird issue left in GTK+ Areas... --- redo/area_unix.go | 3 +- redo/future | 2 -- redo/yz_repaint_test.go | 69 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/redo/area_unix.go b/redo/area_unix.go index c65ca72..781a11b 100644 --- a/redo/area_unix.go +++ b/redo/area_unix.go @@ -75,7 +75,8 @@ func (a *area) Repaint(r image.Rectangle) { if r.Empty() { return } - C.gtk_widget_queue_draw_area(a._widget, C.gint(r.Min.X), C.gint(r.Max.Y), C.gint(r.Dx()), C.gint(r.Dy())) +println(a._widget, C.gint(r.Min.X), C.gint(r.Min.Y), C.gint(r.Dx()), C.gint(r.Dy())) + C.gtk_widget_queue_draw_area(a._widget, C.gint(r.Min.X), C.gint(r.Min.Y), C.gint(r.Dx()), C.gint(r.Dy())) } func (a *area) RepaintAll() { diff --git a/redo/future b/redo/future index b5a997b..db87610 100644 --- a/redo/future +++ b/redo/future @@ -17,9 +17,7 @@ Tab // After Delete(), the effect of accessing the Control of the deleted tab or any of its children is undefned. [TODO reword?] investigate close buttons (especially for LikeTab) Area - Repaint(rect image.Rectangle) keyboard scrolling - GTK+ port: our_area_focus_callback() has something to do with it OpenTextFieldAt() and OpenTextAreaAt() to allow editing of text from within Areas Tree Mac OS X: make sure newScrollView() has the correct parameters for Table and Tree (and that Area has the appropriate ones from both + its own no border) diff --git a/redo/yz_repaint_test.go b/redo/yz_repaint_test.go index 99cc515..254c079 100644 --- a/redo/yz_repaint_test.go +++ b/redo/yz_repaint_test.go @@ -4,6 +4,9 @@ package ui import ( "image" + "image/color" + "image/draw" + "strconv" ) type repainter struct { @@ -16,6 +19,11 @@ type repainter struct { repaint Button all Button stack Stack + + xv int + yv int + wv int + hv int } func newRepainter(times int) *repainter { @@ -23,11 +31,17 @@ func newRepainter(times int) *repainter { r.img = tileImage(times) r.area = NewArea(r.img.Rect.Dx(), r.img.Rect.Dy(), r) r.x = NewTextField() + r.x.OnChanged(r.setx) r.y = NewTextField() + r.y.OnChanged(r.sety) r.width = NewTextField() + r.width.OnChanged(r.setwidth) r.height = NewTextField() + r.height.OnChanged(r.setheight) r.repaint = NewButton("Rect") + r.repaint.OnClicked(r.dorect) r.all = NewButton("All") + r.all.OnClicked(r.doall) r.stack = NewHorizontalStack(r.x, r.y, r.width, r.height, r.repaint, r.all) r.stack.SetStretchy(0) r.stack.SetStretchy(1) @@ -44,3 +58,58 @@ func (r *repainter) Paint(rect image.Rectangle) *image.RGBA { func (r *repainter) Mouse(me MouseEvent) {} func (r *repainter) Key(ke KeyEvent) bool { return false } + +func (r *repainter) setx() { + i, err := strconv.Atoi(r.x.Text()) + if err != nil { + r.x.Invalid(err.Error()) + return + } + r.x.Invalid("") + r.xv = i +} + +func (r *repainter) sety() { + i, err := strconv.Atoi(r.y.Text()) + if err != nil { + r.y.Invalid(err.Error()) + return + } + r.y.Invalid("") + r.yv = i +} + +func (r *repainter) setwidth() { + i, err := strconv.Atoi(r.width.Text()) + if err != nil { + r.width.Invalid(err.Error()) + return + } + r.width.Invalid("") + r.wv = i +} + +func (r *repainter) setheight() { + i, err := strconv.Atoi(r.height.Text()) + if err != nil { + r.height.Invalid(err.Error()) + return + } + r.height.Invalid("") + r.hv = i +} + +func (r *repainter) alter(rect image.Rectangle, c color.Color) { + draw.Draw(r.img, rect, &image.Uniform{c}, image.ZP, draw.Over) +} + +func (r *repainter) dorect() { + rect := image.Rect(r.xv, r.yv, r.xv + r.wv, r.yv + r.hv) + r.alter(rect, color.RGBA{255, 0, 255, 128}) + r.area.Repaint(rect) +} + +func (r *repainter) doall() { + r.alter(r.img.Rect, color.RGBA{255, 255, 0, 128}) + r.area.RepaintAll() +}