Just some atom-beautify to make code look better

This commit is contained in:
Thomas Buckley-Houston 2016-05-21 14:47:02 +09:00
parent 8c7071f8e0
commit 09168fc8ea
4 changed files with 109 additions and 103 deletions

View file

@ -2,14 +2,14 @@ package main
import (
"fmt"
"strings"
"strconv"
"path/filepath"
"time"
"github.com/tombh/termbox-go"
"math"
"os"
"os/exec"
"math"
"github.com/tombh/termbox-go"
"path/filepath"
"strconv"
"strings"
"time"
)
// Import the xzoom C code that creates an X window that zooms
@ -201,8 +201,8 @@ func zoom(direction string) {
C.magnification--
}
}
C.width[C.SRC] = (C.desktop_width + C.magnification - 1) / C.magnification;
C.height[C.SRC] = (C.desktop_height + C.magnification - 1) / C.magnification;
C.width[C.SRC] = (C.desktop_width + C.magnification - 1) / C.magnification
C.height[C.SRC] = (C.desktop_height + C.magnification - 1) / C.magnification
moveViewportForZoom(oldZoom)
keepViewportInDesktop()
@ -294,7 +294,6 @@ func mouseEvent() {
}
}
func pan() {
if panNeedsSetup {
panStartingX = desktopXFloat
@ -302,7 +301,7 @@ func pan() {
panNeedsSetup = false
}
C.xgrab = C.int(float32(C.xgrab) + panStartingX - desktopXFloat)
C.ygrab = C.int(float32(C.ygrab) + panStartingY - desktopYFloat)
C.ygrab = C.int(float32(C.ygrab) + panStartingY - desktopYFloat)
keepViewportInDesktop()
}
@ -356,11 +355,11 @@ func getSpecialKeyPress() string {
var key string
switch curev.Key {
case termbox.KeyEnter:
key = "Return"
key = "Return"
case termbox.KeyBackspace, termbox.KeyBackspace2:
key = "BackSpace"
key = "BackSpace"
case termbox.KeySpace:
key = "Space"
key = "Space"
case termbox.KeyF1:
key = "F1"
case termbox.KeyF2:
@ -427,23 +426,23 @@ func parseInput() {
}
// Run the xzoom window in a background go routine
func xzoomBackground(){
go func(){
defer close(xZoomStoppedChannel)
for {
select {
default:
C.do_iteration()
time.Sleep(40 * time.Millisecond) // 25fps
case <-stopXZoomChannel:
// Gracefully close the xzoom go routine
return
}
}
func xzoomBackground() {
go func() {
defer close(xZoomStoppedChannel)
for {
select {
default:
C.do_iteration()
time.Sleep(40 * time.Millisecond) // 25fps
case <-stopXZoomChannel:
// Gracefully close the xzoom go routine
return
}
}
}()
}
func teardown(){
func teardown() {
termbox.Close()
close(stopXZoomChannel)
<-xZoomStoppedChannel

View file

@ -10,8 +10,8 @@ import (
)
func TestMouseInput(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Mouse Input Suite")
RegisterFailHandler(Fail)
RunSpecs(t, "Mouse Input Suite")
}
var _ = Describe("Mouse Input", func() {
@ -23,58 +23,58 @@ var _ = Describe("Mouse Input", func() {
setupLogging()
termbox.Init()
setupDimensions()
setCurrentDesktopCoords()
setCurrentDesktopCoords()
})
AfterEach(func(){
termbox.Close()
})
AfterEach(func() {
termbox.Close()
})
Describe("Mouse position", func(){
Describe("Mouse position", func() {
It("Should work in the top left", func() {
curev.MouseX = 30
curev.MouseY = 10
curev.MouseY = 10
setCurrentDesktopCoords()
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
Expect(roundedDesktopY).To(Equal(400))
})
It("Should work in the middle", func() {
curev.MouseX = 45
curev.MouseY = 15
curev.MouseY = 15
setCurrentDesktopCoords()
Expect(roundedDesktopX).To(Equal(800))
Expect(roundedDesktopY).To(Equal(600))
Expect(roundedDesktopY).To(Equal(600))
})
It("Should work in the bottom right", func() {
curev.MouseX = 60
curev.MouseY = 20
curev.MouseY = 20
setCurrentDesktopCoords()
Expect(roundedDesktopX).To(Equal(1067))
Expect(roundedDesktopY).To(Equal(800))
Expect(roundedDesktopY).To(Equal(800))
})
})
Describe("Zooming", func() {
BeforeEach(func(){
curev.MouseX = 30
curev.MouseY = 10
setCurrentDesktopCoords()
})
BeforeEach(func() {
curev.MouseX = 30
curev.MouseY = 10
setCurrentDesktopCoords()
})
It("Should zoom in once", func() {
Expect(getXGrab()).To(Equal(0))
Expect(getYGrab()).To(Equal(0))
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
zoom("in")
setCurrentDesktopCoords()
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
zoom("in")
setCurrentDesktopCoords()
Expect(getXGrab()).To(Equal(266))
Expect(getYGrab()).To(Equal(200))
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
})
It("Should zoom in then out", func() {
zoom("in")
setCurrentDesktopCoords()
zoom("in")
setCurrentDesktopCoords()
zoom("out")
// Shouldn't need to do this a second time, but this test helped me
// figure out a different bug, so I'm leaving it like this for now.
@ -82,18 +82,18 @@ var _ = Describe("Mouse Input", func() {
setCurrentDesktopCoords()
Expect(getXGrab()).To(Equal(0))
Expect(getYGrab()).To(Equal(0))
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
Expect(roundedDesktopX).To(Equal(533))
Expect(roundedDesktopY).To(Equal(400))
})
It("Should zoom near an edge without breaking out", func() {
curev.MouseX = 0
curev.MouseY = 0
setCurrentDesktopCoords()
zoom("in")
curev.MouseY = 0
setCurrentDesktopCoords()
zoom("in")
Expect(getXGrab()).To(Equal(0))
Expect(getYGrab()).To(Equal(0))
Expect(roundedDesktopX).To(Equal(0))
Expect(roundedDesktopY).To(Equal(0))
Expect(roundedDesktopX).To(Equal(0))
Expect(roundedDesktopY).To(Equal(0))
})
})
})

View file

@ -1,50 +1,57 @@
/* scale image from SRC to DST - parameterized by type T */
/* get pixel address of point (x,y) in image t */
#define getP(t,x,y) \
(T *) (&ximage[t]->data[(ximage[t]->xoffset+(x))*sizeof(T) + \
(y)*ximage[t]->bytes_per_line])
#define getP(t, x, y) \
(T *)(&ximage[t]->data[(ximage[t]->xoffset + (x)) * sizeof(T) + \
(y) * ximage[t]->bytes_per_line])
{
int i, j, k;
int i, j, k;
/* copy scaled lines from SRC to DST */
j = height[SRC] - 1;
do {
T *p1;
T *p2;
int p2step;
T *p1_save;
/* copy scaled lines from SRC to DST */
j = height[SRC] - 1;
/* p1 point to begining of scanline j*magnification in DST */
p1 = getP(DST, 0, j * magnification);
p1_save = p1;
/* p2 point to begining of scanline j in SRC */
p2 = getP(SRC, 0, j);
do {
T *p1;
T *p2;
int p2step;
T *p1_save;
i = width[SRC];
do {
T c = *p2++;
k = magnification; do *p1++ = c; while (--k > 0);
} while (--i > 0);
/* p1 point to begining of scanline j*magnification in DST */
p1 = getP(DST, 0, j * magnification);
p1_save = p1;
/* duplicate that line as needed */
if (magnification > 1)
{
/* p1 point to begining of scanline j*magnification in DST */
p1 = p1_save;
/* p2 points to begining of next line */
p2 = p1;
p2step = ximage[DST]->bytes_per_line / sizeof(T);
/* p2 point to begining of scanline j in SRC */
p2 = getP(SRC, 0, j);
i = width[DST] * sizeof(T);
k = magnification - 1;
do {
p2 += p2step;
memcpy(p2, p1, i);
} while (--k > 0);
}
} while (--j >= 0);
i = width[SRC];
do {
T c = *p2++;
k = magnification;
do *p1++ = c; while (--k > 0);
} while (--i > 0);
/* duplicate that line as needed */
if (magnification > 1)
{
/* p1 point to begining of scanline j*magnification in DST */
p1 = p1_save;
/* p2 points to begining of next line */
p2 = p1;
p2step = ximage[DST]->bytes_per_line / sizeof(T);
i = width[DST] * sizeof(T);
k = magnification - 1;
do {
p2 += p2step;
memcpy(p2, p1, i);
} while (--k > 0);
}
} while (--j >= 0);
}
#undef getP

View file

@ -1,7 +1,7 @@
/*
This code largely comes from Itai Nahshon's xzoom, see:
http://git.r-36.net/xzoom
*/
This code largely comes from Itai Nahshon's xzoom, see:
http://git.r-36.net/xzoom
*/
#include <stdio.h>
#include <string.h>
@ -20,7 +20,7 @@ Display *dpy;
Screen *scr;
Window win, root, child;
Status status;
int winX, winY;
int winX, winY;
unsigned int mask;
GC gc;
@ -35,7 +35,7 @@ int desktop_height;
int xgrab = 0;
int ygrab = 0;
int magnification = 1;
int magnification = 1;
int old_magnification = 1;
int width[2];
@ -123,7 +123,7 @@ void recreate_images_on_zoom() {
int xzoom_init() {
XSetWindowAttributes xswa;
XGCValues gcv;
char *dpyname = ":0";
char *dpyname = ":0";
atexit(destroy_images);