MCPcopy Create free account
hub / github.com/SpartanJ/eepp / checkColorPickerAction

Method checkColorPickerAction

src/eepp/ui/uicodeeditor.cpp:1962–2003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1960}
1961
1962void UICodeEditor::checkColorPickerAction() {
1963 if ( !mEnableColorPickerOnSelection )
1964 return;
1965 String text( mDoc->getSelectedText() );
1966 TextRange range( mDoc->getSelection( true ) );
1967 if ( range.start().line() != range.end().line() )
1968 return;
1969 const String& line = mDoc->line( range.end().line() ).getText();
1970 bool isHash = range.start().column() > 0 &&
1971 mDoc->line( range.start().line() ).getText()[range.start().column() - 1] == '#' &&
1972 ( text.size() == 6 || text.size() == 8 ) && String::isHexNotation( text );
1973 bool isRgba = !isHash && text == "rgba" && range.end().column() < (Int64)line.size() - 1 &&
1974 line[range.end().column()] == '(';
1975 bool isRgb = !isHash && !isRgba && text == "rgb" &&
1976 range.end().column() < (Int64)line.size() - 1 && line[range.end().column()] == '(';
1977 if ( isHash || isRgb || isRgba ) {
1978 UIColorPicker* colorPicker = NULL;
1979 if ( isHash ) {
1980 colorPicker = UIColorPicker::NewModal( this, [this]( Color color ) {
1981 mDoc->replaceSelection( color.toHexString( false ) );
1982 } );
1983 colorPicker->setColor( Color( '#' + text ) );
1984 } else if ( isRgba || isRgb ) {
1985 TextPosition position =
1986 mDoc->getMatchingBracket( { range.start().line(), range.end().column() }, '(', ')',
1987 TextDocument::MatchDirection::Forward );
1988 if ( position.isValid() ) {
1989 mDoc->setSelection( { position.line(), position.column() + 1 }, range.start() );
1990 colorPicker = UIColorPicker::NewModal( this, [this, isRgba]( Color color ) {
1991 mDoc->replaceSelection( isRgba || color.a != 255 ? color.toRgbaString()
1992 : color.toRgbString() );
1993 } );
1994 colorPicker->setColor( Color::fromString( mDoc->getSelectedText().toUtf8() ) );
1995 }
1996 }
1997 if ( colorPicker )
1998 colorPicker->getUIWindow()->on( Event::OnWindowClose, [this]( const Event* ) {
1999 if ( !SceneManager::instance()->isShuttingDown() )
2000 setFocus();
2001 } );
2002 }
2003}
2004
2005Vector2f UICodeEditor::getRelativeScreenPosition( const TextPosition& pos ) {
2006 Float gutterWidth = getGutterWidth();

Callers

nothing calls this directly

Calls 15

fromStringFunction · 0.85
getSelectedTextMethod · 0.80
columnMethod · 0.80
getMatchingBracketMethod · 0.80
toRgbaStringMethod · 0.80
toRgbStringMethod · 0.80
toUtf8Method · 0.80
getUIWindowMethod · 0.80
getSelectionMethod · 0.45
startMethod · 0.45
endMethod · 0.45
getTextMethod · 0.45

Tested by

no test coverage detected