public void mouseDragged(MouseEvent evt) { Graphics g = canvas.getGraphics(); g.setColor(color); if (type == 0) { g.setXORMode(canvas.getBackground()); g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y); end = evt.getPoint(); g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y); } else if (type == 1) { int radius; g.setXORMode(canvas.getBackground()); radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2)); g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius); end = evt.getPoint(); radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2)); g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius); } else if (type == 2) { g.setXORMode(canvas.getBackground()); g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y); end = evt.getPoint(); g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { Uri imageFileUri = intent.getData(); try { BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); bmpFactoryOptions.inJustDecodeBounds = true; bmp = BitmapFactory.decodeStream( getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions); bmpFactoryOptions.inJustDecodeBounds = false; bmp = BitmapFactory.decodeStream( getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions); alteredBitmap = Bitmap.createBitmap(drawingArea.getWidth(), drawingArea.getHeight(), bmp.getConfig()); canvas = new Canvas(alteredBitmap); paint = new Paint(); paint.setColor(Color.GREEN); paint.setStrokeWidth(5); matrix = new Matrix(); canvas.drawBitmap(bmp, matrix, paint); drawingArea.cache = alteredBitmap; } catch (Exception e) { Log.v("ERROR", e.toString()); } } }
private void RemoveFromCanvas (CGNode root) { super.Remove (root); for (int i = root.NumChilds()-1; i >= 0; --i) { super.Remove (root.ArrowAt(i)); RemoveFromCanvas (root.ChildAt(i)); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); drawingArea = new MyCanvas(this); drawingArea.shapeType = "free"; setContentView(drawingArea); }
public void mouseReleased(MouseEvent evt) { Graphics g = canvas.getGraphics(); g.setColor(color); g.setPaintMode(); end = evt.getPoint(); if (type == 0) { g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y); if (filled.getState() == true) g.fillRect(start.x, start.y, end.x - start.x, end.y - start.y); status.setText("2. Ecke des Rechtecks festgelegt"); } else if (type == 1) { int radius; radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2)); g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius); if (filled.getState() == true) g.fillOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius); status.setText("Radius des Kreises festgelegt"); } else if (type == 2) { g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y); if (filled.getState() == true) g.fillOval(start.x, start.y, end.x - start.x, end.y - start.y); status.setText("Radius der Ellipse festgelegt"); } }
@Override public void start(Stage stage) throws Exception { javafx.scene.text.Font.loadFont( FXGraphics2DDemo1.class.getResourceAsStream( "/org/scilab/forge/jlatexmath/fonts/base/jlm_cmmi10.ttf"), 1); javafx.scene.text.Font.loadFont( FXGraphics2DDemo1.class.getResourceAsStream( "/org/scilab/forge/jlatexmath/fonts/base/jlm_cmex10.ttf"), 1); javafx.scene.text.Font.loadFont( FXGraphics2DDemo1.class.getResourceAsStream( "/org/scilab/forge/jlatexmath/fonts/maths/jlm_cmsy10.ttf"), 1); javafx.scene.text.Font.loadFont( FXGraphics2DDemo1.class.getResourceAsStream( "/org/scilab/forge/jlatexmath/fonts/latin/jlm_cmr10.ttf"), 1); ScrollPane scrollPane = new ScrollPane(); MyCanvas canvas = new MyCanvas(formula); canvas.setWidth(3000); canvas.setHeight(5000); // canvas.widthProperty().bind(scrollPane.hvalueProperty()); // canvas.heightProperty().bind(scrollPane.heightProperty()); scrollPane.setContent(canvas); // scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); Scene scene = new Scene(scrollPane, 700, 200); stage.setScene(scene); stage.setTitle("FXGraphics2DDemo3.java"); stage.show(); }
public void init() { status = new Label("", Label.CENTER); menu = new Panel(); canvas = new MyCanvas(); farbe = new Choice(); color = Color.blue; filled = new Checkbox("ausgefuellt"); namen = new String[] {"Rechteck", "Kreis", "Ellipse"}; farben = new String[] {"blau", "gelb", "gruen", "rot", "schwarz", "weiss"}; button = new Button[namen.length]; type = -1; for (int i = 0; i < namen.length; i++) { button[i] = new Button(namen[i]); button[i].addActionListener(this); menu.add(button[i]); } for (int i = 0; i < farben.length; i++) farbe.add(farben[i]); filled.addItemListener(this); farbe.addItemListener(this); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); menu.add(filled); menu.add(farbe); setLayout(new BorderLayout()); setBackground(Color.lightGray); add(menu, "North"); add(canvas, "Center"); add(status, "South"); }
@SuppressLint("ShowToast") @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.free) { MyCanvas.shapeType = "free"; Toast.makeText(getApplicationContext(), "Free Drawing", Toast.LENGTH_LONG).show(); } else if (id == R.id.line) { MyCanvas.shapeType = "line"; Toast.makeText(getApplicationContext(), "Line", Toast.LENGTH_LONG).show(); } else if (id == R.id.rectangle) { MyCanvas.shapeType = "rectangle"; Toast.makeText(getApplicationContext(), "Rectangle", Toast.LENGTH_LONG).show(); } else if (id == R.id.ellipse) { MyCanvas.shapeType = "ellipse"; Toast.makeText(getApplicationContext(), "Ellipse", Toast.LENGTH_LONG).show(); } else if (id == R.id.circle) { MyCanvas.shapeType = "circle"; Toast.makeText(getApplicationContext(), "Circle", Toast.LENGTH_LONG).show(); } else if (id == R.id.square) { MyCanvas.shapeType = "square"; Toast.makeText(getApplicationContext(), "Square", Toast.LENGTH_LONG).show(); } else if (id == R.id.background_color) { AmbilWarnaDialog colorDialog = new AmbilWarnaDialog( this, Color.WHITE, new OnAmbilWarnaListener() { @Override public void onOk(AmbilWarnaDialog dialog, int color) { drawingArea.setBackgroundColor(color); drawingArea.backgroundColor = color; } @Override public void onCancel(AmbilWarnaDialog dialog) { // cancel was selected by the user } }); colorDialog.show(); } else if (id == R.id.pen_color) { AmbilWarnaDialog colorDialog = new AmbilWarnaDialog( this, Color.WHITE, new OnAmbilWarnaListener() { @Override public void onOk(AmbilWarnaDialog dialog, int color) { drawingArea.paint.setColor(color); drawingArea.penColor = color; } @Override public void onCancel(AmbilWarnaDialog dialog) { // cancel was selected by the user } }); colorDialog.show(); } else if (id == R.id.pen_width) { final EditText input = new EditText(MainActivity.this); new AlertDialog.Builder(MainActivity.this) .setTitle("Stroke Width") .setMessage("Enter an integer") .setView(input) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String width = input.getText().toString(); if (isInteger(width)) { Toast.makeText( getApplicationContext(), "Stroke Width = " + width, Toast.LENGTH_LONG) .show(); strokeWidth = Integer.parseInt(width); drawingArea.strokeWidth = strokeWidth; drawingArea.paint.setStrokeWidth(strokeWidth); } else { Toast.makeText( getApplicationContext(), "Invalid input for stroke width", Toast.LENGTH_LONG) .show(); } } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }) .show(); } else if (id == R.id.clear) { backgroundColor = drawingArea.backgroundColor; penColor = drawingArea.penColor; strokeWidth = drawingArea.strokeWidth; drawingArea = new MyCanvas(this); drawingArea.backgroundColor = backgroundColor; drawingArea.penColor = penColor; drawingArea.strokeWidth = strokeWidth; drawingArea.setBackgroundColor(backgroundColor); drawingArea.paint.setColor(penColor); drawingArea.paint.setStrokeWidth(strokeWidth); setContentView(drawingArea); } else if (id == R.id.save) { startService(new Intent(getBaseContext(), MyIntentService.class)); MyIntentService.counter++; } else if (id == R.id.load) { Intent choosePictureIntent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(choosePictureIntent, 0); } else if (id == R.id.triangle) { MyCanvas.shapeType = "triangle"; Toast.makeText(getApplicationContext(), "Triangle", Toast.LENGTH_LONG).show(); } else if (id == R.id.filled) { drawingArea.paint.setStyle(Paint.Style.FILL_AND_STROKE); drawingArea.filled = true; Toast.makeText(getApplicationContext(), "Filled Shapes", Toast.LENGTH_LONG).show(); } else if (id == R.id.not_filled) { drawingArea.paint.setStyle(Paint.Style.STROKE); drawingArea.filled = false; Toast.makeText(getApplicationContext(), "Unfilled Shapes", Toast.LENGTH_LONG).show(); } return super.onOptionsItemSelected(item); }
protected void startApp() throws MIDletStateChangeException { final Display display = Display.getDisplay(this); final MyCanvas myCanvas = new MyCanvas(); myCanvas.setCommandListener(this); cmd_exit = new Command("Exit", Command.EXIT, 0); myCanvas.addCommand(cmd_exit); display.setCurrent(myCanvas); Thread thread = new Thread() { public void run() { super.run(); InputStream inputStream = null; try { // inputStream = getClass().getResourceAsStream( "Pothana.ttf" ); inputStream = getClass().getResourceAsStream("SCRIPTIN.ttf"); TrueTypeRegistry.instance.registerTrueType("FONT1", inputStream); // inputStream = getClass().getResourceAsStream( "Tikkana.ttf" ); inputStream = getClass().getResourceAsStream("UNCLEBOBMF.ttf"); TrueTypeRegistry.instance.registerTrueType("FONT2", inputStream); text1 = new TrueTypeText( "FONT1", -0.3, 0, // getUTF16FileData( "telugu1.txt" ), "True", 24, COLOR_BLUE, (useFilling ? COLOR_YELLOW : null)); // text1.translate( 0.07d, 0 ); // text1.rotate(-7d*Math.PI/30d, 0, 0 ); text2 = new TrueTypeText( "FONT2", 0.4, 0, // getTeluguUTF16FileDataAndTransposeForTikkanaFont( "telugu1.txt" ), "TYPE", 24, COLOR_RED, (useFilling ? COLOR_GRAY : null)); // text2.translate( 0.07d, 0 ); } catch (TrueTypeException e) { System.out.println("Unable to load font!"); e.printStackTrace(); } catch (Throwable t) { System.out.println("Error!"); t.printStackTrace(); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (Throwable ignore) { } } // initialize graphics int attemptsLeft = 10; Displayable displayCurrent = null; while ((attemptsLeft-- > 0) && (displayCurrent = display.getCurrent()) == null) { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } if (displayCurrent == null) { throw new RuntimeException("Display.getCurrent() returns null!"); } WIDTH = displayCurrent.getWidth(); HEIGHT = displayCurrent.getHeight(); view = new View(WIDTH, HEIGHT); timer = new TimerThread(ANIMATION_DELAY, myCanvas); timer.start(); } }; thread.start(); }