Advertisement
Fernando_Fiore

HPGCC2 libwin

Feb 8th, 2023 (edited)
1,308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.24 KB | Source Code | 0 0
  1. #include <win.h>
  2. #include <hpkeyb49.h>
  3.  
  4. // The HP49G+ screen is 131 by 80 pixels in size
  5. const int HEIGHT = 60;
  6. const int WIDTH = 130;
  7.  
  8. /*
  9.  * drawns and returns an image
  10.  */
  11.  hpg_t* draw()
  12.  {
  13.     hpg_t *img = hpg_alloc_mono_image(30,30);
  14.    
  15.     hpg_clear_on(img);
  16.     hpg_draw_circle_on(img,15,15,14);
  17.     hpg_draw_line_on(img,0,0,29,29);
  18.     hpg_draw_line_on(img,29,0,0,29);
  19.     hpg_draw_rect_on(img,0,0,29,29);
  20.     hpg_clip(img,0,0,29,29);
  21.     return img;
  22. }
  23. /*
  24.  * key typed event handler
  25.  */
  26. int
  27. onkeytyped(void *event_data, void *app_data)
  28. {
  29.     win_keytyped_t *key = (win_keytyped_t *) event_data;
  30.     if ((int)(key->keycode) == KB_ON)
  31.     win_event_quit();
  32.     return 0;
  33. }
  34.  
  35. /*
  36.  * timer event handler
  37.  */
  38. int
  39. ontimer(void *event_data, void *app_data)
  40. {
  41.     static int old = 0;
  42.     win_widget_t *prog = ((win_widget_t *)app_data);
  43.     old++;
  44.     if(old > 10)
  45.         old = 0;
  46.     win_progress_set_value(prog,old);
  47.     return 0;
  48. }
  49.  
  50. /*
  51.  * menu event handler
  52.  */
  53.  int idx = 0;
  54. int
  55. onsoftmenu(void *event_data, void *app_data)
  56. {
  57.     idx++;
  58.     if(idx == 3)
  59.         idx = 0;
  60.     win_choose_set_index((win_widget_t *)app_data,idx);
  61.     switch(idx){
  62.         case 0:
  63.             hpg_set_mode_mono(1);
  64.             break;
  65.         case 1:
  66.             hpg_set_mode_gray4(1);
  67.             break;
  68.         case 2:
  69.             hpg_set_mode_gray16(1);
  70.             break;
  71.         default:
  72.             break;
  73.     }
  74.     hpg_flip();
  75.     return 0;
  76. }
  77.  
  78. int
  79. main(void)
  80. {
  81.     (void) win_init();
  82.     win_add_event_handler(WIN_KEY_TYPED, 0,
  83.               (win_eventhandler) onkeytyped,0);//set keytyped event handler
  84.     //soft menu
  85.     win_widget_t *menu = win_softmenu_new();
  86.     int MENU_EVENT = win_register_event();
  87.     win_softmenu_add_item(menu,"choose",MENU_EVENT,0);
  88.     //  box
  89.     win_widget_t *pBox = win_box_new();
  90.     win_widget_set_location(pBox,0,0);
  91.     win_widget_set_size(pBox,WIDTH,HEIGHT);
  92.     win_widget_t *pBoxtl = win_box_new();
  93.     win_widget_set_location(pBoxtl,0,0);
  94.     win_widget_set_size(pBoxtl,WIDTH/2,HEIGHT/2);
  95.     win_widget_t *pBoxtr = win_box_new();
  96.     win_widget_set_location(pBoxtr,WIDTH/2,0);
  97.     win_widget_set_size(pBoxtr,WIDTH/2,HEIGHT/2);
  98.     win_widget_t *pBoxb = win_box_new();
  99.     win_widget_set_location(pBoxb,0,HEIGHT/2);
  100.     win_widget_set_size(pBoxb,WIDTH,HEIGHT/2);
  101.     // entry
  102.     win_widget_t *pEdit = win_text_new_entry(WIDTH/2);
  103.     win_widget_set_location(pEdit,0,0);
  104.     win_widget_set_size(pEdit,WIDTH/2,8);
  105.     // choose
  106.     win_widget_t *pChoose = win_choose_new();
  107.     win_widget_set_location(pChoose,0,8);
  108.     win_widget_set_size(pChoose,WIDTH/2,8);
  109.     win_add_event_handler(MENU_EVENT, 0,
  110.         (win_eventhandler)onsoftmenu,(void *)pChoose);
  111.     win_choose_add(pChoose,"mono");
  112.     win_choose_add(pChoose,"4 cores");
  113.     win_choose_add(pChoose,"16 cores");
  114.     win_choose_set_menu(pChoose, menu, 0);
  115.     //  progress
  116.     win_widget_t * prog = win_progress_new(WIN_PROGRESS_HORIZ);
  117.     win_progress_set_range(prog,0,10);
  118.     int PROGRESS_EVENT = win_register_event();
  119.     win_progress_set_event(prog,PROGRESS_EVENT);
  120.     win_progress_set_inc(prog,1);
  121.     win_widget_set_location(prog,WIDTH/2,0);
  122.     win_widget_set_size(prog,WIDTH/2,8);
  123.     // checkbox
  124.     win_widget_t *pCheck = win_checkbox_new("check");
  125.     win_widget_set_location(pCheck,WIDTH/2,8);
  126.     win_widget_set_size(pCheck,WIDTH/2,8);
  127.     win_checkbox_set_menu(pCheck,menu,1);
  128.     // image
  129.     win_widget_t *img = win_img_new(0,draw());
  130.     win_widget_set_location(img,0,HEIGHT/2);
  131.     win_widget_set_size(img,WIDTH,HEIGHT/2);
  132.     // add all - required?
  133.     win_add_widget(pEdit);
  134.     win_add_widget(pChoose);
  135.     win_add_widget(pBox);
  136.     win_add_widget(pBoxtl);
  137.     win_add_widget(pBoxtr);
  138.     win_add_widget(pBoxb);
  139.     win_add_widget(menu);
  140.     win_add_widget(prog);
  141.     win_add_widget(img);
  142.     win_add_widget(pCheck);
  143.     // add to box - absolute values
  144.     win_box_add_at(pBox,pBoxtl,0,0);
  145.     win_box_add_at(pBox,pBoxtr,WIDTH/2,0);
  146.     win_box_add_at(pBox,pBoxb,0,HEIGHT/2);
  147.     win_box_add_at(pBoxtl,pEdit,0,0);
  148.     win_box_add_at(pBoxtl,pChoose,0,8);
  149.     win_box_add_at(pBoxtr, prog,WIDTH/2,0);
  150.     win_box_add_at(pBoxtr,pCheck,WIDTH/2,8);
  151.     win_box_add_at(pBoxb,img,0,HEIGHT/2);
  152.     //win_box_layout(pBoxtl);
  153.     //win_box_layout(pBoxtr);
  154.     //win_box_layout(pBoxb);
  155.     win_box_layout(pBox);   /* it can only call the outtermost box*/
  156.     int TIMER_EVENT = win_register_event();
  157.     win_add_event_handler(TIMER_EVENT, 0,
  158.               (win_eventhandler)ontimer,(void *)prog);
  159.     win_add_timer_event(TIMER_EVENT,0,1000,1);
  160.     win_event_loop();
  161.     return 0;
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement