Class: Effects

Inherits:
Object show all
Defined in:
lib/xiki/effects.rb

Overview

Makes visual things happen

Class Method Summary collapse

Class Method Details

Sample usages:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/xiki/effects.rb', line 104

def self.blink options={}
  what = options[:what]
  what ||= :line
  case what
  when :all
    left, right = View.top, View.bottom
  when :region
    left, right = View.range
  when :line
    left, right = Line.bounds
    right += 1
  when :sexp
    left, right = bounds_of_thing_at_point(:sexp).to_a
    return unless left
  end

  left = options[:left] if options[:left]
  right = options[:right] if options[:right]

  time = options[:time] || 0.04
  over2 = $el.make_overlay(left, right)
  $el.overlay_put over2, :face, :color_rb_glow2
  $el.sit_for time
  $el.delete_overlay over2
end

.define_stylesObject

Define font



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/xiki/effects.rb', line 131

def self.define_styles
  Styles.define :color_rb_glow1, :bg => "fec"
  Styles.define :color_rb_glow2, :bg => "f90"

  Styles.define :red, :fg => "f00"
  Styles.define :orange, :fg => "f80"
  Styles.define :yellow, :fg => "ff0"
  Styles.define :green, :fg => "0f0"
  Styles.define :blue, :fg => "00f"
  Styles.define :indigo, :fg => "408"
  Styles.define :violet, :fg => "82e"

  Styles.define :purple, :fg => "808"
  Styles.define :cyan, :fg => "f0f"
end

.glow(options = {}) ⇒ Object

Effects.glow :color=>:forest



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/xiki/effects.rb', line 49

def self.glow options={}

  what = options[:what]
  if what.is_a? Array
    left, right = what
  elsif what == :block
    ignore, left, right = View.block_positions "^[|>]"
  elsif what == :paragraph
    left, right = View.paragraph :bounds=>1
  else
    left, right = Line.left, Line.right
  end


  # Set :times to 1 if no args and fade out
  times = 1 if ! options[:times] && (options[:fade_out] || options[:fade_in])

  times ||= options[:times] || 3

  over = $el.make_overlay left, right

  faces =
    if options[:color] == :fire
      ['font-lock-doc-face', 'font-lock-function-name-face', 'html-helper-server-script-face', 'font-lock-variable-name-face', 'speedbar-tag-face', 'speedbar-tag-face', 'speedbar-tag-face']
    elsif options[:color] == :forest
      ['dired-mark', 'dired-mark', 'widget-documentation', 'widget-documentation', 'widget-documentation', 'bookmark-menu-heading', 'bookmark-menu-heading']
    elsif options[:color] == :water
      ['font-lock-constant-face', 'font-lock-constant-face', 'escape-glyph', 'escape-glyph', 'font-lock-builtin-face', 'font-lock-builtin-face', 'font-lock-builtin-face']
    elsif options[:color] == :rainbow
      ['blue', 'red', 'orange', 'orange', 'green', 'green', 'yellow']
    elsif options[:color] == :fat_rainbow
      ['notes-yellow', 'notes-yellow', 'notes-green', 'notes-green', 'notes-blue', 'notes-red', 'notes-red']
    else
      ['fade1', 'fade2', 'fade3', 'fade4', 'fade5', 'fade6', 'fade7']
    end

  up = [6, 5, 4, 3, 2]
  down = [2, 3, 4, 5, 6]

  sequence =
    if options[:fade_out]; [1] + (down + [7]) * times
    elsif options[:fade_in]; [7] + (up + [1]) * times
    elsif options[:reverse]; [7] + (up + [1] + down + [7]) * times
    else; [1] + (down + [7] + up + [1]) * times
    end

  sequence.each do |i|
    $el.overlay_put over, :face, (faces[i-1] || faces[0])
    $el.sit_for 0.0005
  end

  $el.delete_overlay over
end


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xiki/effects.rb', line 6

def self.menu
  "
  > Do cool-looking things to text
  - api/
    | Try these out by double-clicking on them.
    - Glow/
      @Effects.glow
      @Effects.glow :times=>6
      @Effects.glow :what=>:paragraph
      @Effects.glow :what=>:block
      @Effects.glow :what=>[1, 100]

      - Colors/
        @Effects.glow :color=>:fire
        @Effects.glow :color=>:water
        @Effects.glow :color=>:forest
        @Effects.glow :color=>:rainbow
        @Effects.glow :color=>:fat_rainbow
      - Fade in and out/
        @Effects.glow :fade_in=>1
        @Effects.glow :fade_out=>1
    - Blink/
      | Makes line blink orange. Using a longer time since the blink happens
      | anyway.

      @Effects.blink :time=>1
    - Some View methods that use effects/
      @View.prompt
      @View.flash
      @View.flash 'Saved!'
  - docs/
    > Keys
    | do+line+effects: make line blink
    | up+do+line+effects: make line blink rainbow color

  > See
  << themes/
  "
end