Skip to content

Commit

Permalink
chore(app): removing gui example from bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare committed Mar 17, 2024
1 parent d09d9dc commit 29f6cb9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# You can setup pre-commit in your repository by running `pre-commit install` or `composer dev:precommit`
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
hooks:
- id: remove-tabs
- repo: https://github.com/digitalpulp/pre-commit-php
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
]
},
"files": [
"src/gui_test.php",
"src/scripts/Core/constants.php",
"src/scripts/Core/functions.php",
"src/scripts/Web/constants.php",
Expand Down
2 changes: 1 addition & 1 deletion src/gui_test.php → src/gui-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use CatPaw\Gui\Contract;


function gui_test() {
function main() {
$lib = goffi(Contract::class, asFileName(__DIR__, './lib/Gui/lib/main.so')->withPhar())->try($error);
if ($error) {
return error($error);
Expand Down
115 changes: 57 additions & 58 deletions src/lib/Gui/lib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
import (
"C"
"os"
"strconv"

"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
Expand Down Expand Up @@ -63,85 +62,85 @@ func toStringC(value string) stringC {

// Library stuff

var (
Scene *widgets.QGraphicsScene
View *widgets.QGraphicsView
Item *widgets.QGraphicsPixmapItem
statusbar *widgets.QStatusBar
mp bool
)
// var (
// Scene *widgets.QGraphicsScene
// View *widgets.QGraphicsView
// Item *widgets.QGraphicsPixmapItem
// statusbar *widgets.QStatusBar
// mp bool
// )

func ItemMousePressEvent(event *widgets.QGraphicsSceneMouseEvent) {
mp = true
mousePosition := event.Pos()
x, y := int(mousePosition.X()), int(mousePosition.Y())
drawpixel(x, y)
// func ItemMousePressEvent(event *widgets.QGraphicsSceneMouseEvent) {
// mp = true
// mousePosition := event.Pos()
// x, y := int(mousePosition.X()), int(mousePosition.Y())
// drawpixel(x, y)

}
// }

func ItemMouseReleaseEvent(event *widgets.QGraphicsSceneMouseEvent) {
mp = false
// func ItemMouseReleaseEvent(event *widgets.QGraphicsSceneMouseEvent) {
// mp = false

Item.MousePressEventDefault(event) // absofukinlutely necessary for drag & draw !!
// Item.MousePressEventDefault(event) // absofukinlutely necessary for drag & draw !!

//Item.MouseReleaseEventDefault(event) // worthless
}
// //Item.MouseReleaseEventDefault(event) // worthless
// }

func ItemMouseMoveEvent(event *widgets.QGraphicsSceneMouseEvent) {
mousePosition := event.Pos()
x, y := int(mousePosition.X()), int(mousePosition.Y())
// func ItemMouseMoveEvent(event *widgets.QGraphicsSceneMouseEvent) {
// mousePosition := event.Pos()
// x, y := int(mousePosition.X()), int(mousePosition.Y())

drawpixel(x, y)
// drawpixel(x, y)

}
// }

func ItemHoverMoveEvent(event *widgets.QGraphicsSceneHoverEvent) {
mousePosition := event.Pos()
x, y := int(mousePosition.X()), int(mousePosition.Y())
// func ItemHoverMoveEvent(event *widgets.QGraphicsSceneHoverEvent) {
// mousePosition := event.Pos()
// x, y := int(mousePosition.X()), int(mousePosition.Y())

rgbValue := Item.Pixmap().ToImage().PixelColor2(x, y)
r, g, b := rgbValue.Red(), rgbValue.Green(), rgbValue.Blue()
statusbar.ShowMessage("x: "+strconv.Itoa(x)+" y: "+strconv.Itoa(y)+" r: "+strconv.Itoa(r)+" g: "+strconv.Itoa(g)+" b: "+strconv.Itoa(b), 0)
// rgbValue := Item.Pixmap().ToImage().PixelColor2(x, y)
// r, g, b := rgbValue.Red(), rgbValue.Green(), rgbValue.Blue()
// statusbar.ShowMessage("x: "+strconv.Itoa(x)+" y: "+strconv.Itoa(y)+" r: "+strconv.Itoa(r)+" g: "+strconv.Itoa(g)+" b: "+strconv.Itoa(b), 0)

}
// }

func drawpixel(x, y int) {
// func drawpixel(x, y int) {

if mp {
img := Item.Pixmap().ToImage()
img.SetPixelColor2(x, y, gui.NewQColor3(255, 255, 255, 255))
Item.SetPixmap(gui.NewQPixmap().FromImage(img, 0))
}
// if mp {
// img := Item.Pixmap().ToImage()
// img.SetPixelColor2(x, y, gui.NewQColor3(255, 255, 255, 255))
// Item.SetPixmap(gui.NewQPixmap().FromImage(img, 0))
// }

}
// }

func keyPressEvent(e *gui.QKeyEvent) {
// func keyPressEvent(e *gui.QKeyEvent) {

switch int32(e.Key()) {
case int32(core.Qt__Key_0):
View.Scale(1.25, 1.25)
// switch int32(e.Key()) {
// case int32(core.Qt__Key_0):
// View.Scale(1.25, 1.25)

case int32(core.Qt__Key_9):
View.Scale(0.8, 0.8)
}
// case int32(core.Qt__Key_9):
// View.Scale(0.8, 0.8)
// }

}
// }

func wheelEvent(e *widgets.QGraphicsSceneWheelEvent) {
if gui.QGuiApplication_QueryKeyboardModifiers()&core.Qt__ShiftModifier != 0 {
if e.Delta() > 0 {
View.Scale(1.25, 1.25)
} else {
View.Scale(0.8, 0.8)
}
}
}
// func wheelEvent(e *widgets.QGraphicsSceneWheelEvent) {
// if gui.QGuiApplication_QueryKeyboardModifiers()&core.Qt__ShiftModifier != 0 {
// if e.Delta() > 0 {
// View.Scale(1.25, 1.25)
// } else {
// View.Scale(0.8, 0.8)
// }
// }
// }

func resizeEvent(e *gui.QResizeEvent) {
// func resizeEvent(e *gui.QResizeEvent) {

View.FitInView(Scene.ItemsBoundingRect(), core.Qt__KeepAspectRatio)
// View.FitInView(Scene.ItemsBoundingRect(), core.Qt__KeepAspectRatio)

}
// }

const WindowCode = 1
const StatusBarCode = 2
Expand Down
5 changes: 0 additions & 5 deletions src/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ function main(
bool $build = false,
#[Option("--build-optimize")]
bool $buildOptimize = false,

// ===> GUI
#[Option("--gui")]
bool $gui = false,
): Unsafe {
return anyError(fn () => match (true) {
$build => build(buildOptimize:$buildOptimize),
$tips => tips(),
$hi => out()->write("hello\n"),
$gui => gui_test(),
default => true,
});
}
Expand Down

0 comments on commit 29f6cb9

Please sign in to comment.