Procházet zdrojové kódy

Renamed cgo code to be OS specific.

Steve Thielemann před 2 roky
rodič
revize
2ef2efdc02
4 změnil soubory, kde provedl 40 přidání a 31 odebrání
  1. 2 2
      door/input_windows.c
  2. 1 1
      door/input_windows.go
  3. 1 0
      door/input_windows.h
  4. 36 28
      door/panel.go

+ 2 - 2
door/input_win.c → door/input_windows.c

@@ -1,4 +1,4 @@
-#include "input_win.h"
+#include "input_windows.h"
 
  void init_wsa(void) {
     WSADATA wsa;
@@ -40,4 +40,4 @@
     }
 
     return -1;
- }
+ }

+ 1 - 1
door/input_windows.go

@@ -2,7 +2,7 @@ package door
 
 // #cgo LDFLAGS: -lws2_32
 // #cgo CFLAGS: -Wall
-// #include "input_win.h"
+// #include "input_windows.h"
 import "C"
 
 import (

+ 1 - 0
door/input_win.h → door/input_windows.h

@@ -1,5 +1,6 @@
 #include <winsock2.h>
 #include <string.h>
+#include <errno.h>
 
 void init_wsa(void);
 int windows_read(int fd, char *buffer, int len);

+ 36 - 28
door/panel.go

@@ -27,6 +27,23 @@ type Panel struct {
 	TitleOffset int
 }
 
+func (p *Panel) Range(withBorder bool) (sx, sy, ex, ey int) {
+	sx = p.X
+	sy = p.Y
+	ex = p.X + p.Width
+	ey = p.Y + len(p.Lines)
+	if p.Style > 0 {
+		if withBorder {
+			ex += 2
+			ey += 2
+		} else {
+			sx += 1
+			sy += 1
+		}
+	}
+	return
+}
+
 // Output the panel
 func (p *Panel) Output() string {
 	var style int = int(p.Style)
@@ -130,7 +147,7 @@ func (p *Panel) UpdateLine(index int) string {
 	return output
 }
 
-// Goto the end
+// Position Cursor at the "end" of the panel
 func (p *Panel) GotoEnd() string {
 	var row, col int
 	row = p.Y
@@ -183,34 +200,25 @@ func (p *Panel) CenterY() {
 	p.Y = (Height - len(p.Lines)) / 2
 }
 
-func (p *Panel) Clicked(m Mouse) (line int, clicked bool) {
-	mX := int(m.X)
-	mY := int(m.Y)
-
-	if p.Style == NONE {
-		if mY >= p.Y && mY < p.Y+len(p.Lines) &&
-			mX >= p.X && mX < p.X+p.Width {
-			return p.Y - mY + 1, true
-		}
-		return 0, false
-	} else {
-		if mY == p.Y || mY == p.Y+len(p.Lines)+1 {
-			if mX >= p.X && mX <= p.X+p.Width+1 {
-				// Top/Bottom border clicked
-				return 0, true
-			}
-		}
-		if mY > p.Y && mY < p.Y+len(p.Lines)+1 {
-			if mX == p.X || mX == p.X+p.Width+1 {
-				// Left/Right border clicked
-				return 0, true
-			}
-		}
-		if mY > p.Y && mY < p.Y+len(p.Lines)+1 {
-			if mY > p.X && mY <= p.X+p.Width+1 {
-				return p.Y - mY, true
+// Panel Clicked?
+// If onBorder == true, returns true, 0 for border click.
+// Otherwise true, line clicked on (starting with 1)/
+func (p *Panel) Clicked(m Mouse, onBorder bool) (bool, int) {
+	var sx, sy, ex, ey = p.Range(onBorder)
+	var mx = int(m.X)
+	var my = int(m.Y)
+
+	if (mx >= sx) && (mx <= ex) {
+		if (my >= sy) && (my <= ey) {
+			if onBorder {
+				if my == sy || my == ey {
+					return true, 0
+				}
+				return true, my - sy
+			} else {
+				return true, (my - sy) + 1
 			}
 		}
-		return 0, false
 	}
+	return false, 0
 }