~ubuntu-branches/ubuntu/maverick/grafx2/maverick

« back to all changes in this revision

Viewing changes to input.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2009-09-21 14:24:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090921142419-lhpqq102buior0ol
Tags: 2.1-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
void Handle_window_resize(SDL_ResizeEvent event);
32
32
void Handle_window_exit(SDL_QuitEvent event);
33
33
 
 
34
// public Globals (available as extern)
 
35
 
 
36
int Input_sticky_control = 0;
 
37
int Snap_axis = 0;
 
38
int Snap_axis_origin_X;
 
39
int Snap_axis_origin_Y;
 
40
 
 
41
// --
 
42
 
34
43
byte Directional_up;
35
44
byte Directional_up_right;
36
45
byte Directional_right;
39
48
byte Directional_down_left;
40
49
byte Directional_left;
41
50
byte Directional_up_left;
 
51
byte Directional_click;
 
52
 
42
53
long Directional_delay;
43
54
long Directional_last_move;
44
55
long Directional_step;
45
 
short Mouse_count; // Number of mouse movements received in the current Get_input()
 
56
int  Mouse_moved; ///< Boolean, Set to true if any cursor movement occurs.
46
57
 
47
58
word Input_new_mouse_X;
48
59
word Input_new_mouse_Y;
71
82
 
72
83
int Is_shortcut(word Key, word function)
73
84
{
74
 
  if (Key == 0)
 
85
  if (Key == 0 || function == 0xFFFF)
75
86
    return 0;
76
87
    
77
88
  if (function & 0x100)
101
112
int Move_cursor_with_constraints()
102
113
{
103
114
  int feedback=0;
104
 
  byte bl=0;//BL va indiquer si on doit corriger la position du curseur
 
115
  int  mouse_blocked=0; ///< Boolean, Set to true if mouse movement was clipped.
 
116
 
105
117
  
106
118
  // Clip mouse to the editing area. There can be a border when using big 
107
119
  // pixels, if the SDL screen dimensions are not factors of the pixel size.
108
120
  if (Input_new_mouse_Y>=Screen_height)
109
121
  {
110
122
      Input_new_mouse_Y=Screen_height-1;
111
 
      bl=1;
 
123
      mouse_blocked=1;
112
124
  }
113
125
  if (Input_new_mouse_X>=Screen_width)
114
126
  {
115
127
      Input_new_mouse_X=Screen_width-1;
116
 
      bl=1;
 
128
      mouse_blocked=1;
117
129
  }
118
130
  //Gestion "avanc�e" du curseur: interdire la descente du curseur dans le
119
131
  //menu lorsqu'on est en train de travailler dans l'image
125
137
        if(Menu_Y<=Input_new_mouse_Y)
126
138
        {
127
139
            //On bloque le curseur en fin d'image
128
 
            bl++;
 
140
            mouse_blocked=1;
129
141
            Input_new_mouse_Y=Menu_Y-1; //La ligne !!au-dessus!! du menu
130
142
        }
131
143
 
135
147
            {
136
148
                if(Input_new_mouse_X>=Main_separator_position)
137
149
                {
138
 
                    bl++;
 
150
                    mouse_blocked=1;
139
151
                    Input_new_mouse_X=Main_separator_position-1;
140
152
                }
141
153
            }
143
155
            {
144
156
                if(Input_new_mouse_X<Main_X_zoom)
145
157
                {
146
 
                    bl++;
 
158
                    mouse_blocked=1;
147
159
                    Input_new_mouse_X=Main_X_zoom;
148
160
                }
149
161
            }
153
165
    (Input_new_mouse_Y != Mouse_Y) ||
154
166
    (Input_new_mouse_K != Mouse_K))
155
167
  {
 
168
    // On every change of mouse state
156
169
    if ((Input_new_mouse_K != Mouse_K))
157
 
      feedback=1;        
158
 
    Hide_cursor(); // On efface le curseur AVANT de le d�placer...
 
170
    {
 
171
      feedback=1;
 
172
      
 
173
      if (Input_new_mouse_K == 0)
 
174
        Input_sticky_control = 0;
 
175
    }
 
176
    // Hide cursor, because even just a click change needs it
 
177
    if (!Mouse_moved)
 
178
    {
 
179
      Mouse_moved++;
 
180
      // Hide cursor (erasing icon and brush on screen
 
181
      // before changing the coordinates.
 
182
      Hide_cursor();
 
183
    }
159
184
    if (Input_new_mouse_X != Mouse_X || Input_new_mouse_Y != Mouse_Y)
160
185
    {
161
186
      Mouse_X=Input_new_mouse_X;
162
187
      Mouse_Y=Input_new_mouse_Y;
163
 
      if (bl)
164
 
        Set_mouse_position();
165
188
    }
166
189
    Mouse_K=Input_new_mouse_K;
167
 
    Compute_paintbrush_coordinates();
168
 
    Display_cursor();
169
190
    
170
 
    Mouse_count++;
171
 
    if (Mouse_count>Config.Mouse_merge_movement)
172
 
      feedback=1;
 
191
    if (Mouse_moved > Config.Mouse_merge_movement)
 
192
      if (! Operation[Current_operation][Mouse_K_unique]
 
193
          [Operation_stack_size].Fast_mouse)
 
194
        feedback=1;
173
195
  }
174
 
 
 
196
  if (mouse_blocked)
 
197
    Set_mouse_position();
175
198
  return feedback;
176
199
}
177
200
 
296
319
            Input_new_mouse_K &= ~2;
297
320
            break;
298
321
    }
 
322
    
299
323
    return Move_cursor_with_constraints();
300
324
}
301
325
 
327
351
      Directional_right=1;
328
352
      return 0;
329
353
    }
330
 
    else if(Is_shortcut(Key,SPECIAL_CLICK_LEFT))
 
354
    else if(Is_shortcut(Key,SPECIAL_CLICK_LEFT) && Keyboard_click_allowed > 0)
331
355
    {
332
356
        Input_new_mouse_K=1;
 
357
        Directional_click=1;
333
358
        return Move_cursor_with_constraints();
334
359
    }
335
 
    else if(Is_shortcut(Key,SPECIAL_CLICK_RIGHT))
 
360
    else if(Is_shortcut(Key,SPECIAL_CLICK_RIGHT) && Keyboard_click_allowed > 0)
336
361
    {
337
362
        Input_new_mouse_K=2;
 
363
        Directional_click=2;
338
364
        return Move_cursor_with_constraints();
339
365
    }
340
366
 
344
370
 
345
371
int Release_control(int key_code, int modifier)
346
372
{
347
 
 
348
 
    if(key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
349
 
      key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
 
373
    int need_feedback = 0;
 
374
 
 
375
    if (modifier == MOD_SHIFT)
 
376
    {
 
377
      // Disable "snap axis" mode
 
378
      Snap_axis = 0;
 
379
      need_feedback = 1;
 
380
    }
 
381
 
 
382
    if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
 
383
      (key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
350
384
    {
351
385
      Directional_up=0;
352
386
    }
353
 
    if(key_code == (Config_Key[SPECIAL_MOUSE_DOWN][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_DOWN][0]&modifier) ||
354
 
      key_code == (Config_Key[SPECIAL_MOUSE_DOWN][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_DOWN][1]&modifier))
 
387
    if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_DOWN][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_DOWN][0]&modifier) ||
 
388
      (key_code && key_code == (Config_Key[SPECIAL_MOUSE_DOWN][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_DOWN][1]&modifier))
355
389
    {
356
390
      Directional_down=0;
357
391
    }
358
 
    if(key_code == (Config_Key[SPECIAL_MOUSE_LEFT][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_LEFT][0]&modifier) ||
359
 
      key_code == (Config_Key[SPECIAL_MOUSE_LEFT][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_LEFT][1]&modifier))
 
392
    if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_LEFT][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_LEFT][0]&modifier) ||
 
393
      (key_code && key_code == (Config_Key[SPECIAL_MOUSE_LEFT][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_LEFT][1]&modifier))
360
394
    {
361
395
      Directional_left=0;
362
396
    }
363
 
    if(key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_RIGHT][0]&modifier) ||
364
 
      key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_RIGHT][1]&modifier))
 
397
    if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_RIGHT][0]&modifier) ||
 
398
      (key_code && key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_RIGHT][1]&modifier))
365
399
    {
366
400
      Directional_right=0;
367
401
    }
368
 
    if(key_code == (Config_Key[SPECIAL_CLICK_LEFT][0]&0x0FFF) || (Config_Key[SPECIAL_CLICK_LEFT][0]&modifier) ||
369
 
      key_code == (Config_Key[SPECIAL_CLICK_LEFT][1]&0x0FFF) || (Config_Key[SPECIAL_CLICK_LEFT][1]&modifier))
 
402
    if((key_code && key_code == (Config_Key[SPECIAL_CLICK_LEFT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_LEFT][0]&modifier) ||
 
403
      (key_code && key_code == (Config_Key[SPECIAL_CLICK_LEFT][1]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_LEFT][1]&modifier))
370
404
    {
371
 
        Input_new_mouse_K &= ~1;
372
 
        return Move_cursor_with_constraints();
 
405
        if (Directional_click & 1)
 
406
        {
 
407
            Directional_click &= ~1;
 
408
            Input_new_mouse_K &= ~1;
 
409
            return Move_cursor_with_constraints() || need_feedback;
 
410
        }
373
411
    }
374
 
    if(key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
375
 
      key_code == (Config_Key[SPECIAL_CLICK_RIGHT][1]&0x0FFF) || (Config_Key[SPECIAL_CLICK_RIGHT][1]&modifier))
 
412
    if((key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
 
413
      (key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][1]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][1]&modifier))
376
414
    {
377
 
        Input_new_mouse_K &= ~2;
378
 
        return Move_cursor_with_constraints();
 
415
        if (Directional_click & 2)
 
416
        {
 
417
            Directional_click &= ~2;
 
418
            Input_new_mouse_K &= ~2;
 
419
            return Move_cursor_with_constraints() || need_feedback;
 
420
        }
379
421
    }
380
422
  
381
423
    // Other keys don't need to be released : they are handled as "events" and procesed only once.
382
424
    // These clicks are apart because they need to be continuous (ie move while key pressed)
383
425
    // We are relying on "hardware" keyrepeat to achieve that.
384
 
    return 0;
 
426
    return need_feedback;
385
427
}
386
428
 
387
429
 
614
656
{
615
657
    SDL_Event event;
616
658
    int user_feedback_required = 0; // Flag qui indique si on doit arr�ter de traiter les �v�nements ou si on peut enchainer
617
 
 
 
659
                
618
660
    Key_ANSI = 0;
619
661
    Key = 0;
620
 
    Mouse_count=0;
 
662
    Mouse_moved=0;
 
663
    Input_new_mouse_X = Mouse_X;
 
664
    Input_new_mouse_Y = Mouse_Y;
621
665
 
622
666
    // Process as much events as possible without redrawing the screen.
623
667
    // This mostly allows us to merge mouse events for people with an high
734
778
        }
735
779
      }
736
780
    }
737
 
    // Vidage de toute mise � jour de l'affichage � l'�cran qui serait encore en attente.
738
 
    // (c'est fait ici car on est sur que cette function est apell�e partout ou on a besoin d'interragir avec l'utilisateur)
 
781
    // If the cursor was moved since last update,
 
782
    // it was erased, so we need to redraw it (with the preview brush)
 
783
    if (Mouse_moved)
 
784
    {
 
785
      Compute_paintbrush_coordinates();
 
786
      Display_cursor();
 
787
    }
 
788
    // Commit any pending screen update.
 
789
    // This is done in this function because it's called after reading 
 
790
    // some user input.
739
791
    Flush_update();
740
792
 
741
 
    return user_feedback_required;
 
793
    
 
794
    return (Mouse_moved!=0) || user_feedback_required;
742
795
}
743
796
 
744
797
void Adjust_mouse_sensitivity(word fullscreen)