--include "BetterLuaApi.lua" platform.apiLevel = '2.3' local disp=platform.window local dispX=disp:width() local dispY=disp:height() function centerText(gc, text, midX, midY) gc:drawString(text, midX-gc:getStringWidth(text)/2, midY-gc:getStringHeight(text)/2, "top") end function centerTextWithRect(gc, text, midX, midY, rectColor) centerText(gc, text, midX, midY) gc:setColorRGB(rectColor) gc:drawRect(midX-gc:getStringWidth(text)/2, midY-gc:getStringHeight(text)/2, gc:getStringWidth(text), gc:getStringHeight(text)) end function drawBoard(gc, sBX, sBY, sX, sY, bW, bH)--sB-sizeBoard, sX-startX, sY-startY, bW-boardWidth, bH-boardHeight local sizeRectX=bW/sBX local sizeRectY=bH/sBY for i=0, sBY do gc:drawLine(sX, sY+sizeRectY*i, sX+bW, sY+sizeRectY*i) end for i=0, sBX do gc:drawLine(sX+sizeRectX*i, sY, sX+sizeRectX*i, sY+bH) end end function fTriangle(gc, x1, y1, x2, y2, x3, y3)--f=fill local points={{x1, y1}, {x2, y2}, {x3, y3}} for i=1, 3 do for j=i,3 do if points[i][2]>points[j][2] then local tmp={points[i][1], points[i][2]} points[i][1]=points[j][1] points[i][2]=points[j][2] points[j][1]=tmp[1] points[j][2]=tmp[2] elseif points[i][2]==points[j][2] then if points[i][1]>points[j][1] then local tmp={points[i][1], points[i][2]} points[i][1]=points[j][1] points[i][2]=points[j][2] points[j][1]=tmp[1] points[j][2]=tmp[2] end end end end if points[1][2]==points[2][2] then--two points are smaller coords. increment y local xSlope1=(points[3][1]-points[1][1])/(points[3][2]-points[1][2]) local xSlope2=(points[3][1]-points[2][1])/(points[3][2]-points[2][2]) local startX=points[1][1] local endX=points[2][1] if endX=360 then self.coords[5]=self.coords[5]-360 end if self.coords[6]>=360 then self.coords[6]=self.coords[6]-360 end gc:drawArc(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5], self.coords[6]) elseif self.type==6 then self:moveCoords(1, x, y) gc:drawString(self.data, self.coords[1], self.coords[2]) elseif self.type==7 then self:moveCoords(1, x, y) gc:drawImage(self.data, self.coords[1], self.coords[2]) elseif self.type==8 then self:moveCoords(1, x, y) gc:drawRoundRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5]) elseif self.type==9 then for i=1, #self.coords, 2 do self:moveCoords(i, x, y) end gc:fillPolygon(self.coords) elseif self.type==10 then self:moveCoords(1, x, y) gc:fillRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4]) elseif self.type==11 then self.coords[1]=self.coords[1]+self.tx+x self.coords[2]=self.coords[2]+self.ty+y self.coords[5]=(self.coords[5]+self.rotAngle)%360 if self.coords[5]>=360 then self.coords[5]=self.coords[5]%360 end if self.coords[6]>=360 then self.coords[6]=self.coords[6]%360 end gc:fillArc(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5], self.coords[6]) elseif self.type==12 then self:moveCoords(1, x, y) gc:fillRoundRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], self.coords[5]) elseif self.type==13 then self:moveCoords(1, x, y) centerText(gc, self.data, self.coords[1], self.coords[2]) elseif self.type==14 then self:moveCoords(1, x, y) local tmpcolors1={math.floor(self.color/0x10000), math.floor((self.color%0x10000)/0x100), self.color%0x100} local tmpcolors2={math.floor(self.color2/0x10000), math.floor((self.color2%0x10000)/0x100), self.color%0x100} gc:fillGradientRect(self.coords[1], self.coords[2], self.coords[3], self.coords[4], tmpcolors1, tmpcolors2) elseif self.type==15 then self:moveCoords(1, x, y) gc:fillCircle(self.coords[1], self.coords[2], self.coords[3]) elseif self.type==16 then self.coords[1]=self.coords[1]+self.tx+x self.coords[2]=self.coords[2]+self.ty+y local tmpcolors1={math.floor(self.color/0x10000), math.floor((self.color%0x10000)/0x100), self.color%0x100} local tmpcolors2={math.floor(self.color2/0x10000), math.floor((self.color2%0x10000)/0x100), self.color%0x100} gc:fillGradientCircle(self.coords[1], self.coords[2], self.coords[3], tmpcolors1, tmpcolors2) end for i=1, #self.coords do self.coords[i]=self.tmpCoords[i] end end end do glib=class() function glib:init(width, height) self.width=width self.height=height self.Shapes={} self.rotAngle=0 end function glib:addShape(s, x, y, rotAngle) self.Shapes[#self.Shapes+1]=shape.clone(s) self.Shapes[#self.Shapes]:translate(x, y) end function glib:rotate(angle) self.rotAngle=angle%360 end function glib:changeRot(angle) self.rotAngle=(self.rotAngle+angle)%360 end function glib:draw(gc, x, y, mode) local changeX=0 local changeY=0 if mode~=nil then if mode=="middle" then changeX=self.width/2 changeY=self.height/2 elseif mode=="midtop" then changeX=self.width/2 elseif mode=="midbottom" then changeX=self.width/2 changeY=self.height end end gc:clipRect("set", x-changeX, y-changeY, self.width, self.height) for i=1, #self.Shapes do local tmp=self.Shapes[i].rotAngle self.Shapes[i]:rotate(self.Shapes[i].rotAngle+self.rotAngle) self.Shapes[i]:draw(gc, x, y) self.Shapes[i]:rotate(tmp) end gc:clipRect("reset") end end