~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/windowmanager/intern/wm_gesture.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "BLI_math.h"
41
41
#include "BLI_scanfill.h"   /* lasso tessellation */
42
42
#include "BLI_utildefines.h"
 
43
#include "BLI_lasso.h"
43
44
 
44
45
#include "BKE_context.h"
45
46
 
231
232
        
232
233
}
233
234
 
234
 
static void draw_filled_lasso(wmGesture *gt)
235
 
{
236
 
        ScanFillContext sf_ctx;
237
 
        ScanFillVert *sf_vert = NULL, *sf_vert_last = NULL, *sf_vert_first = NULL;
238
 
        ScanFillFace *sf_tri;
 
235
struct LassoFillData {
 
236
        unsigned int *px;
 
237
        int width;
 
238
};
 
239
 
 
240
static void draw_filled_lasso_px_cb(int x, int y, void *user_data)
 
241
{
 
242
        struct LassoFillData *data = user_data;
 
243
        unsigned char *col = (unsigned char *)&(data->px[(y * data->width) + x]);
 
244
        col[0] = col[1] = col[2] = 0xff;
 
245
        col[3] = 0x10;
 
246
}
 
247
 
 
248
static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
 
249
{
239
250
        short *lasso = (short *)gt->customdata;
 
251
        const int tot = gt->points;
 
252
        int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__);
240
253
        int i;
241
 
        
242
 
        BLI_scanfill_begin(&sf_ctx);
243
 
        for (i = 0; i < gt->points; i++, lasso += 2) {
244
 
                float co[3];
245
 
 
246
 
                co[0] = (float)lasso[0];
247
 
                co[1] = (float)lasso[1];
248
 
                co[2] = 0.0f;
249
 
 
250
 
                sf_vert = BLI_scanfill_vert_add(&sf_ctx, co);
251
 
                if (sf_vert_last)
252
 
                        /* e = */ /* UNUSED */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
253
 
                sf_vert_last = sf_vert;
254
 
                if (sf_vert_first == NULL) sf_vert_first = sf_vert;
 
254
        rcti rect;
 
255
        rcti rect_win;
 
256
 
 
257
        for (i = 0; i < tot; i++, lasso += 2) {
 
258
                moves[i][0] = lasso[0];
 
259
                moves[i][1] = lasso[1];
255
260
        }
256
 
        
257
 
        /* highly unlikely this will fail, but could crash if (gt->points == 0) */
258
 
        if (sf_vert_first) {
259
 
                const float zvec[3] = {0.0f, 0.0f, 1.0f};
260
 
                BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert);
261
 
                BLI_scanfill_calc_ex(&sf_ctx, BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES, zvec);
262
 
        
 
261
 
 
262
        BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
 
263
 
 
264
        wm_subwindow_getrect(win, gt->swinid, &rect_win);
 
265
        BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
 
266
        BLI_rcti_isect(&rect_win, &rect, &rect);
 
267
        BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
 
268
 
 
269
        /* highly unlikely this will fail, but could crash if (tot == 0) */
 
270
        if (BLI_rcti_is_empty(&rect) == false) {
 
271
                const int w = BLI_rcti_size_x(&rect);
 
272
                const int h = BLI_rcti_size_y(&rect);
 
273
                unsigned int *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__);
 
274
                struct LassoFillData lasso_fill_data = {pixel_buf, w};
 
275
 
 
276
                fill_poly_v2i_n(
 
277
                       rect.xmin, rect.ymin, rect.xmax, rect.ymax,
 
278
                       (const int (*)[2])moves, tot,
 
279
                       draw_filled_lasso_px_cb, &lasso_fill_data);
 
280
 
263
281
                glEnable(GL_BLEND);
264
 
                glColor4f(1.0, 1.0, 1.0, 0.05);
265
 
                glBegin(GL_TRIANGLES);
266
 
                for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) {
267
 
                        glVertex2fv(sf_tri->v1->co);
268
 
                        glVertex2fv(sf_tri->v2->co);
269
 
                        glVertex2fv(sf_tri->v3->co);
270
 
                }
271
 
                glEnd();
 
282
                // glColor4f(1.0, 1.0, 1.0, 0.05);
 
283
 
 
284
                glRasterPos2f(rect.xmin, rect.ymin);
 
285
 
 
286
                glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf);
 
287
 
272
288
                glDisable(GL_BLEND);
273
 
        
274
 
                BLI_scanfill_end(&sf_ctx);
 
289
                MEM_freeN(pixel_buf);
275
290
        }
 
291
 
 
292
        MEM_freeN(moves);
276
293
}
277
294
 
278
 
static void wm_gesture_draw_lasso(wmGesture *gt)
 
295
 
 
296
static void wm_gesture_draw_lasso(wmWindow *win, wmGesture *gt)
279
297
{
280
298
        short *lasso = (short *)gt->customdata;
281
299
        int i;
282
300
 
283
 
        draw_filled_lasso(gt);
 
301
        draw_filled_lasso(win, gt);
284
302
        
285
303
        glEnable(GL_LINE_STIPPLE);
286
304
        glColor3ub(96, 96, 96);
347
365
                                wm_gesture_draw_cross(win, gt);
348
366
                }
349
367
                else if (gt->type == WM_GESTURE_LINES)
350
 
                        wm_gesture_draw_lasso(gt);
 
368
                        wm_gesture_draw_lasso(win, gt);
351
369
                else if (gt->type == WM_GESTURE_LASSO)
352
 
                        wm_gesture_draw_lasso(gt);
 
370
                        wm_gesture_draw_lasso(win, gt);
353
371
                else if (gt->type == WM_GESTURE_STRAIGHTLINE)
354
372
                        wm_gesture_draw_line(gt);
355
373
        }