More langtool improvements
This commit is contained in:
@@ -4,141 +4,16 @@ from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication, QMainWindow, QWidget,
|
||||
QHBoxLayout, QVBoxLayout, QPushButton,
|
||||
QLabel, QSlider, QOpenGLWidget, QDialog, QRadioButton, QDialogButtonBox,
|
||||
QLabel, QSlider, QDialog, QRadioButton, QDialogButtonBox,
|
||||
QAction, QFileDialog, QLineEdit
|
||||
)
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
|
||||
class GLWidget(QOpenGLWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.xRot = 20.0
|
||||
self.yRot = 30.0
|
||||
self.zRot = 0.0
|
||||
|
||||
self.rotation_speed = 2.0
|
||||
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self.updateRotation)
|
||||
|
||||
# ---------- OpenGL lifecycle ----------
|
||||
def initializeGL(self):
|
||||
# Check that context is valid
|
||||
version = glGetString(GL_VERSION)
|
||||
print("GL version:", version)
|
||||
|
||||
glClearColor(0.1, 0.1, 0.1, 1.0)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glShadeModel(GL_SMOOTH)
|
||||
|
||||
glEnable(GL_COLOR_MATERIAL)
|
||||
glEnable(GL_LIGHTING)
|
||||
glEnable(GL_LIGHT0)
|
||||
|
||||
light_position = [4.0, 4.0, 8.0, 1.0]
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position)
|
||||
|
||||
def resizeGL(self, w, h):
|
||||
if h == 0:
|
||||
h = 1
|
||||
|
||||
glViewport(0, 0, w, h)
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
glLoadIdentity()
|
||||
gluPerspective(45.0, float(w) / float(h), 0.1, 100.0)
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
|
||||
def paintGL(self):
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
glLoadIdentity()
|
||||
|
||||
glTranslatef(0.0, 0.0, -7.0)
|
||||
|
||||
glRotatef(self.xRot, 1.0, 0.0, 0.0)
|
||||
glRotatef(self.yRot, 0.0, 1.0, 0.0)
|
||||
glRotatef(self.zRot, 0.0, 0.0, 1.0)
|
||||
|
||||
self.drawCube()
|
||||
|
||||
# ---------- 3D object ----------
|
||||
|
||||
def drawCube(self):
|
||||
glBegin(GL_QUADS)
|
||||
|
||||
# Front (red)
|
||||
glColor3f(1.0, 0.0, 0.0)
|
||||
glVertex3f(-1.0, -1.0, 1.0)
|
||||
glVertex3f( 1.0, -1.0, 1.0)
|
||||
glVertex3f( 1.0, 1.0, 1.0)
|
||||
glVertex3f(-1.0, 1.0, 1.0)
|
||||
|
||||
# Back (green)
|
||||
glColor3f(0.0, 1.0, 0.0)
|
||||
glVertex3f(-1.0, -1.0, -1.0)
|
||||
glVertex3f(-1.0, 1.0, -1.0)
|
||||
glVertex3f( 1.0, 1.0, -1.0)
|
||||
glVertex3f( 1.0, -1.0, -1.0)
|
||||
|
||||
# Top (blue)
|
||||
glColor3f(0.0, 0.0, 1.0)
|
||||
glVertex3f(-1.0, 1.0, -1.0)
|
||||
glVertex3f(-1.0, 1.0, 1.0)
|
||||
glVertex3f( 1.0, 1.0, 1.0)
|
||||
glVertex3f( 1.0, 1.0, -1.0)
|
||||
|
||||
# Bottom (yellow)
|
||||
glColor3f(1.0, 1.0, 0.0)
|
||||
glVertex3f(-1.0, -1.0, -1.0)
|
||||
glVertex3f( 1.0, -1.0, -1.0)
|
||||
glVertex3f( 1.0, -1.0, 1.0)
|
||||
glVertex3f(-1.0, -1.0, 1.0)
|
||||
|
||||
# Right (magenta)
|
||||
glColor3f(1.0, 0.0, 1.0)
|
||||
glVertex3f( 1.0, -1.0, -1.0)
|
||||
glVertex3f( 1.0, 1.0, -1.0)
|
||||
glVertex3f( 1.0, 1.0, 1.0)
|
||||
glVertex3f( 1.0, -1.0, 1.0)
|
||||
|
||||
# Left (cyan)
|
||||
glColor3f(0.0, 1.0, 1.0)
|
||||
glVertex3f(-1.0, -1.0, -1.0)
|
||||
glVertex3f(-1.0, -1.0, 1.0)
|
||||
glVertex3f(-1.0, 1.0, 1.0)
|
||||
glVertex3f(-1.0, 1.0, -1.0)
|
||||
|
||||
glEnd()
|
||||
|
||||
# ---------- Animation control ----------
|
||||
|
||||
def startRotation(self):
|
||||
if not self.timer.isActive():
|
||||
self.timer.start(30) # ms
|
||||
|
||||
def stopRotation(self):
|
||||
if self.timer.isActive():
|
||||
self.timer.stop()
|
||||
|
||||
def resetView(self):
|
||||
self.xRot = 20.0
|
||||
self.yRot = 30.0
|
||||
self.zRot = 0.0
|
||||
self.update()
|
||||
|
||||
def updateRotation(self):
|
||||
self.xRot += self.rotation_speed
|
||||
self.yRot += self.rotation_speed * 0.8
|
||||
self.zRot += self.rotation_speed * 0.5
|
||||
self.update()
|
||||
|
||||
from editortool.map.glwidget import GLWidget
|
||||
|
||||
class MapWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("3D Cube with GUI Buttons (QOpenGLWidget)")
|
||||
self.setWindowTitle("Dusk Map Editor")
|
||||
self.resize(1280, 720)
|
||||
|
||||
# File menu setup
|
||||
@@ -222,4 +97,4 @@ class MapWindow(QMainWindow):
|
||||
fname, _ = QFileDialog.getSaveFileName(self, "Save JSON File As", default_dir, "JSON Files (*.json)")
|
||||
if fname:
|
||||
self.current_file = fname
|
||||
# ...save logic...
|
||||
# ...save logic...
|
||||
Reference in New Issue
Block a user