1 / 36

제 7 장 UI 개발에서 Low-Level API 사용하기

제 7 장 UI 개발에서 Low-Level API 사용하기. Canvas Graphics Low-Level Event 와 EventHandling Double Buffering. 1. Canvas class. Low-Level API 의 종류 -Canvas : 그래픽 작업 실행하고 low-level event 가 전달되는 클래스 . -Graphics : 문자열과 이미지 , 도형을 그리고 채우는데 사용하는 클래스. 1-1. paint() 메소드.

Download Presentation

제 7 장 UI 개발에서 Low-Level API 사용하기

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 제 7장 UI개발에서 Low-Level API 사용하기 Canvas Graphics Low-Level Event와 EventHandling Double Buffering

  2. 1. Canvas class • Low-Level API의 종류 -Canvas :그래픽 작업 실행하고 low-level event가 전달되는 클래스. -Graphics : 문자열과 이미지, 도형을 그리고 채우는데 사용하는 클래스.

  3. 1-1. paint() 메소드 • 1. 기능: Canvas에 이미지 등을 그린다. • 2. 사용방법 : abstract class인 Canvas class를 상속 받아 이 메소드를 구현해야 • javax.microedition.lcdui.Canvas • public abstract class Canvas extends Displayable • protected abstract void paint(Graphicsg).

  4. 1-2. Canvas size • 메소드 int getHeight() Gets height of the displayable area in pixels. int getWidth()Gets width of the displayable area in pixels.

  5. 1-3. Event • 1. addCommand() 사용해서 Canvas에 command추가-setCommandListener()메소드 사용해 CommandLisetener Canvas에 등록하여 high-level event 이벤트 실행 할 수 있다.

  6. 2. Graphics class • javax.microedition.lcdui.Graphics • public class Graphics extends Object • 그래픽 객체 획득하기 : 유일한 방법은 Canvas 객체에서 paint(Graphics g)메소드를 사용하는것.

  7. Field Summary Graphics class Field staticint BASELINEConstant for positioning the anchor point at the baseline of text. staticint BOTTOMConstant for positioning the anchor point of text and images below the text or image. staticint DOTTEDConstant for the DOTTED stroke style. staticint HCENTERConstant for centering text and images horizontally around the anchor point staticint LEFTConstant for positioning the anchor point of text and images to the left of the text or image. staticint RIGHTConstant for positioning the anchor point of text and images to the right of the text or image. staticint SOLIDConstant for the SOLID stroke style. staticint TOPConstant for positioning the anchor point of text and images above the text or image. staticint VCENTERConstant for centering images vertically around the anchor point.

  8. 2-1.paint(Graphics g) • 화면에 객체를 표현하는 유일한 방법 • getGraphics()라는 Image class 메소드 통해 이미지 불러와 저장할 수 있다.

  9. 2-2.좌표계 • 왼쪽 위 구석에서 오른쪽(X), 아래쪽(Y)으로 갈수록증가함.

  10. 2-3.그리기와 채우기 • 선,호, 사각형 그리기 메소드 제공

  11. 2-4. Color • boolean isColor() :display class인 이메소드 통해 장치에서 지원되는 색상(TRUE일때), 지원되는 흑백명암(false일때) 알 수 있다.

  12. 2-5. Stroke Style • Graphic class에서는 두 가지 선의 타입이 있다. 하나는 DOTTED(점선), SOLID(살선)이다. • intgetStrokeStyle() : 선의 스타일 정보를 알아낸다. voidsetStrokeStyle(intstyle) : 선의 스타일을 설정한다.

  13. 2-6. 선그리기 • Void drawLine(intx1, inty1, intx2, inty2): 좌표(x1,y1)과 (y2,y2)를 잇는 선을 현재 설정된 색과 스타일로 그린다. 선이 지나가는 좌표의 오른쪽아래 픽셀이 변한다. (226 P)

  14. 2-7. 사각형그리기와 채우기 • void drawRect(intx, inty, intwidth, intheight) :직사각형 그리기 • void fillRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight): 색 채우기 • voiddrawRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight) :둥근사각형 그리기 • voidfillRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight) :색 채우기

  15. 2-8.호 그리기와 채우기 • voiddrawArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle) :호 그리기 • voidfillArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle) : 색 채우기

  16. 3. TEXT 그리기 • voiddrawChar(charcharacter, intx, inty, intanchor) • voiddrawChars(char[]data, intoffset, intlength, intx, inty, intanchor) • voiddrawString(Stringstr, intx, inty, intanchor) • voiddrawSubstring(Stringstr, intoffset, intlen, intx, inty, intanchor)

  17. 3-1.Font • +--javax.microedition.lcdui.Font • public final class Font • FontgetFont(): 폰트의 속성 가져옴.

  18. Field Summary Font class Field staticint FACE_MONOSPACEThe "monospace" font face. staticint FACE_PROPORTIONALThe "proportional" font face. staticint FACE_SYSTEMThe "system" font face. staticint SIZE_LARGEThe "large" system-dependent font size. staticint SIZE_MEDIUMThe "medium" system-dependent font size. staticint SIZE_SMALLThe "small" system-dependent font size. staticint STYLE_BOLDThe bold style constant. staticint STYLE_ITALICThe italicized style constant. staticint STYLE_PLAINThe plain style constant. staticint STYLE_UNDERLINEDThe underlined style constant.

  19. 3-2. 폰트 속성 • 스타일, 크기. 글자체 • 폰트 속성 정보 불러오는 메소드

  20. 3-3. 기준점 • 택스트를 그릴때 기준점을 기준으로 해서 그린다. 위치선정작업의 효율화 위함 • . voiddrawString(Stringstr, intx, inty, intanchor)메소드로 정함. • 가로방향 상수: LEFT,HCENTER,RIGH • 수직방향 상수 : TOP,BASELINE,BOTTOM • 두가지를 논리합으로 조합해 사용- |(OR)

  21. staticint 기준점 속성값 HCENTERConstant for centering text and images horizontally around the anchor point staticint LEFTConstant for positioning the anchor point of text and images to the left of the text or image. staticint RIGHTConstant for positioning the anchor point of text and images to the right of the text or image. staticint SOLIDConstant for the SOLID stroke style. staticint TOPConstant for positioning the anchor point of text and images above the text or image. staticint VCENTERConstant for centering images vertically around the anchor point.

  22. 3-4. 이미지 그리기 • voiddrawImage(Imageimg, intx, inty, intanchor)

  23. 3-5.좌표계 이동 • voidtranslate(intx, inty) :좌표의 원점을 변경. 좌표계의 원점을 (X,Y)로 변경. • intgetTranslateX():좌표계의 원점을 파악하는메소드, • intgetTranslateY()

  24. 3-6.clip • Clip은 사각형의 영역,그래픽 작업 할때 clip영역안에 있는 픽셀만 영향 받음. • voidsetClip(intx, inty, intwidth, intheight) : clip정의 메소드, drawRect()의 파라미터와 동일. -voidclipRect(intx, inty, intwidth, intheight) : 주어진 사각형과 현재의 clip영역 교차한다.

  25. int Clip 위치와 demension(수치)구하기 getClipHeight()Gets the height of the current clipping area. int getClipWidth()Gets the width of the current clipping area. int getClipX()Gets the X offset of the current clipping area, relative to the coordinate system origin of this graphics context. int getClipY()Gets the Y offset of the current clipping area, relative to the coordinate system origin of this graphics context.

  26. 4.Low-level event and handling 1.이벤트 핸들링 메소드 • ; 빈 body로 구현, • Paint()는 추상메소드. • showNotify(): ㅊcanvas객체가 보이기전에 호출. • hideNotify(): canvas객체가 사라진 후 호출

  27. 4-1. Key event • 사용자가 키패드를 눌렀을때 에플리케이션에서는 키이벤트를 받는다. • 전화기의 키패드의 키에 대응하는 값.

  28. 4-2.Key event handling • protected voidkeyPressed(intkeyCode)Called when a key is pressed. • protected voidkeyReleased(intkeyCode)Called when a key is released. -protected voidkeyRepeated(intkeyCode)키를 반복해서 눌렀을 때 발생 - booleanhasRepeatEvents() :key-repeated 이벤트 지원하는지 알고싶을때.

  29. 4-3. Game Action • intgetKeyCode(intgameAction): 키코드와 game action사이 변환 할때 사용 • StringgetKeyName(intkeyCode) : 키코드를 게임action에 멥핑함.

  30. 4-4. 포인터 이벤트 • 터치스크린에서 사용. MIDP지원안함. • protected voidpointerDragged(intx, inty)Called when the pointer is dragged. • protected voidpointerPressed(intx, inty)Called when the pointer is pressed. • protected voidpointerReleased(intx, inty)Called when the pointer is released.

  31. 4-5. Represhing the Display • Canvas 에서 화면이 갱신되면 사용자가 디스플레이 갱신해 주오야 함. • voidrepaint() :canvas에서 지정한 부분만 다시 그림.그래픽 클레스의 paint()호출함. • voidrepaint(intx, inty, intwidth, intheight) : 전부 다시 그림. • voidserviceRepaints() : 갱신요청에 즉시 반응하기 위한 메소드(272 P)

  32. 5. Double Buffering • 캔버스영역에 직접그리는 것이 아니고 보이지 않는 화면(offscreen)에 캔버스의 그릴 영역을 복사해놓고, 업데이트 할 때가 되면 여기다 그림을 그린 후 그 이미지를 캔버스에 복사해서 붙인다. • 버퍼에 잇는 내용이 실제 화면에 그려지;는 것을 말한다. • booleanisDoubleBuffered() : 더블버퍼링 지원하는지 알고싶을때 사용.

  33. Buffer_image=Image.createImage(width,height); : offscreen 이미지 생성 • Bg=buffer_image.getGraphics(); 이미지를 그리기 위한 graphics객체 획득한다. • Graphics객체는 사용후 • Bg=null;이라 해야. 자원낭비 안함.

  34. staticint 게임 action정의 DOWNConstant for the DOWN game action. staticint FIREConstant for the FIRE game action. staticint GAME_AConstant for the general purpose "A" game action. staticint GAME_BConstant for the general purpose "B" game action. staticint GAME_CConstant for the general purpose "C" game action. staticint GAME_DConstant for the general purpose "D" game action.

  35. staticint KEY_NUM0keyCode for ITU-T key 0. staticint KEY_NUM1keyCode for ITU-T key 1. staticint KEY_NUM2keyCode for ITU-T key 2. staticint KEY_NUM3keyCode for ITU-T key 3. staticint KEY_NUM4keyCode for ITU-T key 4. staticint KEY_NUM5keyCode for ITU-T key 5. staticint KEY_NUM6keyCode for ITU-T key 6. staticint KEY_NUM7keyCode for ITU-T key 7. staticint KEY_NUM8keyCode for ITU-T key 8. staticint KEY_NUM9keyCode for ITU-T key 9. staticint KEY_POUNDkeyCode for ITU-T key "pound" (#).

  36. protected void protected void protected void 메소드 keyPressed(intkeyCode)Called when a key is pressed. showNotify() hideNotify() protected void keyReleased(intkeyCode)Called when a key is released. protected void keyRepeated(intkeyCode)Called when a key is repeated (held down). protected abstract void paint(Graphicsg)Renders the Canvas. protected void pointerDragged(intx, inty)Called when the pointer is dragged. protected void pointerPressed(intx, inty)Called when the pointer is pressed. protected void pointerReleased(intx, inty)Called when the pointer

More Related