comparison gui/skin/skin.c @ 37053:84c93a60ead3

Add new item 'rpotmeter'. This is the missing counterpart to hpotmeter and vpotmeter allowing rotary control elements in a GUI skin now. Based on an idea and a realization by Hans-Dieter Kosch, hdkosch kabelbw de. Additionally, update (and revise) documentation.
author ib
date Sat, 12 Apr 2014 23:29:29 +0000
parents 1468239c0fe3
children b28b632efeef
comparison
equal deleted inserted replaced
37052:2ef6693131f7 37053:84c93a60ead3
19 /** 19 /**
20 * @file 20 * @file
21 * @brief Skin parser 21 * @brief Skin parser
22 */ 22 */
23 23
24 #include <math.h>
24 #include <stdio.h> 25 #include <stdio.h>
25 #include <string.h> 26 #include <string.h>
26 27
27 #include "skin.h" 28 #include "skin.h"
28 #include "font.h" 29 #include "font.h"
33 #include "gui/util/misc.h" 34 #include "gui/util/misc.h"
34 #include "gui/util/string.h" 35 #include "gui/util/string.h"
35 36
36 #include "help_mp.h" 37 #include "help_mp.h"
37 #include "mp_msg.h" 38 #include "mp_msg.h"
39 #include "libavutil/attributes.h"
38 #include "libavutil/avstring.h" 40 #include "libavutil/avstring.h"
39 #include "libavutil/common.h" 41 #include "libavutil/common.h"
40 42
41 typedef struct { 43 typedef struct {
42 const char *name; 44 const char *name;
587 589
588 return 0; 590 return 0;
589 } 591 }
590 592
591 /** 593 /**
592 * @brief Parse a hpotmeter or vpotmeter definition. 594 * @brief Parse a hpotmeter, vpotmeter or rpotmeter definition.
593 * 595 *
594 * Parameters: button,bwidth,bheight,phases,numphases,default,x,y,width,height,message 596 * Parameters: button,bwidth,bheight,phases,numphases,[x0,y0,x1,y1,]default,x,y,width,height,message
595 * 597 *
596 * @param item pointer to item to store the parameters in 598 * @param item pointer to item to store the parameters in
597 * @param in definition to be analyzed 599 * @param in definition to be analyzed
600 *
601 * @note item->type is already available.
598 * 602 *
599 * @return 0 (ok) or 1 (error) 603 * @return 0 (ok) or 1 (error)
600 */ 604 */
601 static int parse_potmeter(guiItem *item, char *in) 605 static int parse_potmeter(guiItem *item, char *in)
602 { 606 {
603 unsigned char bfname[256]; 607 unsigned char bfname[256];
604 unsigned char phfname[256]; 608 unsigned char phfname[256];
605 unsigned char buf[512]; 609 unsigned char buf[512];
610 int i = 0, av_uninit(x0), av_uninit(y0), av_uninit(x1), av_uninit(y1);
606 int bwidth, bheight, num, d, x, y, w, h, message; 611 int bwidth, bheight, num, d, x, y, w, h, message;
607 612
608 if (!window_item(currItem)) 613 if (!window_item(currItem))
609 return 1; 614 return 1;
610 615
611 if (in_window("video")) 616 if (in_window("video"))
612 return 1; 617 return 1;
613 if (in_window("menu")) 618 if (in_window("menu"))
614 return 1; 619 return 1;
615 620
616 cutStr(in, bfname, ',', 0); 621 cutStr(in, bfname, ',', i++);
617 bwidth = cutInt(in, ',', 1); 622 bwidth = cutInt(in, ',', i++);
618 bheight = cutInt(in, ',', 2); 623 bheight = cutInt(in, ',', i++);
619 cutStr(in, phfname, ',', 3); 624 cutStr(in, phfname, ',', i++);
620 num = cutInt(in, ',', 4); 625 num = cutInt(in, ',', i++);
621 d = cutInt(in, ',', 5); 626
622 x = cutInt(in, ',', 6); 627 if (item->type == itRPotmeter) {
623 y = cutInt(in, ',', 7); 628 x0 = cutInt(in, ',', i++);
624 w = cutInt(in, ',', 8); 629 y0 = cutInt(in, ',', i++);
625 h = cutInt(in, ',', 9); 630 x1 = cutInt(in, ',', i++);
626 cutStr(in, buf, ',', 10); 631 y1 = cutInt(in, ',', i++);
632 }
633
634 d = cutInt(in, ',', i++);
635 x = cutInt(in, ',', i++);
636 y = cutInt(in, ',', i++);
637 w = cutInt(in, ',', i++);
638 h = cutInt(in, ',', i++);
639 cutStr(in, buf, ',', i++);
627 640
628 message = appFindMessage(buf); 641 message = appFindMessage(buf);
629 642
630 if (message == -1) { 643 if (message == -1) {
631 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, buf); 644 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, buf);
654 item->numphases = num; 667 item->numphases = num;
655 item->value = (float)d; 668 item->value = (float)d;
656 item->message = message; 669 item->message = message;
657 item->pressed = btnReleased; 670 item->pressed = btnReleased;
658 671
672 if (item->type == itRPotmeter) {
673 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] start: %d,%d / stop: %d,%d\n", x0, y0, x1, y1);
674
675 item->zeropoint = appRadian(item, x0, y0);
676 item->arclength = appRadian(item, x1, y1) - item->zeropoint;
677
678 if (item->arclength < 0.0)
679 item->arclength += 2 * M_PI;
680 // else check if radians of (x0,y0) and (x1,y1) only differ below threshold
681 else if (item->arclength < 0.05)
682 item->arclength = 2 * M_PI;
683 }
684
659 item->Bitmap.Image = NULL; 685 item->Bitmap.Image = NULL;
660 686
661 if (strcmp(phfname, "NULL") != 0) { 687 if (strcmp(phfname, "NULL") != 0) {
662 if (num == 0) { 688 if (num == 0) {
663 skin_error(MSGTR_GUI_MSG_SkinErrorNumphases); 689 skin_error(MSGTR_GUI_MSG_SkinErrorNumphases);
728 754
729 if (!item) 755 if (!item)
730 return 1; 756 return 1;
731 757
732 item->type = itVPotmeter; 758 item->type = itVPotmeter;
759
760 return parse_potmeter(item, in);
761 }
762
763 /**
764 * @brief Parse a @a rpotmeter definition.
765 *
766 * Syntax: rpotmeter=button,bwidth,bheight,phases,numphases,x0,y0,x1,y1,default,x,y,width,height,message
767 *
768 * @param in definition to be analyzed
769 *
770 * @return 0 (ok) or 1 (error)
771 */
772 static int item_rpotmeter(char *in)
773 {
774 guiItem *item;
775
776 item = next_item();
777
778 if (!item)
779 return 1;
780
781 item->type = itRPotmeter;
733 782
734 return parse_potmeter(item, in); 783 return parse_potmeter(item, in);
735 } 784 }
736 785
737 /** 786 /**
1073 { "font", item_font }, 1122 { "font", item_font },
1074 { "hpotmeter", item_hpotmeter }, 1123 { "hpotmeter", item_hpotmeter },
1075 { "menu", item_menu }, 1124 { "menu", item_menu },
1076 { "pimage", item_pimage }, 1125 { "pimage", item_pimage },
1077 { "potmeter", item_potmeter }, // legacy 1126 { "potmeter", item_potmeter }, // legacy
1127 { "rpotmeter", item_rpotmeter },
1078 { "section", item_section }, 1128 { "section", item_section },
1079 { "selected", item_selected }, 1129 { "selected", item_selected },
1080 { "slabel", item_slabel }, 1130 { "slabel", item_slabel },
1081 { "vpotmeter", item_vpotmeter }, 1131 { "vpotmeter", item_vpotmeter },
1082 { "window", item_window } 1132 { "window", item_window }