Previous 199869 Revisions Next

r35313 Thursday 26th February, 2015 at 23:19:41 UTC by Couriersud
Introduced osd_rect and osd_dim to allow for more code alignment. (nw)
[src/osd/modules]osdwindow.h
[src/osd/sdl]draw13.c drawogl.c drawsdl.c video.h window.c window.h
[src/osd/windows]drawdd.c video.h window.c window.h

trunk/src/osd/modules/osdwindow.h
r243824r243825
5151
5252   float aspect() const { return monitor()->aspect(); }
5353
54   virtual void get_size(int &w, int &h) = 0;
54   virtual osd_dim get_size() = 0;
5555
5656#ifdef OSD_SDL
5757   virtual void blit_surface_size(int &blitwidth, int &blitheight) = 0;
r243824r243825
6565   virtual win_monitor_info *monitor() const = 0;
6666   virtual bool win_has_menu() = 0;
6767   // FIXME: cann we replace winwindow_video_window_monitor(NULL) with monitor() ?
68   virtual win_monitor_info *winwindow_video_window_monitor(const RECT *proposed) = 0;
68   virtual win_monitor_info *winwindow_video_window_monitor(const osd_rect *proposed) = 0;
6969
7070   // window handle and info
7171   HWND                    m_hwnd;
trunk/src/osd/sdl/draw13.c
r243824r243825
688688      return 0;
689689   }
690690
691   int width = 0; int height = 0;
692   window().get_size(width,height);
691   osd_dim wdim = window().get_size();
693692
694   if (has_flags(FI_CHANGED) || (width != m_width) || (height != m_height))
693   if (has_flags(FI_CHANGED) || (wdim.width() != m_width) || (wdim.height() != m_height))
695694   {
696695      destroy_all_textures();
697      m_width = width;
698      m_height = height;
696      m_width = wdim.width();
697      m_height = wdim.height();
699698      SDL_RenderSetViewport(m_sdl_renderer, NULL);
700699      m_blittimer = 3;
701700      clear_flags(FI_CHANGED);
r243824r243825
720719   {
721720      int ch, cw;
722721
723      ch = height;
724      cw = width;
722      ch = wdim.height();
723      cw = wdim.width();
725724
726725      if (video_config.centerv)
727726      {
trunk/src/osd/sdl/drawogl.c
r243824r243825
14791479   texture_info *texture=NULL;
14801480   float vofs, hofs;
14811481   int  pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE;
1482   int width = 0; int height = 0;
14831482
14841483#ifdef TOBEMIGRATED
14851484   if (video_config.novideo)
r243824r243825
14881487   }
14891488#endif
14901489
1491   window().get_size(width, height);
1490   osd_dim wdim = window().get_size();
14921491
1493   if (has_flags(FI_CHANGED) || (width != m_width) || (height != m_height))
1492   if (has_flags(FI_CHANGED) || (wdim.width() != m_width) || (wdim.height() != m_height))
14941493   {
14951494      destroy_all_textures();
1496      m_width = width;
1497      m_height = height;
1495      m_width = wdim.width();
1496      m_height = wdim.height();
14981497      m_blittimer = 3;
14991498      m_init_context = 1;
15001499      clear_flags(FI_CHANGED);
trunk/src/osd/sdl/drawsdl.c
r243824r243825
559559   UINT8 *surfptr;
560560   INT32 pitch;
561561   Uint32 rmask, gmask, bmask;
562   int width = 0; int height = 0;
563562#if (SDLMAME_SDL2)
564563   Uint32 amask;
565564#endif
r243824r243825
571570      return 0;
572571   }
573572
574   window().get_size(width, height);
575   if (has_flags(FI_CHANGED) || (width != m_last_width) || (height != m_last_height))
573   osd_dim wdim = window().get_size();
574   if (has_flags(FI_CHANGED) || (wdim.width() != m_last_width) || (wdim.height() != m_last_height))
576575   {
577576      destroy_all_textures();
578577      clear_flags(FI_CHANGED);
579578      m_blittimer = 3;
580      m_last_width = width;
581      m_last_height = height;
579      m_last_width = wdim.width();
580      m_last_height = wdim.height();
582581#if (SDLMAME_SDL2)
583582      SDL_RenderSetViewport(m_sdl_renderer, NULL);
584583      if (m_texture_id != NULL)
r243824r243825
619618   // Clear if necessary
620619   if (m_blittimer > 0)
621620   {
622      memset(window().sdl_surface()->pixels, 0, height * window().sdl_surface()->pitch);
621      memset(window().sdl_surface()->pixels, 0, wdim.height() * window().sdl_surface()->pitch);
623622      m_blittimer--;
624623   }
625624
r243824r243825
669668   blitwidth = m_blitwidth;
670669   blitheight = m_blitheight;
671670
672   ch = height;
673   cw = width;
671   ch = wdim.height();
672   cw = wdim.width();
674673
675674   // do not crash if the window's smaller than the blit area
676675   if (blitheight > ch)
trunk/src/osd/sdl/video.h
r243824r243825
5959   int                 height;
6060};
6161
62class osd_dim
63{
64public:
65   osd_dim(const int &w, const int &h)
66   : m_w(w), m_h(h)
67   {
68   }
69   int width() const { return m_w; }
70   int height() const { return m_h; }
71
72private:
73   int m_w;
74   int m_h;
75};
76
77class osd_rect
78{
79public:
80   osd_rect(const int x, const int y, const int &w, const int &h)
81   : m_x(x), m_y(y), m_d(w,h)
82   {
83   }
84   osd_rect(const int x, const int y, const osd_dim &d)
85   : m_x(x), m_y(y), m_d(d)
86   {
87   }
88   int top() const { return m_y; }
89   int left() const { return m_x; }
90   int width() const { return m_d.width(); }
91   int height() const { return m_d.height(); }
92
93   osd_dim dim() const { return m_d; }
94
95   int bottom() const { return m_y + m_d.height(); }
96   int right() const { return m_x + m_d.width(); }
97
98   osd_rect move_by(int dx, int dy) const { return osd_rect(m_x + dx, m_y + dy, m_d); }
99   osd_rect resize(int w, int h) const { return osd_rect(m_x, m_y, w, h); }
100
101private:
102   int m_x;
103   int m_y;
104   osd_dim m_d;
105};
106
107inline osd_rect SDL_Rect_to_osd_rect(const SDL_Rect &r)
108{
109   return osd_rect(r.x, r.y, r.w, r.h);
110}
111
62112// FIXME: This is sort of ugly ... and should be a real interface only
63113class sdl_monitor_info
64114{
r243824r243825
75125   }
76126
77127   const UINT64 handle() { return m_handle; }
78   const SDL_Rect &position_size() { refresh(); return m_dimensions; }
128   const osd_rect position_size() { refresh(); return SDL_Rect_to_osd_rect(m_dimensions); }
79129
80130   const char *devicename() { refresh(); return m_name[0] ? m_name : "UNKNOWN"; }
81131
trunk/src/osd/sdl/window.c
r243824r243825
384384
385385void sdl_window_info::blit_surface_size(int &blitwidth, int &blitheight)
386386{
387   int window_width, window_height;
388   get_size(window_width, window_height);
387   osd_dim window_dim = get_size();
389388
390   INT32 newwidth, newheight;
389   int newwidth, newheight;
391390   int xscale = 1, yscale = 1;
392391   float desired_aspect = 1.0f;
393   INT32 target_width = window_width;
394   INT32 target_height = window_height;
392   INT32 target_width = window_dim.width();
393   INT32 target_height = window_dim.height();
395394
396395   // start with the minimum size
397396   m_target->compute_minimum_size(newwidth, newheight);
r243824r243825
415414      if (video_config.keepaspect)
416415      {
417416         // if we could stretch more in the X direction, and that makes a better fit, bump the xscale
418         while (newwidth * (xscale + 1) <= window_width &&
417         while (newwidth * (xscale + 1) <= window_dim.width() &&
419418            better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale + 1), newheight * yscale, desired_aspect))
420419            xscale++;
421420
422421         // if we could stretch more in the Y direction, and that makes a better fit, bump the yscale
423         while (newheight * (yscale + 1) <= window_height &&
422         while (newheight * (yscale + 1) <= window_dim.height() &&
424423            better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale + 1), desired_aspect))
425424            yscale++;
426425
427426         // now that we've maxed out, see if backing off the maximally stretched one makes a better fit
428         if (window_width - newwidth * xscale < window_height - newheight * yscale)
427         if (window_dim.width() - newwidth * xscale < window_dim.height() - newheight * yscale)
429428         {
430429            while (better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale - 1), newheight * yscale, desired_aspect) && (xscale >= 0))
431430               xscale--;
r243824r243825
454453   //FIXME: really necessary to distinguish for yuv_modes ?
455454   if (m_target->zoom_to_screen()
456455      && (video_config.scale_mode == VIDEO_SCALE_MODE_NONE ))
457      newwidth = window_width;
456      newwidth = window_dim.width();
458457
459#if 0
460   // Fixme: notify_changed really necessary ?
461   if ((blitwidth != newwidth) || (blitheight != newheight))
462      notify_changed();
463#endif
464458   blitwidth = newwidth;
465459   blitheight = newheight;
466460}
r243824r243825
498492{
499493   ASSERT_MAIN_THREAD();
500494
501   int cw=0; int ch=0;
502   get_size(cw, ch);
495   osd_dim cd = get_size();
503496
504   if (width != cw || height != ch)
497   if (width != cd.width() || height != cd.height())
505498      execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height));
506499}
507500
r243824r243825
555548   // If we are going fullscreen (leaving windowed) remember our windowed size
556549   if (!window->fullscreen())
557550   {
558      window->get_size(window->m_windowed_width, window->m_windowed_height);
551      window->m_windowed_dim = window->get_size();
559552   }
560553
561554   window->renderer().destroy();
r243824r243825
853846//============================================================
854847
855848#if SDLMAME_SDL2
856void sdl_window_info::pick_best_mode(int *fswidth, int *fsheight)
849osd_dim sdl_window_info::pick_best_mode()
857850{
858851   int minimum_width, minimum_height, target_width, target_height;
859852   int i;
r243824r243825
912905         if (size_score > best_score)
913906         {
914907            best_score = size_score;
915            *fswidth = mode.w;
916            *fsheight = mode.h;
908            return osd_dim(mode.w, mode.h);
917909         }
918910
919911      }
920912   }
913   return osd_dim(0,0); // please compiler
921914}
922915#else
923void sdl_window_info::pick_best_mode(int *fswidth, int *fsheight)
916osd_dim sdl_window_info::pick_best_mode()
924917{
925918   int minimum_width, minimum_height, target_width, target_height;
926919   int i;
r243824r243825
958951   }
959952   else if (modes == (SDL_Rect **)-1)  // all modes are possible
960953   {
961      *fswidth = m_win_config.width;
962      *fsheight = m_win_config.height;
954      return osd_dim(m_win_config.width, m_win_config.height);
963955   }
964956   else
965957   {
r243824r243825
986978         if (size_score > best_score)
987979         {
988980            best_score = size_score;
989            *fswidth = modes[i]->w;
990            *fsheight = modes[i]->h;
981            return osd_dim(modes[i]->w, modes[i]->h);
991982         }
992983
993984      }
994985   }
986   return osd_dim(0,0);
995987}
996988#endif
997989
r243824r243825
10291021         }
10301022         else if (video_config.switchres)
10311023         {
1032            this->pick_best_mode(&tempwidth, &tempheight);
1033            resize(tempwidth, tempheight);
1024            osd_dim tmp = this->pick_best_mode();
1025            resize(tmp.width(), tmp.height());
10341026         }
10351027      }
10361028
r243824r243825
10861078   worker_param *      wp = (worker_param *) param;
10871079   sdl_window_info *   window = wp->window();
10881080
1089   int tempwidth, tempheight;
1081   osd_dim temp(0,0);
10901082   static int result[2] = {0,1};
10911083
10921084   ASSERT_WINDOW_THREAD();
r243824r243825
10951087   if (window->fullscreen())
10961088   {
10971089      // default to the current mode exactly
1098      tempwidth = window->monitor()->position_size().w;
1099      tempheight = window->monitor()->position_size().h;
1090      temp = window->monitor()->position_size().dim();
11001091
11011092      // if we're allowed to switch resolutions, override with something better
11021093      if (video_config.switchres)
1103         window->pick_best_mode(&tempwidth, &tempheight);
1094         temp = window->pick_best_mode();
11041095   }
1105   else if (window->m_windowed_width)
1096   else if (window->m_windowed_dim.width() > 0)
11061097   {
11071098      // if we have a remembered size force the new window size to it
1108      tempwidth = window->m_windowed_width;
1109      tempheight = window->m_windowed_height;
1099      temp = window->m_windowed_dim;
11101100   }
11111101   else
11121102   {
11131103      if (window->m_startmaximized)
11141104      {
1115         tempwidth = tempheight = 0;
1116         window->get_max_bounds(&tempwidth, &tempheight, video_config.keepaspect );
1105         temp = window->get_max_bounds(video_config.keepaspect );
11171106      }
11181107      else
11191108      {
1109#if 0
1110         // Couriersud: This code never has worked with the last version of get_min_bounds
11201111         /* Create the window directly with the correct aspect
11211112            instead of letting sdlwindow_blit_surface_size() resize it
11221113            this stops the window from "flashing" from the wrong aspect
11231114            size to the right one at startup. */
11241115         tempwidth = (window->m_win_config.width != 0) ? window->m_win_config.width : 640;
11251116         tempheight = (window->m_win_config.height != 0) ? window->m_win_config.height : 480;
1126
1127         window->get_min_bounds(&tempwidth, &tempheight, video_config.keepaspect );
1117#endif
1118         temp = window->get_min_bounds(video_config.keepaspect );
11281119      }
11291120   }
11301121
r243824r243825
11661157#endif
11671158   // create the SDL window
11681159   window->m_sdl_window = SDL_CreateWindow(window->m_title,
1169         window->monitor()->position_size().x, window->monitor()->position_size().y,
1170         tempwidth, tempheight, window->m_extra_flags);
1160         window->monitor()->position_size().left(), window->monitor()->position_size().top(),
1161         temp.width(), temp.height(), window->m_extra_flags);
11711162   //window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
11721163   //      width, height, m_extra_flags);
11731164
r243824r243825
11861177      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
11871178      SDL_GetWindowDisplayMode(window->sdl_window(), &mode);
11881179      window->m_original_mode = mode;
1189      mode.w = tempwidth;
1190      mode.h = tempheight;
1180      mode.w = temp.width();
1181      mode.h = temp.height();
11911182      if (window->m_win_config.refresh)
11921183         mode.refresh_rate = window->m_win_config.refresh;
11931184
r243824r243825
12411232   if (!window->m_sdlsurf)
12421233      printf("completely failed\n");
12431234#endif
1244   window->m_sdlsurf = SDL_SetVideoMode(tempwidth, tempheight,
1235   window->m_sdlsurf = SDL_SetVideoMode(temp.width(), temp.height(),
12451236                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | window->m_extra_flags);
12461237
12471238   if (!window->m_sdlsurf)
r243824r243825
13771368   return NULL;
13781369}
13791370
1371int sdl_window_info::wnd_extra_width()
1372{
1373   return m_fullscreen ? 0 : WINDOW_DECORATION_WIDTH;
1374}
13801375
1376int sdl_window_info::wnd_extra_height()
1377{
1378   return m_fullscreen ? 0 : WINDOW_DECORATION_HEIGHT;
1379}
1380
1381
13811382//============================================================
13821383//  constrain_to_aspect_ratio
13831384//  (window thread)
13841385//============================================================
13851386
1386void sdl_window_info::constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment)
1387osd_rect sdl_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int adjustment)
13871388{
1388   INT32 extrawidth = 0;
1389   INT32 extraheight = 0;
1389   INT32 extrawidth = wnd_extra_width();
1390   INT32 extraheight = wnd_extra_height();
13901391   INT32 propwidth, propheight;
13911392   INT32 minwidth, minheight;
13921393   INT32 maxwidth, maxheight;
13931394   INT32 viswidth, visheight;
1395   INT32 adjwidth, adjheight;
13941396   float pixel_aspect;
13951397
13961398   // get the pixel aspect ratio for the target monitor
13971399   pixel_aspect = m_monitor->aspect();
13981400
13991401   // determine the proposed width/height
1400   propwidth = *window_width - extrawidth;
1401   propheight = *window_height - extraheight;
1402   propwidth = rect.width() - extrawidth;
1403   propheight = rect.height() - extraheight;
14021404
14031405   // based on which edge we are adjusting, take either the width, height, or both as gospel
14041406   // and scale to fit using that as our parameter
r243824r243825
14311433   propheight = MAX(propheight, minheight);
14321434
14331435   // clamp against the maximum (fit on one screen for full screen mode)
1434   maxwidth = m_monitor->position_size().w - extrawidth;
1435   maxheight = m_monitor->position_size().h - extraheight;
1436   if (this->m_fullscreen)
1436   if (m_fullscreen)
14371437   {
1438      // nothing
1438      maxwidth = m_monitor->position_size().width() - extrawidth;
1439      maxheight = m_monitor->position_size().height() - extraheight;
14391440   }
14401441   else
14411442   {
1443      maxwidth = m_monitor->position_size().width() - extrawidth;
1444      maxheight = m_monitor->position_size().height() - extraheight;
1445
14421446      // further clamp to the maximum width/height in the window
1443      if (this->m_win_config.width != 0)
1444         maxwidth = MIN(maxwidth, this->m_win_config.width + extrawidth);
1445      if (this->m_win_config.height != 0)
1446         maxheight = MIN(maxheight, this->m_win_config.height + extraheight);
1447      if (m_win_config.width != 0)
1448         maxwidth = MIN(maxwidth, m_win_config.width + extrawidth);
1449      if (m_win_config.height != 0)
1450         maxheight = MIN(maxheight, m_win_config.height + extraheight);
14471451   }
14481452
14491453   // clamp to the maximum
r243824r243825
14531457   // compute the visible area based on the proposed rectangle
14541458   m_target->compute_visible_area(propwidth, propheight, pixel_aspect, m_target->orientation(), viswidth, visheight);
14551459
1456   *window_width = viswidth;
1457   *window_height = visheight;
1460   // compute the adjustments we need to make
1461   adjwidth = (viswidth + extrawidth) - rect.width();
1462   adjheight = (visheight + extraheight) - rect.height();
1463
1464   // based on which corner we're adjusting, constrain in different ways
1465   osd_rect ret(rect);
1466
1467   switch (adjustment)
1468   {
1469      case WMSZ_BOTTOM:
1470      case WMSZ_BOTTOMRIGHT:
1471      case WMSZ_RIGHT:
1472         ret = rect.resize(rect.width() + adjwidth, rect.height() + adjheight);
1473         break;
1474
1475      case WMSZ_BOTTOMLEFT:
1476         ret = rect.move_by(-adjwidth, 0).resize(rect.width(), rect.height() + adjheight);
1477         break;
1478
1479      case WMSZ_LEFT:
1480      case WMSZ_TOPLEFT:
1481      case WMSZ_TOP:
1482         ret = rect.move_by(-adjwidth, -adjheight);
1483         break;
1484
1485      case WMSZ_TOPRIGHT:
1486         ret = rect.move_by(0, -adjheight).resize(rect.width() + adjwidth, rect.height());
1487         break;
14581488}
1489   return ret;
1490}
14591491
14601492
1493
14611494//============================================================
14621495//  get_min_bounds
14631496//  (window thread)
14641497//============================================================
14651498
1466void sdl_window_info::get_min_bounds(int *window_width, int *window_height, int constrain)
1499osd_dim sdl_window_info::get_min_bounds(int constrain)
14671500{
14681501   INT32 minwidth, minheight;
14691502
14701503   // get the minimum target size
1471   this->m_target->compute_minimum_size(minwidth, minheight);
1504   m_target->compute_minimum_size(minwidth, minheight);
14721505
14731506   // expand to our minimum dimensions
14741507   if (minwidth < MIN_WINDOW_DIM)
r243824r243825
14761509   if (minheight < MIN_WINDOW_DIM)
14771510      minheight = MIN_WINDOW_DIM;
14781511
1512   // account for extra window stuff
1513   minwidth += wnd_extra_width();
1514   minheight += wnd_extra_height();
1515
14791516   // if we want it constrained, figure out which one is larger
14801517   if (constrain)
14811518   {
1482      int test1w, test1h;
1483      int test2w, test2h;
1484
14851519      // first constrain with no height limit
1486      test1w = minwidth; test1h = 10000;
1487      this->constrain_to_aspect_ratio(&test1w, &test1h, WMSZ_BOTTOMRIGHT);
1520      osd_rect test1(0,0,minwidth,10000);
1521      test1 = constrain_to_aspect_ratio(test1, WMSZ_BOTTOMRIGHT);
14881522
14891523      // then constrain with no width limit
1490      test2w = 10000; test2h = minheight;
1491      this->constrain_to_aspect_ratio(&test2w, &test2h, WMSZ_BOTTOMRIGHT);
1524      osd_rect test2(0,0,10000,minheight);
1525      test2 = constrain_to_aspect_ratio(test2, WMSZ_BOTTOMRIGHT);
14921526
14931527      // pick the larger
1494      if ( test1w > test2w )
1528      if (test1.width() > test2.width())
14951529      {
1496         minwidth = test1w;
1497         minheight = test1h;
1530         minwidth = test1.width();
1531         minheight = test1.height();
14981532      }
14991533      else
15001534      {
1501         minwidth = test2w;
1502         minheight = test2h;
1535         minwidth = test2.width();
1536         minheight = test2.height();
15031537      }
15041538   }
15051539
1506   *window_width = minwidth;
1507   *window_height = minheight;
1540   return osd_dim(minwidth, minheight);
15081541}
15091542
15101543
1544
15111545//============================================================
15121546//  get_max_bounds
15131547//  (window thread)
15141548//============================================================
15151549
1516void sdl_window_info::get_max_bounds(int *window_width, int *window_height, int constrain)
1550osd_dim sdl_window_info::get_max_bounds(int constrain)
15171551{
1518   INT32 maxwidth, maxheight;
1519
15201552   // compute the maximum client area
1521   maxwidth = m_monitor->position_size().w;
1522   maxheight = m_monitor->position_size().h;
15231553
1554   osd_rect maximum = m_monitor->position_size();
1555
15241556   // clamp to the window's max
1525   if (this->m_win_config.width != 0)
1557   int tempw = maximum.width();
1558   int temph = maximum.height();
1559   if (m_win_config.width != 0)
15261560   {
1527      int temp = this->m_win_config.width + WINDOW_DECORATION_WIDTH;
1528      if (temp < maxwidth)
1529         maxwidth = temp;
1561      int temp = m_win_config.width + wnd_extra_width();
1562      if (temp < maximum.width())
1563         tempw = temp;
15301564   }
1531   if (this->m_win_config.height != 0)
1565   if (m_win_config.height != 0)
15321566   {
1533      int temp = this->m_win_config.height + WINDOW_DECORATION_HEIGHT;
1534      if (temp < maxheight)
1535         maxheight = temp;
1567      int temp = m_win_config.height + wnd_extra_height();
1568      if (temp < maximum.height())
1569         temph = temp;
15361570   }
15371571
1572   maximum = maximum.resize(tempw, temph);
1573
15381574   // constrain to fit
15391575   if (constrain)
1540      this->constrain_to_aspect_ratio(&maxwidth, &maxheight, WMSZ_BOTTOMRIGHT);
1541   //else
1576      maximum = constrain_to_aspect_ratio(maximum, WMSZ_BOTTOMRIGHT);
1577   else
15421578   {
1543      maxwidth -= WINDOW_DECORATION_WIDTH;
1544      maxheight -= WINDOW_DECORATION_HEIGHT;
1545      *window_width = maxwidth;
1546      *window_height = maxheight;
1579      maximum = maximum.resize(maximum.width() - wnd_extra_width(), maximum.height() - wnd_extra_height());
15471580   }
1581   return maximum.dim();
15481582}
trunk/src/osd/sdl/window.h
r243824r243825
4444      m_resize_height(0),
4545      m_last_resize(0),
4646#endif
47         m_minwidth(0), m_minheight(0),
47      m_minwidth(0), m_minheight(0),
48      m_windowed_dim(0,0),
4849      m_rendered_event(0), m_target(0),
4950#if (SDLMAME_SDL2)
5051      m_sdl_window(NULL),
r243824r243825
6162      m_fullscreen = !video_config.windowed;
6263      m_prescale = video_config.prescale;
6364
64      m_windowed_width = config->width;
65      m_windowed_height = config->height;
65      m_windowed_dim = osd_dim(config->width, config->height);
6666   }
6767
6868   ~sdl_window_info()
r243824r243825
8080
8181   void notify_changed();
8282
83   void get_size(int &w, int &h)
83   osd_dim get_size()
8484   {
8585#if (SDLMAME_SDL2)
86      int w=0; int h=0;
8687      SDL_GetWindowSize(m_sdl_window, &w, &h);
88      return osd_dim(w,h);
8789#else
88      w = m_sdlsurf->w; h = m_sdlsurf->h;
90      return osd_dim(m_sdlsurf->w, m_sdlsurf->h);
8991#endif
9092   }
9193
r243824r243825
122124
123125   // diverse flags
124126   int                 m_minwidth, m_minheight;
125   int                 m_windowed_width;
126   int                 m_windowed_height;
127   osd_dim             m_windowed_dim;
127128
128129   // rendering info
129130   osd_event *         m_rendered_event;
r243824r243825
150151protected:
151152   osd_renderer &renderer() { return *m_renderer; }
152153private:
153   void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment);
154   int wnd_extra_width();
155   int wnd_extra_height();
156   void set_starting_view(running_machine &machine, int index, const char *defview, const char *view);
157   osd_rect constrain_to_aspect_ratio(const osd_rect &rect, int adjustment);
158   osd_dim get_min_bounds(int constrain);
159   osd_dim get_max_bounds(int constrain);
154160   void update_cursor_state();
155   void pick_best_mode(int *fswidth, int *fsheight);
156   void set_starting_view(running_machine &machine, int index, const char *defview, const char *view);
157   void get_min_bounds(int *window_width, int *window_height, int constrain);
158   void get_max_bounds(int *window_width, int *window_height, int constrain);
161   osd_dim pick_best_mode();
159162   void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }
160163
161164   // Pointer to machine
trunk/src/osd/windows/drawdd.c
r243824r243825
964964      ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[1]);
965965
966966      // adjust to be relative to the monitor
967      RECT pos = monitor->position_size();
968      outer.left -= pos.left;
969      outer.right -= pos.left;
970      outer.top -= pos.top;
971      outer.bottom -= pos.top;
967      osd_rect pos = monitor->position_size();
968      outer.left -= pos.left();
969      outer.right -= pos.left();
970      outer.top -= pos.top();
971      outer.bottom -= pos.top();
972972   }
973973
974974   // compute outer rect -- full screen version
trunk/src/osd/windows/video.h
r243824r243825
3535//  TYPE DEFINITIONS
3636//============================================================
3737
38class osd_dim
39{
40public:
41   osd_dim(const int &w, const int &h)
42   : m_w(w), m_h(h)
43   {
44   }
45   int width() const { return m_w; }
46   int height() const { return m_h; }
47
48private:
49   int m_w;
50   int m_h;
51};
52
53class osd_rect
54{
55public:
56   osd_rect(const int x, const int y, const int &w, const int &h)
57   : m_x(x), m_y(y), m_d(w,h)
58   {
59   }
60   osd_rect(const int x, const int y, const osd_dim &d)
61   : m_x(x), m_y(y), m_d(d)
62   {
63   }
64   int top() const { return m_y; }
65   int left() const { return m_x; }
66   int width() const { return m_d.width(); }
67   int height() const { return m_d.height(); }
68
69   osd_dim dim() const { return m_d; }
70
71   int bottom() const { return m_y + m_d.height(); }
72   int right() const { return m_x + m_d.width(); }
73
74   osd_rect move_by(int dx, int dy) const { return osd_rect(m_x + dx, m_y + dy, m_d); }
75   osd_rect resize(int w, int h) const { return osd_rect(m_x, m_y, w, h); }
76
77private:
78   int m_x;
79   int m_y;
80   osd_dim m_d;
81};
82
83inline osd_rect RECT_to_osd_rect(const RECT &r)
84{
85   return osd_rect(r.left, r.top, r.right - r.left, r.bottom - r.top);
86}
87
3888class win_monitor_info
3989{
4090public:
r243824r243825
4494   void refresh();
4595
4696   const HMONITOR handle() { return m_handle; }
47   const RECT &position_size() { refresh(); return m_info.rcMonitor; }
48   const RECT &usuable_position_size() { refresh(); return m_info.rcWork; }
97   // position_size is used only by draw_dd renderer
98   const osd_rect position_size() { refresh(); return RECT_to_osd_rect(m_info.rcMonitor); }
99   const osd_rect usuable_position_size() { refresh(); return RECT_to_osd_rect(m_info.rcWork); }
49100   bool is_primary() { return (m_info.dwFlags & MONITORINFOF_PRIMARY) != 0; }
50101   const char *devicename() { refresh(); return (m_name != NULL) ? m_name : "UNKNOWN"; }
51102
trunk/src/osd/windows/window.c
r243824r243825
831831//  (window thread)
832832//============================================================
833833
834win_monitor_info *win_window_info::winwindow_video_window_monitor(const RECT *proposed)
834win_monitor_info *win_window_info::winwindow_video_window_monitor(const osd_rect *proposed)
835835{
836836   win_monitor_info *monitor;
837837
r243824r243825
839839   if (!m_fullscreen)
840840   {
841841      if (proposed != NULL)
842         monitor = winvideo_monitor_from_handle(MonitorFromRect(proposed, MONITOR_DEFAULTTONEAREST));
842      {
843         RECT p;
844         p.top = proposed->top();
845         p.left = proposed->left();
846         p.bottom = proposed->bottom();
847         p.right = proposed->right();
848         monitor = winvideo_monitor_from_handle(MonitorFromRect(&p, MONITOR_DEFAULTTONEAREST));
849      }
843850      else
844851         monitor = winvideo_monitor_from_handle(MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST));
845852   }
r243824r243825
11531160
11541161int win_window_info::complete_create()
11551162{
1156   RECT monitorbounds, client;
1163   RECT client;
11571164   int tempwidth, tempheight;
11581165   HMENU menu = NULL;
11591166   HDC dc;
r243824r243825
11611168   assert(GetCurrentThreadId() == window_threadid);
11621169
11631170   // get the monitor bounds
1164   monitorbounds = m_monitor->position_size();
1171   osd_rect monitorbounds = m_monitor->position_size();
11651172
11661173   // create the window menu if needed
11671174   if (downcast<windows_options &>(machine().options()).menu())
r243824r243825
11761183                  "MAME",
11771184                  m_title,
11781185                  m_fullscreen ? FULLSCREEN_STYLE : WINDOW_STYLE,
1179                  monitorbounds.left + 20, monitorbounds.top + 20,
1180                  monitorbounds.left + 100, monitorbounds.top + 100,
1186                  monitorbounds.left() + 20, monitorbounds.top() + 20,
1187                  monitorbounds.left() + 100, monitorbounds.top() + 100,
11811188                  NULL,//(win_window_list != NULL) ? win_window_list->m_hwnd : NULL,
11821189                  menu,
11831190                  GetModuleHandle(NULL),
r243824r243825
11981205   // adjust the window position to the initial width/height
11991206   tempwidth = (m_win_config.width != 0) ? m_win_config.width : 640;
12001207   tempheight = (m_win_config.height != 0) ? m_win_config.height : 480;
1201   SetWindowPos(m_hwnd, NULL, monitorbounds.left + 20, monitorbounds.top + 20,
1202         monitorbounds.left + tempwidth + wnd_extra_width(),
1203         monitorbounds.top + tempheight + wnd_extra_height(),
1208   SetWindowPos(m_hwnd, NULL, monitorbounds.left() + 20, monitorbounds.top() + 20,
1209         monitorbounds.left() + tempwidth + wnd_extra_width(),
1210         monitorbounds.top() + tempheight + wnd_extra_height(),
12041211         SWP_NOZORDER);
12051212
12061213   // maximum or minimize as appropriate
r243824r243825
13461353      {
13471354         RECT *rect = (RECT *)lparam;
13481355         if (video_config.keepaspect && !(GetAsyncKeyState(VK_CONTROL) & 0x8000))
1349            window->constrain_to_aspect_ratio(rect, wparam);
1356         {
1357            osd_rect r = window->constrain_to_aspect_ratio(RECT_to_osd_rect(*rect), wparam);
1358            rect->top = r.top();
1359            rect->left = r.left();
1360            rect->bottom = r.bottom();
1361            rect->right = r.right();
1362         }
13501363         InvalidateRect(wnd, NULL, FALSE);
13511364         break;
13521365      }
r243824r243825
15001513//  (window thread)
15011514//============================================================
15021515
1503void win_window_info::constrain_to_aspect_ratio(RECT *rect, int adjustment)
1516osd_rect win_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int adjustment)
15041517{
1505   win_monitor_info *monitor = winwindow_video_window_monitor(rect);
1518   win_monitor_info *monitor = winwindow_video_window_monitor(&rect);
15061519   INT32 extrawidth = wnd_extra_width();
15071520   INT32 extraheight = wnd_extra_height();
15081521   INT32 propwidth, propheight;
r243824r243825
15181531   pixel_aspect = monitor->aspect();
15191532
15201533   // determine the proposed width/height
1521   propwidth = rect_width(rect) - extrawidth;
1522   propheight = rect_height(rect) - extraheight;
1534   propwidth = rect.width() - extrawidth;
1535   propheight = rect.height() - extraheight;
15231536
15241537   // based on which edge we are adjusting, take either the width, height, or both as gospel
15251538   // and scale to fit using that as our parameter
r243824r243825
15541567   // clamp against the maximum (fit on one screen for full screen mode)
15551568   if (m_fullscreen)
15561569   {
1557      maxwidth = rect_width(&monitor->position_size()) - extrawidth;
1558      maxheight = rect_height(&monitor->position_size()) - extraheight;
1570      maxwidth = monitor->position_size().width() - extrawidth;
1571      maxheight = monitor->position_size().height() - extraheight;
15591572   }
15601573   else
15611574   {
1562      maxwidth = rect_width(&monitor->usuable_position_size()) - extrawidth;
1563      maxheight = rect_height(&monitor->usuable_position_size()) - extraheight;
1575      maxwidth = monitor->usuable_position_size().width() - extrawidth;
1576      maxheight = monitor->usuable_position_size().height() - extraheight;
15641577
15651578      // further clamp to the maximum width/height in the window
15661579      if (m_win_config.width != 0)
r243824r243825
15771590   m_target->compute_visible_area(propwidth, propheight, pixel_aspect, m_target->orientation(), viswidth, visheight);
15781591
15791592   // compute the adjustments we need to make
1580   adjwidth = (viswidth + extrawidth) - rect_width(rect);
1581   adjheight = (visheight + extraheight) - rect_height(rect);
1593   adjwidth = (viswidth + extrawidth) - rect.width();
1594   adjheight = (visheight + extraheight) - rect.height();
15821595
15831596   // based on which corner we're adjusting, constrain in different ways
1597   osd_rect ret(rect);
1598
15841599   switch (adjustment)
15851600   {
15861601      case WMSZ_BOTTOM:
15871602      case WMSZ_BOTTOMRIGHT:
15881603      case WMSZ_RIGHT:
1589         rect->right += adjwidth;
1590         rect->bottom += adjheight;
1604         ret = rect.resize(rect.width() + adjwidth, rect.height() + adjheight);
15911605         break;
15921606
15931607      case WMSZ_BOTTOMLEFT:
1594         rect->left -= adjwidth;
1595         rect->bottom += adjheight;
1608         ret = rect.move_by(-adjwidth, 0).resize(rect.width(), rect.height() + adjheight);
15961609         break;
15971610
15981611      case WMSZ_LEFT:
15991612      case WMSZ_TOPLEFT:
16001613      case WMSZ_TOP:
1601         rect->left -= adjwidth;
1602         rect->top -= adjheight;
1614         ret = rect.move_by(-adjwidth, -adjheight);
16031615         break;
16041616
16051617      case WMSZ_TOPRIGHT:
1606         rect->right += adjwidth;
1607         rect->top -= adjheight;
1618         ret = rect.move_by(0, -adjheight).resize(rect.width() + adjwidth, rect.height());
16081619         break;
16091620   }
1621   return ret;
16101622}
16111623
16121624
r243824r243825
16161628//  (window thread)
16171629//============================================================
16181630
1619void win_window_info::get_min_bounds(RECT *bounds, int constrain)
1631osd_dim win_window_info::get_min_bounds(int constrain)
16201632{
16211633   INT32 minwidth, minheight;
16221634
r243824r243825
16381650   // if we want it constrained, figure out which one is larger
16391651   if (constrain)
16401652   {
1641      RECT test1, test2;
1642
16431653      // first constrain with no height limit
1644      test1.top = test1.left = 0;
1645      test1.right = minwidth;
1646      test1.bottom = 10000;
1647      constrain_to_aspect_ratio(&test1, WMSZ_BOTTOMRIGHT);
1654      osd_rect test1(0,0,minwidth,10000);
1655      test1 = constrain_to_aspect_ratio(test1, WMSZ_BOTTOMRIGHT);
16481656
16491657      // then constrain with no width limit
1650      test2.top = test2.left = 0;
1651      test2.right = 10000;
1652      test2.bottom = minheight;
1653      constrain_to_aspect_ratio(&test2, WMSZ_BOTTOMRIGHT);
1658      osd_rect test2(0,0,10000,minheight);
1659      test2 = constrain_to_aspect_ratio(test2, WMSZ_BOTTOMRIGHT);
16541660
16551661      // pick the larger
1656      if (rect_width(&test1) > rect_width(&test2))
1662      if (test1.width() > test2.width())
16571663      {
1658         minwidth = rect_width(&test1);
1659         minheight = rect_height(&test1);
1664         minwidth = test1.width();
1665         minheight = test1.height();
16601666      }
16611667      else
16621668      {
1663         minwidth = rect_width(&test2);
1664         minheight = rect_height(&test2);
1669         minwidth = test2.width();
1670         minheight = test2.height();
16651671      }
16661672   }
16671673
1668   // get the window rect
1669   GetWindowRect(m_hwnd, bounds);
1670
1671   // now adjust
1672   bounds->right = bounds->left + minwidth;
1673   bounds->bottom = bounds->top + minheight;
1674   return osd_dim(minwidth, minheight);
16741675}
16751676
16761677
r243824r243825
16801681//  (window thread)
16811682//============================================================
16821683
1683void win_window_info::get_max_bounds(RECT *bounds, int constrain)
1684osd_dim win_window_info::get_max_bounds(int constrain)
16841685{
1685   RECT maximum;
1686
16871686   assert(GetCurrentThreadId() == window_threadid);
16881687
16891688   // compute the maximum client area
16901689   m_monitor->refresh();
1691   maximum = m_monitor->usuable_position_size();
1690   osd_rect maximum = m_monitor->usuable_position_size();
16921691
16931692   // clamp to the window's max
1693   int tempw = maximum.width();
1694   int temph = maximum.height();
16941695   if (m_win_config.width != 0)
16951696   {
16961697      int temp = m_win_config.width + wnd_extra_width();
1697      if (temp < rect_width(&maximum))
1698         maximum.right = maximum.left + temp;
1698      if (temp < maximum.width())
1699         tempw = temp;
16991700   }
17001701   if (m_win_config.height != 0)
17011702   {
17021703      int temp = m_win_config.height + wnd_extra_height();
1703      if (temp < rect_height(&maximum))
1704         maximum.bottom = maximum.top + temp;
1704      if (temp < maximum.height())
1705         temph = temp;
17051706   }
17061707
1708   maximum = maximum.resize(tempw, temph);
1709
17071710   // constrain to fit
17081711   if (constrain)
1709      constrain_to_aspect_ratio(&maximum, WMSZ_BOTTOMRIGHT);
1712      maximum = constrain_to_aspect_ratio(maximum, WMSZ_BOTTOMRIGHT);
17101713   else
17111714   {
1712      maximum.right -= wnd_extra_width();
1713      maximum.bottom -= wnd_extra_height();
1715      maximum = maximum.resize(maximum.width() - wnd_extra_width(), maximum.height() - wnd_extra_height());
17141716   }
1715
1716   // center within the work area
1717   RECT work = m_monitor->usuable_position_size();
1718   bounds->left = work.left + (rect_width(&work) - rect_width(&maximum)) / 2;
1719   bounds->top = work.top + (rect_height(&work) - rect_height(&maximum)) / 2;
1720   bounds->right = bounds->left + rect_width(&maximum);
1721   bounds->bottom = bounds->top + rect_height(&maximum);
1717   return maximum.dim();
17221718}
17231719
17241720
r243824r243825
17341730
17351731   if (!m_fullscreen)
17361732   {
1737      RECT bounds, minbounds, maxbounds;
1733      RECT bounds;
17381734
17391735      // compare the maximum bounds versus the current bounds
1740      get_min_bounds(&minbounds, video_config.keepaspect);
1741      get_max_bounds(&maxbounds, video_config.keepaspect);
1736      osd_dim minbounds = get_min_bounds(video_config.keepaspect);
1737      osd_dim maxbounds = get_max_bounds(video_config.keepaspect);
17421738      GetWindowRect(m_hwnd, &bounds);
17431739
17441740      // if either the width or height matches, we were maximized
1745      m_isminimized = (rect_width(&bounds) == rect_width(&minbounds) ||
1746                        rect_height(&bounds) == rect_height(&minbounds));
1747      m_ismaximized = (rect_width(&bounds) == rect_width(&maxbounds) ||
1748                        rect_height(&bounds) == rect_height(&maxbounds));
1741      m_isminimized = (rect_width(&bounds) == minbounds.width()) ||
1742                        (rect_height(&bounds) == minbounds.height());
1743      m_ismaximized = (rect_width(&bounds) == maxbounds.width()) ||
1744                        (rect_height(&bounds) == maxbounds.height());
17491745   }
17501746   else
17511747   {
r243824r243825
17631759
17641760void win_window_info::minimize_window()
17651761{
1766   RECT newsize;
1767
17681762   assert(GetCurrentThreadId() == window_threadid);
17691763
1770   get_min_bounds(&newsize, video_config.keepaspect);
1771   SetWindowPos(m_hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER);
1764   osd_dim newsize = get_min_bounds(video_config.keepaspect);
1765
1766   // get the window rect
1767   RECT bounds;
1768   GetWindowRect(m_hwnd, &bounds);
1769
1770   osd_rect newrect(bounds.left, bounds.top, newsize );
1771
1772
1773   SetWindowPos(m_hwnd, NULL, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER);
17721774}
17731775
17741776
r243824r243825
17801782
17811783void win_window_info::maximize_window()
17821784{
1783   RECT newsize;
1784
17851785   assert(GetCurrentThreadId() == window_threadid);
17861786
1787   get_max_bounds(&newsize, video_config.keepaspect);
1788   SetWindowPos(m_hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER);
1787   osd_dim newsize = get_max_bounds(video_config.keepaspect);
1788
1789   // center within the work area
1790   osd_rect work = m_monitor->usuable_position_size();
1791   osd_rect newrect = osd_rect(work.left() + (work.width() - newsize.width()) / 2,
1792         work.top() + (work.height() - newsize.height()) / 2,
1793         newsize);
1794
1795   SetWindowPos(m_hwnd, NULL, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER);
17891796}
17901797
17911798
r243824r243825
17971804
17981805void win_window_info::adjust_window_position_after_major_change()
17991806{
1800   RECT oldrect, newrect;
1807   RECT oldrect;
18011808
18021809   assert(GetCurrentThreadId() == window_threadid);
18031810
18041811   // get the current size
18051812   GetWindowRect(m_hwnd, &oldrect);
1813   osd_rect newrect = RECT_to_osd_rect(oldrect);
18061814
18071815   // adjust the window size so the client area is what we want
18081816   if (!m_fullscreen)
18091817   {
18101818      // constrain the existing size to the aspect ratio
1811      newrect = oldrect;
18121819      if (video_config.keepaspect)
1813         constrain_to_aspect_ratio(&newrect, WMSZ_BOTTOMRIGHT);
1820         newrect = constrain_to_aspect_ratio(newrect, WMSZ_BOTTOMRIGHT);
18141821   }
18151822
18161823   // in full screen, make sure it covers the primary display
r243824r243825
18211828   }
18221829
18231830   // adjust the position if different
1824   if (oldrect.left != newrect.left || oldrect.top != newrect.top ||
1825      oldrect.right != newrect.right || oldrect.bottom != newrect.bottom)
1831   if (oldrect.left != newrect.left() || oldrect.top != newrect.top() ||
1832      oldrect.right != newrect.right() || oldrect.bottom != newrect.bottom())
18261833      SetWindowPos(m_hwnd, m_fullscreen ? HWND_TOPMOST : HWND_TOP,
1827            newrect.left, newrect.top,
1828            rect_width(&newrect), rect_height(&newrect), 0);
1834            newrect.left(), newrect.top(),
1835            newrect.width(), newrect.height(), 0);
18291836
18301837   // take note of physical window size (used for lightgun coordinate calculation)
18311838   if (this == win_window_list)
18321839   {
1833      win_physical_width = rect_width(&newrect);
1834      win_physical_height = rect_height(&newrect);
1840      win_physical_width = newrect.width();
1841      win_physical_height = newrect.height();
18351842      logerror("Physical width %d, height %d\n",win_physical_width,win_physical_height);
18361843   }
18371844}
trunk/src/osd/windows/window.h
r243824r243825
4646
4747   void update();
4848
49   win_monitor_info *winwindow_video_window_monitor(const RECT *proposed);
49   win_monitor_info *winwindow_video_window_monitor(const osd_rect *proposed);
5050
5151   bool win_has_menu()
5252   {
r243824r243825
109109
110110private:
111111   void draw_video_contents(HDC dc, int update);
112   int complete_create();
112113   void set_starting_view(int index, const char *view);
113114   int wnd_extra_width();
114115   int wnd_extra_height();
115   int complete_create();
116   void constrain_to_aspect_ratio(RECT *rect, int adjustment);
117   void get_min_bounds(RECT *bounds, int constrain);
118   void get_max_bounds(RECT *bounds, int constrain);
116   osd_rect constrain_to_aspect_ratio(const osd_rect &rect, int adjustment);
117   osd_dim get_min_bounds(int constrain);
118   osd_dim get_max_bounds(int constrain);
119119   void update_minmax_state();
120120   void minimize_window();
121121   void maximize_window();


Previous 199869 Revisions Next


© 1997-2024 The MAME Team