Changeset 330
- Timestamp:
- Feb 1, 2011, 11:07:12 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/board.cpp
r326 r330 56 56 int2 src_cell, dst_cell; 57 57 58 int2 mouse;59 int3 buttons;58 int2 oldmouse; 59 int3 oldbuttons; 60 60 float nextblink, whipdelay; 61 61 … … 109 109 Ticker::Ref(data->scoretext); 110 110 data->score = 0; 111 112 position = int3(24, 72, 1); 113 bbox[0] = position; 114 bbox[1] = bbox[0] + int3(384, 384, 0); 115 116 Input::TrackMouse(this); 111 117 } 112 118 … … 115 121 Entity::TickGame(deltams); 116 122 117 int2 mouse = Input::GetMousePos();118 123 int3 buttons = Input::GetMouseButtons(); 119 124 … … 150 155 case BoardData::IDLE: 151 156 /* Should we start dragging something? */ 152 if (buttons[0] && !data->buttons[0]) 153 { 154 int x = mouse.x - 24; 155 int y = mouse.y - 72; 156 if (x >= 0 && x < data->dim.i * 48 157 && y >= 0 && y < data->dim.j * 48) 158 { 159 if (data->pairs[x / 48][y / 48].piece->Grab(int2(0, 0))) 160 { 161 Sampler::PlaySample(data->click); 162 data->grabbed = data->pairs[x / 48][y / 48]; 163 data->src_cell = int2(x / 48, y / 48); 164 data->dst_cell = int2(-1); 165 data->state = BoardData::GRAB; 166 } 167 else 168 data->state = BoardData::BADCLICK; 157 if (buttons[0] && !data->oldbuttons[0] && mousepos.x != -1) 158 { 159 int2 cell = mousepos / 48; 160 if (data->pairs[cell.x][cell.y].piece->Grab(int2(0, 0))) 161 { 162 Sampler::PlaySample(data->click); 163 data->grabbed = data->pairs[cell.x][cell.y]; 164 data->src_cell = mousepos / 48; 165 data->dst_cell = int2(-1); 166 data->state = BoardData::GRAB; 169 167 } 170 168 else … … 173 171 break; 174 172 case BoardData::GRAB: 175 if (mouse .x >= 0 && mouse.y >= 0)173 if (mousepos.x != -1) 176 174 { 177 175 /* Mouse is still in the window, keep grabbing */ 178 data->grabbed.piece->Grab(mouse - data->mouse);176 data->grabbed.piece->Grab(mousepos - data->oldmouse); 179 177 int2 cur_pos = data->grabbed.piece->GetPos(); 180 178 int2 cur_cell = (cur_pos + 24) / 48; … … 201 199 } 202 200 } 203 if (!buttons[0] || mouse .x < 0 || mouse.y < 0201 if (!buttons[0] || mousepos.x == -1 204 202 || (data->src_cell * 48 205 203 - data->grabbed.piece->GetPos()).sqlen() > 100 * 100) … … 218 216 } 219 217 220 data-> mouse = mouse;221 data-> buttons = buttons;218 data->oldmouse = mousepos; 219 data->oldbuttons = buttons; 222 220 } 223 221 … … 237 235 238 236 /* Mouse pointer */ 239 if (data-> mouse.x >= 0 && data->mouse.y >= 0)240 { 241 int2 m = data-> mouse+ int2(-6, 6 - 48);237 if (data->oldmouse.x >= 0 && data->oldmouse.y >= 0) 238 { 239 int2 m = data->oldmouse + (int2)(float2)position + int2(-6, 6 - 48); 242 240 Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0); 243 241 } … … 531 529 Board::~Board() 532 530 { 531 Input::UntrackMouse(this); 532 533 533 for (int j = 0; j < data->dim.j; j++) 534 534 for (int i = 0; i < data->dim.i; i++) -
trunk/src/input.cpp
r329 r330 104 104 data->mouse = coord; 105 105 106 /* FIXME: parse all subscribed entities and update them */ 106 WorldEntity *best = NULL; 107 108 for (int n = 0; n < data->nentities; n++) 109 { 110 if (coord.x < data->entities[n]->bbox[0].x 111 || coord.x >= data->entities[n]->bbox[1].x 112 || coord.y < data->entities[n]->bbox[0].y 113 || coord.y >= data->entities[n]->bbox[1].y) 114 continue; 115 116 if (!best || best->bbox[1].z < data->entities[n]->bbox[1].z) 117 best = data->entities[n]; 118 } 119 120 for (int n = 0; n < data->nentities; n++) 121 { 122 if (data->entities[n] == best) 123 data->entities[n]->mousepos = (int2)((int3)coord - best->bbox[0]); 124 else 125 data->entities[n]->mousepos = int2(-1); 126 } 107 127 } 108 128
Note: See TracChangeset
for help on using the changeset viewer.