~compiz-team/compiz/0.9.12

« back to all changes in this revision

Viewing changes to plugins/staticswitcher/src/staticswitcher.cpp

  • Committer: Sam Spilsbury
  • Date: 2012-08-22 10:07:45 UTC
  • mfrom: (3201.2.177 gles2)
  • mto: (3248.1.29 compiz)
  • mto: This revision was merged to the branch mainline in revision 3451.
  • Revision ID: sam.spilsbury@canonical.com-20120822100745-j5bofdehkq79wcvq
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
793
793
}
794
794
 
795
795
void
796
 
StaticSwitchScreen::paintRect (CompRect &box,
 
796
StaticSwitchScreen::paintRect (const GLMatrix &transform,
 
797
                               CompRect       &box,
797
798
                               int offset,
798
799
                               unsigned short *color,
799
 
                               int opacity)
 
800
                               unsigned short opacity)
800
801
{
801
 
    glColor4us (color[0], color[1], color[2], color[3] * opacity / 100);
802
 
    glBegin (GL_LINE_LOOP);
803
 
    glVertex2i (box.x1 () + offset, box.y1 () + offset);
804
 
    glVertex2i (box.x2 () - offset, box.y1 () + offset);
805
 
    glVertex2i (box.x2 () - offset, box.y2 () - offset);
806
 
    glVertex2i (box.x1 () + offset, box.y2 () - offset);
807
 
    glEnd ();
 
802
    GLushort colorData[4] = {
 
803
        color[0],
 
804
        color[1],
 
805
        color[2],
 
806
        static_cast <GLushort> (color[3] * opacity / 100)
 
807
    };
 
808
 
 
809
    GLfloat vertexData[12] = {
 
810
        static_cast <GLfloat> (box.x1 () + offset), static_cast <GLfloat> (box.y1 () + offset), 0,
 
811
        static_cast <GLfloat> (box.x2 () - offset), static_cast <GLfloat> (box.y1 () + offset), 0,
 
812
        static_cast <GLfloat> (box.x2 () - offset), static_cast <GLfloat> (box.y2 () - offset), 0,
 
813
        static_cast <GLfloat> (box.x1 () + offset), static_cast <GLfloat> (box.y2 () - offset), 0
 
814
    };
 
815
 
 
816
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
817
    streamingBuffer->begin (GL_LINE_LOOP);
 
818
 
 
819
    streamingBuffer->addColors (1, colorData);
 
820
    streamingBuffer->addVertices (4, vertexData);
 
821
 
 
822
    streamingBuffer->end ();
 
823
    streamingBuffer->render (transform);
808
824
}
809
825
 
810
826
bool
874
890
 
875
891
            sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
876
892
 
877
 
            glPushMatrix ();
878
 
            glLoadMatrixf (sTransform.getMatrix ());
879
 
 
880
893
            if (mode == HighlightModeShowRectangle)
881
894
            {
882
895
                CompWindow *w;
891
904
                    if (getPaintRectangle (w, box, &opacity))
892
905
                    {
893
906
                        unsigned short *color;
894
 
                        GLushort       r, g, b, a;
 
907
                        GLushort        colorData[4];
 
908
                        GLfloat         vertexData[12];
 
909
                        GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
895
910
 
896
911
                        glEnable (GL_BLEND);
897
912
 
898
913
                        /* fill rectangle */
899
 
                        r = optionGetHighlightColorRed ();
900
 
                        g = optionGetHighlightColorGreen ();
901
 
                        b = optionGetHighlightColorBlue ();
902
 
                        a = optionGetHighlightColorAlpha ();
903
 
                        a = a * opacity / 100;
904
 
 
905
 
                        glColor4us (r, g, b, a);
906
 
                        glRecti (box.x1 (), box.y2 (), box.x2 (), box.y1 ());
 
914
                        colorData[0] = optionGetHighlightColorRed ();
 
915
                        colorData[1] = optionGetHighlightColorGreen ();
 
916
                        colorData[2] = optionGetHighlightColorBlue ();
 
917
                        colorData[3] = optionGetHighlightColorAlpha ();
 
918
                        colorData[3] = colorData[3] * opacity / 100;
 
919
 
 
920
                        vertexData[0]  = box.x1 ();
 
921
                        vertexData[1]  = box.y2 ();
 
922
                        vertexData[2]  = 0.0f;
 
923
                        vertexData[3]  = box.x1 ();
 
924
                        vertexData[4]  = box.y1 ();
 
925
                        vertexData[5]  = 0.0f;
 
926
                        vertexData[6]  = box.x2 ();
 
927
                        vertexData[7]  = box.y2 ();
 
928
                        vertexData[8]  = 0.0f;
 
929
                        vertexData[9]  = box.x2 ();
 
930
                        vertexData[10] = box.y1 ();
 
931
                        vertexData[11] = 0.0f;
 
932
 
 
933
                        streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
934
                        streamingBuffer->addColors (1, colorData);
 
935
                        streamingBuffer->addVertices (4, vertexData);
 
936
                        streamingBuffer->end ();
 
937
                        streamingBuffer->render (sTransform);
907
938
 
908
939
                        /* draw outline */
909
940
                        glLineWidth (1.0);
910
 
                        glDisable (GL_LINE_SMOOTH);
911
941
 
912
942
                        color = optionGetHighlightBorderColor ();
913
 
                        paintRect (box, 0, color, opacity);
914
 
                        paintRect (box, 2, color, opacity);
 
943
                        paintRect (sTransform, box, 0, color, opacity);
 
944
                        paintRect (sTransform, box, 2, color, opacity);
915
945
                        color = optionGetHighlightBorderInlayColor ();
916
 
                        paintRect (box, 1, color, opacity);
 
946
                        paintRect (sTransform, box, 1, color, opacity);
917
947
 
918
 
                        /* clean up */
919
 
                        glColor4usv (defaultColor);
920
948
                        glDisable (GL_BLEND);
921
949
                    }
922
950
                }
934
962
                                          sTransform, infiniteRegion, 0);
935
963
                }
936
964
            }
937
 
 
938
 
            glPopMatrix ();
939
965
        }
940
966
    }
941
967
    else
978
1004
}
979
1005
 
980
1006
void
981
 
StaticSwitchScreen::paintSelectionRect (int          x,
 
1007
StaticSwitchScreen::paintSelectionRect (const GLMatrix &transform,
 
1008
                                        int             x,
982
1009
                                        int          y,
983
1010
                                        float        dx,
984
1011
                                        float        dy,
985
1012
                                        unsigned int opacity)
986
1013
{
987
 
    float color[4], op;
 
1014
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
1015
    GLushort        colorData[4];
 
1016
    GLfloat         vertexData[18];
 
1017
    GLMatrix        sTransform (transform);
 
1018
    float op;
988
1019
    int   w, h;
989
1020
    int   count = windows.size ();
990
1021
 
1003
1034
        op = 1.0;
1004
1035
 
1005
1036
    for (unsigned int i = 0; i < 4; i++)
1006
 
        color[i] = (float)fgColor[i] * opacity * op / 0xffffffff;
 
1037
        colorData[i] = (float)fgColor[i] * opacity * op / 0xffff;
1007
1038
 
1008
 
    glColor4fv (color);
1009
 
    glPushMatrix ();
1010
 
    glTranslatef (x + previewBorder / 2 + (dx * w),
 
1039
    sTransform.translate (x + previewBorder / 2 + (dx * w),
1011
1040
                  y + previewBorder / 2 + (dy * h), 0.0f);
1012
1041
 
1013
 
    glBegin (GL_QUADS);
1014
 
    glVertex2i (-1, -1);
1015
 
    glVertex2i (-1, 1);
1016
 
    glVertex2i (w + 1, 1);
1017
 
    glVertex2i (w + 1, -1);
1018
 
    glVertex2i (-1, h - 1);
1019
 
    glVertex2i (-1, h + 1);
1020
 
    glVertex2i (w + 1, h + 1);
1021
 
    glVertex2i (w + 1, h - 1);
1022
 
    glVertex2i (-1, 1);
1023
 
    glVertex2i (-1, h - 1);
1024
 
    glVertex2i (1, h - 1);
1025
 
    glVertex2i (1, 1);
1026
 
    glVertex2i (w - 1, 1);
1027
 
    glVertex2i (w - 1, h - 1);
1028
 
    glVertex2i (w + 1, h - 1);
1029
 
    glVertex2i (w + 1, 1);
1030
 
    glEnd ();
1031
 
 
1032
 
    glPopMatrix ();
1033
 
    glColor4usv (defaultColor);
 
1042
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1043
 
 
1044
    vertexData[0]  = -1;
 
1045
    vertexData[1]  = -1;
 
1046
    vertexData[2]  = 0;
 
1047
    vertexData[3]  = -1;
 
1048
    vertexData[4]  = 1;
 
1049
    vertexData[5]  = 0;
 
1050
    vertexData[6]  = w + 1;
 
1051
    vertexData[7]  = -1;
 
1052
    vertexData[8]  = 0;
 
1053
    vertexData[9]  = w + 1;
 
1054
    vertexData[10] = 1;
 
1055
    vertexData[11] = 0;
 
1056
 
 
1057
    streamingBuffer->addColors (1, colorData);
 
1058
    streamingBuffer->addVertices (4, vertexData);
 
1059
 
 
1060
    streamingBuffer->end ();
 
1061
    streamingBuffer->render (sTransform);
 
1062
 
 
1063
 
 
1064
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1065
 
 
1066
    vertexData[0]  = -1;
 
1067
    vertexData[1]  = h - 1;
 
1068
    vertexData[2]  = 0;
 
1069
    vertexData[3]  = -1;
 
1070
    vertexData[4]  = h + 1;
 
1071
    vertexData[5]  = 0;
 
1072
    vertexData[6]  = w + 1;
 
1073
    vertexData[7]  = h - 1;
 
1074
    vertexData[8]  = 0;
 
1075
    vertexData[9]  = w + 1;
 
1076
    vertexData[10] = h + 1;
 
1077
    vertexData[11] = 0;
 
1078
 
 
1079
    streamingBuffer->addColors (1, colorData);
 
1080
    streamingBuffer->addVertices (4, vertexData);
 
1081
 
 
1082
    streamingBuffer->end ();
 
1083
    streamingBuffer->render (sTransform);
 
1084
 
 
1085
 
 
1086
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1087
 
 
1088
    vertexData[0]  = -1;
 
1089
    vertexData[1]  = 1;
 
1090
    vertexData[2]  = 0;
 
1091
    vertexData[3]  = -1;
 
1092
    vertexData[4]  = h - 1;
 
1093
    vertexData[5]  = 0;
 
1094
    vertexData[6]  = 1;
 
1095
    vertexData[7]  = 1;
 
1096
    vertexData[8]  = 0;
 
1097
    vertexData[9]  = 1;
 
1098
    vertexData[10] = h - 1;
 
1099
    vertexData[11] = 0;
 
1100
 
 
1101
    streamingBuffer->addColors (1, colorData);
 
1102
    streamingBuffer->addVertices (4, vertexData);
 
1103
 
 
1104
    streamingBuffer->end ();
 
1105
    streamingBuffer->render (sTransform);
 
1106
 
 
1107
 
 
1108
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1109
 
 
1110
    vertexData[0]  = w - 1;
 
1111
    vertexData[1]  = 1;
 
1112
    vertexData[2]  = 0;
 
1113
    vertexData[3]  = w - 1;
 
1114
    vertexData[4]  = h - 1;
 
1115
    vertexData[5]  = 0;
 
1116
    vertexData[6]  = w + 1;
 
1117
    vertexData[7]  = 1;
 
1118
    vertexData[8]  = 0;
 
1119
    vertexData[9]  = w + 1;
 
1120
    vertexData[10] = h - 1;
 
1121
    vertexData[11] = 0;
 
1122
 
 
1123
    streamingBuffer->addColors (1, colorData);
 
1124
    streamingBuffer->addVertices (4, vertexData);
 
1125
 
 
1126
    streamingBuffer->end ();
 
1127
    streamingBuffer->render (sTransform);
 
1128
 
1034
1129
    glDisable (GL_BLEND);
1035
1130
}
1036
1131
 
1157
1252
        if (!(mask & PAINT_WINDOW_TRANSFORMED_MASK) && region.isEmpty ())
1158
1253
            return true;
1159
1254
 
1160
 
        glPushAttrib (GL_SCISSOR_BIT);
1161
 
 
1162
1255
        glEnable (GL_SCISSOR_TEST);
1163
1256
        glScissor (g.x (), 0, g.width (), ::screen->height ());
1164
1257
 
1181
1274
        if (pos > count - 1)
1182
1275
        {
1183
1276
            px = fmod (pos - count, sScreen->xCount);
1184
 
            sScreen->paintSelectionRect (g.x (), g.y (), px, 0.0,
 
1277
            sScreen->paintSelectionRect (transform, g.x (), g.y (), px, 0.0,
1185
1278
                                         gWindow->lastPaintAttrib ().opacity);
1186
1279
 
1187
1280
            px = fmod (pos, sScreen->xCount);
1188
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1281
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1189
1282
                                         px, py,
1190
1283
                                         gWindow->lastPaintAttrib ().opacity);
1191
1284
        }
1192
1285
        if (px > sScreen->xCount - 1)
1193
1286
        {
1194
 
            sScreen->paintSelectionRect (g.x (), g.y (), px, py,
 
1287
            sScreen->paintSelectionRect (transform, g.x (), g.y (), px, py,
1195
1288
                                         gWindow->lastPaintAttrib ().opacity);
1196
1289
 
1197
1290
            py = fmod (py + 1, ceil ((double) count / sScreen->xCount));
1198
1291
            offX = sScreen->getRowXOffset (py);
1199
1292
 
1200
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1293
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1201
1294
                                         px - sScreen->xCount, py,
1202
1295
                                         gWindow->lastPaintAttrib ().opacity);
1203
1296
        }
1204
1297
        else
1205
1298
        {
1206
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1299
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1207
1300
                                         px, py,
1208
1301
                                         gWindow->lastPaintAttrib ().opacity);
1209
1302
        }
1210
1303
        glDisable (GL_SCISSOR_TEST);
1211
 
        glPopAttrib ();
1212
1304
    }
1213
1305
    /* Adjust opacity/brightness/saturation of windows that are
1214
1306
     * not selected