Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ void slop::Framebuffer::unbind() {
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
}

void slop::Framebuffer::draw(glm::vec2 mouse, float time, glm::vec4 color){
void slop::Framebuffer::draw(int mouseScroll, glm::vec2 mouse, float time, glm::vec4 color){
shader->bind();
shader->setParameter( "texture", 0 );
shader->setAttribute( "position", buffers[0], 2 );
shader->setAttribute( "uv", buffers[1], 2 );
if ( shader->hasParameter( "scroll" ) ) {
shader->setParameter( "scroll", mouseScroll );
}
if ( shader->hasParameter( "mouse" ) ) {
shader->setParameter( "mouse", mouse );
}
Expand Down
2 changes: 1 addition & 1 deletion src/framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Framebuffer {
Framebuffer( int w, int h );
~Framebuffer();
void setShader( slop::Shader* shader );
void draw(glm::vec2 mouse, float time, glm::vec4 color);
void draw(int mouseScroll, glm::vec2 mouse, float time, glm::vec4 color);
void resize( int w, int h );
void bind();
void unbind();
Expand Down
24 changes: 21 additions & 3 deletions src/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ void slop::Mouse::setButton( int button, int state ) {
buttons.push_back(glm::ivec2(button,state));
}

int slop::Mouse::getScroll() {
return scroll;
}

void slop::Mouse::setScroll(int s) {
scroll = s;
}

void slop::Mouse::updateScroll(int button) {
switch (button) {
case Button4: { scroll += 1; } break;
case Button5: { scroll -= 1; } break;
case Button2: { scroll = 0; } break;
}
}

int slop::Mouse::getButton( int button ) {
for (unsigned int i=0;i<buttons.size();i++ ) {
if ( buttons[i].x == button ) {
Expand Down Expand Up @@ -62,6 +78,7 @@ slop::Mouse::Mouse(X11* x11, int nodecorations, Window ignoreWindow ) {
}
this->nodecorations = nodecorations;
this->ignoreWindow = ignoreWindow;
this->scroll = 0;
hoverWindow = findWindow(x11->root);
}

Expand All @@ -72,7 +89,8 @@ slop::Mouse::~Mouse() {
void slop::Mouse::update() {
XEvent event;
while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
setButton( event.xbutton.button, 1 );
setButton( event.xbutton.button, 1 );
updateScroll( event.xbutton.button );
}
bool findNewWindow = false;
while ( XCheckTypedEvent( x11->display, MotionNotify, &event ) ) {
Expand All @@ -82,7 +100,7 @@ void slop::Mouse::update() {
hoverWindow = findWindow(x11->root);
}
while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) {
setButton( event.xbutton.button, 0 );
setButton( event.xbutton.button, 0 );
}
while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) {
hoverWindow = event.xcrossing.window;
Expand All @@ -105,7 +123,7 @@ Window slop::Mouse::findWindow( Window foo ) {
continue;
}
// We need to make sure the window is mapped.
XWindowAttributes attr;
XWindowAttributes attr;
XGetWindowAttributes( x11->display, children[i], &attr );
if ( attr.map_state != IsViewable ) {
continue;
Expand Down
4 changes: 4 additions & 0 deletions src/mouse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Mouse {
int currentCursor;
Window findWindow( Window foo );
int nodecorations;
int scroll;
Window ignoreWindow;
public:
Window hoverWindow;
Expand All @@ -48,6 +49,9 @@ class Mouse {
glm::vec2 getMousePos();
void setButton( int button, int state );
int getButton( int button );
int getScroll(void);
void setScroll(int);
void updateScroll(int);
};

extern Mouse* mouse;
Expand Down
4 changes: 2 additions & 2 deletions src/slop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, SlopWindow*
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
pong->setShader( shaders[i] );
pong->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
pong->draw(slop::mouse->getScroll(), slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
ping->unbind();
std::swap(ping, pong);
}
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
pong->setShader( shaders[shaders.size() - 1] );
pong->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
pong->draw(slop::mouse->getScroll(), slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
glDisable( GL_BLEND );

window->display();
Expand Down