range: [0, 0xffffff],\r
}\r
},\r
+ orientation: {\r
+ type: 'number',\r
+ rules : {\r
+ required: true,\r
+ number: true,\r
+ range: [0, 1],\r
+ }\r
+ },\r
+ xy: {\r
+ type: 'number',\r
+ rules : {\r
+ number: true,\r
+ }\r
+ },\r
+ wh: {\r
+ type: 'number',\r
+ rules : {\r
+ number: true,\r
+ }\r
+ },\r
z: {\r
type: 'number',\r
rules : {\r
}\r
},\r
},\r
+ orientation: {\r
+ column: 'orientation',\r
+ type: 'select',\r
+ label: {\r
+ },\r
+ options: {\r
+ source: 'magic_number',\r
+ key: 'ground_color_orientation_items',\r
+ row_break: true\r
+ }\r
+ },\r
+ xy: {\r
+ column: 'xy',\r
+ type: 'number',\r
+ label: {\r
+ },\r
+ options: {\r
+ size: 5, \r
+ }\r
+ },\r
+ wh: {\r
+ column: 'wh',\r
+ type: 'number',\r
+ label: {\r
+ },\r
+ options: {\r
+ size: 5, \r
+ row_break: true\r
+ }\r
+ },\r
z: {\r
column: 'z',\r
type: 'hidden',\r
'panel_id',\r
'caption',\r
'code',\r
+ 'orientation',\r
+ 'xy',\r
+ 'wh',\r
'z',\r
't',\r
]\r
\r
\r
# ground-picture\r
+ refresh_ground_picture = (element_trace) ->\r
+ x = parseInt($(element_trace + 'x').val()).toString() + 'px'\r
+ y = parseInt($(element_trace + 'y').val()).toString() + 'px'\r
+ $(element_trace).css('background-position', x + ' ' + y)\r
+ \r
# sync view \r
$('input').map ->\r
if editor.element_is('ground_picture', $(@))\r
- $(@).focusout ->\r
- switch $(@).attr('column')\r
- when 'x', 'y'\r
+ switch $(@).attr('column')\r
+ when 'x', 'y'\r
+ $(@).focusout ->\r
trace = editor.element_tag_id($(@))\r
- x = parseInt($(trace + 'x').val()).toString() + 'px'\r
- y = parseInt($(trace + 'y').val()).toString() + 'px'\r
- $(trace).css('background-position', x + ' ' + y)\r
+ refresh_ground_picture(trace)\r
+ $(@).spinner {\r
+ stop: ( event, ui ) ->\r
+ trace = editor.element_tag_id($(@))\r
+ refresh_ground_picture(trace)\r
+ }\r
$('select').map ->\r
if editor.element_is('ground_picture', $(@))\r
$(@).change ->\r
# ground_color\r
ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')\r
\r
+ refresh_ground_color = (element_trace) ->\r
+ orientation = parseInt( $(element_trace + 'orientation').val() )\r
+ xy = $(element_trace + 'xy').val()\r
+ wh = $(element_trace + 'wh').val()\r
+ div_offset = if xy\r
+ xy\r
+ else\r
+ 0\r
+ div_size = if wh\r
+ wh\r
+ else\r
+ 100 - div_offset\r
+ div_x = if orientation == 0\r
+ 0\r
+ else\r
+ div_offset\r
+ div_y = if orientation == 0\r
+ div_offset\r
+ else\r
+ 0\r
+ div_width = if orientation == 0\r
+ 100\r
+ else\r
+ div_size\r
+ div_height = if orientation == 0\r
+ div_size\r
+ else\r
+ 100\r
+ div = $(element_trace)\r
+ div.css('left', div_x.toString() + '%')\r
+ div.css('top', div_y.toString() + '%')\r
+ div.css('width', div_width.toString() + '%')\r
+ div.css('height', div_height.toString() + '%')\r
+ \r
# sync view \r
$('input').map ->\r
if editor.element_is('ground_color', $(@))\r
- if $(@).attr('column') == 'code'\r
- $(@).hide()\r
+ switch $(@).attr('column')\r
+ when 'code'\r
+ $(@).hide()\r
+ when 'xy', 'wh'\r
+ $(@).spinner {\r
+ stop: ( event, ui ) ->\r
+ trace = editor.element_tag_id($(@))\r
+ refresh_ground_color(trace)\r
+ , min: 0\r
+ , max: 100\r
+ }\r
+ $(@).focusout ->\r
+ trace = editor.element_tag_id($(@))\r
+ refresh_ground_color(trace)\r
+ \r
+ $('select').map ->\r
+ if editor.element_is('ground_color', $(@))\r
+ switch $(@).attr('column')\r
+ when 'orientation'\r
+ $(@).change ->\r
+ trace = editor.element_tag_id($(@))\r
+ refresh_ground_color(trace)\r
\r
update_t = (ultrace) -> \r
t = 0\r
},
"caption": {
"type": "text",
- "rules": {
- }
+ "rules": {}
},
"publish": {
"type": "number",
]
}
},
+ "orientation": {
+ "type": "number",
+ "rules": {
+ "required": true,
+ "number": true,
+ "range": [
+ 0,
+ 1
+ ]
+ }
+ },
+ "xy": {
+ "type": "number",
+ "rules": {
+ "number": true
+ }
+ },
+ "wh": {
+ "type": "number",
+ "rules": {
+ "number": true
+ }
+ },
"z": {
"type": "number",
"rules": {
}
}
},
+ "orientation": {
+ "column": "orientation",
+ "type": "select",
+ "label": {},
+ "options": {
+ "source": "magic_number",
+ "key": "ground_color_orientation_items",
+ "row_break": true
+ }
+ },
+ "xy": {
+ "column": "xy",
+ "type": "number",
+ "label": {},
+ "options": {
+ "size": 5
+ }
+ },
+ "wh": {
+ "column": "wh",
+ "type": "number",
+ "label": {},
+ "options": {
+ "size": 5,
+ "row_break": true
+ }
+ },
"z": {
"column": "z",
"type": "hidden",
"panel_id",
"caption",
"code",
+ "orientation",
+ "xy",
+ "wh",
"z",
"t"
]
validates :panel_id, :numericality => {:allow_blank => true}
validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
+ validates :orientation, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+ validates :xy, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
+ validates :wh, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
self.panel.visible? roles
end
+ def div_offset
+ xy ? xy : 0
+ end
+
+ def div_size
+ wh ? wh : 100 - self.div_offset
+ end
+
+ def div_x
+ if self.orientation == 0
+ 0
+ else
+ self.div_offset
+ end
+ end
+
+ def div_y
+ if self.orientation == 0
+ self.div_offset
+ else
+ 0
+ end
+ end
+
+ def div_width
+ if self.orientation == 0
+ 100
+ else
+ self.div_size
+ end
+ end
+
+ def div_height
+ if self.orientation == 0
+ self.div_size
+ else
+ 100
+ end
+ end
+
def opt_div_style spot = nil, opacity = 20
o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
- "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
+ "position: absolute; left:#{self.div_x}%; top:#{self.div_y}%; width:#{self.div_width}%; height:#{self.div_height}%; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
end
def boost
<div class="row_break">
</div>
<div class="field">
+ <%= f.label :orientation %>
+ <%= f.collection_select :orientation, t_select_items(MagicNumber['ground_color_orientation_items']), :last, :first, :html => {:selected => elm.orientation} %>
+
+ <%= f.label :xy %>
+ <%= f.number_field :xy, elm.field_tag_attributes(:xy, no_attr, :size => 5) %>
+
+ <%= f.label :wh %>
+ <%= f.number_field :wh, elm.field_tag_attributes(:wh, no_attr, :size => 5) %>
+ </div>
+ <div class="row_break">
+ </div>
+ <div class="field">
<%= f.label :z %>
<%= f.number_field :z, elm.field_tag_attributes(:z, no_attr, :size => 5) %>
</div>
<%= f.label :t %>
<%= f.number_field :t, elm.field_tag_attributes(:t, no_attr, :size => 5) %>
</div>
+ <div class="row_break">
+ </div>
<%= f.hidden_field :panel_id, elm.field_tag_attributes(:panel_id, no_attr) %>
<% unless elm.new_record? %>
</p>
<p>
+ <b><%= t_m 'GroundColor.orientation' -%>:</b>
+ <%= t_selected_item('ground_color_orientation_items', @ground_color.orientation) %>
+</p>
+
+<p>
+ <b><%= t_m 'GroundColor.xy' -%>:</b>
+ <%= @ground_color.xy %>
+</p>
+
+<p>
+ <b><%= t_m 'GroundColor.wh' -%>:</b>
+ <%= @ground_color.wh %>
+</p>
+
+<p>
<b><%= t_m 'GroundColor.z' -%>:</b>
<%= @ground_color.z %>
</p>
</div>
<% end %>
</div>
- <%# text_field_tag "json", '', :id => 'pettanr-configurations' %>
+ <%= text_field_tag "json", '', :id => 'pettanr-configurations' %>
ground_color:
panel_id: コマ
code: カラーコード
+ orientation: 方向
+ xy: オフセット
+ wh: サイズ
z: 重なり
t: 話順
caption: 様子
repeat-x: 横方向
repeat-y: 縦方向
no-repeat: なし
+ ground_color:
+ orientation:
+ horizontal: 横方向
+ vertical: 縦方向
speeches:
font_size:
ultra_small: 極小
['select_items.ground_pictures.repeat.repeat-y', 2],
['select_items.ground_pictures.repeat.no-repeat', 3]
]
+ ground_color_orientation_items: [
+ ['select_items.ground_color.orientation.horizontal', 0],
+ ['select_items.ground_color.orientation.vertical', 1]
+ ]
speech_font_size_items: [
['select_items.speeches.font_size.ultra_small', 0.2],
['select_items.speeches.font_size.very_small', 0.4],
--- /dev/null
+class AddOffsetOnGroundColor < ActiveRecord::Migration
+ def up
+ add_column :ground_colors, :orientation, :integer, :null => false, :default => 0
+ add_column :ground_colors, :xy, :integer
+ add_column :ground_colors, :wh, :integer
+ end
+
+ def down
+ remove_column :ground_colors, :orientation
+ remove_column :ground_colors, :xy
+ remove_column :ground_colors, :wh
+ end
+end
factory :ground_color, :class => GroundColor do |gc|
gc.panel_id 1
gc.code 1
+ gc.orientation 0
gc.z 1
end
context 'オーソドックスなデータのとき' do
it '下限データが通る' do
@gc.code = 0
+ @gc.orientation = 0
+ @gc.xy = 0
+ @gc.wh = 0
@gc.z = 1
@gc.t = 0
@gc.should be_valid
end
it '上限データが通る' do
@gc.code = 99999
+ @gc.orientation = 1
+ @gc.xy = 100
+ @gc.wh = 100
@gc.z = 99999
@gc.t = 99999
@gc.should be_valid
@gc.should_not be_valid
end
end
+ context 'orientationを検証するとき' do
+ it 'nullなら失敗する' do
+ @gc.orientation = nil
+ @gc.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @gc.orientation = 'a'
+ @gc.should_not be_valid
+ end
+ it '負なら失敗する' do
+ @gc.orientation = -1
+ @gc.should_not be_valid
+ end
+ it '2以上なら失敗する' do
+ @gc.orientation = 2
+ @gc.should_not be_valid
+ end
+ end
+ context 'xyを検証するとき' do
+ it 'nullでも通る' do
+ @gc.xy = nil
+ @gc.should be_valid
+ end
+ it '数値でなければ失敗する' do
+ @gc.xy = 'a'
+ @gc.should_not be_valid
+ end
+ it '負なら失敗する' do
+ @gc.xy = -1
+ @gc.should_not be_valid
+ end
+ end
+ context 'whを検証するとき' do
+ it 'nullでも通る' do
+ @gc.wh = nil
+ @gc.should be_valid
+ end
+ it '数値でなければ失敗する' do
+ @gc.wh = 'a'
+ @gc.should_not be_valid
+ end
+ it '負なら失敗する' do
+ @gc.wh = -1
+ @gc.should_not be_valid
+ end
+ end
context 'zを検証するとき' do
it 'nullなら失敗する' do
@gc.z = nil
@gc.z = -1
@gc.should_not be_valid
end
- it '負なら失敗する' do
+ it '0なら失敗する' do
@gc.z = 0
@gc.should_not be_valid
end