4 # Copyright (c) 2012 project bchan
6 # This software is provided 'as-is', without any express or implied
7 # warranty. In no event will the authors be held liable for any damages
8 # arising from the use of this software.
10 # Permission is granted to anyone to use this software for any purpose,
11 # including commercial applications, and to alter it and redistribute it
12 # freely, subject to the following restrictions:
14 # 1. The origin of this software must not be misrepresented; you must not
15 # claim that you wrote the original software. If you use this software
16 # in a product, an acknowledgment in the product documentation would be
17 # appreciated but is not required.
19 # 2. Altered source versions must be plainly marked as such, and must not be
20 # misrepresented as being the original software.
22 # 3. This notice may not be removed or altered from any source
30 def conv_euc_to_TCArray(str)
39 ret.push(val & 0x7f7f);
44 def conv_TCArray_to_hex_definition(a)
47 str += "0x" + x.to_s(16) + ", "
52 def calc_euc_to_TCArray_length(str)
53 str = conv_euc_to_TCArray(str);
72 if @yaml["size"] != nil and @yaml["size"]["h"]
73 return @yaml["size"]["h"]
77 if @yaml["size"] != nil and @yaml["size"]["v"]
78 return @yaml["size"]["v"]
81 def item_text_to_hex_definition()
82 conv_TCArray_to_hex_definition(conv_euc_to_TCArray(@yaml["text"]));
84 def item_text_length_in_TC
85 return calc_euc_to_TCArray_length(@yaml["text"]);
88 def generate_pnl_item_value(i, left, top)
93 class PanelFixedTextItem < PanelItem
99 return 16 * item_text_length_in_TC;
109 def generate_pnl_item_value(i, left, top)
111 pnl_item[<%= i %>].itype = TEXT_ITEM|ATR_TEXT;
112 pnl_item[<%= i %>].info = 0;
113 pnl_item[<%= i %>].ir = (RECT){{<%= left %>,<%= top %>,<%= left %>+<%= self.width %>,<%= top %>+<%= self.height %>}};
114 pnl_item[<%= i %>].desc = 0;
115 pnl_item[<%= i %>].dnum = 0;
116 pnl_item[<%= i %>].ptr = (H*)(TC[]){<%= self.item_text_to_hex_definition() %>};
119 erb = ERB.new(script, nil, '-');
124 class PanelNullItem < PanelItem
125 def generate_pnl_item_value(i, left, top)
127 pnl_item[<%= i %>].itype = NULL_ITEM;
128 pnl_item[<%= i %>].info = 0;
129 pnl_item[<%= i %>].ir = (RECT){{<%= left %>,<%= top %>,<%= left %>+<%= self.width %>,<%= top %>+<%= self.height %>}};
130 pnl_item[<%= i %>].desc = 0;
131 pnl_item[<%= i %>].dnum = 0;
132 pnl_item[<%= i %>].ptr = NULL;
135 erb = ERB.new(script, nil, '-');
140 class PanelButtonItem < PanelItem
146 return 16 * item_text_length_in_TC + 16;
156 def generate_pnl_item_value(i, left, top)
158 pnl_item[<%= i %>].itype = PARTS_ITEM;
159 pnl_item[<%= i %>].info = 0;
160 pnl_item[<%= i %>].ir = (RECT){{<%= left %>,<%= top %>,<%= left %>+<%= self.width %>,<%= top %>+<%= self.height%>}};
161 pnl_item[<%= i %>].desc = 0;
162 pnl_item[<%= i %>].dnum = 0;
163 pnl_item[<%= i %>].ptr = (H*)&(SWSEL){MS_PARTS|P_DISP, (RECT){{0, 0, <%= self.width %>, <%= self.height %>}}, 0, (TC[]){MC_STR, <%= self.item_text_to_hex_definition() %>}, {0, 0, -1, 0}};
166 erb = ERB.new(script, nil, '-');
171 def generate_parts(type, a)
174 return PanelFixedTextItem.new(a);
176 return PanelNullItem.new(a);
178 return PanelButtonItem.new(a);
183 attr_accessor :yaml, :items
186 @items = Array.new();
187 if yaml["items"] != nil
188 yaml["items"].each { |a|
189 i = generate_parts(a["type"], a)
196 when "flush left", "flush right", "centering", "justification"
197 return @yaml["layout"];
215 w += item.width + margin;
222 attr_accessor :yaml, :lines, :margin_left, :margin_top, :margin_right, :margine_bottom, :panel_padding_left, :panel_padding_top, :panel_padding_right, :panel_padding_bottom
225 @lines = Array.new();
226 if yaml["lines"] != nil
227 yaml["lines"].each { |a|
228 l = PanelLine.new(a);
236 @panel_padding_left = 20;
237 @panel_padding_top = 20;
238 @panel_padding_right = 20;
239 @panel_padding_bottom = 20;
244 def panel_function_name()
247 def panel_result_type_name()
248 self.panel_name().upcase + "_RESULT";
250 def panel_arguments()
268 def each_item_type(type)
279 w = @margin_left + @margin_right;
281 w2 = @margin_left + line.width(@margin_left + @margin_right) + @margin_right;
291 h += @margin_top + line.height + @margin_bottom;
296 def generate_header_retval_definition()
298 enum <%= panel_result_type_name() %>_ {
299 <%- self.each_item_type("button") do |i| -%>
300 <%= panel_result_type_name().upcase %>_<%= i.name().upcase %>,
303 typedef enum <%= panel_result_type_name() %>_ <%= panel_result_type_name() %>;
306 erb = ERB.new(script, nil, '-');
309 def generate_header_function()
311 IMPORT <%= panel_result_type_name() %> <%= panel_function_name() %>(<%= panel_arguments() %>);
314 erb = ERB.new(script, nil, '-');
318 def calc_line_layout_left(content_width, line)
320 when "flush left", "justification"
321 return @panel_padding_left + @margin_left;
323 return @panel_padding_left + content_width - line.width;
325 return @panel_padding_left + (content_width - line.width) / 2;
328 def calc_line_layout_item_margin(content_width, line)
331 return @margin_right + @margin_left + (content_width - line.width(@margin_left + @margin_right)) / (line.items.length - 1);
333 return @margin_right + @margin_left;
337 def generate_source_function_pnl_item_value_each()
338 cw = self.content_width;
340 top = @panel_padding_top + @margin_top;
342 left = self.calc_line_layout_left(cw, l);
343 margin = self.calc_line_layout_item_margin(cw, l);
345 s = i.generate_pnl_item_value(n, left, top);
348 left += i.width + margin;
350 top += l.height + @margin_bottom + @margin_top;
353 def generate_source_function_ret_handler()
356 <%- self.each_item() do |i| -%><%- if i.type == "button" -%>
357 if (itemno == (<%= n %> + 1)) {
358 ret = <%= panel_result_type_name().upcase %>_<%= i.name().upcase %>;
361 <%- end -%><%- n += 1 -%><%- end -%>
364 erb = ERB.new(script, nil, '-');
368 def generate_source_function_function_name()
370 EXPORT <%= panel_result_type_name() %> <%= panel_function_name() %>(<%= panel_arguments() %>)
373 erb = ERB.new(script, nil, '-');
377 def generate_source_function_pnl_item_value()
379 <%- self.generate_source_function_pnl_item_value_each() do |s| -%><%= s %><%- end -%>
382 erb = ERB.new(script, nil, '-');
386 def generate_source_function()
388 <%= self.generate_source_function_function_name() %>{
389 PNL_ITEM pnl_item[<%= number_items %>];
391 PNT p0 = {0x8000,0x8000};
394 <%= panel_result_type_name().upcase %> ret;
397 {{0, 0, <%= self.panel_padding_left + self.content_width + self.panel_padding_right %>, <%= self.panel_padding_top + self.content_height + self.panel_padding_bottom %>}},
403 <%= self.generate_source_function_pnl_item_value() %>
404 pnid0 = pcre_pnl(&pnl, &p0);
406 DP_ER("pcre_pnl error", pnid0);
412 stat = pact_pnl(pnid0, &wev0.e, &itemno);
415 if (wev0.s.type == EV_DEVICE) {
416 oprc_dev(&wev0.e, NULL, 0);
420 <%= self.generate_source_function_ret_handler() %>
425 <%= self.generate_source_function_ret_handler() %>
443 erb = ERB.new(script, nil, '-');
449 attr_accessor :yaml, :panels, :name
452 @panels = Array.new();
453 yaml["panels"].each { |a|
459 @yaml["generator"]["lisence_header"]
462 @yaml["generator"]["lisence_source"]
464 def filename_header()
465 @yaml["generator"]["output_header"]
468 def generate_header()
470 <%- @panels.each do |p| -%>
471 <%= p.generate_header_retval_definition() %>
472 <%= p.generate_header_function() %>
476 erb = ERB.new(script, nil, '-');
479 def generate_source_include_files()
481 #include "<%= self.filename_header() %>"
487 #include <btron/btron.h>
488 #include <btron/hmi.h>
489 #include <btron/vobj.h>
492 # define DP(arg) printf arg
493 # define DP_ER(msg, err) printf("%s (%d/%x)\\n", msg, err>>16, err)
495 # define DP(arg) /**/
496 # define DP_ER(msg, err) /**/
501 erb = ERB.new(script, nil, '-');
504 def generate_source()
506 <%- @panels.each do |p| -%>
507 <%= p.generate_source_function() %>
511 erb = ERB.new(script, nil, '-');
516 def generate_header(filename, data)
517 fd = File.open(filename, "w");
518 fd.puts data.lisence_header();
521 /* This file is automatically generated. */
524 #include <btron/dp.h>
525 #include <btron/hmi.h>
528 fd.puts "#ifndef __" + filename.upcase.gsub(/\./, '_') + "__";
529 fd.puts "#define __" + filename.upcase.gsub(/\./, '_') + "__";
531 fd.puts data.generate_header();
536 def generate_source(filename, data)
537 fd = File.open(filename, "w");
538 fd.puts data.lisence_source();
541 /* This file is automatically generated. */
544 fd.puts data.generate_source_include_files();
546 fd.puts data.generate_source();
552 yaml = YAML.load_file(ARGV[0]);
553 data = PanelData.new(yaml);
555 fname_header = yaml["generator"]["output_header"]
556 fname_source = yaml["generator"]["output_source"]
558 generate_header(fname_header, data);
559 generate_source(fname_source, data);