7b340d6c6d38e38cf4f7ad6fa27e7a2825364421
[platform/upstream/tbb.git] / examples / task_arena / fractal / fractal_video.h
1 /*
2     Copyright (c) 2005-2019 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 FRACTAL_VIDEO_H_
18 #define FRACTAL_VIDEO_H_
19
20 #include "../../common/gui/video.h"
21 #include "fractal.h"
22
23 extern video *v;
24 extern bool single;
25
26 class fractal_video : public video
27 {
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:
43                 running = false; break;
44             case ' ': // space
45                 if( fg ) fg->switch_priorities(); break;
46
47             case 'q':
48                 if( fg ) fg->active_fractal_zoom_in(); break;
49             case 'e':
50                 if( fg ) fg->active_fractal_zoom_out(); break;
51
52             case 'r':
53                 if( fg ) fg->active_fractal_quality_inc(); break;
54             case 'f':
55                 if( fg ) fg->active_fractal_quality_dec(); break;
56
57             case 'w':
58                 if( fg ) fg->active_fractal_move_up(); break;
59             case 'a':
60                 if( fg ) fg->active_fractal_move_left(); break;
61             case 's':
62                 if( fg ) fg->active_fractal_move_down(); break;
63             case 'd':
64                 if( fg ) fg->active_fractal_move_right(); break;
65         }
66         if( fg ) fg->set_num_frames_at_least(20);
67     }
68
69     void on_process() {
70         if ( fg ) {
71             fg->run( !single );
72         }
73     }
74
75 public:
76     fractal_video() :fg(0) {
77         title = "Dynamic Priorities in TBB: Fractal Example";
78         v = this;
79     }
80
81     void set_fractal_group( fractal_group &_fg ) {
82         fg = &_fg;
83     }
84 };
85
86 #endif /* FRACTAL_VIDEO_H_ */