The ControlBar
class draws the video controls
that are displayed on top of the canvas.
The drawControlBar
method is called from the VideoCanvas
class when it wants to draw the controls on top of the canvas.
The method first draws the box for the icons, and then checks which
buttons it should draw and calls for the drawIconButton
method for each icon.
public void drawControlBar(Graphics g) { dg = DirectUtils.getDirectGraphics(g); button_width = (width / 3) - W_GAP; button_height = (height) - 2 * H_GAP; first_button_x = x + W_GAP; first_button_y = y + H_GAP; second_button_x = first_button_x + button_width + W_GAP; second_button_y = y + H_GAP; third_button_x = second_button_x + button_width + W_GAP; third_button_y = y + H_GAP; // The whole ControlBar area dg.setARGBColor(TRANSPARENT_COLOR); g.drawRoundRect(x, y, width, height, 30, 30); // First button: Camera takes snapshot, video toggles play/stop if (parent.getType() == VideoOverlayMIDlet.CAMERA) { if (this.button_type == VideoOverlayMIDlet.ICON && snap_icon != null) { this.drawIconButton(g, first_button_x, first_button_y, button_width, button_height, snap_icon); } } else { if (parent.getPlayerState() == Player.PREFETCHED) { if (this.button_type == VideoOverlayMIDlet.ICON && play_icon != null) { this.drawIconButton(g, first_button_x, first_button_y, button_width, button_height, play_icon); } } else { if (this.button_type == VideoOverlayMIDlet.ICON && pause_icon != null) { this.drawIconButton(g, first_button_x, first_button_y, button_width, button_height, pause_icon); } } } // Second button: Toggles full screen mode if (parent.isFullScreen()) { if (this.button_type == VideoOverlayMIDlet.ICON && normalScreen_icon != null) { this.drawIconButton(g, second_button_x, second_button_y, button_width, button_height, normalScreen_icon); } } else { if (this.button_type == VideoOverlayMIDlet.ICON && fullScreen_icon != null) { this.drawIconButton(g, second_button_x, second_button_y, button_width, button_height, fullScreen_icon); } } // Third button: Hides ControlBar if (this.button_type == VideoOverlayMIDlet.ICON && hide_icon != null) { this.drawIconButton(g, third_button_x, third_button_y, button_width, button_height, hide_icon); } }
The drawIconButton
method draws the individual
icon for the control bar:
private void drawIconButton(Graphics g, int x, int y, int width, int height, Image icon) { dg.setARGBColor(BUTTON_TRANSPARENT_COLOR); g.fillRect(x, y, width, height); g.drawImage(icon, x + (width / 2), y + (height / 2), Graphics.VCENTER | Graphics.HCENTER); }