| 1 |
/* |
| 2 |
Copyright (c) 2005-2022 Intel Corporation |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef TBB_examples_fractal_video_H |
| 18 |
#define TBB_examples_fractal_video_H |
| 19 |
|
| 20 |
#include "common/gui/video.hpp" |
| 21 |
|
| 22 |
#include "fractal.hpp" |
| 23 |
|
| 24 |
extern video *v; |
| 25 |
extern bool single; |
| 26 |
|
| 27 |
class fractal_video : public video { |
| 28 |
fractal_group *fg; |
| 29 |
|
| 30 |
private: |
| 31 |
void on_mouse(int x, int y, int key) { |
| 32 |
if (key == 1) { |
| 33 |
if (fg) { |
| 34 |
fg->set_num_frames_at_least(20); |
| 35 |
fg->mouse_click(x, y); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void on_key(int key) { |
| 41 |
switch (key & 0xff) { |
| 42 |
case esc_key: running = false; break; |
| 43 |
|
| 44 |
case 'q': |
| 45 |
if (fg) |
| 46 |
fg->active_fractal_zoom_in(); |
| 47 |
break; |
| 48 |
case 'e': |
| 49 |
if (fg) |
| 50 |
fg->active_fractal_zoom_out(); |
| 51 |
break; |
| 52 |
|
| 53 |
case 'r': |
| 54 |
if (fg) |
| 55 |
fg->active_fractal_quality_inc(); |
| 56 |
break; |
| 57 |
case 'f': |
| 58 |
if (fg) |
| 59 |
fg->active_fractal_quality_dec(); |
| 60 |
break; |
| 61 |
|
| 62 |
case 'w': |
| 63 |
if (fg) |
| 64 |
fg->active_fractal_move_up(); |
| 65 |
break; |
| 66 |
case 'a': |
| 67 |
if (fg) |
| 68 |
fg->active_fractal_move_left(); |
| 69 |
break; |
| 70 |
case 's': |
| 71 |
if (fg) |
| 72 |
fg->active_fractal_move_down(); |
| 73 |
break; |
| 74 |
case 'd': |
| 75 |
if (fg) |
| 76 |
fg->active_fractal_move_right(); |
| 77 |
break; |
| 78 |
} |
| 79 |
if (fg) |
| 80 |
fg->set_num_frames_at_least(20); |
| 81 |
} |
| 82 |
|
| 83 |
void on_process() { |
| 84 |
if (fg) { |
| 85 |
fg->run(!single); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
public: |
| 90 |
fractal_video() : fg(nullptr) { |
| 91 |
title = "oneTBB: Fractal Example"; |
| 92 |
v = this; |
| 93 |
} |
| 94 |
|
| 95 |
void set_fractal_group(fractal_group &_fg) { |
| 96 |
fg = &_fg; |
| 97 |
} |
| 98 |
}; |
| 99 |
|
| 100 |
#endif /* TBB_examples_fractal_video_H */ |