Changeset 11030
- Timestamp:
- 01/29/10 15:55:52 (3 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgWidget/Input.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgWidget/Input.cpp
r11016 r11030 141 141 for (unsigned int i=0; i<glyphs.size(); ++i) 142 142 { 143 static osgText::Font::Glyph* previous_g = 0; 144 143 145 osgText::Font::Glyph* g = glyphs.at(i); 144 146 if (g->getGlyphCode()==key) … … 155 157 _offsets[idx] += g->getHorizontalAdvance(); 156 158 ++idx; 159 160 if (previous_g) 161 { 162 { 163 point_type& ref = _offsets[idx]; 164 ref += previous_g->getHorizontalAdvance(); 165 } 166 { 167 point_type& ref = _widths[idx]; 168 ref += previous_g->getHorizontalAdvance(); 169 } 170 } 171 previous_g = g; 157 172 158 173 glyphs.erase(glyphs.begin()+i); … … 233 248 if (_selectionMax-_selectionMin>0) 234 249 { 235 unsigned int size = 0; 236 237 for (unsigned int i=_selectionMin; i<_selectionMax; ++i) 238 { 239 size += _widths[i]; 240 } 241 point_type xoffset = _selectionMin > 0 ? _offsets[_selectionMin - 1] : 0.0f; 242 243 _selection->setSize(size, getHeight()); 244 _selection->setOrigin(getX() + xoffset, getY()); 250 point_type xstart = _selectionMin > 0 ? _offsets[_selectionMin - 1] : 0.0f; 251 point_type xend = (_selectionMax > 0 ? _offsets[_selectionMax - 1] : 0.0f) + _widths[_selectionMax]; 252 253 _selection->setSize(xend-xstart, getHeight()); 254 _selection->setOrigin(getX() + xstart, getY()); 245 255 _selection->setZ(_calculateZ(LAYER_MIDDLE-2)); 246 256 } … … 260 270 x = _mouseClickX; 261 271 262 unsigned int size = 0; 263 for ( unsigned int i=0; i< _widths.size(); ++i ) 264 { 265 if (x > size && x < size+_widths.at(i)) 266 { 267 _selectionEndIndex = _index = i; 272 for ( unsigned int i=0; i< _offsets.size()-1; ++i ) 273 { 274 point_type offset1 = i > 0 ? _offsets.at(i-1) : 0; 275 point_type offset2 = _offsets.at(i); 276 if (x >= offset1 && x <= offset2) 277 { 278 _selectionEndIndex = _index = i; 268 279 positioned(); 269 280 break; 270 281 } 271 size += _widths.at(i);272 } 282 } 283 273 284 return false; 274 285 } 275 286 276 bool Input::mousePush (double x, double y, const WindowManager* )287 bool Input::mousePush (double x, double y, const WindowManager* wm) 277 288 { 278 289 double offset = getOrigin().x(); 279 290 Window* window = getParent(); 280 while (window) { offset += window->getOrigin().x(); window = window->getParent(); } 291 if (window) 292 { 293 offset += window->getOrigin().x(); 294 } 281 295 282 296 x -= offset; 283 297 _mouseClickX = x; 284 285 unsigned int size = 0; 286 for ( unsigned int i=0; i< _widths.size(); ++i ) 287 { 288 if (x > size && x < size+_widths.at(i)) 289 { 290 _selectionStartIndex = _selectionEndIndex = _index = i; 298 299 for ( unsigned int i=0; i< _offsets.size()-1; ++i ) 300 { 301 point_type offset1 = i > 0 ? _offsets.at(i-1) : 0; 302 point_type offset2 = i == 0 ? _offsets.at(1) : _offsets.at(i); 303 if (x >= offset1 && x <= offset2) 304 { 305 _selectionStartIndex = _selectionEndIndex = _index = i; 291 306 positioned(); 292 307 break; 293 308 } 294 size += _widths.at(i);295 309 } 296 310 return false; … … 402 416 for (unsigned int i=0; i < s.size()-_selectionMin; ++i) 403 417 { 404 s[_selectionMin+i] = deleteToIdx+i < s.size() ? s[deleteToIdx+i] : ' ';418 s[_selectionMin+i] = deleteToIdx+i+1 < s.size() ? s[deleteToIdx+i+1] : ' '; 405 419 } 406 420 … … 462 476 for (unsigned int i=0; i < s.size()-_selectionMin; ++i) 463 477 { 464 s[_selectionMin+i] = deleteToIdx+i < s.size() ? s[deleteToIdx+i] : ' ';478 s[_selectionMin+i] = deleteToIdx+i+1 < s.size() ? s[deleteToIdx+i+1] : ' '; 465 479 } 466 480 … … 550 564 { 551 565 std::string data; 552 for (unsigned int i=_selectionMin; i< _selectionMax; ++i)566 for (unsigned int i=_selectionMin; i<=_selectionMax; ++i) 553 567 { 554 568 data.push_back(s[i]); … … 580 594 for (unsigned int i=0; i < s.size()-_selectionMin; ++i) 581 595 { 582 s[_selectionMin+i] = deleteToIdx+i < s.size() ? s[deleteToIdx+i] : ' ';596 s[_selectionMin+i] = deleteToIdx+i+1 < s.size() ? s[deleteToIdx+i+1] : ' '; 583 597 } 584 598 … … 629 643 unsigned int Input::calculateBestYOffset(const std::string& s) 630 644 { 645 if (!_text->getFont()) return 0; 646 631 647 const osgText::FontResolution fr(static_cast<unsigned int>(_text->getCharacterHeight()), 632 648 static_cast<unsigned int>(_text->getCharacterHeight()));
