amarullz

UEFI Dialog with shadow

Jan 13th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.86 KB | None | 0 0
  1. /*
  2.  * MENU DIALOG UEFI
  3.  *
  4.  */
  5.  
  6. void button_draw(const char* text, int x, int y, int w, int h) {
  7.   word colorAccent = RGB(ff8800);
  8.   /* draw text */
  9.   LIBAROMA_TEXT textp = libaroma_text(
  10.     text,
  11.     colorAccent,
  12.     w - libaroma_dp(16),
  13.     LIBAROMA_FONT(1,4)|
  14.     LIBAROMA_TEXT_SINGLELINE|
  15.     LIBAROMA_TEXT_CENTER|
  16.     LIBAROMA_TEXT_FIXED_INDENT|
  17.     LIBAROMA_TEXT_FIXED_COLOR|
  18.     LIBAROMA_TEXT_NOHR,
  19.     100
  20.   );
  21.   int ty = y + (h>>1) - ((libaroma_text_height(textp)>>1));
  22.   libaroma_text_draw(dc,textp,x + libaroma_dp(8),ty);
  23.   libaroma_text_free(textp);
  24. }
  25. int button_width(const char* text) {
  26.   /* draw text */
  27.   LIBAROMA_TEXT textp = libaroma_text(
  28.     text,
  29.     0,
  30.     dc->w,
  31.     LIBAROMA_FONT(1,4)|
  32.     LIBAROMA_TEXT_SINGLELINE|
  33.     LIBAROMA_TEXT_CENTER|
  34.     LIBAROMA_TEXT_FIXED_INDENT|
  35.     LIBAROMA_TEXT_FIXED_COLOR|
  36.     LIBAROMA_TEXT_NOHR,
  37.     100
  38.   );
  39.   int w = libaroma_dp(8) + libaroma_text_width(textp) + libaroma_dp(8);
  40.   libaroma_text_free(textp);
  41.   return w;
  42. }
  43.  
  44. int MenuShowDialog(
  45.   const char * Title,
  46.   const char * Message,
  47.   const char * Button1,
  48.   const char * Button2
  49. ){
  50.   int Selection = 0;
  51.   int MaxSelection = (Button1?1:0) + (Button2?1:0);
  52.  
  53.  
  54.   /* COLORS */
  55.   word colorTextSecondary = RGB(cccccc);
  56.   word colorTextPrimary = RGB(ffffff);
  57.   word colorBackground = RGB(444444);
  58.   word colorSelection = RGB(aaaaaa);
  59.  
  60.   /*
  61.     if(Initialized==FALSE)
  62.       return -1;
  63.     UINT32 OldMode = mGop->Mode->Mode;
  64.     mGop->SetMode(mGop, gLKDisplay->GetPortraitMode());
  65.   */
  66.  
  67.   /* Mask Dark */
  68.   libaroma_draw_rect(
  69.     dc, 0, 0, dc->w, dc->h, RGB(000000), 0x7a
  70.   );
  71.  
  72.   /* Init Message & Title Text */
  73.   int dialog_w = dc->w-libaroma_dp(48);
  74.   LIBAROMA_TEXT messagetextp = libaroma_text(
  75.     Message,
  76.     colorTextSecondary,
  77.     dialog_w-libaroma_dp(48),
  78.     LIBAROMA_FONT(0,4)|
  79.     LIBAROMA_TEXT_LEFT|
  80.     LIBAROMA_TEXT_FIXED_INDENT|
  81.     LIBAROMA_TEXT_FIXED_COLOR|
  82.     LIBAROMA_TEXT_NOHR,
  83.     100
  84.   );
  85.   LIBAROMA_TEXT textp = libaroma_text(
  86.     Title,
  87.     colorTextPrimary,
  88.     dialog_w-libaroma_dp(48),
  89.     LIBAROMA_FONT(1,6)|
  90.     LIBAROMA_TEXT_LEFT|
  91.     LIBAROMA_TEXT_FIXED_INDENT|
  92.     LIBAROMA_TEXT_FIXED_COLOR|
  93.     LIBAROMA_TEXT_NOHR,
  94.     100
  95.   );
  96.  
  97.   int dialog_h =
  98.     libaroma_dp(120)+
  99.     libaroma_text_height(textp)+
  100.     libaroma_text_height(messagetextp);
  101.   int dialog_x = libaroma_dp(24);
  102.   int dialog_y = (dc->h>>1)-(dialog_h>>1);
  103.  
  104.   /* create & draw dialog canvas */
  105.   LIBAROMA_CANVASP dialog_canvas = libaroma_canvas_ex(dialog_w,dialog_h,1);
  106.   libaroma_canvas_setcolor(dialog_canvas,0,0);
  107.   libaroma_gradient(dialog_canvas,
  108.     0,0,
  109.     dialog_w, dialog_h,
  110.     colorBackground,colorBackground,
  111.     libaroma_dp(2), /* rounded 2dp */
  112.     0x1111 /* all corners */
  113.   );
  114.  
  115.   /* draw texts */
  116.   libaroma_text_draw(
  117.     dialog_canvas,
  118.     textp,
  119.     libaroma_dp(24),
  120.     libaroma_dp(24)
  121.   );
  122.   libaroma_text_free(textp);
  123.  
  124.   /* draw text */
  125.   libaroma_text_draw(
  126.     dialog_canvas,
  127.     messagetextp,
  128.     libaroma_dp(24),
  129.     libaroma_dp(24)+libaroma_text_height(textp) + libaroma_dp(20)
  130.   );
  131.   libaroma_text_free(messagetextp);
  132.  
  133.   /* draw zshadow */
  134.   libaroma_draw_zshadow(
  135.     dc, dialog_canvas, dialog_x, dialog_y,
  136.     4 /* z-index = 4 */
  137.   );
  138.   /* draw dialog into display canvas */
  139.   libaroma_draw(dc,dialog_canvas,dialog_x, dialog_y, 1);
  140.  
  141.   /* free dialog canvas */
  142.   libaroma_canvas_free(dialog_canvas);
  143.  
  144.   int i; /* i is selection */
  145.   for (i=0;i<2;i++){
  146.     Selection=i;
  147.     int button_y = dialog_y+dialog_h-libaroma_dp(52);
  148.    
  149.     /* clean button area */
  150.     libaroma_draw_rect(dc, dialog_x, button_y, dialog_w, libaroma_dp(36), colorBackground, 0xff);
  151.      
  152.     if(Button1) {
  153.       /* button1 */
  154.       int button_w = button_width(Button1);
  155.       int button_x = dialog_x+dialog_w-button_w-libaroma_dp(16);
  156.      
  157.       if(Selection==0) {
  158.         libaroma_gradient_ex(dc,
  159.           button_x,button_y,
  160.           button_w, libaroma_dp(36),
  161.           colorSelection,colorSelection,
  162.           libaroma_dp(2), /* rounded 2dp */
  163.           0x1111, /* all corners */
  164.           0x40, 0x40 /* start & end alpha */
  165.         );
  166.       }
  167.       button_draw(Button1, button_x, button_y-libaroma_dp(2), button_w, libaroma_dp(36));
  168.  
  169.       /* button2 */
  170.       if(Button2) {
  171.         button_w = button_width(Button2);
  172.         button_x -= (libaroma_dp(8)+button_w);
  173.         if(Selection==1) {
  174.           libaroma_gradient_ex(dc,
  175.             button_x,button_y,
  176.             button_w, libaroma_dp(36),
  177.             colorSelection,colorSelection,
  178.             libaroma_dp(2), /* rounded 2dp */
  179.             0x1111, /* all corners */
  180.             0x40, 0x40 /* start & end alpha */
  181.           );
  182.         }
  183.         button_draw(Button2, button_x, button_y-libaroma_dp(2), button_w, libaroma_dp(36));
  184.       }
  185.     }
  186.     libaroma_sync();
  187.     sleep(2);
  188.   }
  189.   return -1;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment