~vanvugt/mir/log-level

« back to all changes in this revision

Viewing changes to examples/fingerpaint.c

  • Committer: Daniel van Vugt
  • Date: 2015-01-23 03:08:41 UTC
  • mfrom: (2201.2.50 development-branch)
  • Revision ID: daniel.van.vugt@canonical.com-20150123030841-zn39cao9um2o9x0p
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
212
212
        static float max_pressure = 1.0f;
213
213
 
214
214
        MirInputEvent const* input_event = mir_event_get_input_event(event);
215
 
        if (mir_input_event_get_type(input_event) != mir_input_event_type_touch)
216
 
            return;
217
 
        MirTouchInputEvent const* tev = mir_input_event_get_touch_input_event(input_event);
218
 
        unsigned touch_count = mir_touch_input_event_get_touch_count(tev);
219
 
        
220
 
        if (touch_count == 1 && mir_touch_input_event_get_touch_action(tev, 0) == mir_touch_input_event_action_up)
 
215
        MirTouchInputEvent const* tev = NULL;
 
216
        MirPointerInputEvent const* pev = NULL;
 
217
        unsigned touch_count = 0;
 
218
        bool ended = false;
 
219
        MirInputEventType type = mir_input_event_get_type(input_event);
 
220
 
 
221
        switch (type)
 
222
        {
 
223
        case mir_input_event_type_touch:
 
224
            tev = mir_input_event_get_touch_input_event(input_event);
 
225
            touch_count = mir_touch_input_event_get_touch_count(tev);
 
226
            ended = touch_count == 1 &&
 
227
                    (mir_touch_input_event_get_touch_action(tev, 0) ==
 
228
                     mir_touch_input_event_action_up);
 
229
            break;
 
230
        case mir_input_event_type_pointer:
 
231
            pev = mir_input_event_get_pointer_input_event(input_event);
 
232
            ended = mir_pointer_input_event_get_action(pev) ==
 
233
                mir_pointer_input_event_action_button_up;
 
234
            touch_count = mir_pointer_input_event_get_button_state(pev,
 
235
                               mir_pointer_input_button_primary) ? 1 : 0;
 
236
        default:
 
237
            break;
 
238
        }
 
239
 
 
240
        if (ended)
221
241
        {
222
242
            base_color = (base_color + max_fingers) %
223
243
                         (sizeof(color)/sizeof(color[0]));
224
244
            max_fingers = 0;
225
245
        }
226
 
        else
 
246
        else if (touch_count)
227
247
        {
228
248
            size_t p;
229
249
 
232
252
 
233
253
            for (p = 0; p < touch_count; p++)
234
254
            {
235
 
                int x = mir_touch_input_event_get_touch_axis_value(tev, p, mir_touch_input_axis_x);
236
 
                int y = mir_touch_input_event_get_touch_axis_value(tev, p, mir_touch_input_axis_y);
237
 
                float size = mir_touch_input_event_get_touch_axis_value(tev, p, mir_touch_input_axis_size);
238
 
                float pressure = mir_touch_input_event_get_touch_axis_value(tev, p, mir_touch_input_axis_pressure);
239
 
 
240
 
                int radius = size * 50.0f
241
 
                             + 1.0f;
 
255
                int x = 0;
 
256
                int y = 0;
 
257
                int radius = 1;
 
258
                float pressure = 1.0f;
 
259
 
 
260
                if (tev != NULL)
 
261
                {
 
262
                    x = mir_touch_input_event_get_touch_axis_value(tev, p,
 
263
                        mir_touch_input_axis_x);
 
264
                    y = mir_touch_input_event_get_touch_axis_value(tev, p,
 
265
                        mir_touch_input_axis_y);
 
266
                    float size = mir_touch_input_event_get_touch_axis_value(
 
267
                        tev, p, mir_touch_input_axis_size);
 
268
                    pressure = mir_touch_input_event_get_touch_axis_value(tev,
 
269
                        p, mir_touch_input_axis_pressure);
 
270
                    radius = size * 50.0f + 1.0f;
 
271
                }
 
272
                else if (pev != NULL)
 
273
                {
 
274
                    x = mir_pointer_input_event_get_axis_value(pev,
 
275
                        mir_pointer_input_axis_x);
 
276
                    y = mir_pointer_input_event_get_axis_value(pev,
 
277
                        mir_pointer_input_axis_y);
 
278
                    pressure = 0.5f;
 
279
                    radius = 5;
 
280
                }
 
281
 
242
282
                size_t c = (base_color + p) %
243
283
                           (sizeof(color)/sizeof(color[0]));
244
284
                Color tone = color[c];