void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard) { DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); ASSERT(dataObject); if (gtk_clipboard_wait_is_text_available(clipboard)) { GOwnPtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard)); if (textData) dataObject->setText(String::fromUTF8(textData.get())); } if (gtk_clipboard_wait_is_target_available(clipboard, markupAtom)) { if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, markupAtom)) { String markup(selectionDataToUTF8String(data)); removeMarkupPrefix(markup); dataObject->setMarkup(markup); gtk_selection_data_free(data); } } if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) { if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) { dataObject->setURIList(selectionDataToUTF8String(data)); gtk_selection_data_free(data); } } }
void gqbBrowser::OnBeginDrag(wxTreeEvent &event) { wxTreeItemId itemId = event.GetItem(); // Simplest solution, simulate DnD but actually don't do it gqbObject *object = (gqbObject *) GetItemData(itemId); if(object != NULL && (object->getType() == GQB_TABLE || object->getType() == GQB_VIEW)) { gqbTable *item = (gqbTable *) object; wxString tableName = item->getName(); wxTextDataObject textData(tableName); wxDropSource dragSource(this); dragSource.SetData(textData); wxDragResult result = dragSource.DoDragDrop(wxDrag_CopyOnly); if(result == wxDragCopy) { controller->getView()->CalcUnscrolledPosition(xx, yy, &xx, &yy); gqbQueryObject *queryObj = controller->addTableToModel(item, wxPoint(xx, yy)); controller->getView()->Refresh(); if (queryObj) { controller->getView()->Update(); controller->getView()->updateModelSize(queryObj, false); } } } }
void GUIInputTool::updateText(const GUIElement* element, const TEXT_SPRITE_DESC& textDesc) { mElement = element; mTextDesc = textDesc; mNumChars = UTF8::count(mTextDesc.text); mLineDescs.clear(); bs_frame_mark(); { const U32String utf32text = UTF8::toUTF32(mTextDesc.text); TextData<FrameAlloc> textData(utf32text, mTextDesc.font, mTextDesc.fontSize, mTextDesc.width, mTextDesc.height, mTextDesc.wordWrap, mTextDesc.wordBreak); UINT32 numLines = textData.getNumLines(); UINT32 numPages = textData.getNumPages(); mNumQuads = 0; for (UINT32 i = 0; i < numPages; i++) mNumQuads += textData.getNumQuadsForPage(i); if (mQuads != nullptr) bs_delete(mQuads); mQuads = bs_newN<Vector2>(mNumQuads * 4); TextSprite::genTextQuads(textData, mTextDesc.width, mTextDesc.height, mTextDesc.horzAlign, mTextDesc.vertAlign, mTextDesc.anchor, mQuads, nullptr, nullptr, mNumQuads); // Store cached line data UINT32 curCharIdx = 0; UINT32 curLineIdx = 0; Vector2I* alignmentOffsets = bs_frame_new<Vector2I>(numLines); TextSprite::getAlignmentOffsets(textData, mTextDesc.width, mTextDesc.height, mTextDesc.horzAlign, mTextDesc.vertAlign, alignmentOffsets); for (UINT32 i = 0; i < numLines; i++) { const TextDataBase::TextLine& line = textData.getLine(i); // Line has a newline char only if it wasn't created by word wrap and it isn't the last line bool hasNewline = line.hasNewlineChar() && (curLineIdx != (numLines - 1)); UINT32 startChar = curCharIdx; UINT32 endChar = curCharIdx + line.getNumChars() + (hasNewline ? 1 : 0); UINT32 lineHeight = line.getYOffset(); INT32 lineYStart = alignmentOffsets[curLineIdx].y; GUIInputLineDesc lineDesc(startChar, endChar, lineHeight, lineYStart, hasNewline); mLineDescs.push_back(lineDesc); curCharIdx = lineDesc.getEndChar(); curLineIdx++; } bs_frame_delete(alignmentOffsets); } bs_frame_clear(); }
void CAnimation::init(CDefFile * file) { if (file) { const std::map<size_t, size_t> defEntries = file->getEntries(); for (auto & defEntry : defEntries) source[defEntry.first].resize(defEntry.second); } ResourceID resID(std::string("SPRITES/") + name, EResType::TEXT); if (vstd::contains(graphics->imageLists, resID.getName())) initFromJson(graphics->imageLists[resID.getName()]); auto configList = CResourceHandler::get()->getResourcesWithName(resID); for(auto & loader : configList) { auto stream = loader->load(resID); std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]); stream->read(textData.get(), stream->getSize()); const JsonNode config((char*)textData.get(), stream->getSize()); initFromJson(config); } }
Vector2I GUIHelper::calcOptimalContentsSize(const String& text, const GUIElementStyle& style, const GUIDimensions& dimensions) { UINT32 wordWrapWidth = 0; if(style.wordWrap) wordWrapWidth = dimensions.maxWidth; UINT32 contentWidth = style.margins.left + style.margins.right + style.contentOffset.left + style.contentOffset.right; UINT32 contentHeight = style.margins.top + style.margins.bottom + style.contentOffset.top + style.contentOffset.bottom; if(style.font != nullptr && !text.empty()) { bs_frame_mark(); const U32String utf32text = UTF8::toUTF32(text); TextData<FrameAlloc> textData(utf32text, style.font, style.fontSize, wordWrapWidth, 0, style.wordWrap); contentWidth += textData.getWidth(); contentHeight += textData.getNumLines() * textData.getLineHeight(); bs_frame_clear(); } return Vector2I(contentWidth, contentHeight); }
void PHILinkItem::ideInit() { textData()->setText( L1( "Link item" ) ); setColor( PHIPalette::WidgetText, PHIPalette::Link, page()->phiPalette().color( PHIPalette::Link ) ); setColor( PHIPalette::WidgetBase, PHIPalette::Window, page()->phiPalette().color( PHIPalette::Window ) ); setColor( PHIPalette::Hover, PHIPalette::HighlightText, page()->phiPalette().color( PHIPalette::HighlightText ) ); setColor( PHIPalette::HoverBackground, PHIPalette::Window, page()->phiPalette().color( PHIPalette::Window ) ); }
void TextSprite::update(const TEXT_SPRITE_DESC& desc, UINT64 groupId) { bs_frame_mark(); { TextData<FrameAlloc> textData(desc.text, desc.font, desc.fontSize, desc.width, desc.height, desc.wordWrap, desc.wordBreak); UINT32 numPages = textData.getNumPages(); // Free all previous memory for (auto& cachedElem : mCachedRenderElements) { if (cachedElem.vertices != nullptr) mAlloc.free(cachedElem.vertices); if (cachedElem.uvs != nullptr) mAlloc.free(cachedElem.uvs); if (cachedElem.indexes != nullptr) mAlloc.free(cachedElem.indexes); } mAlloc.clear(); // Resize cached mesh array to needed size if (mCachedRenderElements.size() != numPages) mCachedRenderElements.resize(numPages); // Actually generate a mesh UINT32 texPage = 0; for (auto& cachedElem : mCachedRenderElements) { UINT32 newNumQuads = textData.getNumQuadsForPage(texPage); cachedElem.vertices = (Vector2*)mAlloc.alloc(sizeof(Vector2) * newNumQuads * 4); cachedElem.uvs = (Vector2*)mAlloc.alloc(sizeof(Vector2) * newNumQuads * 4); cachedElem.indexes = (UINT32*)mAlloc.alloc(sizeof(UINT32) * newNumQuads * 6); cachedElem.numQuads = newNumQuads; const HTexture& tex = textData.getTextureForPage(texPage); SpriteMaterialInfo& matInfo = cachedElem.matInfo; matInfo.groupId = groupId; matInfo.texture = tex; matInfo.tint = desc.color; matInfo.type = SpriteMaterial::Text; texPage++; } // Calc alignment and anchor offsets and set final line positions for (UINT32 j = 0; j < numPages; j++) { SpriteRenderElement& renderElem = mCachedRenderElements[j]; genTextQuads(j, textData, desc.width, desc.height, desc.horzAlign, desc.vertAlign, desc.anchor, renderElem.vertices, renderElem.uvs, renderElem.indexes, renderElem.numQuads); } } bs_frame_clear(); updateBounds(); }
void DebugRenderer::AddText(const string& text, const Vector3f& position, const Color& color, Lifespan lifespan) { TextData textData(text, position, color); if (lifespan == Temporary) { temporaryTextData.push_back(textData); } else { permanentTextData.push_back(textData); } }
GpuTexture::GpuTexture(void) { this->textureCount = 0; // load up the default texture TextureData textData( "HotPink.tga" ); this->pDefaultTexture = this->privCreate( textData ); assert(this->pDefaultTexture); }
Vector2I GUIHelper::calcTextSize(const String& text, const HFont& font, UINT32 fontSize) { Vector2I size; if (font != nullptr) { bs_frame_mark(); const U32String utf32text = UTF8::toUTF32(text); TextData<FrameAlloc> textData(utf32text, font, fontSize, 0, 0, false); size.x = textData.getWidth(); size.y = textData.getNumLines() * textData.getLineHeight(); bs_frame_clear(); } return size; }
const bool CCTextureFontPageFile::load(const char *name, const CCResourceType resourceType, const bool generateMipMap) { CCText textureFilename( name ); textureFilename += ".png"; texturePageIndex = gEngine->textureManager->assignTextureIndex( textureFilename.buffer, resourceType, true, generateMipMap ); CCText filename( name ); filename += ".data"; // Load the descriptor file char *fileData = NULL; CCFileManager::getPackagedFile( filename.buffer, &fileData ); CCText textData( fileData ); FREE_POINTER( fileData ); CCList<char> *lettersSplit = textData.split( "\n" ); CCText rawLetterData; for( int i=0; i<lettersSplit->length; ++i ) { const char *raw = lettersSplit->list[i]; rawLetterData.set( raw ); CCList<char> *letterDataSplit = rawLetterData.split( "," ); ASSERT( letterDataSplit->length == 4 ); Letters &letter = letters[i]; letter.start.x = (float)atof( letterDataSplit->list[0] ); letter.start.y = (float)atof( letterDataSplit->list[1] ); letter.end.x = (float)atof( letterDataSplit->list[2] ); letter.end.y = (float)atof( letterDataSplit->list[3] ); // 16.0f because there's 16 tiles per font page letter.size.width = ( letter.end.x - letter.start.x ) * 16.0f; letter.size.height = ( letter.end.y - letter.start.y ) * 16.0f; DELETE_POINTER( letterDataSplit ); } DELETE_POINTER( lettersSplit ); return true; }
void ddModelBrowser::OnBeginDrag(wxTreeEvent &event) { wxTreeItemId itemId = event.GetItem(); // Simplest solution, simulate DnD but actually don't do it ddBrowserDataContainer *object = (ddBrowserDataContainer *) GetItemData(itemId); if(object != NULL && (object->getFigureKindId() == DDTABLEFIGURE)) { ddTableFigure *item = (ddTableFigure *) object->getFigure(); wxString tableName = item->getTableName(); wxTextDataObject textData(tableName); wxDropSource dragSource(this); dragSource.SetData(textData); wxDragResult result = dragSource.DoDragDrop(wxDrag_CopyOnly); if(result != wxDragCopy) { wxMessageBox(wxT("Invalid kind of data during drag and drop operation"), wxT("Drag and drop error"), wxICON_ERROR); } } }
bool EQStr::load(const QString& fileName) { // clear out any existing contents m_messageStrings.clear(); // create a QFile on the file QFile formatFile(fileName); // open the file read only if (!formatFile.open(IO_ReadOnly)) { seqWarn("EQStr: Failed to open '%s'", fileName.latin1()); return false; } // allocate a QCString large enough to hold the entire file QCString textData(formatFile.size() + 1); // read in the entire file formatFile.readBlock(textData.data(), textData.size()); // construct a regex to deal with either style line termination QRegExp lineTerm("[\r\n]{1,2}"); // split the data into lines at the line termination QStringList lines = QStringList::split(lineTerm, QString::fromUtf8(textData), false); // start iterating over the lines QStringList::Iterator it = lines.begin(); // first is the magic id string QString magicString = (*it++); int spc; uint32_t formatId; QString formatString; uint32_t maxFormatId = 0; // next skip over the count, etc... it++; // now iterate over the format lines for (; it != lines.end(); ++it) { // find the beginning space spc = (*it).find(' '); // convert the beginnign of the string to a ULong formatId = (*it).left(spc).toULong(); if (formatId > maxFormatId) maxFormatId = formatId; // insert the format string into the dictionary. m_messageStrings.insert(formatId, new QString((*it).mid(spc+1))); } // note that strings are loaded m_loaded = true; seqInfo("Loaded %d message strings from '%s' maxFormat=%d", m_messageStrings.count(), fileName.latin1(), maxFormatId); return true; }
Texture *GpuTexture::Create( const char * const textNameString ) { assert(textNameString); TextureData textData( textNameString ); return ( privGetInstance()->privCreate( textData ) ); }
void PHILabelItem::ideInit() { textData()->setText( L1( "Label" ) ); setColor( PHIPalette::WidgetBase, PHIPalette::Window, page()->phiPalette().color( PHIPalette::Window ) ); setColor( PHIPalette::WidgetText, PHIPalette::WindowText, page()->phiPalette().color( PHIPalette::WindowText ) ); }
wex::grid::grid(const window_data& data) : wxGrid( data.parent(), data.id(), data.pos(), data.size(), data.style(), data.name()) { SetDropTarget(new text_droptarget(this)); m_use_drag_and_drop = true; Bind(wxEVT_MENU, [=](wxCommandEvent& event) { empty_selection();}, wxID_DELETE); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { SelectAll();}, wxID_SELECTALL); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { ClearSelection();}, ID_EDIT_SELECT_NONE); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { copy_selected_cells_to_clipboard();}, wxID_COPY); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { copy_selected_cells_to_clipboard(); empty_selection();}, wxID_CUT); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { paste_cells_from_clipboard();}, wxID_PASTE); Bind(wxEVT_FIND, [=](wxFindDialogEvent& event) { find_next( find_replace_data::get()->get_find_string(), find_replace_data::get()->search_down());}); Bind(wxEVT_FIND_NEXT, [=](wxFindDialogEvent& event) { find_next( find_replace_data::get()->get_find_string(), find_replace_data::get()->search_down());}); Bind(wxEVT_GRID_CELL_LEFT_CLICK, [=](wxGridEvent& event) { // Removed extra check for !IsEditable(), // drag/drop is different from editing, so allow that. if (!IsSelection()) { event.Skip(); return; } if (m_use_drag_and_drop) { // This is because drag/drop is not really supported by the wxGrid. // Even the wxEVT_GRID_CELL_BEGIN_DRAG does not seem to come in. // Therefore, we are really dragging if you click again in // your selection and move mouse and drop elsewhere. // So, if not clicked in the selection, do nothing, this was no drag. if (!IsInSelection(event.GetRow(), event.GetCol())) { event.Skip(); return; } // Is it allowed to drag current selection?? if (!is_allowed_drag_selection()) { event.Skip(); return; } // Start drag operation. wxTextDataObject textData(get_selected_cells_value()); wxDropSource source(textData, this); wxDragResult result = source.DoDragDrop(wxDrag_DefaultMove); if (result != wxDragError && result != wxDragNone && result != wxDragCancel) { // The old contents is not deleted, as should be by moving. // To fix this, do not call Skip so selection remains active, // and call empty_selection. // event.Skip(); empty_selection(); ClearSelection(); } else { // Do not call Skip so selection remains active. // event.Skip(); } } else { event.Skip(); } }); Bind(wxEVT_GRID_CELL_RIGHT_CLICK, [=](wxGridEvent& event) { int style = (IsEditable() ? wex::menu::DEFAULT: wex::menu::IS_READ_ONLY); if (IsSelection()) style |= wex::menu::IS_SELECTED; wex::menu menu(style); build_popup_menu(menu); PopupMenu(&menu); }); Bind(wxEVT_GRID_SELECT_CELL, [=](wxGridEvent& event) { frame::statustext( std::to_string(1 + event.GetCol()) + "," + std::to_string(1 + event.GetRow()), "PaneInfo"); event.Skip();}); Bind(wxEVT_GRID_RANGE_SELECT, [=](wxGridRangeSelectEvent& event) { event.Skip(); frame::statustext(std::to_string(GetSelectedCells().GetCount()), "PaneInfo"); }); Bind(wxEVT_SET_FOCUS, [=](wxFocusEvent& event) { wex::frame* frame = dynamic_cast<wex::frame*>(wxTheApp->GetTopWindow()); if (frame != nullptr) { frame->set_find_focus(this); } event.Skip();}); }