Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20.  
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #include "maths.h"
  25. #include "pstypes.h"
  26. #include "event.h"
  27. #include "gr.h"
  28. #include "ui.h"
  29. #include "mouse.h"
  30. #include "key.h"
  31.  
  32. namespace dcx {
  33.  
  34. void ui_draw_userbox( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox )
  35. {
  36. #if 0  //ndef OGL
  37.         if ( userbox->status==1 )
  38. #endif
  39.         {
  40.                 userbox->status = 0;
  41.  
  42.                 gr_set_current_canvas( userbox->canvas );
  43.  
  44.                 const uint8_t color = (dlg->keyboard_focus_gadget == userbox)
  45.                         ? CRED
  46.                         : CBRIGHT;
  47.                 gr_ubox(*grd_curcanv, -1, -1, userbox->width, userbox->height, color);
  48.         }
  49. }
  50.  
  51.  
  52. std::unique_ptr<UI_GADGET_USERBOX> ui_add_gadget_userbox(UI_DIALOG * dlg, short x, short y, short w, short h)
  53. {
  54.         std::unique_ptr<UI_GADGET_USERBOX> userbox{ui_gadget_add<UI_GADGET_USERBOX>(dlg, x, y, x+w-1, y+h-1)};
  55.         userbox->width = w;
  56.         userbox->height = h;
  57.         userbox->b1_held_down=0;
  58.         userbox->b1_clicked=0;
  59.         userbox->b1_double_clicked=0;
  60.         userbox->b1_dragging=0;
  61.         userbox->b1_drag_x1=0;
  62.         userbox->b1_drag_y1=0;
  63.         userbox->b1_drag_x2=0;
  64.         userbox->b1_drag_y2=0;
  65.         userbox->b1_done_dragging = 0;
  66.         userbox->keypress = 0;
  67.         userbox->mouse_onme = 0;
  68.         userbox->mouse_x = 0;
  69.         userbox->mouse_y = 0;
  70.         userbox->bitmap = &(userbox->canvas->cv_bitmap);
  71.         return userbox;
  72. }
  73.  
  74. window_event_result ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox,const d_event &event )
  75. {
  76.         int OnMe, olddrag;
  77.         int x, y, z;
  78.         int keypress = 0;
  79.         window_event_result rval = window_event_result::ignored;
  80.        
  81.         if (event.type == EVENT_WINDOW_DRAW)
  82.                 ui_draw_userbox( dlg, userbox );
  83.        
  84.         if (event.type == EVENT_KEY_COMMAND)
  85.                 keypress = event_key_get(event);
  86.                
  87.         mouse_get_pos(&x, &y, &z);
  88.         OnMe = ui_mouse_on_gadget( userbox );
  89.  
  90.         olddrag  = userbox->b1_held_down;
  91.  
  92.         userbox->mouse_onme = OnMe;
  93.         userbox->mouse_x = x - userbox->x1;
  94.         userbox->mouse_y = y - userbox->y1;
  95.  
  96.         userbox->b1_dragging = 0;
  97.         userbox->b1_clicked = 0;
  98.  
  99.         if (OnMe)
  100.         {
  101.                 if ( B1_JUST_PRESSED )
  102.                 {
  103.                         userbox->b1_held_down = 1;
  104.                         userbox->b1_drag_x1 = x - userbox->x1;
  105.                         userbox->b1_drag_y1 = y - userbox->y1;
  106.                         rval = window_event_result::handled;
  107.                 }
  108.                 else if (B1_JUST_RELEASED)
  109.                 {
  110.                         if (userbox->b1_held_down)
  111.                                 userbox->b1_clicked = 1;
  112.                         userbox->b1_held_down = 0;
  113.                         rval = window_event_result::handled;
  114.                 }
  115.  
  116.                 if ( (event.type == EVENT_MOUSE_MOVED) && userbox->b1_held_down )
  117.                 {
  118.                         userbox->b1_dragging = 1;
  119.                         userbox->b1_drag_x2 = x - userbox->x1;
  120.                         userbox->b1_drag_y2 = y - userbox->y1;
  121.                 }
  122.  
  123.                 if ( B1_DOUBLE_CLICKED )
  124.                 {
  125.                         userbox->b1_double_clicked = 1;
  126.                         rval = window_event_result::handled;
  127.                 }
  128.                 else
  129.                         userbox->b1_double_clicked = 0;
  130.  
  131.         }
  132.  
  133.         if (B1_JUST_RELEASED)
  134.                 userbox->b1_held_down = 0;
  135.  
  136.         userbox->b1_done_dragging = 0;
  137.  
  138.         if (olddrag==1 && userbox->b1_held_down==0 )
  139.         {
  140.                 if ((userbox->b1_drag_x1 !=  userbox->b1_drag_x2) || (userbox->b1_drag_y1 !=  userbox->b1_drag_y2) )
  141.                         userbox->b1_done_dragging = 1;
  142.         }
  143.  
  144.         if (dlg->keyboard_focus_gadget==userbox)
  145.         {
  146.                 userbox->keypress = keypress;
  147.                 rval = window_event_result::handled;
  148.         }
  149.        
  150.         if (userbox->b1_clicked || userbox->b1_dragging)
  151.         {
  152.                 rval = ui_gadget_send_event(dlg, userbox->b1_clicked ? EVENT_UI_GADGET_PRESSED : EVENT_UI_USERBOX_DRAGGED, userbox);
  153.                 if (rval == window_event_result::ignored)
  154.                         rval = window_event_result::handled;
  155.         }
  156.  
  157.         return rval;
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164. }
  165.