Browse Source

Added basic textured themes.

Dalton Nell 9 years ago
parent
commit
2200ce763a
6 changed files with 257 additions and 5 deletions
  1. 10
    0
      CMakeLists.txt
  2. 115
    5
      src/glselectrectangle.cpp
  3. 10
    0
      src/glselectrectangle.hpp
  4. 2
    0
      src/main.cpp
  5. 68
    0
      src/resource.cpp
  6. 52
    0
      src/resource.hpp

+ 10
- 0
CMakeLists.txt View File

79
      src/cmdline.c
79
      src/cmdline.c
80
      src/selectrectangle.cpp
80
      src/selectrectangle.cpp
81
      src/glselectrectangle.cpp
81
      src/glselectrectangle.cpp
82
+     src/resource.cpp
82
      src/xselectrectangle.cpp
83
      src/xselectrectangle.cpp
83
      src/x.cpp
84
      src/x.cpp
84
      src/main.cpp )
85
      src/main.cpp )
91
 find_package( GLX       REQUIRED )
92
 find_package( GLX       REQUIRED )
92
 find_package( XRender   REQUIRED )
93
 find_package( XRender   REQUIRED )
93
 find_package( XRandr    REQUIRED )
94
 find_package( XRandr    REQUIRED )
95
+find_package( DevIL     REQUIRED )
94
 # This library is needed only for Ubuntu it seems, some platforms don't even
96
 # This library is needed only for Ubuntu it seems, some platforms don't even
95
 # ship with it. I couldn't find a way to do a test compile to check if librt
97
 # ship with it. I couldn't find a way to do a test compile to check if librt
96
 # was needed, so instead I just didn't mark it as REQUIRED.
98
 # was needed, so instead I just didn't mark it as REQUIRED.
105
                          ${XEXT_INCLUDE_DIR}
107
                          ${XEXT_INCLUDE_DIR}
106
                          ${XRANDR_INCLUDE_DIR}
108
                          ${XRANDR_INCLUDE_DIR}
107
                          ${OPENGL_INCLUDE_DIR}
109
                          ${OPENGL_INCLUDE_DIR}
110
+                         ${IL_INCLUDE_DIR}
108
                          ${GLX_INCLUDE_DIR}
111
                          ${GLX_INCLUDE_DIR}
109
                          ${XRENDER_INCLUDE_DIRS}
112
                          ${XRENDER_INCLUDE_DIRS}
110
                          ${RT_INCLUDE_DIR} )
113
                          ${RT_INCLUDE_DIR} )
111
 else()
114
 else()
112
     include_directories( ${X11_INCLUDE_DIR}
115
     include_directories( ${X11_INCLUDE_DIR}
113
                          ${OPENGL_INCLUDE_DIR}
116
                          ${OPENGL_INCLUDE_DIR}
117
+                         ${IL_INCLUDE_DIR}
114
                          ${GLX_INCLUDE_DIR}
118
                          ${GLX_INCLUDE_DIR}
115
                          ${XEXT_INCLUDE_DIR} )
119
                          ${XEXT_INCLUDE_DIR} )
116
 endif()
120
 endif()
123
     target_link_libraries( "${BIN_TARGET}"
127
     target_link_libraries( "${BIN_TARGET}"
124
                            ${X11_LIBRARIES}
128
                            ${X11_LIBRARIES}
125
                            ${OPENGL_LIBRARIES}
129
                            ${OPENGL_LIBRARIES}
130
+                           ${IL_LIBRARIES}
131
+                           ${ILUT_LIBRARIES}
126
                            ${GLX_LIBRARIES}
132
                            ${GLX_LIBRARIES}
127
                            ${XRENDER_LIBRARIES}
133
                            ${XRENDER_LIBRARIES}
128
                            "${XEXT_LIBRARY}"
134
                            "${XEXT_LIBRARY}"
131
 else()
137
 else()
132
     target_link_libraries( "${BIN_TARGET}"
138
     target_link_libraries( "${BIN_TARGET}"
133
                            ${OPENGL_LIBRARIES}
139
                            ${OPENGL_LIBRARIES}
140
+                           ${IL_LIBRARIES}
141
+                           ${ILUT_LIBRARIES}
134
                            ${GLX_LIBRARIES}
142
                            ${GLX_LIBRARIES}
135
                            ${X11_LIBRARIES}
143
                            ${X11_LIBRARIES}
136
                            "${XEXT_LIBRARY}" )
144
                            "${XEXT_LIBRARY}" )
138
 
146
 
139
 install( TARGETS ${BIN_TARGET}
147
 install( TARGETS ${BIN_TARGET}
140
          DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
148
          DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
149
+
150
+add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")

+ 115
- 5
src/glselectrectangle.cpp View File

222
     glDisable(GL_TEXTURE_2D);
222
     glDisable(GL_TEXTURE_2D);
223
 }
223
 }
224
 
224
 
225
+void slop::GLSelectRectangle::setTheme( bool on, std::string name ) {
226
+    if ( !on ) {
227
+        return;
228
+    }
229
+    std::string root = resource->getRealPath( name );
230
+    std::string tl = root + "/corner_tl.png";
231
+    std::string bl = root + "/corner_bl.png";
232
+    std::string tr = root + "/corner_tr.png";
233
+    std::string br = root + "/corner_br.png";
234
+    std::string straight = root + "/straight.png";
235
+    // One of the textures didn't exist, so we cancel the theme.
236
+    if (!resource->validatePath( tl ) ||
237
+        !resource->validatePath( bl ) ||
238
+        !resource->validatePath( tr ) ||
239
+        !resource->validatePath( br ) ||
240
+        !resource->validatePath( straight ) ) {
241
+        fprintf( stderr, "One of the textures was missing in the theme... disabling.\n" );
242
+        return;
243
+    }
244
+    // Otherwise we load each one :)
245
+    ilInit();
246
+    ilutInit();
247
+    ilutRenderer(ILUT_OPENGL);
248
+    ILuint corner;
249
+    ilGenImages( 1, &corner );
250
+    ilBindImage( corner );
251
+    ilLoadImage( tl.c_str() );
252
+    m_cornerids[0] = ilutGLBindMipmaps();
253
+    ilLoadImage( tr.c_str() );
254
+    m_cornerids[1] = ilutGLBindMipmaps();
255
+    ilLoadImage( bl.c_str() );
256
+    m_cornerids[2] = ilutGLBindMipmaps();
257
+    ilLoadImage( br.c_str() );
258
+    m_cornerids[3] = ilutGLBindMipmaps();
259
+    ilLoadImage( straight.c_str() );
260
+    m_straightwidth = ilGetInteger( IL_IMAGE_WIDTH );
261
+    m_straightheight = ilGetInteger( IL_IMAGE_HEIGHT );
262
+    m_straightid = ilutGLBindMipmaps();
263
+    // And clean up after.
264
+    ilDeleteImages( 1, &corner );
265
+    m_themed = on;
266
+}
267
+
225
 slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
268
 slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
226
     m_x = std::min( sx, ex );
269
     m_x = std::min( sx, ex );
227
     m_y = std::min( sy, ey );
270
     m_y = std::min( sy, ey );
242
     m_glassSize = 4;
285
     m_glassSize = 4;
243
     m_glassBorder = 1;
286
     m_glassBorder = 1;
244
     m_monitors = xengine->getCRTCS();
287
     m_monitors = xengine->getCRTCS();
288
+    m_themed = false;
245
 
289
 
246
     // If we don't have a border, we don't exist, so just die.
290
     // If we don't have a border, we don't exist, so just die.
247
     if ( m_border == 0 ) {
291
     if ( m_border == 0 ) {
352
     if ( !glXMakeContextCurrent( xengine->m_display, m_glxWindow, m_glxWindow, m_renderContext ) ) {
396
     if ( !glXMakeContextCurrent( xengine->m_display, m_glxWindow, m_glxWindow, m_renderContext ) ) {
353
         fprintf( stderr, "Failed to attach GL context to window!\n" );
397
         fprintf( stderr, "Failed to attach GL context to window!\n" );
354
     }
398
     }
399
+    glEnable( GL_BLEND );
400
+    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
355
     glClearColor( 0, 0, 0, 0 );
401
     glClearColor( 0, 0, 0, 0 );
356
     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
402
     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
357
     glXSwapBuffers( xengine->m_display, m_glxWindow );
403
     glXSwapBuffers( xengine->m_display, m_glxWindow );
382
     glMatrixMode( GL_MODELVIEW );
428
     glMatrixMode( GL_MODELVIEW );
383
     glLoadIdentity();
429
     glLoadIdentity();
384
 
430
 
385
-    glColor4f( m_r, m_g, m_b, m_a );
386
-    glRecti( m_x-m_border, m_y, m_x+m_width+m_border, m_y-m_border );
387
-    glRecti( m_x-m_border, m_y+m_height, m_x+m_width+m_border, m_y+m_height+m_border );
388
-    glRecti( m_x-m_border, m_y, m_x, m_y+m_height );
389
-    glRecti( m_x+m_width, m_y, m_x+m_width+m_border, m_y+m_height );
431
+    if ( !m_themed ) {
432
+        glColor4f( m_r, m_g, m_b, m_a );
433
+        glRecti( m_x-m_border, m_y, m_x+m_width+m_border, m_y-m_border );
434
+        glRecti( m_x-m_border, m_y+m_height, m_x+m_width+m_border, m_y+m_height+m_border );
435
+        glRecti( m_x-m_border, m_y, m_x, m_y+m_height );
436
+        glRecti( m_x+m_width, m_y, m_x+m_width+m_border, m_y+m_height );
437
+    } else {
438
+        glColor4f( m_r, m_g, m_b, m_a );
439
+        glEnable( GL_TEXTURE_2D );
440
+        glBindTexture( GL_TEXTURE_2D, m_straightid );
441
+        float something = (float)(m_border)/(float)m_straightheight;
442
+        float txoffset = (((float)m_width+m_border)/(float)m_straightwidth)/something;
443
+        float tyoffset = (((float)m_height+m_border)/(float)m_straightwidth)/something;
444
+        //float ratio = ((float)m_straightwidth/(float)m_straightheight);
445
+        glBegin( GL_QUADS );
446
+        // straight top
447
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y-m_border );
448
+        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y-m_border );
449
+        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y );
450
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y );
451
+        // straight bot
452
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y+m_height );
453
+        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height );
454
+        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height+m_border );
455
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y+m_height+m_border );
456
+        // straight left
457
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y-m_border/2 );
458
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x, m_y-m_border/2 );
459
+        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x, m_y+m_height+m_border/2 );
460
+        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x-m_border, m_y+m_height+m_border/2 );
461
+        // straight right
462
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y-m_border/2 );
463
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y-m_border/2 );
464
+        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border/2 );
465
+        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x+m_width, m_y+m_height+m_border/2 );
466
+        glEnd();
467
+        // top left corner
468
+        glBindTexture( GL_TEXTURE_2D, m_cornerids[0] );
469
+        glBegin( GL_QUADS );
470
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y-m_border );
471
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y-m_border );
472
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y );
473
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y );
474
+        glEnd();
475
+        // top right
476
+        glBindTexture( GL_TEXTURE_2D, m_cornerids[1] );
477
+        glBegin( GL_QUADS );
478
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y-m_border );
479
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y-m_border );
480
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y );
481
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y );
482
+        glEnd();
483
+        // bottom left
484
+        glBindTexture( GL_TEXTURE_2D, m_cornerids[2] );
485
+        glBegin( GL_QUADS );
486
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y+m_height );
487
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y+m_height );
488
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y+m_height+m_border );
489
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y+m_height+m_border );
490
+        glEnd();
491
+        // bottom right
492
+        glBindTexture( GL_TEXTURE_2D, m_cornerids[2] );
493
+        glBegin( GL_QUADS );
494
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y+m_height );
495
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y+m_height );
496
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border );
497
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y+m_height+m_border );
498
+        glEnd();
499
+    }
390
 
500
 
391
     if ( m_glassEnabled ) {
501
     if ( m_glassEnabled ) {
392
         generateMagnifyingGlass();
502
         generateMagnifyingGlass();

+ 10
- 0
src/glselectrectangle.hpp View File

23
 
23
 
24
 #include "x.hpp"
24
 #include "x.hpp"
25
 #include "selectrectangle.hpp"
25
 #include "selectrectangle.hpp"
26
+#include "resource.hpp"
26
 
27
 
27
 #include <unistd.h>
28
 #include <unistd.h>
28
 
29
 
29
 #include <GL/gl.h>
30
 #include <GL/gl.h>
30
 #include <GL/glx.h>
31
 #include <GL/glx.h>
31
 #include <GL/glxext.h>
32
 #include <GL/glxext.h>
33
+#define ILUT_USE_OPENGL
34
+#include <IL/il.h>
35
+#include <IL/ilut.h>
32
 #include <X11/Xlib.h>
36
 #include <X11/Xlib.h>
33
 #include <X11/Xatom.h>
37
 #include <X11/Xatom.h>
34
 #include <X11/extensions/Xrender.h>
38
 #include <X11/extensions/Xrender.h>
54
     void                pushOut( int* x, int* y, int w, int h, int rx, int ry, int rw, int rh );
58
     void                pushOut( int* x, int* y, int w, int h, int rx, int ry, int rw, int rh );
55
     void                findOptimalGlassPosition();
59
     void                findOptimalGlassPosition();
56
     void                constrainWithinMonitor( int* x, int* y, int* w, int* h );
60
     void                constrainWithinMonitor( int* x, int* y, int* w, int* h );
61
+    void                setTheme( bool on, std::string name );
57
     float               m_r;
62
     float               m_r;
58
     float               m_g;
63
     float               m_g;
59
     float               m_b;
64
     float               m_b;
64
     GLXContext          m_renderContext;
69
     GLXContext          m_renderContext;
65
     GLXWindow           m_glxWindow;
70
     GLXWindow           m_glxWindow;
66
     Colormap            m_cmap;
71
     Colormap            m_cmap;
72
+    bool                m_themed;
67
     unsigned int        m_texid;
73
     unsigned int        m_texid;
74
+    unsigned int        m_cornerids[4];
75
+    unsigned int        m_straightid;
76
+    unsigned int        m_straightwidth;
77
+    unsigned int        m_straightheight;
68
     int                 m_offsetx;
78
     int                 m_offsetx;
69
     int                 m_offsety;
79
     int                 m_offsety;
70
     int                 m_offsetw;
80
     int                 m_offsetw;

+ 2
- 0
src/main.cpp View File

369
                                                                      r, g, b, a );
369
                                                                      r, g, b, a );
370
                             // Haha why is this so hard to cast?
370
                             // Haha why is this so hard to cast?
371
                             ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
371
                             ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
372
+                            ((slop::GLSelectRectangle*)(selection))->setTheme( true, "gothic" );
372
                         } else {
373
                         } else {
373
                             selection = new slop::XSelectRectangle( t.m_x, t.m_y,
374
                             selection = new slop::XSelectRectangle( t.m_x, t.m_y,
374
                                                                     t.m_x + t.m_width,
375
                                                                     t.m_x + t.m_width,
426
                                                                  r, g, b, a );
427
                                                                  r, g, b, a );
427
                         // Haha why is this so hard to cast?
428
                         // Haha why is this so hard to cast?
428
                         ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
429
                         ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
430
+                        ((slop::GLSelectRectangle*)(selection))->setTheme( true, "gothic" );
429
                     } else {
431
                     } else {
430
                         selection = new slop::XSelectRectangle( sx, sy,
432
                         selection = new slop::XSelectRectangle( sx, sy,
431
                                                                 ex, ey,
433
                                                                 ex, ey,

+ 68
- 0
src/resource.cpp View File

1
+/* resource.cpp: Handles getting resources like textures and stuff.
2
+ *
3
+ * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4
+ *
5
+ * This file is part of Slop.
6
+ *
7
+ * Slop is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * Slop is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with Slop.  If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+#include "resource.hpp"
22
+
23
+slop::Resource* resource = new slop::Resource();
24
+
25
+slop::Resource::Resource() {
26
+    // Find the configuration directory.
27
+    // usually ~/.config/slop and /usr/share/slop
28
+    char* config = getenv( "XDG_CONFIG_HOME" );
29
+    if ( config == NULL ) {
30
+        char* home = getpwuid(getuid())->pw_dir;
31
+        m_usrconfig += home;
32
+        m_usrconfig += "/.config/slop/";
33
+        return;
34
+    }
35
+    m_usrconfig += config;
36
+    m_usrconfig += "/slop/";
37
+    m_sysconfig = INSTALL_PREFIX;
38
+    m_sysconfig += "/share/slop";
39
+}
40
+
41
+std::string slop::Resource::getRealPath( std::string localpath ) {
42
+    if ( !validatePath( m_usrconfig + localpath ) ) {
43
+        if ( !validatePath( m_sysconfig + localpath ) ) {
44
+            fprintf( stderr, "Failed to find directory %s in %s or %s...\n", localpath.c_str(), m_usrconfig.c_str(), m_sysconfig.c_str() );
45
+        }
46
+        return m_sysconfig + localpath;
47
+    }
48
+    return m_usrconfig + localpath;
49
+}
50
+
51
+bool slop::Resource::validatePath( std::string path ) {
52
+
53
+    struct stat st;
54
+
55
+    const char* dirname = path.c_str();
56
+    if ( stat( dirname, &st ) != 0 ) {
57
+        return false;
58
+    }
59
+    // No read permissions.
60
+    //if ( !(st.st_mode & S_IROTH) &&
61
+         //(st.st_uid != getuid() || !(st.st_mode & S_IRUSR)) &&
62
+         //(st.st_gid != getgid() || !(st.st_mode & S_IRGRP)) ) {
63
+        //return false;
64
+    //}
65
+    // Lookin' good!
66
+    return true;
67
+}
68
+

+ 52
- 0
src/resource.hpp View File

1
+/* resource.hpp: Handles getting resources like textures and stuff.
2
+ *
3
+ * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4
+ *
5
+ * This file is part of Slop.
6
+ *
7
+ * Slop is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * Slop is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with Slop.  If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+#ifndef IS_RESOURCE_H_
22
+#define IS_RESOURCE_H_
23
+
24
+#include <stdlib.h>
25
+#include <cstdio>
26
+#include <string>
27
+#include <unistd.h>
28
+#include <sys/types.h>
29
+#include <sys/param.h>
30
+#include <sys/types.h>
31
+#include <sys/stat.h>
32
+#include <pwd.h>
33
+
34
+namespace slop {
35
+
36
+class Resource {
37
+public:
38
+
39
+                    Resource();
40
+                    ~Resource();
41
+    std::string     getRealPath( std::string localpath );
42
+    bool            validatePath( std::string path );
43
+private:
44
+    std::string     m_usrconfig;
45
+    std::string     m_sysconfig;
46
+};
47
+
48
+}
49
+
50
+extern slop::Resource* resource;
51
+
52
+#endif // IS_RESOURCE_H_