Starting resize support.
This commit is contained in:
parent
cea3d2c39f
commit
9ade0e2d4b
26 changed files with 197 additions and 44 deletions
|
@ -12,7 +12,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Start the gui app
|
||||
auto app = MediaTool(std::move(args));
|
||||
app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
|
||||
//app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
|
||||
app.run();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -26,22 +26,22 @@ std::unique_ptr<Color> Color::Create(const Color& color)
|
|||
return std::make_unique<Color>(color);
|
||||
}
|
||||
|
||||
unsigned Color::GetR() const
|
||||
unsigned Color::getR() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
unsigned Color::GetG() const
|
||||
unsigned Color::getG() const
|
||||
{
|
||||
return mG;
|
||||
}
|
||||
|
||||
unsigned Color::GetB() const
|
||||
unsigned Color::getB() const
|
||||
{
|
||||
return mB;
|
||||
}
|
||||
|
||||
double Color::GetAlpha() const
|
||||
double Color::getAlpha() const
|
||||
{
|
||||
return mAlpha;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
class Color
|
||||
{
|
||||
|
@ -10,10 +13,10 @@ public:
|
|||
static std::unique_ptr<Color> Create(unsigned r, unsigned g, unsigned b, double a = 1.0);
|
||||
static std::unique_ptr<Color> Create(const Color& color);
|
||||
|
||||
unsigned GetR() const;
|
||||
unsigned GetG() const;
|
||||
unsigned GetB() const;
|
||||
double GetAlpha() const;
|
||||
unsigned getR() const;
|
||||
unsigned getG() const;
|
||||
unsigned getB() const;
|
||||
double getAlpha() const;
|
||||
|
||||
bool operator==(const Color& rhs) const
|
||||
{
|
||||
|
@ -28,6 +31,16 @@ public:
|
|||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
std::vector<double> getAsVectorDouble() const
|
||||
{
|
||||
return {mR/255.0, mG/255.0, mB/255.0, mAlpha/255.0};
|
||||
}
|
||||
|
||||
uint32_t getAsUInt32() const
|
||||
{
|
||||
return mB + (mG<<8) + (mR<<16);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned mR{0};
|
||||
unsigned mG{0};
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
|
||||
static std::unique_ptr<DrawingSurface> Create();
|
||||
|
||||
void setSize(unsigned width, unsigned height);
|
||||
virtual void setSize(unsigned width, unsigned height);
|
||||
|
||||
unsigned getWidth() const;
|
||||
|
||||
|
|
|
@ -21,35 +21,43 @@ void OpenGlPainter::paint(DrawingContext* context)
|
|||
|
||||
const auto num_mesh = context->getScene()->getNumMeshes();
|
||||
|
||||
glClearColor(0.4, 0.4, 0.4, 0.4);
|
||||
glClearColor(1.0, 1.0, 1.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||
//glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||
|
||||
for (std::size_t idx=0; idx<num_mesh; idx++)
|
||||
{
|
||||
auto mesh = context->getScene()->getMesh(idx);
|
||||
const auto faces = mesh->getFaceVertices();
|
||||
const auto colors = mesh->getFaceVectorAttributes("Color");
|
||||
|
||||
glColor3f(1.0, 0.0, 1.0);
|
||||
|
||||
std::size_t counter{0};
|
||||
for (const auto& face : faces)
|
||||
{
|
||||
const auto r = colors[counter][0];
|
||||
const auto g = colors[counter][1];
|
||||
const auto b = colors[counter][2];
|
||||
|
||||
glColor3f(r, g, b);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
double x0 = 2.0*face[0].getX() / width - 1.0;
|
||||
double y0 = 2.0*face[0].getY() / height - 1.0;
|
||||
double y0 = 1.0 - 2.0*face[0].getY() / height;
|
||||
|
||||
double x1 = 2.0*face[1].getX() / width - 1.0;
|
||||
double y1 = 2.0*face[1].getY() / height - 1.0;
|
||||
double y1 = 1.0 - 2.0*face[1].getY() / height;
|
||||
|
||||
double x2 = 2.0*face[2].getX() / width - 1.0;
|
||||
double y2 = 2.0*face[2].getY() / height - 1.0;
|
||||
double y2 = 1.0 - 2.0*face[2].getY() / height;
|
||||
|
||||
glVertex3f(x0, y0, 0);
|
||||
glVertex3f(x1, y1, 0);
|
||||
glVertex3f(x2, y2, 0);
|
||||
|
||||
glEnd();
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ void Image<T>::setPixelValue(unsigned idx, unsigned jdx, const Color& color)
|
|||
initialize();
|
||||
}
|
||||
|
||||
mData[jdx*getBytesPerRow() + idx*3] = static_cast<T>(color.GetR());
|
||||
mData[jdx*getBytesPerRow() + idx*3 + 1] = static_cast<T>(color.GetG());
|
||||
mData[jdx*getBytesPerRow() + idx*3 + 2] = static_cast<T>(color.GetB());
|
||||
mData[jdx*getBytesPerRow() + idx*3] = static_cast<T>(color.getR());
|
||||
mData[jdx*getBytesPerRow() + idx*3 + 1] = static_cast<T>(color.getG());
|
||||
mData[jdx*getBytesPerRow() + idx*3 + 2] = static_cast<T>(color.getB());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -25,3 +25,18 @@ std::vector<unsigned> TriFace::getNodeIds() const
|
|||
{
|
||||
return {mEdge0->getNode0Id(), mEdge0->getNode1Id(), mEdge1->getNode1Id()};
|
||||
}
|
||||
|
||||
void TriFace::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
mVectorAttributes[tag] = values;
|
||||
}
|
||||
|
||||
std::vector<double> TriFace::getVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
auto iter = mVectorAttributes.find(tag);
|
||||
if (iter != mVectorAttributes.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
class Edge;
|
||||
|
||||
|
@ -14,8 +16,14 @@ public:
|
|||
static std::unique_ptr<TriFace> Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
|
||||
|
||||
std::vector<unsigned> getNodeIds() const;
|
||||
|
||||
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<double> getVectorAttribute(const std::string& tag) const;
|
||||
|
||||
private:
|
||||
unsigned mId{0};
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
Edge* mEdge0{nullptr};
|
||||
Edge* mEdge1{nullptr};
|
||||
Edge* mEdge2{nullptr};
|
||||
|
|
|
@ -27,3 +27,21 @@ std::vector<std::vector<Point> > TriMesh::getFaceVertices() const
|
|||
}
|
||||
return verts;
|
||||
}
|
||||
|
||||
std::vector<std::vector<double> > TriMesh::getFaceVectorAttributes(const std::string& tag)
|
||||
{
|
||||
std::vector<std::vector<double> > attribs(mFaces.size());
|
||||
for(std::size_t idx=0; idx<mFaces.size(); idx++)
|
||||
{
|
||||
attribs[idx] = {mFaces[idx]->getVectorAttribute(tag)};
|
||||
}
|
||||
return attribs;
|
||||
}
|
||||
|
||||
void TriMesh::addConstantFaceVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
for (const auto& face : mFaces)
|
||||
{
|
||||
face->addVectorAttribute(tag, values);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ public:
|
|||
|
||||
std::vector<std::vector<Point> > getFaceVertices() const;
|
||||
|
||||
void addConstantFaceVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<std::vector<double> > getFaceVectorAttributes(const std::string& tag);
|
||||
|
||||
private:
|
||||
VecNodes mNodes;
|
||||
VecEdges mEdges;
|
||||
|
|
|
@ -12,6 +12,8 @@ list(APPEND ui_elements_LIB_INCLUDES
|
|||
ui_events/MouseEvent.h
|
||||
ui_events/UiEvent.h
|
||||
ui_events/PaintEvent.h
|
||||
ui_events/ResizeEvent.h
|
||||
ui_events/ResizeEvent.cpp
|
||||
widgets/Widget.cpp
|
||||
widgets/Button.cpp
|
||||
widgets/Label.cpp
|
||||
|
|
|
@ -37,6 +37,12 @@ std::unique_ptr<Window> Window::Create()
|
|||
return std::make_unique<Window>();
|
||||
}
|
||||
|
||||
void Window::setSize(unsigned width, unsigned height)
|
||||
{
|
||||
DrawingSurface::setSize(width, height);
|
||||
mWidget->setBounds(width, height);
|
||||
}
|
||||
|
||||
void Window::clearPlatformWindow()
|
||||
{
|
||||
mPlatformWindow.reset();
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
|
||||
void clearPlatformWindow();
|
||||
|
||||
void setSize(unsigned width, unsigned height) override;
|
||||
|
||||
private:
|
||||
WidgetPtr mWidget {nullptr};
|
||||
IPlatformWindowPtr mPlatformWindow {nullptr};
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
class PaintEvent : public UiEvent
|
||||
{
|
||||
public:
|
||||
|
||||
PaintEvent();
|
||||
|
||||
~PaintEvent();
|
||||
|
|
20
src/ui_elements/ui_events/ResizeEvent.cpp
Normal file
20
src/ui_elements/ui_events/ResizeEvent.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "ResizeEvent.h"
|
||||
|
||||
ResizeEvent::ResizeEvent(unsigned width, unsigned height)
|
||||
: UiEvent(),
|
||||
mWidth(),
|
||||
mHeight()
|
||||
{
|
||||
mType = UiEvent::Type::Resize;
|
||||
}
|
||||
|
||||
ResizeEvent::~ResizeEvent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<ResizeEvent> ResizeEvent::Create(unsigned width, unsigned height)
|
||||
{
|
||||
return std::make_unique<ResizeEvent>(width, height);
|
||||
}
|
||||
|
30
src/ui_elements/ui_events/ResizeEvent.h
Normal file
30
src/ui_elements/ui_events/ResizeEvent.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "UiEvent.h"
|
||||
|
||||
class ResizeEvent : public UiEvent
|
||||
{
|
||||
public:
|
||||
ResizeEvent(unsigned width, unsigned height);
|
||||
|
||||
~ResizeEvent();
|
||||
|
||||
static std::unique_ptr<ResizeEvent> Create(unsigned width, unsigned height);
|
||||
|
||||
unsigned getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned mWidth{0};
|
||||
unsigned mHeight{0};
|
||||
};
|
||||
using ResizeEventPtr = std::unique_ptr<ResizeEvent>;
|
|
@ -10,7 +10,8 @@ public:
|
|||
Unknown,
|
||||
Paint,
|
||||
Mouse,
|
||||
Keyboard
|
||||
Keyboard,
|
||||
Resize
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -38,5 +38,8 @@ void RectangleNode::updateMesh()
|
|||
const auto rect = Rectangle(mLocation, mWidth, mHeight);
|
||||
|
||||
auto mesh = MeshPrimitives::build(rect);
|
||||
auto color = getFillColor();
|
||||
|
||||
mesh->addConstantFaceVectorAttribute("Color", color.getAsVectorDouble());
|
||||
mMesh = std::move(mesh);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,13 @@ void DesktopManager::onUiEvent(UiEventUPtr eventUPtr)
|
|||
mModified = true;
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Resize):
|
||||
{
|
||||
auto resize_event = dynamic_cast<const ResizeEvent*>(event);
|
||||
mWindowManager->onResizeEvent(resize_event);
|
||||
//mModified = true;
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Mouse):
|
||||
{
|
||||
auto mouseEvent = dynamic_cast<const MouseEvent*>(event);
|
||||
|
|
|
@ -26,6 +26,11 @@ void WindowManager::onMouseEvent(const MouseEvent* event)
|
|||
getMainWindow()->onMouseEvent(event);
|
||||
}
|
||||
|
||||
void WindowManager::onResizeEvent(const ResizeEvent* event)
|
||||
{
|
||||
getMainWindow()->setSize(event->getWidth(), event->getHeight());
|
||||
}
|
||||
|
||||
void WindowManager::onKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
getMainWindow()->onKeyboardEvent(event);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "Window.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "ResizeEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
class WindowManager
|
||||
|
@ -27,6 +28,8 @@ public:
|
|||
|
||||
void onKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
void onResizeEvent(const ResizeEvent* event);
|
||||
|
||||
void clearPlatformWindows();
|
||||
|
||||
std::size_t getNumWindows() const
|
||||
|
|
|
@ -9,11 +9,13 @@ XcbGlInterface::XcbGlInterface(Display* display, int default_screen)
|
|||
mContext(),
|
||||
mConfig()
|
||||
{
|
||||
MLOG_INFO("Creating XcbGlInterface");
|
||||
setupContext(default_screen);
|
||||
}
|
||||
|
||||
XcbGlInterface::~XcbGlInterface()
|
||||
{
|
||||
MLOG_INFO("Destroying XcbGlInterface");
|
||||
destroyContext();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,20 @@
|
|||
#include <xcb/xcb.h>
|
||||
|
||||
#include "PaintEvent.h"
|
||||
#include "ResizeEvent.h"
|
||||
#include "Screen.h"
|
||||
#include "XcbScreen.h"
|
||||
#include "Color.h"
|
||||
#include "UiEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "XcbKeyboard.h"
|
||||
#include "XcbWindow.h"
|
||||
#include "XcbLayerInterface.h"
|
||||
#include "XcbEventInterface.h"
|
||||
#include "XcbGlInterface.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware)
|
||||
: AbstractUIInterface(desktopManager, useHardware),
|
||||
|
@ -120,7 +123,8 @@ void XcbInterface::createGraphicsContext()
|
|||
auto gc = xcb_generate_id(mConnection);
|
||||
xcb_drawable_t window = xcb_screen->GetNativeScreen()->root;
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::getColor(240, 240, 240), 0};
|
||||
auto color = Color(240, 240, 240);
|
||||
uint32_t values[2] = {color.getAsUInt32(), 0};
|
||||
xcb_create_gc(mConnection, gc, window, mask, values);
|
||||
xcb_screen->SetGraphicsContext(gc);
|
||||
}
|
||||
|
@ -140,7 +144,8 @@ uint32_t XcbInterface::getEventMask()
|
|||
return XCB_EVENT_MASK_KEY_RELEASE |
|
||||
XCB_EVENT_MASK_BUTTON_PRESS |
|
||||
XCB_EVENT_MASK_BUTTON_RELEASE |
|
||||
XCB_EVENT_MASK_EXPOSURE;
|
||||
XCB_EVENT_MASK_EXPOSURE |
|
||||
XCB_EVENT_MASK_RESIZE_REDIRECT;
|
||||
}
|
||||
|
||||
void XcbInterface::addWindow(mt::Window* window)
|
||||
|
@ -205,6 +210,23 @@ void XcbInterface::loop()
|
|||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
case XCB_RESIZE_REQUEST:
|
||||
{
|
||||
auto resize = (xcb_resize_request_event_t*) event;
|
||||
int width = 1;
|
||||
int height = 1;
|
||||
if (resize->width > 0)
|
||||
{
|
||||
width = resize->width;
|
||||
}
|
||||
if (resize->height > 0)
|
||||
{
|
||||
height = resize->height;
|
||||
}
|
||||
auto ui_event = std::make_unique<ResizeEvent>(width, height);
|
||||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* Unknown event type, ignore it */
|
||||
break;
|
||||
|
|
|
@ -6,20 +6,10 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
uint32_t XcbLayerInterface::getColor(const Color* color)
|
||||
{
|
||||
return XcbLayerInterface::getColor(color->GetR(), color->GetG(), color->GetB());
|
||||
}
|
||||
|
||||
uint32_t XcbLayerInterface::getColor(int r, int g, int b)
|
||||
{
|
||||
return b + (g<<8) + (r<<16);
|
||||
}
|
||||
|
||||
void XcbLayerInterface::modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color)
|
||||
void XcbLayerInterface::modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color& color)
|
||||
{
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::getColor(color), 0};
|
||||
uint32_t values[2] = {color.getAsUInt32(), 0};
|
||||
|
||||
xcb_change_gc(connection, gc, mask, values);
|
||||
}
|
||||
|
|
|
@ -8,11 +8,7 @@ class VisualLayer;
|
|||
class XcbLayerInterface
|
||||
{
|
||||
public:
|
||||
static uint32_t getColor(const Color* color);
|
||||
|
||||
static uint32_t getColor(int r, int g, int b);
|
||||
|
||||
static void modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color);
|
||||
static void modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color& color);
|
||||
|
||||
static void addLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "XcbTextInterface.h"
|
||||
|
||||
#include "XcbLayerInterface.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "Color.h"
|
||||
|
||||
|
@ -16,7 +15,7 @@ xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
|||
/* create graphics context */
|
||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||
auto fillColor = XcbLayerInterface::getColor(&textElement->getFillColor());
|
||||
auto fillColor = textElement->getFillColor().getAsUInt32();
|
||||
uint32_t value_list[3] = {screen->black_pixel, fillColor, font };
|
||||
|
||||
xcb_create_gc(connection, gc, window, mask, value_list);
|
||||
|
|
Loading…
Reference in a new issue