rawtextconsole.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 113 行

JAVA
113
字号
/*
 * $Id: RawTextConsole.java,v 1.6 2004/02/21 18:29:31 vchira_2000 Exp $
 */
package org.jnode.driver.console.x86;

import org.jnode.driver.console.Console;
import org.jnode.driver.console.ConsoleException;
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.input.PointerEvent;
import org.jnode.system.event.FocusEvent;

/**
 * @author vali
 *
 */
public class RawTextConsole extends AbstractTextConsole {


	/* 
	 * Mouse currsor variables 
	 */
	
	private char oldChar = 0; 
	private char oldCharBgColor = 0; 
	private int mouseCurX = 10;
	private int mouseCurY = 10;
	
	/**
	 * @param mgr
	 * @param name
	 * @throws ConsoleException
	 */
	public RawTextConsole(ConsoleManager mgr, String name) throws ConsoleException {
		super(mgr, name);
	}


	/* (non-Javadoc)
	 * @see org.jnode.driver.console.Console#setChar(int, int, char, int)
	 */
	public void setChar(int x, int y, char ch, int color) {
		screen.set(x,y,ch,color);
	}

	public void pointerStateChanged(PointerEvent event) {
		updateMouseCurrsor(event.getX(),event.getY());
	}
	public void updateMouseCurrsor(int incX, int incY)
	{
		// if cursor was moved
		int newX = this.mouseCurX + incX;
		int newY = this.mouseCurY + incY;
		if(newX < 0)
			newX = 0;
		else if(newX >= this.getWidth())
			newX = getWidth() - 1;
		if(newY < 0)
			newY = 0;
		else if(newY >= this.getHeight())
			newY = getHeight() - 1;
		
		// write old character to old position if needed
		if(oldChar != 0)
		{
			this.setChar(this.mouseCurX,this.mouseCurY,oldChar,oldCharBgColor);
		}			
		// write cursor to new pos
		// increment the pos
		// remember the old char and old bgColor
		oldChar = getChar(newX,newY);
		oldCharBgColor = getBgColor(newX,newY);
		
		this.setChar(newX,newY,Console.MOUSE_CURSOR_CHAR,0x07);
		this.mouseCurX = newX;
		this.mouseCurY = newY;
			
		
	}

	/* (non-Javadoc)
	 * @see org.jnode.driver.console.Console#getChar(int, int)
	 */
	public char getChar(int x, int y) {
		return screen.get(x,y);
	}


	/* (non-Javadoc)
	 * @see org.jnode.driver.console.Console#getBgColor(int, int)
	 */
	public char getBgColor(int x, int y) {
		return screen.getColor(x,y);
	}


	/* (non-Javadoc)
	 * @see org.jnode.system.event.FocusListener#focusLost(org.jnode.system.event.FocusEvent)
	 */
	public void focusLost(FocusEvent event) {
		
	}


	/* (non-Javadoc)
	 * @see org.jnode.system.event.FocusListener#focusGained(org.jnode.system.event.FocusEvent)
	 */
	public void focusGained(FocusEvent event) {
		
	}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?