~mar-kolya/compiz/fix-for-1158267

« back to all changes in this revision

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

Annotate plugin, code cleanup:

Use prefix instead of postfix increment.
Declaration and assignment of local variables in one line.
Removed redundant brackets.
Added and removed newlines if appropriate.
Fixed indentation.

Annotate plugin, fixes:

Use GL_LINE_LOOP to draw the rectangle outline as glRecti is not supported on GLES.
Simplified the coordinate calculation as the offset is not really needed here.

Approved by PS Jenkins bot, Sam Spilsbury.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#define DEG2RAD (M_PI / 180.0f)
31
31
 
32
32
void
33
 
AnnoScreen::cairoClear (cairo_t    *cr)
 
33
AnnoScreen::cairoClear (cairo_t *cr)
34
34
{
35
35
    cairo_save (cr);
36
36
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
47
47
    {
48
48
        XRenderPictFormat *format;
49
49
        Screen            *xScreen;
50
 
        int               w, h;
51
50
 
52
51
        xScreen = ScreenOfDisplay (screen->dpy (), screen->screenNum ());
53
52
 
54
 
        w = screen->width ();
55
 
        h = screen->height ();
 
53
        int w = screen->width ();
 
54
        int h = screen->height ();
56
55
 
57
56
        format = XRenderFindStandardFormat (screen->dpy (),
58
57
                                            PictStandardARGB32);
75
74
        damage = XDamageCreate (screen->dpy (), pixmap,
76
75
                                XDamageReportBoundingBox);
77
76
 
78
 
        surface =
79
 
            cairo_xlib_surface_create_with_xrender_format (screen->dpy (),
80
 
                                                           pixmap, xScreen,
81
 
                                                           format, w, h);
 
77
        surface = cairo_xlib_surface_create_with_xrender_format (screen->dpy (),
 
78
                                                                 pixmap, xScreen,
 
79
                                                                 format, w, h);
82
80
 
83
81
        cairo = cairo_create (surface);
84
82
        
91
89
                                                     cairoBuffer.c_str (),
92
90
                                                     CAIRO_FORMAT_ARGB32,
93
91
                                                     w, h, stride);
94
 
            
 
92
 
95
93
            if (cr && raw_source)
96
 
            {         
 
94
            {
97
95
                cairo_set_source_surface (cr, raw_source, 0, 0);
98
96
                cairo_paint (cr);
99
97
                
102
100
                cairoBuffer.clear ();
103
101
            }
104
102
        }
105
 
        else        
 
103
        else
106
104
            cairoClear (cairo);
107
105
    }
108
106
 
110
108
}
111
109
 
112
110
void
113
 
AnnoScreen::setSourceColor (cairo_t        *cr,
 
111
AnnoScreen::setSourceColor (cairo_t        *cr,
114
112
                            unsigned short *color)
115
113
{
116
114
    cairo_set_source_rgba (cr,
121
119
}
122
120
 
123
121
void
124
 
AnnoScreen::drawEllipse (double         xc,
125
 
                         double         yc,
126
 
                         double         radiusX,
127
 
                         double         radiusY,
128
 
                         unsigned short *fillColor,
129
 
                         unsigned short *strokeColor,
130
 
                         double         strokeWidth)
 
122
AnnoScreen::drawEllipse (double         xc,
 
123
                         double         yc,
 
124
                         double         radiusX,
 
125
                         double         radiusY,
 
126
                         unsigned short *fillColor,
 
127
                         unsigned short *strokeColor,
 
128
                         double         strokeWidth)
131
129
{
132
 
    cairo_t *cr;
 
130
    cairo_t *cr = cairoContext ();
133
131
 
134
 
    cr = cairoContext ();
135
132
    if (cr)
136
133
    {
137
134
        setSourceColor (cr, fillColor);
138
135
        cairo_save (cr);
139
136
        cairo_translate (cr, xc, yc);
 
137
 
140
138
        if (radiusX > radiusY)
141
139
        {
142
140
            cairo_scale (cr, 1.0, radiusY/radiusX);
147
145
            cairo_scale (cr, radiusX/radiusY, 1.0);
148
146
            cairo_arc (cr, 0, 0, radiusY, 0, 2 * M_PI);
149
147
        }
 
148
 
150
149
        cairo_restore (cr);
151
150
        cairo_fill_preserve (cr);
152
151
        cairo_set_line_width (cr, strokeWidth);
158
157
}
159
158
 
160
159
void
161
 
AnnoScreen::drawRectangle (double         x,
162
 
                           double         y,
163
 
                           double         w,
164
 
                           double         h,
 
160
AnnoScreen::drawRectangle (double         x,
 
161
                           double         y,
 
162
                           double         w,
 
163
                           double         h,
165
164
                           unsigned short *fillColor,
166
165
                           unsigned short *strokeColor,
167
 
                           double         strokeWidth)
 
166
                           double         strokeWidth)
168
167
{
169
 
    cairo_t *cr;
 
168
    cairo_t *cr = cairoContext ();
170
169
 
171
 
    cr = cairoContext ();
172
170
    if (cr)
173
171
    {
174
172
        double  ex1, ey1, ex2, ey2;
186
184
}
187
185
 
188
186
void
189
 
AnnoScreen::drawLine (double         x1,
190
 
                      double         y1,
191
 
                      double         x2,
192
 
                      double         y2,
193
 
                      double         width,
 
187
AnnoScreen::drawLine (double         x1,
 
188
                      double         y1,
 
189
                      double         x2,
 
190
                      double         y2,
 
191
                      double         width,
194
192
                      unsigned short *color)
195
193
{
196
 
    cairo_t *cr;
 
194
    cairo_t *cr = cairoContext ();
197
195
 
198
 
    cr = cairoContext ();
199
196
    if (cr)
200
197
    {
201
198
        double ex1, ey1, ex2, ey2;
213
210
}
214
211
 
215
212
void
216
 
AnnoScreen::drawText (double                         x,
217
 
                      double                         y,
218
 
                      const char                     *text,
219
 
                      const char                     *fontFamily,
220
 
                      double                         fontSize,
221
 
                      cairo_font_slant_t             fontSlant,
222
 
                      cairo_font_weight_t            fontWeight,
223
 
                      unsigned short                 *fillColor,
224
 
                      unsigned short                 *strokeColor,
225
 
                      double                         strokeWidth)
 
213
AnnoScreen::drawText (double              x,
 
214
                      double              y,
 
215
                      const char          *text,
 
216
                      const char          *fontFamily,
 
217
                      double              fontSize,
 
218
                      cairo_font_slant_t  fontSlant,
 
219
                      cairo_font_weight_t fontWeight,
 
220
                      unsigned short      *fillColor,
 
221
                      unsigned short      *strokeColor,
 
222
                      double              strokeWidth)
226
223
{
227
224
    REGION reg;
228
 
    cairo_t *cr;
 
225
    cairo_t *cr = cairoContext ();
229
226
 
230
 
    cr = cairoContext ();
231
227
    if (cr)
232
228
    {
233
229
        cairo_text_extents_t extents;
297
293
bool
298
294
AnnoScreen::draw (CompAction         *action,
299
295
                  CompAction::State  state,
300
 
                  CompOption::Vector& options)
 
296
                  CompOption::Vector &options)
301
297
{
302
 
    cairo_t *cr;
 
298
    cairo_t *cr = cairoContext ();
303
299
 
304
 
    cr = cairoContext ();
305
300
    if (cr)
306
301
    {
307
 
        const char      *tool;
308
 
        unsigned short  *fillColor, *strokeColor;
309
 
        double          strokeWidth;
310
 
 
311
 
        tool =
312
 
         CompOption::getStringOptionNamed (options, "tool", "line").c_str ();
313
 
 
314
 
        cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
315
 
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
316
 
 
317
 
        fillColor = optionGetFillColor ();
318
 
        fillColor = CompOption::getColorOptionNamed (options, "fill_color",
319
 
                                         fillColor);
320
 
 
321
 
        strokeColor = optionGetStrokeColor ();
322
 
        strokeColor = CompOption::getColorOptionNamed (options,
323
 
                                           "stroke_color", strokeColor);
324
 
 
325
 
        strokeWidth = optionGetStrokeWidth ();
326
 
        strokeWidth = CompOption::getFloatOptionNamed (options, "stroke_width",
327
 
                                           strokeWidth);
328
 
 
329
 
        if (strcasecmp (tool, "rectangle") == 0)
330
 
        {
331
 
            double x, y, w, h;
332
 
 
333
 
            x = CompOption::getFloatOptionNamed (options, "x", 0);
334
 
            y = CompOption::getFloatOptionNamed (options, "y", 0);
335
 
            w = CompOption::getFloatOptionNamed (options, "w", 100);
336
 
            h = CompOption::getFloatOptionNamed (options, "h", 100);
 
302
        const char      *tool;
 
303
        unsigned short  *fillColor, *strokeColor;
 
304
 
 
305
        tool = CompOption::getStringOptionNamed (options, "tool", "line").c_str ();
 
306
 
 
307
        cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
308
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
 
309
 
 
310
        fillColor = optionGetFillColor ();
 
311
        fillColor = CompOption::getColorOptionNamed (options, "fill_color",
 
312
                                                     fillColor);
 
313
 
 
314
        strokeColor = optionGetStrokeColor ();
 
315
        strokeColor = CompOption::getColorOptionNamed (options,
 
316
                                                       "stroke_color", strokeColor);
 
317
 
 
318
        double strokeWidth = optionGetStrokeWidth ();
 
319
        strokeWidth = CompOption::getFloatOptionNamed (options, "stroke_width",
 
320
                                                       strokeWidth);
 
321
 
 
322
        if (strcasecmp (tool, "rectangle") == 0)
 
323
        {
 
324
            double x = CompOption::getFloatOptionNamed (options, "x", 0);
 
325
            double y = CompOption::getFloatOptionNamed (options, "y", 0);
 
326
            double w = CompOption::getFloatOptionNamed (options, "w", 100);
 
327
            double h = CompOption::getFloatOptionNamed (options, "h", 100);
337
328
 
338
329
            drawRectangle (x, y, w, h, fillColor, strokeColor,
339
 
                               strokeWidth);
340
 
        }
341
 
        else if (strcasecmp (tool, "ellipse") == 0)
342
 
        {
343
 
            double xc, yc, xr, yr;
344
 
 
345
 
            xc = CompOption::getFloatOptionNamed (options, "xc", 0);
346
 
            yc = CompOption::getFloatOptionNamed (options, "yc", 0);
347
 
            xr = CompOption::getFloatOptionNamed (options, "radiusX", 100);
348
 
            yr = CompOption::getFloatOptionNamed (options, "radiusY", 100);
 
330
                           strokeWidth);
 
331
        }
 
332
        else if (strcasecmp (tool, "ellipse") == 0)
 
333
        {
 
334
            double xc = CompOption::getFloatOptionNamed (options, "xc", 0);
 
335
            double yc = CompOption::getFloatOptionNamed (options, "yc", 0);
 
336
            double xr = CompOption::getFloatOptionNamed (options, "radiusX", 100);
 
337
            double yr = CompOption::getFloatOptionNamed (options, "radiusY", 100);
349
338
 
350
339
            drawEllipse (xc, yc, xr, yr, fillColor, strokeColor,
351
 
                            strokeWidth);
352
 
        }
353
 
        else if (strcasecmp (tool, "line") == 0)
354
 
        {
355
 
            double x1, y1, x2, y2;
356
 
 
357
 
            x1 = CompOption::getFloatOptionNamed (options, "x1", 0);
358
 
            y1 = CompOption::getFloatOptionNamed (options, "y1", 0);
359
 
            x2 = CompOption::getFloatOptionNamed (options, "x2", 100);
360
 
            y2 = CompOption::getFloatOptionNamed (options, "y2", 100);
 
340
                         strokeWidth);
 
341
        }
 
342
        else if (strcasecmp (tool, "line") == 0)
 
343
        {
 
344
            double x1 = CompOption::getFloatOptionNamed (options, "x1", 0);
 
345
            double y1 = CompOption::getFloatOptionNamed (options, "y1", 0);
 
346
            double x2 = CompOption::getFloatOptionNamed (options, "x2", 100);
 
347
            double y2 = CompOption::getFloatOptionNamed (options, "y2", 100);
361
348
 
362
349
            drawLine (x1, y1, x2, y2, strokeWidth, fillColor);
363
 
        }
364
 
        else if (strcasecmp (tool, "text") == 0)
365
 
        {
366
 
            double           x, y, size;
367
 
            const char       *text, *family;
368
 
            cairo_font_slant_t slant;
 
350
        }
 
351
        else if (strcasecmp (tool, "text") == 0)
 
352
        {
 
353
            const char          *text, *family;
 
354
            cairo_font_slant_t  slant;
369
355
            cairo_font_weight_t weight;
370
 
            const char       *str;
371
 
 
372
 
            str =
373
 
               CompOption::getStringOptionNamed (options, "slant", "").c_str ();
 
356
            const char          *str;
 
357
 
 
358
            str = CompOption::getStringOptionNamed (options, "slant", "").c_str ();
 
359
 
374
360
            if (strcasecmp (str, "oblique") == 0)
375
 
                slant = CAIRO_FONT_SLANT_OBLIQUE;
 
361
                slant = CAIRO_FONT_SLANT_OBLIQUE;
376
362
            else if (strcasecmp (str, "italic") == 0)
377
 
                slant = CAIRO_FONT_SLANT_ITALIC;
 
363
                slant = CAIRO_FONT_SLANT_ITALIC;
378
364
            else
379
 
                slant = CAIRO_FONT_SLANT_NORMAL;
380
 
 
381
 
            str = 
382
 
              CompOption::getStringOptionNamed (options, "weight", "").c_str ();
 
365
                slant = CAIRO_FONT_SLANT_NORMAL;
 
366
 
 
367
            str = CompOption::getStringOptionNamed (options, "weight", "").c_str ();
 
368
 
383
369
            if (strcasecmp (str, "bold") == 0)
384
 
                weight = CAIRO_FONT_WEIGHT_BOLD;
 
370
                weight = CAIRO_FONT_WEIGHT_BOLD;
385
371
            else
386
 
                weight = CAIRO_FONT_WEIGHT_NORMAL;
387
 
 
388
 
            x      = CompOption::getFloatOptionNamed (options, "x", 0);
389
 
            y      = CompOption::getFloatOptionNamed (options, "y", 0);
390
 
            text   = 
391
 
                CompOption::getStringOptionNamed (options, "text", "").c_str ();
 
372
                weight = CAIRO_FONT_WEIGHT_NORMAL;
 
373
 
 
374
            double x = CompOption::getFloatOptionNamed (options, "x", 0);
 
375
            double y = CompOption::getFloatOptionNamed (options, "y", 0);
 
376
 
 
377
            text = CompOption::getStringOptionNamed (options, "text", "").c_str ();
 
378
 
392
379
            family = CompOption::getStringOptionNamed (options, "family",
393
 
                                           "Sans").c_str ();
394
 
            size   = CompOption::getFloatOptionNamed (options, "size", 36.0);
 
380
                                                       "Sans").c_str ();
 
381
 
 
382
            double size = CompOption::getFloatOptionNamed (options, "size", 36.0);
395
383
 
396
384
            drawText (x, y, text, family, size, slant, weight,
397
 
                          fillColor, strokeColor, strokeWidth);
398
 
        }
 
385
                      fillColor, strokeColor, strokeWidth);
 
386
        }
399
387
    }
400
388
 
401
389
    return true;
408
396
{
409
397
    if (grabIndex)
410
398
    {
411
 
        screen->removeGrab (grabIndex, NULL);
412
 
        grabIndex = 0;
 
399
        screen->removeGrab (grabIndex, NULL);
 
400
        grabIndex = 0;
413
401
    }
414
402
 
415
403
    action->setState (action->state () & ~(CompAction::StateTermKey |
456
444
bool
457
445
AnnoScreen::initiateErase (CompAction         *action,
458
446
                           CompAction::State  state,
459
 
                           CompOption::Vector& options)
 
447
                           CompOption::Vector &options)
460
448
{
461
449
    if (screen->otherGrabExist (NULL))
462
 
        return false;
 
450
        return false;
463
451
 
464
452
    if (!grabIndex)
465
 
        grabIndex = screen->pushGrab (None, "annotate");
 
453
        grabIndex = screen->pushGrab (None, "annotate");
466
454
 
467
455
    if (state & CompAction::StateInitButton)
468
 
        action->setState (action->state () | CompAction::StateTermButton);
 
456
        action->setState (action->state () | CompAction::StateTermButton);
469
457
 
470
458
    if (state & CompAction::StateInitKey)
471
 
        action->setState (action->state () | CompAction::StateTermKey);
 
459
        action->setState (action->state () | CompAction::StateTermKey);
472
460
 
473
461
    annoLastPointerX = pointerX;
474
462
    annoLastPointerY = pointerY;
483
471
bool
484
472
AnnoScreen::initiateFreeDraw (CompAction         *action,
485
473
                              CompAction::State  state,
486
 
                              CompOption::Vector& options)
 
474
                              CompOption::Vector &options)
487
475
{
488
476
    if (screen->otherGrabExist (NULL))
489
 
        return false;
 
477
        return false;
490
478
 
491
479
    if (!grabIndex)
492
 
        grabIndex = screen->pushGrab (None, "annotate");
 
480
        grabIndex = screen->pushGrab (None, "annotate");
493
481
 
494
482
    if (state & CompAction::StateInitButton)
495
 
        action->setState (action->state () | CompAction::StateTermButton);
 
483
        action->setState (action->state () | CompAction::StateTermButton);
496
484
 
497
485
    if (state & CompAction::StateInitKey)
498
 
        action->setState (action->state () | CompAction::StateTermKey);
 
486
        action->setState (action->state () | CompAction::StateTermKey);
499
487
 
500
488
    annoLastPointerX = pointerX;
501
489
    annoLastPointerY = pointerY;
510
498
bool
511
499
AnnoScreen::initiateLine (CompAction         *action,
512
500
                          CompAction::State  state,
513
 
                          CompOption::Vector& options)
 
501
                          CompOption::Vector &options)
514
502
{
515
503
    if (screen->otherGrabExist (NULL))
516
 
        return false;
 
504
        return false;
517
505
 
518
506
    if (!grabIndex)
519
 
        grabIndex = screen->pushGrab (None, "annotate");
 
507
        grabIndex = screen->pushGrab (None, "annotate");
520
508
 
521
509
    if (state & CompAction::StateInitButton)
522
 
        action->setState (action->state () | CompAction::StateTermButton);
 
510
        action->setState (action->state () | CompAction::StateTermButton);
523
511
 
524
512
    if (state & CompAction::StateInitKey)
525
 
        action->setState (action->state () | CompAction::StateTermKey);
 
513
        action->setState (action->state () | CompAction::StateTermKey);
526
514
 
527
515
    initialPointerX = pointerX;
528
516
    initialPointerY = pointerY;
537
525
bool
538
526
AnnoScreen::initiateRectangle (CompAction         *action,
539
527
                               CompAction::State  state,
540
 
                               CompOption::Vector& options)
 
528
                               CompOption::Vector &options)
541
529
{
542
530
    if (screen->otherGrabExist (NULL))
543
 
        return false;
 
531
        return false;
544
532
 
545
533
    if (!grabIndex)
546
 
        grabIndex = screen->pushGrab (None, "annotate");
 
534
        grabIndex = screen->pushGrab (None, "annotate");
547
535
 
548
536
    if (state & CompAction::StateInitButton)
549
 
        action->setState (action->state () | CompAction::StateTermButton);
 
537
        action->setState (action->state () | CompAction::StateTermButton);
550
538
 
551
539
    if (state & CompAction::StateInitKey)
552
 
        action->setState (action->state () | CompAction::StateTermKey);
 
540
        action->setState (action->state () | CompAction::StateTermKey);
553
541
 
554
542
    drawMode = RectangleMode;
555
543
 
566
554
bool
567
555
AnnoScreen::initiateEllipse (CompAction         *action,
568
556
                             CompAction::State  state,
569
 
                             CompOption::Vector& options)
 
557
                             CompOption::Vector &options)
570
558
{
571
559
    if (screen->otherGrabExist (NULL))
572
 
        return false;
 
560
        return false;
573
561
 
574
562
    if (!grabIndex)
575
 
        grabIndex = screen->pushGrab (None, "annotate");
 
563
        grabIndex = screen->pushGrab (None, "annotate");
576
564
 
577
565
    if (state & CompAction::StateInitButton)
578
 
        action->setState (action->state () | CompAction::StateTermButton);
 
566
        action->setState (action->state () | CompAction::StateTermButton);
579
567
 
580
568
    if (state & CompAction::StateInitKey)
581
 
        action->setState (action->state () | CompAction::StateTermKey);
 
569
        action->setState (action->state () | CompAction::StateTermKey);
582
570
 
583
571
    drawMode = EllipseMode;
584
572
 
596
584
bool
597
585
AnnoScreen::clear (CompAction         *action,
598
586
                   CompAction::State  state,
599
 
                   CompOption::Vector& options)
 
587
                   CompOption::Vector &options)
600
588
{
601
589
    if (content)
602
590
    {
603
 
        cairo_t *cr;
 
591
        cairo_t *cr = cairoContext ();
604
592
 
605
 
        cr = cairoContext ();
606
 
        if (cr)
 
593
        if (cr)
607
594
            cairoClear (cairo);
608
595
 
609
 
        cScreen->damageScreen ();
 
596
        cScreen->damageScreen ();
610
597
 
611
598
        /* We don't need to refresh the screen or handle events anymore */
612
599
        screen->handleEventSetEnabled (this, false);
618
605
 
619
606
bool
620
607
AnnoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
621
 
                           const GLMatrix            &transform,
622
 
                           const CompRegion          &region,
623
 
                           CompOutput                *output,
624
 
                           unsigned int              mask)
 
608
                           const GLMatrix            &transform,
 
609
                           const CompRegion          &region,
 
610
                           CompOutput                *output,
 
611
                           unsigned int              mask)
625
612
{
626
 
    bool status;
627
 
 
628
 
    status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
 
613
    bool status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
629
614
 
630
615
    if (status)
631
616
    {
632
617
        GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
633
618
        GLfloat         vertexData[18];
634
619
        GLfloat         textureData[12];
635
 
        CompRect        rect;
636
 
        GLMatrix        sTransform = transform;
637
 
        int             numRect;
638
 
        int             pos = 0;
639
 
        float           offset;
640
 
        int             angle;
 
620
        CompRect        rect;
 
621
        GLMatrix        sTransform = transform;
 
622
        int             numRect;
 
623
        int             pos = 0;
 
624
        int             angle;
641
625
 
642
 
        offset = optionGetStrokeWidth () / 2;
 
626
        float offset = optionGetStrokeWidth () / 2;
643
627
 
644
628
        /* This replaced prepareXCoords (s, output, -DEFAULT_Z_CAMERA) */
645
629
        sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
650
634
        {
651
635
            foreach (GLTexture *tex, texture)
652
636
            {
653
 
                CompRect::vector rect = region.rects ();
654
 
                numRect = region.rects ().size ();
655
 
 
656
 
                tex->enable (GLTexture::Fast);
657
 
 
658
 
                streamingBuffer->begin (GL_TRIANGLES);
659
 
 
660
 
                while (numRect--)
661
 
                {
 
637
                CompRect::vector rect = region.rects ();
 
638
                numRect = region.rects ().size ();
 
639
 
 
640
                tex->enable (GLTexture::Fast);
 
641
 
 
642
                streamingBuffer->begin (GL_TRIANGLES);
 
643
 
 
644
                while (numRect--)
 
645
                {
662
646
                    GLfloat tx1 = COMP_TEX_COORD_X (tex->matrix (),
663
 
                                                       rect.at (pos).x1 ());
 
647
                                                    rect.at (pos).x1 ());
664
648
                    GLfloat tx2 = COMP_TEX_COORD_X (tex->matrix (),
665
 
                                                       rect.at (pos).x2 ());
 
649
                                                    rect.at (pos).x2 ());
666
650
                    GLfloat ty1 = COMP_TEX_COORD_Y (tex->matrix (),
667
 
                                                       rect.at (pos).y1 ());
 
651
                                                    rect.at (pos).y1 ());
668
652
                    GLfloat ty2 = COMP_TEX_COORD_Y (tex->matrix (),
669
 
                                                       rect.at (pos).y2 ());
 
653
                                                    rect.at (pos).y2 ());
670
654
 
671
655
                    vertexData[0]  = rect.at (pos).x1 ();
672
656
                    vertexData[1]  = rect.at (pos).y1 ();
709
693
 
710
694
                    streamingBuffer->addVertices (6, vertexData);
711
695
                    streamingBuffer->addTexCoords (0, 6, textureData);
712
 
                    pos++;
713
 
                }
 
696
                    ++pos;
 
697
                }
714
698
 
715
699
                streamingBuffer->end ();
716
700
                streamingBuffer->render (sTransform);
717
701
 
718
 
                tex->disable ();
 
702
                tex->disable ();
719
703
            }
720
704
        }
721
705
 
764
748
            streamingBuffer->render (sTransform);
765
749
 
766
750
            /* draw rectangle outline */
767
 
/*          streamingBuffer->begin ();
 
751
            vertexData[0]  = rectangle.x1 ();
 
752
            vertexData[1]  = rectangle.y1 ();
 
753
            vertexData[2]  = 0.0f;
 
754
            vertexData[3]  = rectangle.x2 ();
 
755
            vertexData[4]  = rectangle.y1 ();
 
756
            vertexData[5]  = 0.0f;
 
757
            vertexData[6]  = rectangle.x2 ();
 
758
            vertexData[7]  = rectangle.y2 ();
 
759
            vertexData[8]  = 0.0f;
 
760
            vertexData[9]  = rectangle.x1 ();
 
761
            vertexData[10] = rectangle.y2 ();
 
762
            vertexData[11] = 0.0f;
 
763
 
 
764
            glLineWidth (optionGetStrokeWidth ());
 
765
 
 
766
            streamingBuffer->begin (GL_LINE_LOOP);
768
767
 
769
768
            streamingBuffer->addColors (1, optionGetStrokeColor ());
770
 
 
771
 
            vertexData[0] = rectangle.x1 () - offset;
772
 
            vertexData[3] = rectangle.x1 () - offset;
773
769
            streamingBuffer->addVertices (4, vertexData);
774
770
 
775
 
            glRecti (rectangle.x2 () - offset, rectangle.y2 (),
776
 
                     rectangle.x2 () + offset, rectangle.y1 ());
777
 
            glRecti (rectangle.x1 () - offset, rectangle.y1 () + offset,
778
 
                     rectangle.x2 () + offset, rectangle.y1 () - offset);
779
 
            glRecti (rectangle.x1 () - offset, rectangle.y2 () + offset,
780
 
                     rectangle.x2 () + offset, rectangle.y2 () - offset);*/
 
771
            streamingBuffer->end ();
 
772
            streamingBuffer->render (sTransform);
 
773
 
781
774
            break;
782
775
 
783
776
        case EllipseMode:
854
847
}
855
848
 
856
849
void
857
 
AnnoScreen::handleMotionEvent (int        xRoot,
858
 
                               int        yRoot)
 
850
AnnoScreen::handleMotionEvent (int xRoot,
 
851
                               int yRoot)
859
852
{
860
853
    CompRect damageRect;
861
854
 
862
855
    if (grabIndex)
863
856
    {
864
857
        static unsigned short clearColor[] = { 0, 0, 0, 0 };
 
858
 
865
859
        switch (drawMode)
866
860
        {
867
861
        case EraseMode:
931
925
            break;
932
926
        }
933
927
 
934
 
        if (cScreen && (drawMode == LineMode ||
935
 
                        drawMode == RectangleMode ||
 
928
        if (cScreen && (drawMode == LineMode        ||
 
929
                        drawMode == RectangleMode   ||
936
930
                        drawMode == EllipseMode))
937
931
        {
938
932
            /* Add border width to the damage region */
959
953
}
960
954
 
961
955
void
962
 
AnnoScreen::handleEvent (XEvent      *event)
 
956
AnnoScreen::handleEvent (XEvent *event)
963
957
{
964
958
    switch (event->type)
965
959
    {
968
962
    case LeaveNotify:
969
963
        handleMotionEvent (pointerX, pointerY);
970
964
        break;
 
965
 
971
966
    default:
972
967
        if (event->type == cScreen->damageEvent () + XDamageNotify)
973
968
        {
974
969
            XDamageNotifyEvent *de = (XDamageNotifyEvent *) event;
 
970
 
975
971
            if (pixmap == de->drawable)
976
972
                cScreen->damageRegion (CompRegion (CompRect (de->area)));
977
973
        }
 
974
 
978
975
        break;
979
976
    }
980
977