zoukankan      html  css  js  c++  java
  • 用Flash MX 2004自制调色版和配色组件(四)

    王咏刚,2005年4月

    ColorPicker类里封装了HS色环和B亮度槽的MovieClip,这两种MovieClip又分别对应了ColorWheel和ColorTube两个类。它们的代码如下:

    import wix.*;
    class wix.ColorWheel extends MovieClip
    {
     private var pressed:Boolean;
     private var pointer:MovieClip = null;
     private var mask:MovieClip = null;
     
     public function init(p:MovieClip, m:MovieClip) {
      pointer = p;
      mask = m;
     }
     
     public function ColorWheel() {
      pressed = false;
      this.onMouseDown = doPress;
      this.onMouseUp = doRelease;
      this.onMouseMove = doMove;
     }
     
     private function doPress(){
      if (enabled) {
       if (mask.hitTest(_root._xmouse, _root._ymouse, true)) {
        pressed = true;
        doMove();
       }
      }
     }
     
     private function doRelease() {
      if (enabled)
       pressed = false;
     }
     
     private function doMove() {
      if (enabled) {
       if (pressed && pointer && mask ) {
        if (mask.hitTest(_root._xmouse, _root._ymouse, true)) {
         pointer._x = _parent._xmouse;
         pointer._y = _parent._ymouse;
         _parent.updateHSB();
        }
        else {    
         var x1 = _parent._xmouse - this._x - this._width / 2;
         var y1 = _parent._ymouse - this._y - this._height / 2;
         var theta = ColorMan.getThetaByXY(x1, y1);    
         _parent.setHSB(theta, 100, null);
        }    
       }
      }
     }
     
     public function setBrightness(brightness:Number) {
      if (enabled)
       this._alpha = brightness;
     }
    }


    import wix.ColorMan;
    class wix.ColorTube extends MovieClip
    {
     private var pressed:Boolean;
     private var pointer:MovieClip = null;
     
     public function init(p:MovieClip) {
      pointer = p;
     }
     
     public function ColorTube() {
      pressed = false;
      this.onMouseDown = doPress;
      this.onMouseUp = doRelease;
      this.onMouseMove = doMove;
     }
     
     private function doPress(){
      if (enabled) {
       if (this.hitTest(_root._xmouse, _root._ymouse, true) ||
         pointer.hitTest(_root._xmouse, _root._ymouse, true)) {
        pressed = true;
        doMove();
       }
      }
     }
     
     private function doRelease() {
      if (enabled)
       pressed = false;
     }
     
     private function doMove() {
      if (enabled) {
       if (pressed && pointer) {
        pointer._y = Math.min(Math.max(this._y + 2, _parent._ymouse),
                  this._y + this._height - 2);
        _parent.updateHSB();
       }
      }
     }
     
     public function paint(h:Number, s:Number) {
      if (enabled) {
       var b, rgb:Number;
       this.clear();
       for(b = 0; b <= 100; b++)
       {
        rgb = ColorMan.hsb2rgbValue(h, s, b);  
        this.lineStyle(2, rgb, 100);
        this.moveTo(2, 203 - b * 2);
        this.lineTo(19, 203 - b * 2);
       }
      }
     }
    }

    ……未完待续……

  • 相关阅读:
    LeetCode 515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
    LeetCode 114. 二叉树展开为链表(Flatten Binary Tree to Linked List)
    LeetCode 199. 二叉树的右视图(Binary Tree Right Side View)
    LeetCode 1022. 从根到叶的二进制数之和(Sum of Root To Leaf Binary Numbers)
    LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)
    LeetCode 617. 合并二叉树(Merge Two Binary Trees)
    LeetCode 206. 反转链表(Reverse Linked List) 16
    LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
    LeetCode 110. 平衡二叉树(Balanced Binary Tree) 15
    LeetCode 108. 将有序数组转换为二叉搜索树(Convert Sorted Array to Binary Search Tree) 14
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157224.html
Copyright © 2011-2022 走看看