mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
commit
52056b1aa1
5 changed files with 224 additions and 5 deletions
|
@ -852,6 +852,8 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
|
|||
deleteVoxelUnderCursor();
|
||||
}
|
||||
}
|
||||
|
||||
_pieMenu.mouseMoveEvent(_mouseX, _mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -869,7 +871,12 @@ void Application::mousePressEvent(QMouseEvent* event) {
|
|||
_mouseDragStartedY = _mouseY;
|
||||
_mouseVoxelDragging = _mouseVoxel;
|
||||
_mousePressed = true;
|
||||
maybeEditVoxelUnderCursor();
|
||||
|
||||
|
||||
if (!maybeEditVoxelUnderCursor()) {
|
||||
_pieMenu.mousePressEvent(_mouseX, _mouseY);
|
||||
}
|
||||
|
||||
if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) {
|
||||
_hoverVoxelOriginalColor[0] = _hoverVoxel.red;
|
||||
_hoverVoxelOriginalColor[1] = _hoverVoxel.green;
|
||||
|
@ -892,6 +899,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event) {
|
|||
_mouseY = event->y();
|
||||
_mousePressed = false;
|
||||
checkBandwidthMeterClick();
|
||||
|
||||
_pieMenu.mouseReleaseEvent(_mouseX, _mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2057,7 +2066,11 @@ void Application::init() {
|
|||
_palette.addTool(&_swatch);
|
||||
_palette.addAction(_colorVoxelMode, 0, 2);
|
||||
_palette.addAction(_eyedropperMode, 0, 3);
|
||||
_palette.addAction(_selectVoxelMode, 0, 4);
|
||||
_palette.addAction(_selectVoxelMode, 0, 4);
|
||||
|
||||
_pieMenu.init("./resources/images/hifi-interface-tools-v2-pie.svg",
|
||||
_glWidget->width(),
|
||||
_glWidget->height());
|
||||
}
|
||||
|
||||
|
||||
|
@ -2992,6 +3005,10 @@ void Application::displayOverlay() {
|
|||
_swatch.checkColor();
|
||||
}
|
||||
|
||||
if (_pieMenu.isDisplayed()) {
|
||||
_pieMenu.render();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -3391,7 +3408,7 @@ void Application::shiftPaintingColor() {
|
|||
}
|
||||
|
||||
|
||||
void Application::maybeEditVoxelUnderCursor() {
|
||||
bool Application::maybeEditVoxelUnderCursor() {
|
||||
if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
|
||||
if (_mouseVoxel.s != 0) {
|
||||
PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ?
|
||||
|
@ -3462,7 +3479,11 @@ void Application::maybeEditVoxelUnderCursor() {
|
|||
deleteVoxelUnderCursor();
|
||||
} else if (_eyedropperMode->isChecked()) {
|
||||
eyedropperVoxelUnderCursor();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::deleteVoxelUnderCursor() {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "ViewFrustum.h"
|
||||
#include "VoxelSystem.h"
|
||||
#include "Webcam.h"
|
||||
#include "PieMenu.h"
|
||||
#include "avatar/Avatar.h"
|
||||
#include "avatar/HandControl.h"
|
||||
#include "ui/BandwidthDialog.h"
|
||||
|
@ -222,7 +223,7 @@ private:
|
|||
|
||||
void setupPaintingVoxel();
|
||||
void shiftPaintingColor();
|
||||
void maybeEditVoxelUnderCursor();
|
||||
bool maybeEditVoxelUnderCursor();
|
||||
void deleteVoxelUnderCursor();
|
||||
void eyedropperVoxelUnderCursor();
|
||||
void resetSensors();
|
||||
|
@ -429,6 +430,8 @@ private:
|
|||
|
||||
ToolsPalette _palette;
|
||||
Swatch _swatch;
|
||||
|
||||
PieMenu _pieMenu;
|
||||
|
||||
VoxelSceneStats _voxelSceneStats;
|
||||
};
|
||||
|
|
138
interface/src/PieMenu.cpp
Normal file
138
interface/src/PieMenu.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
//
|
||||
// PieMenu.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Clement Brisset on 7/18/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "PieMenu.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QAction>
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QGLWidget>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
PieMenu::PieMenu() :
|
||||
_radiusIntern(30),
|
||||
_radiusExtern(70),
|
||||
_magnification(1.2f),
|
||||
_isDisplayed(false) {
|
||||
}
|
||||
|
||||
void PieMenu::init(const char *fileName, int screenWidth, int screenHeight) {
|
||||
// Load SVG
|
||||
switchToResourcesParentIfRequired();
|
||||
QSvgRenderer renderer((QString) QString(fileName));
|
||||
|
||||
// Prepare a QImage with desired characteritisc
|
||||
QImage image(2 * _radiusExtern, 2 * _radiusExtern, QImage::Format_ARGB32);
|
||||
image.fill(0x0);
|
||||
|
||||
// Get QPainter that paints to the image
|
||||
QPainter painter(&image);
|
||||
renderer.render(&painter);
|
||||
|
||||
//get the OpenGL-friendly image
|
||||
_textureImage = QGLWidget::convertToGLFormat(image);
|
||||
|
||||
glGenTextures(1, &_textureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureID);
|
||||
|
||||
//generate the texture
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
||||
_textureImage.width(),
|
||||
_textureImage.height(),
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
_textureImage.bits());
|
||||
|
||||
//texture parameters
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
void PieMenu::addAction(QAction* action){
|
||||
_actions.push_back(action);
|
||||
}
|
||||
|
||||
void PieMenu::render() {
|
||||
if (_actions.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float start = M_PI / 2.0f;
|
||||
float end = start + 2.0f * M_PI;
|
||||
float step = 2.0f * M_PI / 100.0f;
|
||||
float distance = sqrt((_mouseX - _x) * (_mouseX - _x) +
|
||||
(_mouseY - _y) * (_mouseY - _y));
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureID);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (_radiusIntern < distance) {
|
||||
float angle = atan2((_mouseY - _y), (_mouseX - _x)) - start;
|
||||
angle = (0.0f < angle) ? angle : angle + 2.0f * M_PI;
|
||||
|
||||
_selectedAction = floor(angle / (2.0f * M_PI / _actions.size()));
|
||||
|
||||
start = start + _selectedAction * 2.0f * M_PI / _actions.size();
|
||||
end = start + 2.0f * M_PI / _actions.size();
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(0.5f, 0.5f);
|
||||
glVertex2f(_x, _y);
|
||||
for (float i = start; i < end; i += step) {
|
||||
glTexCoord2f(0.5f + 0.5f * cos(i), 0.5f - 0.5f * sin(i));
|
||||
glVertex2f(_x + _magnification * _radiusExtern * cos(i),
|
||||
_y + _magnification * _radiusExtern * sin(i));
|
||||
}
|
||||
glTexCoord2f(0.5f + 0.5f * cos(end), 0.5f + - 0.5f * sin(end));
|
||||
glVertex2f(_x + _magnification * _radiusExtern * cos(end),
|
||||
_y + _magnification * _radiusExtern * sin(end));
|
||||
glEnd();
|
||||
} else {
|
||||
_selectedAction = -1;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(_x + _radiusExtern, _y - _radiusExtern);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2f(_x + _radiusExtern, _y + _radiusExtern);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(_x - _radiusExtern, _y + _radiusExtern);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2f(_x - _radiusExtern, _y - _radiusExtern);
|
||||
glEnd();
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void PieMenu::resize(int screenWidth, int screenHeight) {
|
||||
}
|
||||
|
||||
void PieMenu::mouseMoveEvent(int x, int y) {
|
||||
_mouseX = x;
|
||||
_mouseY = y;
|
||||
}
|
||||
|
||||
void PieMenu::mousePressEvent(int x, int y) {
|
||||
_x = _mouseX = x;
|
||||
_y = _mouseY = y;
|
||||
_selectedAction = -1;
|
||||
_isDisplayed = true;
|
||||
}
|
||||
|
||||
void PieMenu::mouseReleaseEvent(int x, int y) {
|
||||
if (0 <= _selectedAction && _selectedAction < _actions.size() && _actions[_selectedAction]) {
|
||||
_actions[_selectedAction]->trigger();
|
||||
}
|
||||
|
||||
_isDisplayed = false;
|
||||
}
|
57
interface/src/PieMenu.h
Normal file
57
interface/src/PieMenu.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// PieMenu.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Clement Brisset on 7/18/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__PieMenu__
|
||||
#define __hifi__PieMenu__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
class QAction;
|
||||
|
||||
class PieMenu {
|
||||
public:
|
||||
PieMenu();
|
||||
|
||||
void init(const char* fileName, int screenWidth, int screenHeight);
|
||||
void addAction(QAction* action);
|
||||
void render();
|
||||
void resize(int screenWidth, int screenHeight);
|
||||
|
||||
bool isDisplayed() const {return _isDisplayed;}
|
||||
|
||||
void mouseMoveEvent (int x, int y);
|
||||
void mousePressEvent (int x, int y);
|
||||
void mouseReleaseEvent(int x, int y);
|
||||
|
||||
private:
|
||||
QImage _textureImage;
|
||||
GLuint _textureID;
|
||||
|
||||
// position of the menu
|
||||
int _x;
|
||||
int _y;
|
||||
int _radiusIntern;
|
||||
int _radiusExtern;
|
||||
float _magnification;
|
||||
|
||||
int _mouseX;
|
||||
int _mouseY;
|
||||
|
||||
int _selectedAction;
|
||||
|
||||
bool _isDisplayed;
|
||||
|
||||
std::vector<QAction*> _actions;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__PieMenu__) */
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Tags.h
|
||||
// Tags.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Clement Brisset on 7/3/13.
|
||||
|
|
Loading…
Reference in a new issue