设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3367|回复: 4
打印 上一主题 下一主题

[RMVA发布] 开坑YUI=Yangff's UI

[复制链接]

Lv2.观梦者

傻♂逼

梦石
0
星屑
369
在线时间
1605 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

跳转到指定楼层
1
发表于 2012-1-19 01:50:59 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 yangff 于 2012-1-19 19:02 编辑

绝大多数内容未完成。。各种坑中,希望年前能坑出来吧~估计BUG很多,很多地方也没有优化。求测试,还有要放置Pointer作为鼠标图片。。别的没什么了,可能比较卡,开了摸你傻会更卡,是个大坑呢~目的是简化窗口制作。
http://yangff.is-programmer.com/posts/31786.html
截图

前置定义
WndProc&Mouse for YUI 最新版本:1
  1. $apicache = {}
  2. class String
  3.    def apicall(*args)
  4.        $apicache[self] = Win32API.new(*self.split("|")) unless $apicache.include? self
  5.        $apicache[self].call(*args)
  6.    end
  7. end

  8. class Symbol
  9.   def method_missing(*args, &block)
  10.      self.to_s.send(*args, &block)
  11.   end
  12. end
  13. class Win32API
  14.   WM_ACTIVATEAPP=0x1C
  15.   WM_MOUSEMOVE=0x200
  16.   WM_MOUSEWHEEL = 0x020A
  17.   WM_LBUTTONDOWN = 0x201
  18.   WM_RBUTTONDOWN = 0x204
  19.   WM_MOUSEDOWN = 0x210
  20.   WM_LBUTTONUP = 0x202
  21.   WM_RBUTTONUP = 0x205
  22.   WM_LBUTTONDBLCLK  = 0x203
  23.   WM_RBUTTONDBLCLK  = 0x204
  24. end
  25. module Roost   
  26.     module MainWindow
  27.         def self.getwndproc
  28.            @wndproc
  29.          end
  30.         def self.setwndproc(obj)
  31.            @wndproc=obj
  32.         end
  33.         def self.addwndproc(obj)
  34.           @@wndprocs.push(obj)
  35.         end
  36.         @@wndprocs=[]
  37.         @wndproc = lambda {|hwnd, msg, wp, lp|
  38.           @@handle=false
  39.           for i in @@wndprocs
  40.             i.call(hwnd, msg, wp, lp)
  41.           end
  42.           return Roost::MainWindow.use_rm_proc(hwnd, msg, wp, lp)
  43.         }
  44.         def self.use_rm_proc(hwnd,msg,wp,lp)
  45.           if (not @@handle)
  46.             @@handle=true
  47.             return :"user32|CallWindowProc|iiiii|i".apicall(@@oHandle,hwnd,msg,wp,lp)
  48.           end
  49.         end
  50.         def self.disable_rm_proc
  51.           @@handle=true
  52.         end
  53.         def self.enable
  54.               Roost::MainWindow.instance_eval do
  55.                 def self.enable
  56.                 end
  57.               end
  58.             Roost::MainWindow.instance_eval do
  59.               @msg = "\0"*24
  60.               @hwnd = 0
  61.               while @hwnd==0
  62.                :"user32|GetMessage|piii|v".apicall(@msg, 0, 0, 0)
  63.                @kmsg = @msg
  64.                :"user32|TranslateMessage|p|v".apicall(@kmsg)
  65.                :"user32|DispatchMessage|p|v".apicall(@kmsg)
  66.                @hwnd = @msg.unpack("i*")[0]
  67.              end
  68.             @hdc = :"user32|GetDC|i|i".apicall(@hwnd)
  69.             def self.hwnd
  70.                return @hwnd
  71.             end
  72.             def self.hdc
  73.               return @hdc
  74.             end
  75.             
  76.             def self.findProc(l, n)
  77.                    lib = :"kernel32|LoadLibrary|p|i".apicall(l);
  78.                    ret = :"kernel32|GetProcAddress|ip|l".apicall(lib, n);
  79.                    :"kernel32|FreeLibrary|l|v".apicall(lib)
  80.                    return ret
  81.             end
  82.                  def self.loadfindProc(l, n)
  83.                    lib = :"kernel32|LoadLibrary|p|i".apicall(l);
  84.                    ret = :"kernel32|GetProcAddress|ip|l".apicall(lib, n);
  85.                    return ret
  86.             end
  87.             def self.enableWndProc
  88.               Roost::MainWindow.instance_eval do
  89.                 def self.enableWndProc
  90.                 end
  91.               end
  92.               @malloc = :"msvcrt|malloc|i|i"
  93.               @memcpy = :"msvcrt|memcpy|ipi|v"
  94.               
  95.               
  96.              sprintf    = self.findProc("msvcrt",    "sprintf")
  97.              rgsseval   = self.findProc("RGSS300",  "RGSSGetInt")
  98.              old        = :"user32|GetWindowLong|ll|l".apicall(@hwnd, -4)
  99.              buf        = @malloc.apicall(1024)  
  100.              fmt        = @malloc.apicall(2048)
  101.              sprintfvar = @malloc.apicall(8)
  102.              rgssevalvar= @malloc.apicall(8)
  103.              oldvar     = @malloc.apicall(8)
  104.              fmtvar     = @malloc.apicall(8)
  105.              bufvar     = @malloc.apicall(8)
  106.              defvar     = @malloc.apicall(8)
  107.             
  108.              :"msvcrt|strcpy|pp|p".apicall(fmt, "Roost::MainWindow.getwndproc.call(%d,%d,%d,%d)")
  109.             
  110.              @memcpy.apicall(sprintfvar, [sprintf].pack("i"),  4)
  111.              @memcpy.apicall(rgssevalvar,[rgsseval].pack("i"), 4)
  112.              @memcpy.apicall(oldvar,     [old].pack("i"),      4)
  113.              @memcpy.apicall(fmtvar,     [fmt].pack("i"),      4)
  114.              @memcpy.apicall(bufvar,     [buf].pack("i"),      4)
  115.              @memcpy.apicall(defvar,     [self.findProc("user32", "DefWindowProcA")].pack("i"),      4)
  116.             
  117.              @code = [0x55,0x89,0xe5,0xff,0x75,0x14,
  118.                       0xff,0x75,0x10,0xff,0x75,0x0c,
  119.                       0xff,0x75,0x08,0xff,0x35].pack('C*')
  120.              @code << [fmtvar].pack('l') << [0xff, 0x35].pack('C*')
  121.              @code << [bufvar].pack('l') << [0xff, 0x15].pack('C*')
  122.              @code << [sprintfvar].pack("l")
  123.              @code << [0xff, 0x15].pack('C*')
  124.              @code << [rgssevalvar].pack("l")
  125. =begin
  126.              @code << [0x83,0xc4,0x18, 0xff, 0x75, 0x14,
  127.                        0xff,0x75, 0x10, 0xff, 0x75, 0x0c,
  128.                        0xff,0x75, 0x08, 0xff, 0x15].pack('C*')
  129.              @code << [oldvar].pack("l")
  130. =end
  131.              @code << [0x83,0xc4,0x18].pack('C*')
  132.              @code << [0xc9,0xc2,0x10,0x00].pack('C*')
  133.              #0xD1, 0xE8
  134.              @shellcode = @malloc.apicall(2048)  
  135.              @memcpy.apicall(@shellcode, @code, @code.size)
  136.              @@oHandle= :"user32|SetWindowLong|iii|i".apicall(@hwnd, -4, @shellcode)
  137.               #Returning Test : should be 5
  138.               #Roost::MainWindow.setwndproc (lambda{|hwnd, msg, wp, lp| 5})
  139.               #p :"user32|CallWindowProc|iiiii|i".apicall(@shellcode, 0, 0, 0, 0)
  140.             end
  141.           end
  142.          
  143.         end
  144.         
  145.   end
  146. end

  147. Roost::MainWindow.enable
  148. Roost::MainWindow.enableWndProc
  149. module Mouse
  150.   module_function
  151.   LKEY,RKEY,MKEY   = 1,2,4
  152.   DBLCTIME         = (Win32API.new('user32','GetDoubleClickTime','','l').call * 60.0 / 1000).round
  153.   @count    = 0     ## 双击时间计数
  154.   @dblc     = []    ## 双击记录[key,wait,[mouse_x,mouse_y]]
  155.   @move_pos = []    ## 移动记录
  156.   @clicks   = []    ## 单击记录
  157.   def _init_
  158.     @press,@toggled=0,0
  159.    
  160.     @pos=[0,0]

  161.     Roost::MainWindow.addwndproc (lambda {|hwnd, msg, wp, lp|
  162.       Mouse.onLMouseDown if msg==Win32API::WM_LBUTTONDOWN
  163.       Mouse.onRMouseDown if msg==Win32API::WM_RBUTTONDOWN
  164.       Mouse.onLMouseUp if msg==Win32API::WM_LBUTTONUP
  165.       Mouse.onRMouseUp if msg==Win32API::WM_RBUTTONUP
  166.       Mouse.onLMouseDD if msg==Win32API::WM_LBUTTONDBLCLK
  167.       Mouse.onRMouseDD if msg==Win32API::WM_RBUTTONDBLCLK
  168.       if msg==Win32API::WM_MOUSEMOVE
  169.         Mouse.setMouse([lp&0xffff,lp>>16])
  170.       end
  171.       if msg==Win32API::WM_LBUTTONDOWN or msg==Win32API::WM_RBUTTONDOWN
  172.         UIManager.onMouseDown
  173.       end
  174.       if msg==Win32API::WM_LBUTTONUP or msg==Win32API::WM_RBUTTONUP
  175.         UIManager.onMouseUp
  176.       end
  177.       if msg==Win32API::WM_MOUSEMOVE
  178.         
  179.         UIManager.onMouseMove
  180.       end
  181.     })
  182.     @ldown=false
  183.     @ltd=false
  184.     @rdown=false
  185.     @rtd=false
  186.     @lup=false
  187.     @rup=false
  188.   end
  189.   def onLMouseDown
  190.     @ltd=true
  191.     @ltd=false if @ldown
  192.     @ldown=true
  193.     #UIManager.onLMouseDown
  194.   end
  195.   def onLMouseUp
  196.     @ldown=false
  197.     @ltd=false
  198.     #UIManager.onLMouseUp
  199.   end
  200.   def onLMouseDD
  201.    
  202.   end
  203.   def onRMouseDown
  204.     @rtd=true
  205.     @rtd=false if @rdown
  206.     @rdown=true
  207.     #UIManager.onRMouseDown
  208.   end
  209.   def onRMouseUp
  210.     @rdown=false
  211.     @rtd=false
  212.     #UIManager.onRMouseUp
  213.   end
  214.   def onRMouseDD
  215.    
  216.   end
  217.   def setMouse(p)
  218.     @pos=p
  219.   end
  220.   
  221.   #--------------------------------------------------------------------------
  222.   # ## 触发?
  223.   #--------------------------------------------------------------------------
  224.   def self.toggled?(key)
  225.     return @toggled & key != 0
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # ## 按下?
  229.   #--------------------------------------------------------------------------
  230.   def Mouse.press?(key)
  231.     return @press & key != 0
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # ## 单击?
  235.   #--------------------------------------------------------------------------
  236.   def self.click?(key)
  237.     return false if key == LKEY and !$click_abled
  238.     return @clicks[0] & key == 0 && @clicks[1] & key != 0
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ## 双击?
  242.   #--------------------------------------------------------------------------
  243.   def self.dbl_click?(key)
  244.     return false if @dblc.size < 2
  245.     ## 键值有效
  246.     if @dblc[1][0] & key != 0 and @dblc[0][0] & key != 0
  247.       ## 间隔有效
  248.       if @dblc[1][1] - @dblc[0][1] < DBLCTIME
  249.         ## 坐标有效
  250.         if @dblc[1][2] == @dblc[0][2]
  251.           return @clicks[0] & key == 0 && @clicks[1] & key != 0
  252.         end
  253.       end
  254.     end
  255.     return false
  256.   end
  257.   def pos
  258.     return @pos
  259.   end
  260.   def update
  261.     @press,@toggled=0,0
  262.     @press += LKEY   if @ldown
  263.     @press += RKEY   if @rdown
  264.     @toggled += LKEY if @ltd
  265.     @toggled += RKEY  if @rtd
  266.     @clicks.shift if @clicks.size >=2
  267.     @clicks.push @press
  268.     if @dblc.size >= 2
  269.       @dblc.clear
  270.       @count = 0
  271.     end
  272.     if @dblc.size == 1 and @count - @dblc[0][1] > DBLCTIME
  273.       @dblc.clear
  274.       @count = 0
  275.     end
  276.     if @clicks[0] == 0 and @clicks[1] != 0
  277.       if @dblc.size == 1 and @dblc[0][0] != @clicks[1]
  278.         @dblc.clear
  279.         @count = 0
  280.       end
  281.       @dblc.push [@press,@count,@pos]
  282.     end
  283.     @count += 1 unless @dblc.empty?
  284.     @move_pos.shift if @move_pos.size >= 2
  285.     @move_pos.push @pos
  286.     $click_abled=true
  287.   end
  288.   def down(p)
  289.     if (p==LEFT)
  290.       return @ldown
  291.     else
  292.       return @rdown
  293.     end
  294.   end
  295. end
  296. Roost::MainWindow.addwndproc (lambda {|hwnd, msg, wp, lp|
  297. if (msg==Win32API::WM_ACTIVATEAPP)
  298.   Roost::MainWindow.disable_rm_proc
  299.   return 0
  300. end

  301. })
  302. Mouse._init_






  303. class << Mouse
  304.   Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
  305.   $mousec = Sprite.new
  306.   $mousec.z = 10001
  307.   $mousec.x = $mousec.y = 1000
  308.   $mouse_icon = 'Pointer'
  309.   $mousec.bitmap = Cache.system($mouse_icon)
  310.   
  311.   alias wor_mouse_upd_mouse update unless $@
  312.   def Mouse.update
  313.     wor_mouse_upd_mouse
  314.     if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
  315.       $mouse_old_icon = $mouse_icon
  316.       $mousec.bitmap = Cache.system($mouse_old_icon)
  317.     end
  318.     if @pos.nil?
  319.       $mousec.x = 1000 if $mousec.x != 1000
  320.       $mousec.y = 1000 if $mousec.y != 1000
  321.       Win32API.new('user32', 'ShowCursor', 'l', 'l').call(1)
  322.     else
  323.       $mousec.x = @pos[0] if $mousec.x != @pos[0]
  324.       $mousec.y = @pos[1] if $mousec.y != @pos[1]
  325.       Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
  326.     end
  327.     ## 鼠标刷新
  328.     $mousec.update
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # ## 经过?
  332.   #     obj       : 对象实例
  333.   #                 **支持Sprite,Window,Viewport,Rect,Plane,可补充
  334.   #--------------------------------------------------------------------------
  335.   def Mouse.over?(obj)
  336.     case obj
  337.     when Sprite
  338.       x = obj.x-obj.ox; y = obj.y-obj.oy
  339.       unless obj.viewport.nil?
  340.         x += obj.viewport.rect.x
  341.         y += obj.viewport.rect.y
  342.       end
  343.       return Mouse.area?(x, y, obj.width, obj.height)
  344.     when Window
  345.       x = obj.x;y = obj.y
  346.       unless obj.viewport.nil?
  347.         x += obj.viewport.rect.x
  348.         y += obj.viewport.rect.y
  349.       end
  350.       return Mouse.area?(x, y, obj.width, obj.height)
  351.     when Viewport
  352.       return Mouse.area?(obj.rect.x, obj.rect.y, obj.rect.width, obj.rect.height)
  353.     when Rect
  354.       return Mouse.area?(obj.x, obj.y, obj.width, obj.height)
  355.     when Plane
  356.       x = obj.x;y = obj.y
  357.       unless obj.viewport.nil?
  358.         x += obj.viewport.rect.x
  359.         y += obj.viewport.rect.y
  360.       end
  361.       return Mouse.area?(x, y, obj.width, obj.height)
  362.     end
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Mouse in_area
  366.   #--------------------------------------------------------------------------
  367.   def Mouse.area?(x, y, width=32, height=32)
  368.     return false if @pos == nil
  369.     return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
  370.     return false
  371.   end

  372. end







  373. #==============================================================================
  374. # ## Window_Selectable
  375. #==============================================================================
  376. class Window_Selectable < Window_Base
  377.   alias wor_winsel_ini_mouse initialize
  378.   alias wor_winsel_upd_mouse update
  379.   def initialize(*args)
  380.     wor_winsel_ini_mouse(*args)
  381.     @scroll_wait = 0
  382.     @cursor_wait = 0
  383.   end

  384.   def update
  385.     wor_winsel_upd_mouse
  386.     if self.active and self.visible
  387.       update_mouse
  388.     end
  389.   end
  390.   
  391.   def update_mouse
  392.     @cursor_wait -= 1 if @cursor_wait > 0
  393.     (0...item_max).each do |i|
  394.       irect = mouse_rect(i)
  395.       irx = self.x + 16 + irect.x - self.ox
  396.       iry = self.y + 16 + irect.y - self.oy
  397.       result = Mouse.area?(irx, iry, irect.width, irect.height)
  398.       move_cursor(i) if result
  399.       ## 控制单击条件
  400.       $click_abled = false if i == @index and !result
  401.     end

  402.   end
  403.   
  404.   ## 鼠标区域
  405.   def mouse_rect(i)
  406.     rect = item_rect(i)
  407.     return rect if rect.width <= 32
  408.     rect.x += 4
  409.     rect.y += 4
  410.     rect.width -= 8
  411.     rect.height -= 8
  412.     return rect
  413.   end
  414.   def column_max
  415.     return row_max
  416.   end
  417.   def move_cursor(index)
  418.     ## 不响应
  419.     return if @cursor_wait > 0
  420.     return if self.index == index
  421.     @scroll_wait -= 1 if @scroll_wait > 0
  422.     row1 = self.index / column_max
  423.     row2 = index / column_max
  424.     bottom = self.top_row + (self.page_row_max - 1)
  425.     if row1 == self.top_row and row2 < self.top_row
  426.       return if @scroll_wait > 0
  427.       self.index = [self.index - column_max, 0].max
  428.       @scroll_wait = 4
  429.     elsif row1 == bottom and row2 > bottom
  430.       return if @scroll_wait > 0
  431.       self.index = [self.index + column_max, item_max - 1].min
  432.       @scroll_wait = 4
  433.     else
  434.       self.index = index
  435.     end
  436.     return if @cursor_wait > 0
  437.     Sound.play_cursor
  438.     @cursor_wait += 2
  439.   end
  440. end
复制代码
设定:YUI 最新版本:1
  1. $摸你傻效果开关,慎用!= false          #开启后在99%的机器上会SB
  2. =begin
  3.                   YUI = Yangff's User Interface
  4. Class Tree:
  5.   UIManager:
  6.     Window {Page{Controlers},Page{Controlers},...,Page{Controlers}}
  7.     Window {Page{Controlers},Page{Controlers},...,Page{Controlers}}
  8.     Window {Page{Controlers},Page{Controlers},...,Page{Controlers}}
  9.     ......
  10.     Window {Page{Controlers},Page{Controlers},...,Page{Controlers}}
  11. All method that start with yui_ is used for create Window Normally.
  12.   But ,you can also Create your Window by using
  13.   * set_child
  14.   * set_parent
  15.   * addListen
  16.   ...
  17.   in OnCreate.
  18.   Every Element has a parent.
  19.   Element in a page has a parent ,it's page
  20.   There can be a page in a window .
  21.   There can be a panel in a page or panel.
  22.   Window can only create by function:createWindow.
  23.   
  24.   Evnets:
  25.     YUI is running with EventSystem.
  26.     But you must know ,when you are designing an Window,
  27.     It's IMPOLITE for you to wirte :
  28.       def onCreate
  29.         super
  30.         ...
  31.       end
  32.     You should wirte them as
  33.       def onWindowCreate(sender,e)
  34.         
  35.       end
  36.       yui_addEvent YUI::Events::OnCreate ,:onWindowCreate
  37.     Or
  38.       def onWindowCreate(sender,e)
  39.         yui_addEvent YUI::Events::OnCreate ,:onWindowRender
  40.       end
  41.       
  42. =end
复制代码
UIManager 最新版本:1
  1. class Rect
  2.   def inarea?(pos)
  3.     xok = pos[0].between?((self.x),self.width+self.x)
  4.     yok = pos[1].between?((self.y),self.height+self.y)
  5.     return ((xok) and (yok))
  6.   end
  7. end
  8. module UIManager
  9.   module_function
  10.   def _init_
  11.     @@windowlist=[]
  12.     @@topwindowlist=[]
  13.     @@vireport=Viewport.new
  14.     @@vireport.z=9990
  15.     @@active=nil
  16.     @@draging=false
  17.     @@mousepos=[0,0]
  18.     @jumpflag=0
  19.     @handlemouse=false
  20.     @@windowSprite=Sprite.new(@@vireport)
  21.     @@windowSprite.bitmap=Bitmap.new(Graphics.width,Graphics.height)
  22.     @redraw=true
  23.   end
  24.   def viewport
  25.     return @@vireport
  26.   end
  27.   def onMouseDown
  28.     @hlist=@@windowlist+@@topwindowlist
  29.     for z in [email protected]
  30.       i=@hlist[@hlist.size-z-1]
  31.       if i.rect.inarea?(Mouse.pos)
  32.         i.startEvent(YUI::Events::OnMouseDown,Mouse,YUI::EventMessage.new({}))
  33.         return
  34.       end
  35.     end   
  36.   end
  37.   def onMouseUp
  38.     @hlist=@@windowlist+@@topwindowlist
  39.     for z in [email protected]
  40.       i=@hlist[@hlist.size-z-1]
  41.       if i.rect.inarea?(Mouse.pos)
  42.         i.startEvent(YUI::Events::OnMouseUp,Mouse,YUI::EventMessage.new({}) )
  43.         return
  44.       end
  45.     end
  46.   end
  47.   def onMouseMove
  48.     @hlist=@@windowlist+@@topwindowlist
  49.     @hked=false
  50.     for z in [email protected]
  51.       i=@hlist[@hlist.size-z-1]
  52.       if i.rect.inarea?(Mouse.pos)
  53.         i.startEvent(YUI::Events::OnMouseMove,Mouse,YUI::EventMessage.new({}) )
  54.         return
  55.       end
  56.     end
  57.   end
  58.   def _update_
  59.     rst = YUI::EventResult.new {}
  60.     @z=100
  61.     @click=false
  62.     Mouse.update
  63.     @click = true if Mouse.click?(Mouse::LKEY)
  64.     @tlist=[]
  65.     @mouseskip=false
  66.     @hlist=@@windowlist+@@topwindowlist
  67.     @redraw=false
  68.     for z in [email protected]
  69.       i=@hlist[@hlist.size-z-1]
  70.       
  71.       if (not @mouseskip) or @@dragobj==i
  72.         
  73.         if (i.rect.inarea?(Mouse.pos))and (@click)
  74.           @handlemouse=true
  75.          
  76.           if (@@active!=i)
  77.             @@active.startEvent(YUI::Events::OnLoseActive,self,nil) if @@active!=nil
  78.             @@active=i
  79.             @@oldactive=i
  80.             msg=YUI::EventMessage.new({})
  81.             i.startEvent(YUI::Events::OnActive,self,msg)
  82.             if @@windowlist.include?(i)
  83.               @@windowlist.delete(i)
  84.               @@windowlist<<i

  85.             end
  86.             i.need_render=true
  87.             @redraw=true
  88.           end
  89.           dragRect=Rect.new(i.rect.x+i.childrect.x,i.rect.y+i.childrect.y,i.childrect.width,i.childrect.height)
  90.           unless (dragRect.inarea?(Mouse.pos))
  91.             @@draging=true
  92.             @@dragobj=i
  93.             @@mousepos=Mouse.pos
  94.             @jumpflag=0
  95.           end
  96.         end
  97.         if ((Mouse.press?(Mouse::LKEY) or @jumpflag<0) and @@draging)
  98.           @jumpflag+=1 unless Mouse.press?(Mouse::LKEY)
  99.           @jumpflag=0 if Mouse.press?(Mouse::LKEY)
  100.           @handlemouse=true
  101.           if (i.rect.inarea?(Mouse.pos))
  102.             dragRect=Rect.new(i.rect.x+i.childrect.x,i.rect.y+i.childrect.y,i.childrect.width,i.childrect.height)
  103.             unless (dragRect.inarea?(Mouse.pos))
  104.               i.rect.x+=Mouse.pos[0]-@@mousepos[0]
  105.               i.rect.y+=Mouse.pos[1]-@@mousepos[1]
  106.               @redraw=true
  107.               @@mousepos=Mouse.pos
  108.               @jumpflag=0
  109.             end
  110.           end
  111.         else
  112.           @redraw=true if @@draging
  113.           @@draging=false
  114.          
  115.           @@dragobj=nil
  116.           @@mousepos=[0,0]
  117.         end
  118.         if i.rect.inarea?(Mouse.pos)
  119.           @mouseskip=true
  120.         end
  121.       end
  122.       i.sprite.x=i.rect.x
  123.       i.sprite.y=i.rect.y
  124.       @redraw=true if (i.sprite.x!=i.rect.x) or (i.sprite.y!=i.rect.y)
  125.       if i.need_render
  126.         @redraw=true
  127.         if i.sprite.bitmap.nil? or (i.sprite.bitmap.width!=i.rect.width) or(i.sprite.bitmap.height!=i.rect.height)
  128.           i.sprite.bitmap.dispose unless i.sprite.bitmap.nil? or i.sprite.bitmap.disposed?
  129.           bit = Bitmap.new(i.rect.width,i.rect.height)
  130.         else
  131.           bit=i.sprite.bitmap
  132.           bit.clear
  133.         end
  134.         
  135.         frameUpdate = YUI::EventMessage.new ({:result => rst,:bitmap => bit} )
  136.         
  137.         i.sprite.bitmap=bit   
  138.         
  139.         i.startEvent(YUI::Events::OnRender,self,frameUpdate)
  140.         i.bak_bitmap=i.sprite.bitmap.clone
  141.         i.need_render=false
  142.       end
  143.       [email protected]
  144.     end
  145.     if $摸你傻效果开关,慎用!
  146.     if @redraw
  147.       @@windowSprite.bitmap.clear#dispose
  148.       #@@windowSprite.bitmap=Graphics.snap_to_bitmap #.clear
  149.       for z in [email protected]
  150.         i=@hlist[z]
  151.         if not @@draging
  152.           bitmap=Bitmap.new(i.rect.width,i.rect.height)
  153.           bitmap.blt(0,0,@@windowSprite.bitmap,Rect.new(i.rect.x,i.rect.y,i.rect.width,i.rect.height))
  154.           #bitmap.radial_blur(120,16)#blur
  155.           2.times {bitmap.blur}
  156.           @@windowSprite.bitmap.clear_rect(Rect.new(i.rect.x,i.rect.y,i.rect.width,i.rect.height))
  157.           @@windowSprite.bitmap.blt(i.rect.x,i.rect.y,bitmap,Rect.new(0,0,i.rect.width,i.rect.height))
  158.         end
  159.         @@windowSprite.bitmap.blt(i.rect.x,i.rect.y,i.sprite.bitmap,Rect.new(0,0,i.rect.width,i.rect.height))
  160.       end
  161.       
  162.       #@@windowSprite.bitmap.blur if not @@draging
  163.     end
  164.    
  165.     end

  166.   end
  167.   def createWindow(window,*args)
  168.     return @@windowlist<<window.new(window,*args)# if window.is_a?(YUI::Window)
  169.     return false
  170.   end
  171.   def change_theme
  172.     for i in @@windowlist+@@topwindowlist
  173.       i.setThemeData
  174.       i.need_render=true
  175.     end
  176.   end
  177.   def disposeWindow(window)

  178.     result=YUI::EventResult.new{|o|o.cancel=false}

  179.     window.startEvent(YUI::Events::OnDispose,self,YUI::EventMessage.new({:result=>result}) )
  180.    
  181.     unless result.cancel
  182.       @@windowlist.delete(window)
  183.       @@topwindowlist.delete(window)
  184.       
  185.       window.sprite.bitmap.dispose
  186.       window.sprite.dispose
  187.     end
  188.   end
  189.   def handlemouse?
  190.     return @handlemouse
  191.   end
  192. end
  193. UIManager._init_
  194. #Innerface To Update
  195. class <<Graphics
  196. #  if @@old_update_UIManager.nil?
  197. #p methods
  198.     alias old_update update
  199.     def update
  200.       UIManager._update_
  201.       old_update
  202.     end
  203. #  end
  204. end
复制代码
UITheme 最新版本:1
  1. module YUI
  2.   class Theme
  3.     @@list={
  4.     :WindowNCBackGroundColor=>[Color.new(0,0,0,120),Color.new(255,255,255,120),false],
  5.     :WindowBackGroundColor=>Color.new(255,255,255,220),
  6.     :CT=>32,
  7.     :CL=>1,
  8.     :CR=>1,
  9.     :CB=>1,
  10.     :titleFont=>Font.new("微软雅黑",24),
  11.     :WindowContentOpcity=>120
  12.     }
  13.     @@functions={}
  14.   #  @@list[:titleFont].shadow=true
  15.   #  @@list[:titleFont].bold  = true
  16.     @@list[:titleFont].color=Color.new(255,255,255)
  17.     def [](k)
  18.       if not @@args[1].theme.nil?
  19.         if not @@args[1].theme[k].nil?
  20.           return @@args[1].theme[k]
  21.         end
  22.       end
  23.       return @@list[k]
  24.     end
  25.     def regfunc(name,proc)
  26.       @@functions[name]=proc
  27.     end
  28.     def setdata(sender,*args)
  29.       @@args=[nil,sender,args]
  30.     end
  31.     def func(name,sender,*args)
  32.       @@args=[name,sender,args]
  33.       if not sender.theme[name].nil?
  34.         sender.theme[name].call(name,sender,*args)
  35.         return
  36.       end
  37.       if args.size>0
  38.         case name
  39.         when :WindowNCBackGround
  40.           args[0].gradient_fill_rect(0,0,args[0].width,args[0].height,self[:WindowNCBackGroundColor][0],self[:WindowNCBackGroundColor][1],self[:WindowNCBackGroundColor][2])
  41.           if args[2][1]==:Normally
  42.             args[0].font = self[:titleFont]
  43.             
  44.           else
  45.             args[0].font = args[2][1]
  46.           end

  47.           args[0].draw_text(5,5,args[0].width-10,24,args[2][0])
  48.           #args[0].blur
  49.         when :WindowBackGround
  50.           args[0].clear_rect(self[:CL],self[:CT],args[0].width-self[:CL]-self[:CR],args[0].height-self[:CT]-self[:CB])
  51.           args[0].fill_rect(self[:CL],self[:CT],args[0].width-self[:CL]-self[:CR],args[0].height-self[:CT]-self[:CB],self[:WindowBackGroundColor])
  52.         else
  53.           unless @@functions[name].nil?
  54.             @@functions[name].call(name,*args)
  55.           else
  56.             raise "not defined theme"
  57.           end
  58.         end
  59.       end
  60.     end
  61.   end
  62.   module Themes
  63.     module_function
  64.     @@reg={}
  65.     def _init_
  66.       @theme=Theme.new
  67.     end
  68.     def regnewfunc(name,&proc)
  69.       @@reg[name]=proc
  70.       @theme.regfunc(name,proc)
  71.     end
  72.     def _load(filename,classname)
  73.       require filename
  74.       @theme = eval(classname+".new")
  75.       for i in @@reg.keys
  76.         @theme.regfunc(i,@@reg[i])
  77.       end
  78.       UIManager.change_theme
  79.     end
  80.     def _load_by_monery_(data,classname)
  81.       eval(data)
  82.       @theme = eval(classname+".new")
  83.       for i in @@reg.keys
  84.         @theme.regfunc(i,@@reg[i])
  85.       end
  86.       UIManager.change_theme
  87.     end
  88.     def get(name,sender,*args)
  89.       @theme.setdata(sender,*args)
  90.       return @theme[name]
  91.     end
  92.     def draw(func,sender,*args)
  93.       @theme.func(func,sender,*args)
  94.     end
  95.   end
  96. end
  97. YUI::Themes._init_
复制代码
UIFrame 最新版本:1
  1. module YUI
  2.   module Events
  3.     @@count=1
  4.     Ents={}
  5.     def self.yui_getfreeid
  6.       return @@count
  7.     end
  8.     def self.yui_addfreeid
  9.       @@count+=1
  10.     end
  11.     def self.yui_getaddfreeid(name)
  12.       yui_addfreeid
  13.       Ents[yui_getfreeid-1]=name
  14.       return yui_getfreeid-1
  15.     end
  16.     OnCreate=yui_getaddfreeid          :OnCreate
  17.     OnDispose=yui_getaddfreeid         :OnDispose
  18.     OnMouseMove=yui_getaddfreeid       :OnMouseMove
  19.     OnMouseDown=yui_getaddfreeid       :OnMouseDown
  20.     OnMouseUp=yui_getaddfreeid         :OnMouseUp
  21.     OnMouseOver=yui_getaddfreeid       :OnMouseOver
  22.     OnMouseLeave=yui_getaddfreeid      :OnMouseLeave
  23.     OnKeyBoardDown=yui_getaddfreeid    :OnKeyBoardDown
  24.     OnKeyBoardUp=yui_getaddfreeid      :OnKeyBoardUp
  25.     OnClick=yui_getaddfreeid           :OnClick
  26.     OnDoubleClick=yui_getaddfreeid     :OnDoubleClick
  27.     OnRender=yui_getaddfreeid          :OnRender
  28.     OnActive=yui_getaddfreeid          :OnActive
  29.     OnLoseActive=yui_getaddfreeid      :OnLoseActive
  30.     OnCommand=yui_getaddfreeid         :OnCommand
  31.   end
  32.   class UIFrame
  33.     @@events=[]
  34.     def self.yui_addEvent(event,method,first=false)
  35.       @@events<<{"Event"=>event,"method"=>method,"first"=>first,"src"=>self}
  36.     end
  37.   end
  38.   class EventMessage
  39.     attr_reader :cb
  40.     def initialize(cb)
  41.       @cb=cb
  42.     end
  43.     def get(name)
  44.       return @cb[name]
  45.     end
  46.     def set(name,data)
  47.       @cb[name]=data
  48.     end
  49.   end
  50.   class EventResult
  51.     attr_accessor :result
  52.     attr_accessor :cancel
  53.    
  54.     def initialize(&cb)
  55.       cb.call(self)
  56.     end
  57.   end
  58.   class UIFrame
  59.     attr_accessor :need_render
  60.     attr_accessor   :theme
  61.     def topparent
  62.       return @parent.topparent
  63.     end
  64.     def initialize(selfo,*args)
  65.       @events=[]
  66.       @need_render=true
  67.       for i in @@events
  68.         next unless self.kind_of?(i["src"])
  69.         @events[i["Event"]]=[] if @events[i["Event"]].nil?
  70.         if ((i["method"].is_a?(Symbol)) or (i["method"].is_a?(String)))
  71.           @events[i["Event"]]<<[method(i["method"]),i["first"]]
  72.         else
  73.           @events[i["Event"]]<<[i["method"],i["first"]]
  74.         end
  75.       end
  76.       @selfObject=selfo
  77.       startEvent(YUI::Events::OnCreate,self,EventMessage.new({:args=>args}))
  78.     end
  79.     def myName
  80.       return @selfObject.to_s
  81.     end
  82.     def addEvent(event,cb,first=false)
  83.       @events[event]=[] if @events[event].nil?
  84.       @events[event]<<[cb,first]
  85.     end
  86.     def realrect
  87.       @[email protected]
  88.       @crect=Rect.new(@[email protected],@[email protected],@rect.width,@rect.height)
  89.       return @crect
  90.     end
  91.     def OnCreate(sender,e)
  92.       return false
  93.     end
  94.     def OnDispose(sender,e)
  95.       return false
  96.     end
  97.     def OnMouseMove(sender,e)
  98.       return false
  99.     end
  100.     def OnMouseDown(sender,e)
  101.       return false
  102.     end
  103.     def OnMouseUp(sender,e)
  104.       return false
  105.     end
  106.     def OnMouseOver(sender,e)
  107.       return false
  108.     end
  109.     def OnMouseLeave(sender,e)
  110.       return false
  111.     end
  112.     def OnKeyBoardDown(sender,e)
  113.       return false
  114.     end
  115.     def OnKeyBoardUp(sender,e)
  116.       return false
  117.     end
  118.     def OnClick(sender,e)
  119.       return false
  120.     end
  121.     def OnDoubleClick(sender,e)
  122.       return false
  123.     end
  124.     def OnRender(sender,e)
  125.       return false
  126.     end
  127.     def OnActive(sender,e)
  128.       return false
  129.     end
  130.     def OnLoseActive(sender,e)
  131.       return false
  132.     end
  133.    
  134.     def startEvent(ent,sender,e)
  135.       if not @events[ent].nil?
  136.         for i in @events[ent]
  137.          
  138.           if (i[1])
  139.             return if i[0].call(sender,e)
  140.           end
  141.         end
  142.       end
  143.       method(Events::Ents[ent]).call(sender,e)
  144.       if not @events[ent].nil?
  145.         for i in @events[ent]
  146.           unless (i[1])
  147.             return if i[0].call(sender,e)
  148.           end
  149.         end
  150.       end
  151.     end
  152.   end
  153. end
复制代码
Window 最新版本:1
  1. =begin
  2.   YUI::Window
  3.    * It'a Frame that can include Page.
  4.      It has own SpriteList.
  5. =end
  6. module YUI
  7.   class Window < UIFrame
  8.     @@rect=[]
  9.     def self.yui_set_rect(rect)
  10.       @@rect<<[rect,self]
  11.     end
  12.   end
  13. end
  14. if $摸你傻效果开关,慎用!
  15. module YUI
  16.   class UISprite
  17.     attr_accessor                 :x
  18.     attr_accessor                 :y
  19.     attr_accessor                 :bitmap
  20.     attr_accessor                 :z
  21.   end
  22. end
  23. else
  24.     YUI::UISprite=Sprite
  25. end
  26. module YUI
  27.   class Window < UIFrame
  28.     attr_reader                    :rect
  29.     attr_reader                   :sprite
  30.     attr_reader                   :ncbackground
  31.     attr_reader                   :background
  32.     attr_reader                   :pages
  33.     attr_reader                   :activeid
  34.     attr_reader                   :childrect
  35.     attr_accessor                 :bak_bitmap
  36.     attr_accessor                 :contentOpacity
  37.     @@title=[]
  38.     @@pages={}
  39.     @@defaultpage=[]
  40.     def self.yui_addPage(name , page , &proc)
  41.      #@@pages={} if @@pages[self].nil?
  42.       @@pages[name]=[page,proc,self]
  43.     end
  44.     def topparent
  45.       return self
  46.     end
  47.     def addPage(name,page,&proc)
  48.       @pages[name]=page.new(page,proc,self,@childrect)
  49.     end
  50.     def changPage(name)
  51.       if @page.startEvent(YUI::Events::OnLoseActive,self,YUI::EventMessage.new({}))
  52.         @page=@pages[name]
  53.         @page.startEvent(YUI::Events::OnActive,self,YUI::EventMessage.new({}))
  54.         @need_render=true
  55.       end
  56.     end
  57.     def self.yui_set_default_page(name)
  58.       for i in @@defaultpage
  59.         if i[1]==self
  60.           i[0]=[name,self]
  61.           return
  62.         end
  63.       end
  64.       @@defaultpage<<[name,self]
  65.     end
  66.     def self.yui_set_title(name,font=:Normally)
  67.       for i in @@title
  68.         if i[1]==self
  69.           i[0]=[[name,font],self]
  70.         end
  71.       end
  72.       @@title<<[[name,font],self]
  73.     end
  74.     yui_set_title "undefined"
  75.     def setTitle(name,font=:Normally)
  76.       @title=[name,font]
  77.       @need_render=true
  78.     end
  79.     def set_render(render)
  80.       @need_render=render
  81.     end
  82.     def onWindowMouseMove(sender,e)
  83.       @page.startEvent(YUI::Events::OnMouseMove,Mouse,YUI::EventMessage.new({}))
  84.     end
  85.     yui_addEvent  Events::OnMouseMove ,:onWindowMouseMove ,true
  86.     def onWindowMouseDown(sender,e)
  87.       @page.startEvent(YUI::Events::OnMouseDown,Mouse,YUI::EventMessage.new({}))
  88.     end
  89.     yui_addEvent  Events::OnMouseDown ,:onWindowMouseDown ,true
  90.     def realrect
  91.       return @rect
  92.     end
  93.     def onWindowRender(sender,e)
  94.       if @ncbackground.nil?
  95.         YUI::Themes.draw(:WindowNCBackGround,self,e.get(:bitmap),@active,@title)
  96.       else
  97.         e.get(:bitmap).fill_rect(0,0,rect.width,rect.height,@ncbackground)
  98.       end
  99.       if @background.nil?
  100.         YUI::Themes.draw(:WindowBackGround,self,e.get(:bitmap))
  101.       else
  102.         e.get(:bitmap).fill_rect(0,0,rect.width,rect.height,@background)
  103.       end
  104.       
  105.       unless @page.nil?
  106. #        p @rect
  107.         @pagebit=Bitmap.new(@childrect.width,@childrect.height)
  108.         @msg=YUI::EventMessage.new ({:bitmap=>@pagebit,:childrect=>@childrect})
  109.         @page.startEvent(YUI::Events::OnRender,self,@msg )
  110.         e.get(:bitmap).stretch_blt(@msg.get(:childrect),@msg.get(:bitmap),Rect.new(0,0,@msg.get(:bitmap).width,@msg.get(:bitmap).height),@contentOpacity)
  111.         @msg.get(:bitmap).dispose
  112.       end
  113.       return false
  114.     end
  115.     def setThemeData
  116.       @contentOpacity=Themes.get(:WindowContentOpcity,self)
  117.       @childrect=Rect.new(Themes.get(:CL,self),Themes.get(:CT,self),@rect.width-Themes.get(:CL,self)-Themes.get(:CR,self),@rect.height-Themes.get(:CT,self)-Themes.get(:CB,self))
  118.       for i in @pages.keys
  119.         @pages[i].rect=@childrect
  120.       end
  121.     end
  122.     yui_addEvent  Events::OnRender ,:onWindowRender ,true
  123.     def onWindowCreate(sender,e)
  124.       @theme={}
  125.       @sprite = UISprite.new(UIManager.viewport)
  126.       if e.get(:args)[0].is_a?(Rect)
  127.         @rect=e.get(:args)[0]
  128.       else
  129.         for i in @@rect
  130.           if i[1]==@selfObject
  131.             @rect=i[0]
  132.           end
  133.         end
  134.       end
  135.       for i in @@title
  136.         if i[1]==@selfObject
  137.           @title=i[0]
  138.         end
  139.       end
  140.       @childrect=Rect.new(Themes.get(:CL,self),Themes.get(:CT,self),@rect.width-Themes.get(:CL,self)-Themes.get(:CR,self),@rect.height-Themes.get(:CT,self)-Themes.get(:CB,self))
  141.       e.get(:args)[1].call(sender,e,self) if (e.get(:args)[1].is_a?(Proc))
  142.       @pages={}
  143.       for i in @@pages.keys
  144.         if @@pages[i][2]==@selfObject
  145.           @pages[i]=@@pages[i][0].new(@@pages[i][0],@@pages[i][1],self,@childrect)
  146.          
  147.         end
  148.       end
  149.       for i in @@defaultpage
  150.         if i[1]==@selfObject
  151.           @page=@pages[i[0]]
  152.         end
  153.       end
  154.       setThemeData
  155.       @need_render=true
  156.       #相对Rect坐标
  157.       return false
  158.     end
  159.     yui_addEvent  Events::OnCreate ,:onWindowCreate ,true
  160.     def onWindowActive(sender,e)
  161.       return false
  162.     end
  163.     yui_addEvent  Events::OnActive ,:onWindowActive ,true
  164.     def onWindowLoseActive(sender,e)
  165.       return false
  166.     end
  167.     yui_addEvent  Events::OnLoseActive ,:onWindowLoseActive ,true
  168.   end
  169. end
复制代码
Container 最新版本:1
  1. module YUI
  2.   #Container和Window的区别在于,Window的构造是在模块中进行的,而Container是在
  3.   #Create中进行的。
  4.   #Rect 全部是相对父容器的Rect
  5.   class Container<UIFrame
  6.     attr_accessor                 :rect
  7.     def addControler(name,controler,rect,*args,&proc)
  8.       @controlers[name]=controler.new(controler,proc,self,rect,*args)
  9.       set_render(true)
  10.     end
  11.     def addPanel(name,panel,rect,&proc)
  12.       @panels[name]=panel.new(proc,self,rect)
  13.       set_render(true)
  14.     end
  15.     def getControlerByName(name)
  16.       return @controlers[name]
  17.     end
  18.     def getPanelByName(name)
  19.       return @panels[name]
  20.     end
  21.     def disposePanel(panel)
  22.       rst = YUI::EventResult.new{|o|o.cancel=false}
  23.       panel.startEvent(YUI::Events::OnDispose,self,YUI::EventMessage.new({:result=>rst}) )
  24.       if rst.cancel==true
  25.         return false
  26.       else
  27.         @panels.delete(panel)
  28.         set_render(true)
  29.         return true
  30.       end
  31.     end
  32.     def disposeControler(controler)
  33.       rst = YUI::EventResult.new{|o|o.cancel=false}
  34.       controler.startEvent(YUI::Events::OnDispose,self,YUI::EventMessage.new({:result=>rst}) )
  35.       if rst.cancel==true
  36.         return false
  37.       else
  38.         @controlers.delete(controler)
  39.         set_render(true)
  40.         return true
  41.       end
  42.     end
  43.     def set_render(render)
  44.       @need_render=render
  45.       @parent.set_render(render)
  46.     end
  47.     def onContainerCreate(sender,e)
  48.       args=e.get(:args)
  49.       @panels={}
  50.       @controlers={}
  51.       @parent=args[1]
  52.       @rect=args[2]
  53.       set_render true
  54.       
  55.       args[0].call(self)
  56.       return false
  57.     end
  58.     yui_addEvent  Events::OnCreate ,:onContainerCreate ,true
  59.     def onContainerRender(sender,e)
  60.       for i in @controlers.keys
  61.         bitmap=Bitmap.new(@controlers[i].rect.width,@controlers[i].rect.height)
  62.         @msg=YUI::EventMessage.new ({:bitmap=>bitmap})
  63.         @controlers[i].startEvent(YUI::Events::OnRender,self,@msg )
  64.         e.get(:bitmap).stretch_blt(@controlers[i].rect,@msg.get(:bitmap),Rect.new(0,0,@controlers[i].rect.width,@controlers[i].rect.height))
  65.         bitmap.dispose
  66.       end
  67.       return false
  68.     end
  69.     yui_addEvent  Events::OnRender ,:onContainerRender ,true
  70.     def onContainerMouseMove(sender,e)
  71.       for i in @controlers.keys
  72.       
  73.         @controlers[i].startEvent(YUI::Events::OnMouseMove,sender,e)
  74.       end
  75.       for i in @panels.keys
  76.         @panels[i].startEvent(YUI::Events::OnMouseMove,sender,e)
  77.       end
  78.       return false
  79.     end

  80.     yui_addEvent  Events::OnMouseMove ,:onContainerMouseMove ,true
  81.     def onContainerMouseDown(sender,e)

  82.       for i in @controlers.keys
  83.         
  84.         @controlers[i].startEvent(YUI::Events::OnMouseDown,sender,e)
  85.       end

  86.       for i in @panels.keys
  87.         @panels[i].startEvent(YUI::Events::OnMouseDown,sender,e)
  88.       end
  89.       return false
  90.     end

  91.     yui_addEvent  Events::OnMouseDown ,:onContainerMouseDown ,true

  92.   end

  93. end
复制代码
Page(未完成)
  1. YUI::Page=YUI::Container
复制代码
Panel(未开始写)
    Controler(半成品) 最新版本:1
  1. module YUI
  2.   class Controler<UIFrame
  3.     def set_render(render)
  4.       @need_render=render
  5.       @parent.set_render(render)
  6.     end
  7.     def onContainerCreate(sender,e)
  8.       args=e.get(:args)
  9.       
  10.       @parent=args[1]
  11.       @rect=args[2]
  12.       @mousein=false
  13.       set_render true
  14.       args[0].call(self)
  15.       return false
  16.     end
  17.     def rect
  18.       return @rect
  19.     end
  20.     def onControlerMouseMove(sender,e)

  21.       if realrect.inarea?(Mouse.pos)
  22.         if not @mousein
  23.           @mousein=true
  24.           startEvent(Events::OnMouseOver,sender,e)
  25.         end
  26.       elsif @mousein
  27.         @mousein=false
  28.         startEvent(Events::OnMouseLeave,sender,e)
  29.       end
  30.       return false
  31.     end
  32.     yui_addEvent  Events::OnMouseMove ,:onControlerMouseMove ,true
  33.     yui_addEvent  Events::OnCreate ,:onContainerCreate ,true
  34.   end
  35. end
复制代码
Textarea 最新版本:1
  1. module YUI
  2.   class Textarea<Controler
  3.     def text
  4.       set_render true
  5.       return @text
  6.     end
  7.     def text=(v)
  8.       @text=v
  9.       set_render true
  10.     end
  11.     def font
  12.       set_render true
  13.       return @font
  14.     end
  15.     def font=(f)
  16.       @font=f
  17.       set_render true
  18.     end
  19.     def onTextareaCreate(sender,e)
  20.       args=e.get(:args)
  21.       @text=args[3] if @text.nil?
  22.       @text=""  if @text.nil?
  23.       @font=Font.new if @font.nil?
  24.       return false
  25.     end
  26.     yui_addEvent  Events::OnCreate ,:onTextareaCreate ,true
  27.     def onTextareaRender(sender,e)
  28.       bitmap=e.get(:bitmap)
  29.       bitmap.clear
  30.       bitmap.font=@font
  31.       @x=0
  32.       @y=0
  33.       @maxheight=0
  34.       #@text.each_byte{|b|
  35.       for i in [email protected]
  36.         b=@text[i]
  37.         if b!="\r"
  38.           @size=bitmap.text_size(b)
  39.           @maxheight = 0 if @maxheight.nil?
  40.           @maxheight=[@maxheight,@size.height].max
  41.           if (@[email protected]>@rect.width) or b=="\n"
  42.             @x=0
  43.             @y+=@maxheight
  44.             @maxheight=0
  45.           end
  46.           bitmap.draw_text(@x,@y,@size.width*2+1,@size.height+1,b) if b!="\n"
  47.           @[email protected] if b!="\n"
  48.         end
  49.       end
  50.       #}
  51.       return false
  52.     end
  53.     yui_addEvent  Events::OnRender ,:onTextareaRender ,true
  54.   end
  55. end
复制代码
Edit(未开始)
  1. =begin
  2. Windows 单行输入框规则
  3. 1- 光标位置小于0时,首字符位置前移N个像素。
  4. 2- 光标位置大于编辑框宽度时,尾字符位置后移N个像素。
  5. 3- 字符串长度增长时,保持首字符位置不变。
  6. 4- 字符串减少时,首先保持首字符位置不变,收缩尾部位置,
  7. 直至尾字符不超出编辑框大小,然后收缩首部位置,直至首字
  8. 符位置在字符串位置首位,然后收缩尾部。
  9. =end
复制代码
Button(部分实现) 最新版本:1
  1. module YUI
  2.   class Button < Textarea
  3.    
  4.     YUI::Themes.regnewfunc(:ButtonDraw){|name,bitmap,action,flag|
  5.       
  6.       bitmap.gradient_fill_rect(0,0,bitmap.width,bitmap.height,Color.new(40,45,210),Color.new(8,10,140),true)
  7.       bitmap.gradient_fill_rect(1,1,bitmap.width-2,bitmap.height-2,Color.new(60,67,230),Color.new(20,25,120),true)

  8.     }
  9.     def onTextareaCreate(sender,e)
  10.       @action=:Nomorlly
  11.       @flag = e.get(:args)[4]
  12.       @callback=e.get(:args)[5]
  13.       super(sender,e)
  14.     end
  15.     def onTextareaRender(sender,e)
  16.       super(sender,e)
  17.       bitmap=e.get(:bitmap)
  18.       bitmap1=Bitmap.new(bitmap.width,bitmap.height)
  19.       YUI::Themes.draw(:ButtonDraw,self.topparent,bitmap1,@action,@flag)
  20.       bitmap1.blt(5,3,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
  21.       if @action==:Moving
  22.         b=Bitmap.new(bitmap.width,bitmap.height)
  23.         b.fill_rect(0,0,bitmap1.width,bitmap1.height,Color.new(255,255,255,255))
  24.         bitmap1.blt(0,0,b,Rect.new(0,0,bitmap.width,bitmap.height),50)
  25.       end
  26.       bitmap.dispose
  27.       e.set(:bitmap,bitmap1)
  28.     end
  29.     def onButtonMouseOver(sender,e)
  30.       unless @action==:Disabled
  31.         @action=:Moving
  32.         set_render true
  33.       end
  34.       return false
  35.     end
  36.     def onButtonMouseLeave(sender,e)
  37.       unless @action==:Disabled
  38.       
  39.         @action=:Nomorlly
  40.         set_render true
  41.       end
  42.       return false
  43.     end

  44.     yui_addEvent Events::OnMouseOver,:onButtonMouseOver,true
  45.     yui_addEvent Events::OnMouseLeave,:onButtonMouseLeave,true
  46.     def onButtonMouseDown(sender,e)
  47.       if realrect.inarea?(Mouse.pos)
  48.         startEvent(Events::OnCommand,self,e)
  49.       end
  50.       return false
  51.     end
  52.     yui_addEvent YUI::Events::OnMouseDown,:onButtonMouseDown,true
  53.     def onButtonCommand(sender,e)
  54.       @callback.call(sender,e)
  55.       return false
  56.     end
  57.     yui_addEvent Events::OnCommand,:onButtonCommand,true
  58.    
  59.   end
  60. end
复制代码
Opinion(未开始)
      List(未开始)
      Image(未开始)
      PopUpMenu(未开始)
    WindowMaker(未开始) 最新版本:1
  1. module UIManager
  2.   module_function
  3.   class Easy
  4.     @@windowList={}
  5.     def self.yui_addEasyMaker(name,clasname)
  6.       @@windowList[name]=clasname
  7.     end
  8.   end
  9.   class MessageWindow < YUI::Window
  10.       
  11.   end
  12.   Easy.yui_addEasyMaker :MessageWindow,MessageWindow
  13.   class JsonWindow < YUI::Window
  14.    
  15.   end
  16.   Easy.yui_addEasyMaker :JsonWindow,JsonWindow
  17. end
复制代码
UITest(测试,范例) 最新版本:1
  1. class MyWindow < YUI::Window
  2.   yui_set_rect Rect.new(80,70,300,350)
  3.   yui_set_title "My Window Test1"
  4.   yui_addPage(:Page1,YUI::Page){|my|
  5.   my.addControler(:TextArea1,YUI::Textarea,Rect.new(5,5,300-64,120),"\\Hello World/\n\r\\YUI/!中文测试。。自动换行测试。。"){  |my1|
  6.     my1.font=Font.new("微软雅黑",24)
  7.     my1.font.shadow=true
  8.     my1.font.bold  = true
  9.   }
  10.   my.addControler(:Button1,YUI::Button,Rect.new(5,200,60+4,26+4+30),"\\按钮/\n两行",:First,proc{|sender,e| UIManager.disposeWindow(my.topparent) }){  |my1|
  11.     my1.font=Font.new("微软雅黑",24)
  12.     my1.font.shadow=true
  13.     my1.font.bold  = true
  14.   }
  15.   }
  16.   yui_set_default_page :Page1
  17. end

  18. class MyWindow1 < YUI::Window
  19.   yui_set_rect Rect.new(80+32,70+32,300,350)
  20.   yui_set_title "My Window Test2"
  21. end
  22. UIManager.createWindow(MyWindow)
  23. #UIManager.createWindow(MyWindow,Rect.new(80+32,70+32,300,350))
  24. UIManager.createWindow(MyWindow1,Rect.new(80+32,70+32,300,350),proc{|sender,e,my|my.theme[:CL],my.theme[:CR],my.theme[:CB]=16,16,16;})
  25. #UIManager.createWindow(MyWindow1)
  26. =begin
  27. TO BE CONTINUE
  28. UIManager.createWindowMaker("json","xxx.json")
  29. {|my|
  30.   addListen(getOOByName:button,YUI::Controler::Button){|sender,e|
  31.     UIManager.createWindowMaker("messageBox","Hi","欢迎使用|cffff00ffYUI界面核心",UIManager::Msgbox::MSG_OKAY | UIManager::Msgbox::MSG_CANCEL)
  32.     {|sender1,e1|
  33.       if (e1.get(:result)==UIManager::Msgbox::MSG_OKAY)
  34.         (my.getOOByName:label).setCaption("确定")
  35.       else
  36.         (my.getOOByName:label).setCaption("不确定")
  37.       end
  38.     }
  39. }
  40. =end
复制代码

评分

参与人数 1星屑 +200 收起 理由
忧雪の伤 + 200 辛苦了。

查看全部评分

哎呀,蛋疼什么的最有爱了

Lv3.寻梦者 (暗夜天使)

名侦探小柯

梦石
0
星屑
3268
在线时间
3617 小时
注册时间
2006-9-6
帖子
37399

开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

2
发表于 2012-1-19 01:53:36 | 只看该作者
于是你是不是忘了截图啊……

虚假广告词:让RMVA实现win7的磨砂玻璃效果!

点评

截图已放  发表于 2012-1-19 02:03
截图中。。  发表于 2012-1-19 01:53
回复 支持 反对

使用道具 举报

Lv1.梦旅人

小小的百鬼夜行<

梦石
0
星屑
54
在线时间
579 小时
注册时间
2010-7-29
帖子
2682

贵宾

3
发表于 2012-1-19 10:01:45 | 只看该作者
这么多个脚本敢不敢合一起发或者扔个范例上来= =
虽然效果的确很美好,但米工需要加强呀= =
\你确定老爷机能跑吗/

点评

范例不敢扔,我这里的DLL全都是破解过的,原版的都不见了。米工因为没有,所以直接取材自一些Ajax特效。老爷机问题 不大,可能帧率在55到60之间  发表于 2012-1-19 11:03
某只PHP/HTML小白鼠→退屈の间


Cause I knew you were trouble when you walked in
So shame is on me now
I flow me to place i ve never been
till you put me down oh
Now Im lying on the cold hard ground
回复 支持 反对

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
309
在线时间
1194 小时
注册时间
2010-12-18
帖子
3928

贵宾

4
发表于 2012-1-19 11:29:17 | 只看该作者
不打包个工程还真的……挺麻烦的。

点评

我也希望6R的脚本框可以折叠啊,长代码太难发了= =  发表于 2012-1-19 12:24
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
461 小时
注册时间
2008-11-19
帖子
607
5
发表于 2012-1-20 19:53:04 | 只看该作者
樓主強大了!這功能好! 期待了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-17 22:34

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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