Cadence Skill 论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 20071|回复: 16

FORM中的图形绘制步骤简介

[复制链接]
发表于 2013-6-5 19:59:28 | 显示全部楼层 |阅读模式
简介:因学习这个东西浪费了几个小时,特此写出来给大家看看,多多指正。
在窗体中添加图形和图片,用于示意、logo等,如Paddesigner的views,在form中新建一个图形或图片可以概括为四个步骤
1.首先在form中定义一块区域,用于放置图像与图形。
关于尺寸没有严格要求,只要你比例得当就好。如你想画一个3X4的图形框,那么可以就定义图框的长宽为(axlGRPDrwmapWindow handle 3 4),那么其他的图形属性都要比例一致。为了更精细的图形比例,可以定义成(axlGRPDrwMapWindow handle 3000 4000);那么线宽要可能要达到50或100了,把握比例就好。通常为达到效果可以现在绘图软件中绘制好,然后标注,确定比例尺寸。
2.调用axlGRPDrwInit函数,这个函数的参数是form、field、callback。
这个函数是调用图形包的函数,通过它可以让图形包显示在form中,callback就是图形包。
3.用提供的函数绘制图形函数。
第二条讲的callback就是调用图形的函数包,这个包包含图形属性和路径等。
4.用于更新图形。
update,为了实时控制,可能需要更新,如果是静态logo的话一般就不用了。
注意:不要图形不要超出边界

主要结构:

图形的form结构:
A. 图片form的结构
FIELD bitmap
THUMBNAIL                        ;图形块的格式类型,位图不能大于256色
OPTIONS stretch                   ;用于图片尺寸自适应调整,默认以图片中心调整
FLOC 5 17
FSIZE 29 5                        ;块的尺寸
ENDFIELD
B. 图片包的结构
图片包与图形包都是一个函数,图形源点都是左上。
defun( bitmap_callback (handle) ;handle是axlGRPDrwInit函数值的句柄,即通过handle就可以为axlGRPDrwInit函数值添加属性
    axlGRPDrwMapWindow( handle 232 60);为Form的块映射一个图形区域,好比有outline了也要有routekeepin。
       
    putprop( handle "unfilled" 'fill)        ;为将要绘制的矩形框添加一些属性,具体参照allegroskill;
    putprop( handle "black" 'color)                ;在16.3版本中有color、fill、width、text_align、text_bkmode、infos;
    putprop( handle 2 'width)                        ;这个属性也可表达为handle->width = 2,同样是添加属性。
    axlGRPDrwRectangle( handle '(1 1) '(249 54));绘制一个矩形框,参数是句柄,矩形的左上与右下

    axlGRPDrwBitmap( handle "D:/skill/test.bmp");加载一张图片,这个图片可以是绝对路径,也可以是相对路径。
);defun bitmap_callback
C. 图形包的结构(同上)
defun( graphic_callback (handle)

    (axlGRPDrwMapWindow handle 1200 1800);为Form的块映射一个图形区域,

    putprop( handle "unfilled" 'fill)        ;填充
    putprop( handle "red" 'color)                ;红色
    putprop( handle 3 'width)                        ;3个单位的线宽
        axlGRPDrwRectangle( handle '(1 1) '(1200 1800));尺寸
);defun graphic_callback
D. 调用图形包与图片包
bitmap_handle = axlGRPDrwInit(form "bitmap" 'bitmap_callback);调用图片包
此函数参数为:form、块、图片包函数(无参数)
graphic_handle = axlGRPDrwInit(form "graphic" 'graphic_handle);调用图形包
此函数参数为:form、块、图形包函数(无参数)
就是调用2和3的函数,handle 的属性间接的添加到bitmap_handle的属性中:
bitmap_handle->?
=》(color fill width transparent left infos)

函数:
axlGRPDrwBitmap(handle_bmp path_bmp)
载入位图函数,参数为:图形句柄,位图有效路径,可以是相对或绝对路径。位图必须是256色或以下。
axlGRPDrwCircle(handle_ origin R);圆
axlGRPDrwRectangle( handle '(1 1) '(1200 1800));矩形
axlGRPDrwLine( handle (list '(500 500) '(750 750)));线
axlGRPDrwLine( handle (list '(100 1500) '(150 1600) '(200 1400)));多边形
axlGRPDrwText( handle '(300 100) "Left text");字符

axlGRPDrwInit(r_form t_field t_func);图形包调用函数,
其用处是不仅可以调用图形包,也可以通过它去对图形包进行操作,如显示、更新、动态等。
axlGRPDrwMapWindow(r_graphics x_hgt x_width);为Field映射一个绘图区域
如同逻辑管脚与物理管脚映射一样,hight与width只是一个相对的值,主要是保持比例
axlGRPDrwUpdate(r_graphics);对图形进行更新,对于动态图形来说是一个重要的函数。

allegro 代码示例
  1. defun( IFormTest ()

  2. defvar(FFORM ,
  3. "
  4. \n FILE_TYPE=FORM_DEFN VERSION=2 \n
  5. \n FORM AUTOGREYTEXT \n
  6. \n FIXED\n
  7. \n PORT 44 14\n
  8. \n HEADER "Form"\n
  9. \n TILE\n
  10. \n
  11. \n FIELD redraw\n
  12. \n FLOC 21 8\n
  13. \n MENUBUTTON "Draw" 14 4\n
  14. \n ENDFIELD\n

  15. \n FIELD bitmap\n
  16. \n THUMBNAIL\n
  17. \n OPTIONS stretch\n   
  18. \n FLOC 5 17\n
  19. \n FSIZE 29 5\n
  20. \n ENDFIELD\n

  21. \n FIELD graphic\n
  22. \n THUMBNAIL\n
  23. \n FLOC 3 1\n
  24. \n FSIZE 15 15\n
  25. \n ENDFIELD\n

  26. \n ENDTILE\n
  27. \n ENDFORM\n
  28. "
  29. );defvar

  30.     fw = axlFormCreate((gensym) list("logoshow" FFORM)  '("NE" "msglines" 1) '_afCallback t nil )

  31.     bitmap_handle = axlGRPDrwInit(fw "bitmap" 'FlipIt) ;'FlipIt是callback函数,可以直接是'bitmap_callback
  32.     bitmap_handle->Flip = 0 ;图形区域显示控制变量
  33.         graphic_handle = axlGRPDrwInit(fw "graphic" 'FlipIt);'FlipIt是callback函数,可以直接是'graphic_callback
  34.     graphic_handle->Flip = 1 ;图形区域显示控制变量
  35.     fw->Bitmap_handle = bitmap_handle ;此式不是必须
  36.     fw->Graphic_handle = graphic_handle ;此式不是必须

  37.     axlFormDisplay(fw)
  38. );defun IFormTest()

  39. /* ***********************callback************************* */
  40. defun(_afCallback (fw)
  41.         case(fw->curField
  42.             ("redraw"
  43.             axlGRPDrwUpdate(fw->Bitmap_handle)
  44.             axlGRPDrwUpdate(fw->Graphic_handle)
  45.                 );#"redraw"
  46.         );case
  47. );defun callback

  48. ;其实如下的flip不是一个特定属性,只是将两个THUMBNAIL做交换而已,1与0也只是一个返回值。
  49. defun( FlipIt (handle)
  50.         if(handle->Flip == 0
  51.                 then
  52.                         bitmap_callback(handle)
  53.                         handle->Flip = 1
  54.                 else
  55.                     graphic_callback(handle)
  56.                         handle->Flip = 0
  57.         )
  58. );defun flip


  59. /* ***********************.bmp************************* */
  60. defun( bitmap_callback (handle)
  61. ; Must map the window
  62.     (axlGRPDrwMapWindow handle 232 60)
  63. ; Properties for outline rectangle
  64.     putprop( handle "unfilled" 'fill)
  65.     putprop( handle "black" 'color)
  66.     putprop( handle 2 'width)

  67.     axlGRPDrwRectangle( handle '(1 1) '(249 54))

  68. ; Example of using a bitmap
  69.     (axlGRPDrwBitmap handle "D:/skill/test.bmp")
  70. )

  71. /* ***********************graphic************************* */
  72. defun( graphic_callback (handle)
  73. ; Must map the window
  74.     (axlGRPDrwMapWindow handle 1200 1800)

  75. ; Example of setting option properties for fill, color and width
  76.     putprop( handle "unfilled" 'fill)
  77.     putprop( handle "red" 'color)
  78.     putprop( handle 3 'width)

  79. ; Example of  an unfilled, red,  rectangle
  80.     axlGRPDrwRectangle( handle '(1 1) '(1200 1800))

  81. ; Example of a filled black rectangle
  82.     putprop( handle "black" 'color)
  83.     putprop( handle "filled" 'fill)
  84.     axlGRPDrwRectangle( handle '(50 50) '(200 200))

  85. ; Example of an unfilled yellow rectangle with a really thick line
  86.     putprop( handle "unfilled" 'fill)
  87.     putprop( handle "yellow" 'color)
  88.     putprop( handle 50 'width)
  89.     axlGRPDrwRectangle( handle '(950 50) '(1100 500))
  90.     putprop( handle 3 'width)

  91. ; Example of a blue, unfilled circle
  92.     putprop( handle "blue" 'color)
  93.     axlGRPDrwCircle( handle '(600 900) 300)

  94. ; Example of a filled, green circle
  95.     putprop( handle "green" 'color)
  96.     putprop( handle "filled" 'fill)
  97.     axlGRPDrwCircle( handle '(600 900) 50)

  98. ; Example of a solid filled, green circle
  99.     putprop( handle "blue" 'color)
  100.     putprop( handle "filled_solid" 'fill)
  101.     axlGRPDrwCircle( handle '(200 1300) 90)

  102. ; Example of a red, simple line
  103.     putprop( handle "red" 'color)
  104.    ;handle->color = "green"
  105.     putprop( handle 50 'width)
  106.     axlGRPDrwLine( handle (list '(500 500) '(750 750)))

  107. ; Example of a red, poly line
  108.     putprop( handle "red" 'color)
  109.     putprop( handle 50 'width)
  110.     axlGRPDrwLine( handle (list '(100 1500) '(150 1600) '(200 1400)))

  111. ; Example of a white, filled, polygon
  112.     putprop( handle "white" 'color)
  113.     axlGRPDrwPoly( handle (list '(500 1500) '(650 1600) '(700 1400)))

  114. ; Example of a black, text, opaque background, left justified
  115.     putprop( handle "black" 'color)
  116.     putprop( handle "opaque" 'text_bkmode)
  117.     axlGRPDrwText( handle '(300 100) "Left text")

  118. ; Example of a red, text, transparent background. center justified
  119.     putprop( handle "red" 'color)
  120.     putprop( handle "transparent" 'text_bkmode)
  121.     putprop( handle "center" 'text_align)
  122.     axlGRPDrwText( handle '(300 200) "center text")
  123. );defun graphic_callback
复制代码
图片案例在附件,将其放在某一路径下,并在(axlGRPDrwBitmap handle "D:/skill/test.bmp");设置自己的路径即可使用。

test.rar

659 Bytes, 下载次数: 102, 下载积分: 贡献 1

案例

评分

参与人数 1威望 +5 SKILL币 +4 贡献 +2 收起 理由
vivienluo + 5 + 4 + 2 很给力!

查看全部评分

发表于 2013-6-5 21:49:49 | 显示全部楼层
{:soso_e100:}
感谢楼主的无私奉献。。。
发表于 2015-1-3 08:41:48 来自手机 | 显示全部楼层
非常感谢分享!!!
发表于 2015-6-4 08:57:02 | 显示全部楼层
谢谢楼主的分享,下载下来学习学习
发表于 2015-6-17 09:59:25 | 显示全部楼层
感谢楼主的无私奉献
发表于 2015-8-13 16:44:33 | 显示全部楼层
请问这个defvar()是你自己定义的函数么?
发表于 2015-8-29 10:38:57 | 显示全部楼层
非常感谢分享!!!
发表于 2015-8-31 18:45:30 来自手机 | 显示全部楼层
写的很详细,赞一个!
发表于 2016-7-7 14:16:15 | 显示全部楼层
请问如何把显示的图片以线条的形式放入板子中呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|网站地图|Cadence Skill 论坛 ( 蜀ICP备13024417号 )

GMT+8, 2024-4-16 23:16 , Processed in 0.197765 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表