Skip to content

Commit

Permalink
Merge pull request #5 from v-yadli/dvhhVariant
Browse files Browse the repository at this point in the history
implement cursor style setting, thanks to v-yadli
  • Loading branch information
dvhh authored Aug 12, 2016
2 parents 1b1ccab + 22a9cc1 commit 2ef5f57
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ abstract class BaseTextRenderer implements TextRenderer {
private Bitmap mCursorBitmap;
private Bitmap mWorkBitmap;
private int mCursorBitmapCursorMode = -1;
private int mCursorStyle = 0;

public BaseTextRenderer(ColorScheme scheme) {
if (scheme == null) {
Expand Down Expand Up @@ -393,6 +394,19 @@ private static int[] cloneDefaultColors() {

protected void drawCursorImp(Canvas canvas, float x, float y, float charWidth, float charHeight,
int cursorMode) {

switch(mCursorStyle){
case 1:
charHeight = charHeight / 10.0f;
break;
case 2:
charWidth = charWidth / 10.0f;
break;
case 0:
default:
break;
}

if (cursorMode == 0) {
canvas.drawRect(x, y - charHeight, x + charWidth, y, mCursorScreenPaint);
return;
Expand Down Expand Up @@ -444,5 +458,10 @@ private void drawCursorHelper(Canvas canvas, Path path, int mode, int shift) {
break;
}
}

public void setCursorStyle(int cursorStyle)
{
mCursorStyle = cursorStyle;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe
/**
* Used to render text
*/
private TextRenderer mTextRenderer;
private BaseTextRenderer mTextRenderer;

/**
* Text size. Zero means 4 x 8 font.
Expand Down Expand Up @@ -166,6 +166,7 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe
private static final int CURSOR_BLINK_PERIOD = 1000;

private boolean mCursorVisible = true;
private int mCursorStyle = 0;

private boolean mIsSelectingText = false;

Expand Down Expand Up @@ -614,6 +615,18 @@ public void onPause() {
}
}

/**
* Set this <code>EmulatorView</code>'s cursor style.
* @param cursorStyle The cursor style to use.
* 0 for block
* 1 for underdash
* 2 for vertical line
*/
public void setCursorStyle(int cursorStyle)
{
mCursorStyle = cursorStyle;
}

/**
* Set this <code>EmulatorView</code>'s color scheme.
*
Expand Down Expand Up @@ -1469,12 +1482,14 @@ private void clearSpecialKeyStatus() {
private void updateText() {
ColorScheme scheme = mColorScheme;
if (mTextSize > 0) {
mTextRenderer = new CustomFontPaintRenderer(mTextSize, scheme,mTypeface);
mTextRenderer = new CustomFontPaintRenderer(mTextSize, scheme, mTypeface);
}
else {
mTextRenderer = new Bitmap4x8FontRenderer(getResources(), scheme);
}

mTextRenderer.setCursorStyle(mCursorStyle);

mForegroundPaint.setColor(scheme.getForeColor());
mBackgroundPaint.setColor(scheme.getBackColor());
mCharacterWidth = mTextRenderer.getCharacterWidth();
Expand Down
1 change: 1 addition & 0 deletions term/src/main/java/jackpal/androidterm/TermView.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void updatePrefs(TermSettings settings, ColorScheme scheme) {
setTextSize(settings.getFontSize());
setUseCookedIME(settings.useCookedIME());
setColorScheme(scheme);
setCursorStyle(settings.getCursorStyle());
setBackKeyCharacter(settings.getBackKeyCharacter());
setAltSendsEsc(settings.getAltSendsEscFlag());
setControlKeyCode(settings.getControlKeyCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class TermSettings {
private static final String ACTIONBAR_KEY = "actionbar";
private static final String ORIENTATION_KEY = "orientation";
private static final String SAFE_MARGINS_KEY = "safe_margins";
private static final String CURSORSTYLE_KEY = "cursorstyle";
private static final String FONTSIZE_KEY = "fontsize";
private static final String COLOR_KEY = "color";
private static final String UTF8_KEY = "utf8_by_default";
Expand Down Expand Up @@ -221,7 +222,7 @@ public void readPrefs(SharedPreferences prefs) {
mActionBarMode = readIntPref(ACTIONBAR_KEY, mActionBarMode, ACTION_BAR_MODE_MAX);
mOrientation = readIntPref(ORIENTATION_KEY, mOrientation, 2);
mSafeMargins = readBooleanPref(SAFE_MARGINS_KEY, mSafeMargins);
// mCursorStyle = readIntPref(CURSORSTYLE_KEY, mCursorStyle, 2);
mCursorStyle = readIntPref(CURSORSTYLE_KEY, mCursorStyle, 2);
// mCursorBlink = readIntPref(CURSORBLINK_KEY, mCursorBlink, 1);
mFontSize = readIntPref(FONTSIZE_KEY, mFontSize, 288);
mColorId = readIntPref(COLOR_KEY, mColorId, COLOR_SCHEMES.length - 1);
Expand Down
20 changes: 10 additions & 10 deletions term/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
android:dialogMessage="@string/dialog_use_system_wallpaper_preference"
android:summary="@string/summary_transparency_preference"
/>
<!--
<ListPreference
android:key="cursorstyle"
android:defaultValue="@string/pref_cursorstyle_default"
Expand All @@ -89,15 +88,16 @@
android:entryValues="@array/entryvalues_cursorstyle_preference"
android:dialogTitle="@string/dialog_title_cursorstyle_preference" />

<ListPreference
android:key="cursorblink"
android:defaultValue="@string/pref_cursorblink_default"
android:title="@string/title_cursorblink_preference"
android:summary="@string/summary_cursorblink_preference"
android:entries="@array/entries_cursorblink_preference"
android:entryValues="@array/entryvalues_cursorblink_preference"
android:dialogTitle="@string/dialog_title_cursorblink_preference" />
-->
<!--
<ListPreference
android:key="cursorblink"
android:defaultValue="@string/pref_cursorblink_default"
android:title="@string/title_cursorblink_preference"
android:summary="@string/summary_cursorblink_preference"
android:entries="@array/entries_cursorblink_preference"
android:entryValues="@array/entryvalues_cursorblink_preference"
android:dialogTitle="@string/dialog_title_cursorblink_preference" />
-->

</PreferenceCategory>

Expand Down

0 comments on commit 2ef5f57

Please sign in to comment.