1
1
#[ cfg( feature = "hlua" ) ]
2
2
use std:: cell:: UnsafeCell ;
3
3
use std:: collections:: HashMap ;
4
- #[ cfg( not( feature = "hlua" ) ) ]
5
- use std:: marker:: PhantomData ;
6
4
use std:: ops:: DerefMut ;
7
5
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
8
6
use std:: sync:: RwLock ;
9
7
10
- use aabb_quadtree:: { geom , ItemId , QuadTree } ;
11
- # [ cfg ( feature = "hlua" ) ]
12
- use log :: warn ;
8
+ use aabb_quadtree:: { ItemId , QuadTree } ;
9
+ use euclid :: { Rect , TypedPoint2D , TypedRect , UnknownUnit } ;
10
+ use smallvec :: Array ;
13
11
14
12
use crate :: framebuffer:: cgmath;
15
13
use crate :: framebuffer:: common:: * ;
@@ -44,7 +42,7 @@ pub struct ApplicationContext<'a> {
44
42
#[ cfg( feature = "hlua" ) ]
45
43
lua : UnsafeCell < Lua < ' a > > ,
46
44
#[ cfg( not( feature = "hlua" ) ) ]
47
- lua : PhantomData < & ' a ( ) > ,
45
+ lua : std :: marker :: PhantomData < & ' a ( ) > ,
48
46
49
47
input_tx : std:: sync:: mpsc:: Sender < InputEvent > ,
50
48
input_rx : std:: sync:: mpsc:: Receiver < InputEvent > ,
@@ -53,7 +51,7 @@ pub struct ApplicationContext<'a> {
53
51
wacom_ctx : RwLock < Option < ev:: EvDevContext > > ,
54
52
touch_ctx : RwLock < Option < ev:: EvDevContext > > ,
55
53
56
- active_regions : QuadTree < ActiveRegionHandler > ,
54
+ active_regions : QuadTree < ActiveRegionHandler , f32 , Array < Item = ( ItemId , TypedRect < f32 > ) > > ,
57
55
ui_elements : HashMap < String , UIElementHandle > ,
58
56
}
59
57
@@ -80,13 +78,13 @@ impl Default for ApplicationContext<'static> {
80
78
input_rx,
81
79
input_tx,
82
80
ui_elements : HashMap :: new ( ) ,
83
- active_regions : QuadTree :: default ( geom :: Rect :: from_points (
84
- & geom :: Point { x : 0.0 , y : 0.0 } ,
85
- & geom :: Point {
86
- x : xres as f32 ,
87
- y : yres as f32 ,
88
- } ,
89
- ) ) ,
81
+ active_regions : QuadTree :: default (
82
+ TypedRect :: from_points ( [
83
+ TypedPoint2D :: new ( 0.0 , 0.0 ) ,
84
+ TypedPoint2D :: new ( xres as f32 , yres as f32 ) ,
85
+ ] ) ,
86
+ 10 , // size hint for underlying HashMap::with_capacity_and_hasher
87
+ ) ,
90
88
} ;
91
89
92
90
// Enable all std lib
@@ -149,7 +147,7 @@ impl<'a> ApplicationContext<'a> {
149
147
pub fn execute_lua ( & mut self , code : & str ) {
150
148
let lua = self . get_lua_ref ( ) ;
151
149
if let Err ( e) = lua. execute :: < hlua:: AnyLuaValue > ( code) {
152
- warn ! ( "Error in Lua Context: {:?}" , e) ;
150
+ log :: warn!( "Error in Lua Context: {:?}" , e) ;
153
151
}
154
152
}
155
153
@@ -534,14 +532,14 @@ impl<'a> ApplicationContext<'a> {
534
532
}
535
533
536
534
pub fn find_active_region ( & self , y : u16 , x : u16 ) -> Option < ( & ActiveRegionHandler , ItemId ) > {
537
- let matches = self . active_regions . query ( geom :: Rect :: centered_with_radius (
538
- & geom :: Point {
539
- y : f32 :: from ( y ) ,
540
- x : f32:: from ( x) ,
541
- } ,
542
- 2.0 ,
543
- ) ) ;
544
- matches. first ( ) . map ( |res | ( res . 0 , res . 2 ) )
535
+ let matches = self . active_regions . query ( {
536
+ let radius = 2.0 ;
537
+ let v = euclid :: TypedVector2D :: new ( radius , radius ) ;
538
+ let p = euclid :: TypedPoint2D :: new ( f32:: from ( x) , f32 :: from ( y ) ) ;
539
+ // A rect centered on (x,y) with radius 2
540
+ TypedRect :: from_points ( [ ( p - v ) , ( p + v ) ] )
541
+ } ) ;
542
+ matches. first ( ) . map ( |( region , _ , item ) | ( region , item ) )
545
543
}
546
544
547
545
pub fn remove_active_region_at_point ( & mut self , y : u16 , x : u16 ) -> bool {
@@ -562,16 +560,10 @@ impl<'a> ApplicationContext<'a> {
562
560
) {
563
561
self . active_regions . insert_with_box (
564
562
ActiveRegionHandler { handler, element } ,
565
- geom:: Rect :: from_points (
566
- & geom:: Point {
567
- x : f32:: from ( x) ,
568
- y : f32:: from ( y) ,
569
- } ,
570
- & geom:: Point {
571
- x : f32:: from ( x + width) ,
572
- y : f32:: from ( y + height) ,
573
- } ,
574
- ) ,
563
+ TypedRect :: from_points ( [
564
+ TypedPoint2D :: new ( f32:: from ( x) , f32:: from ( y) ) ,
565
+ TypedPoint2D :: new ( f32:: from ( x + width) , f32:: from ( y + height) ) ,
566
+ ] ) ,
575
567
) ;
576
568
}
577
569
}
0 commit comments