source: branches/reyalp-flt/CHDK/LUALIB/drawings.lua @ 1493

Revision 1493, 6.5 KB checked in by tsv, 17 months ago (diff)

Flat module branch update:

  • Reconcile to trunk1492
  • Improve usermenu to store menuitems absent in .lng as hash (for better processing modules menu)
  • Improve core auto-versioning (use x.xx.xx instead of revision, which allow to compile-from-box)
  • Improve module load checks (cancel load if autoimport symbol is empty [module base on obsolete chdk mechanizm])
  • Improve makeexport to simplify sharing defines from core to modules
  • Separate module_exportlist.c compilation
RevLine 
[1493]1--[[
2Special Lua module that makes drawing much more usefull and easy-to-use.
3This module requires function such as: draw_pixel(), draw_rect() and others to be present
4]]
5
6--Author:  Outslider
7--License: GPL all versions
8
9SCREEN_DRAWINGS={}
10
11draw={}
12
13draw.add = function( d_type, p1, p2, p3, p4, p5, p6, p7 )
14    local n=table.getn(SCREEN_DRAWINGS)+1
15    if d_type=="pixel" then
16        SCREEN_DRAWINGS[n]={"p",p1,p2,p3}--x,y,cl
17        return n;
18        end
19    if d_type=="line" then
20        SCREEN_DRAWINGS[n]={"l",p1,p2,p3,p4,p5}--x1,y1,x2,y2,cl
21        return n;
22        end
23    if d_type=="rect" then
24        SCREEN_DRAWINGS[n]={"r",p1,p2,p3,p4,p5,p6}--x1,y1,x2,y2,cl,th
25        return n;
26        end
27    if d_type=="rectf" then
28        SCREEN_DRAWINGS[n]={"rf",p1,p2,p3,p4,p5,p6,p7}--x1,y1,x2,y2,clf,clb,th
29        return n;
30        end
31    if d_type=="elps" then
32        SCREEN_DRAWINGS[n]={"e",p1,p2,p3,p4,p5}--x,y,a,b,cl
33        return n;
34        end
35    if d_type=="elpsf" then
36        SCREEN_DRAWINGS[n]={"ef",p1,p2,p3,p4,p5}--x,y,a,b,clf
37        return n;
38        end
39    if d_type=="string" then
40        SCREEN_DRAWINGS[n]={"s",p1,p2,p3,p4,p5}--x,y,string,foreg_cl,backgr_cl
41        return n;
42        end
43    return false
44    end
45
46draw.replace = function( n, d_type, p1, p2, p3, p4, p5, p6, p7 )
47    draw.remove(n)
48    if d_type=="pixel" then
49        SCREEN_DRAWINGS[n]={"p",p1,p2,p3}--x,y,cl
50        return n;
51        end
52    if d_type=="line" then
53        SCREEN_DRAWINGS[n]={"l",p1,p2,p3,p4,p5}--x1,y1,x2,y2,cl
54        return n;
55        end
56    if d_type=="rect" then
57        SCREEN_DRAWINGS[n]={"r",p1,p2,p3,p4,p5,p6}--x1,y1,x2,y2,cl,th
58        return n;
59        end
60    if d_type=="rectf" then
61        SCREEN_DRAWINGS[n]={"rf",p1,p2,p3,p4,p5,p6,p7}--x1,y1,x2,y2,clf,clb,th
62        return n;
63        end
64    if d_type=="elps" then
65        SCREEN_DRAWINGS[n]={"e",p1,p2,p3,p4,p5}--x,y,a,b,cl
66        return n;
67        end
68    if d_type=="elpsf" then
69        SCREEN_DRAWINGS[n]={"ef",p1,p2,p3,p4,p5}--x,y,a,b,cl
70        return n;
71        end
72    if d_type=="string" then
73        SCREEN_DRAWINGS[n]={"s",p1,p2,p3,p4,p5}--x,y,string,foreg_cl,backgr_cl
74        return n;
75        end
76    return false
77    end
78
79draw.get_params = function(n)
80    local out={nil}
81    if SCREEN_DRAWINGS[n][1] == "p" then out[1]="pixel" end
82    if SCREEN_DRAWINGS[n][1] == "l" then out[1]="line" end
83    if SCREEN_DRAWINGS[n][1] == "r" then out[1]"rect" end
84    if SCREEN_DRAWINGS[n][1] == "rf" then out[1]"rectf" end
85    if SCREEN_DRAWINGS[n][1] == "e" then out[1]="elps" end
86    if SCREEN_DRAWINGS[n][1] == "ef" then out[1]="elpsf" end
87    if SCREEN_DRAWINGS[n][1] == "s" then out[1]="string" end
88    if (out[1]~=nil) then
89        for i=2, table.getn(SCREEN_DRAWINGS[n]) do
90            out[i]=SCREEN_DRAWINGS[n][i]
91            end
92        end
93    return out
94    end
95
96draw.overdraw = function()
97    for i=1,table.getn(SCREEN_DRAWINGS) do
98        local d_type=SCREEN_DRAWINGS[i][1]
99        if d_type=="p" then
100            local x=SCREEN_DRAWINGS[i][2]
101            local y=SCREEN_DRAWINGS[i][3]
102            local c=SCREEN_DRAWINGS[i][4]
103            draw_pixel(x,y,draw.make_color(c))
104            end
105        if d_type=="l" then
106            local x1=SCREEN_DRAWINGS[i][2]
107            local y1=SCREEN_DRAWINGS[i][3]
108            local x2=SCREEN_DRAWINGS[i][4]
109            local y2=SCREEN_DRAWINGS[i][5]
110            local c=SCREEN_DRAWINGS[i][6]
111            draw_line(x1,y1,x2,y2,draw.make_color(c))
112            end
113        if d_type=="r" then
114            local x1=SCREEN_DRAWINGS[i][2]
115            local y1=SCREEN_DRAWINGS[i][3]
116            local x2=SCREEN_DRAWINGS[i][4]
117            local y2=SCREEN_DRAWINGS[i][5]
118            local c=SCREEN_DRAWINGS[i][6]
119            local t=SCREEN_DRAWINGS[i][7]
120            draw_rect(x1,y1,x2,y2,draw.make_color(c),t)
121            end
122        if d_type=="rf" then
123            local x1=SCREEN_DRAWINGS[i][2]
124            local y1=SCREEN_DRAWINGS[i][3]
125            local x2=SCREEN_DRAWINGS[i][4]
126            local y2=SCREEN_DRAWINGS[i][5]
127            local cf=SCREEN_DRAWINGS[i][6]
128            local cb=SCREEN_DRAWINGS[i][7]
129            local t=SCREEN_DRAWINGS[i][8]
130            draw_rect_filled(x1,y1,x2,y2,draw.make_color(cf),draw.make_color(cb),t)
131            end
132        if d_type=="e" then
133            local x=SCREEN_DRAWINGS[i][2]
134            local y=SCREEN_DRAWINGS[i][3]
135            local a=SCREEN_DRAWINGS[i][4]
136            local b=SCREEN_DRAWINGS[i][5]
137            local c=SCREEN_DRAWINGS[i][6]
138            draw_ellipse(x,y,a,b,draw.make_color(c))
139            end
140        if d_type=="ef" then
141            local x=SCREEN_DRAWINGS[i][2]
142            local y=SCREEN_DRAWINGS[i][3]
143            local a=SCREEN_DRAWINGS[i][4]
144            local b=SCREEN_DRAWINGS[i][5]
145            local c=SCREEN_DRAWINGS[i][6]
146            draw_ellipse_filled(x,y,a,b,draw.make_color(c))
147            end
148        if d_type=="s" then
149            local x=SCREEN_DRAWINGS[i][2]
150            local y=SCREEN_DRAWINGS[i][3]
151            local s=SCREEN_DRAWINGS[i][4]
152            local cf=SCREEN_DRAWINGS[i][5]
153            local cb=SCREEN_DRAWINGS[i][6]
154            draw_string(x,y,s,draw.make_color(cf),draw.make_color(cb))
155            end
156        end
157    end
158
159draw.redraw = function()
160    draw_clear()  --note: it's not "draw.clear()" from this module but "draw_clear()" - a lua command!
161    draw.overdraw()
162    end
163
164draw.make_color = function(c)
165    --note - c variable changes type if it's a correct string!
166    if (c=="trans")         then c=255+1 end
167    if (c=="black")         then c=255+2 end
168    if (c=="white")         then c=255+3 end
169    if (c=="red")           then c=255+4 end
170    if (c=="red_dark")      then c=255+5 end
171    if (c=="red_light")     then c=255+6 end
172    if (c=="green")         then c=255+7 end
173    if (c=="green_dark")    then c=255+8 end
174    if (c=="green_light")   then c=255+9 end
175    if (c=="blue")          then c=255+10 end
176    if (c=="blue_dark")     then c=255+11 end
177    if (c=="blue_light")    then c=255+12 end
178    if (c=="grey")          then c=255+13 end
179    if (c=="grey_dark")     then c=255+14 end
180    if (c=="grey_light")    then c=255+15 end
181    if (c=="yellow")        then c=255+16 end
182    if (c=="yellow_dark")   then c=255+17 end
183    if (c=="yellow_light")  then c=255+18 end
184    return c
185    end
186
187draw.remove = function(n)
188    if (n<=table.getn(SCREEN_DRAWINGS)) then
189        for i=1,table.getn(SCREEN_DRAWINGS[n]) do
190            SCREEN_DRAWINGS[n][i]=nil
191            end
192        end
193    end
194
195draw.clear = function()
196    for i=1, table.getn(SCREEN_DRAWINGS) do
197        draw.remove(i)
198        end
199    draw_clear()
200    end
Note: See TracBrowser for help on using the repository browser.