Free Hero Mesh

Check-in [633696a6f5]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement scrollbars
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 633696a6f50f2507afeec670105b80f13b0501ca
User & Date: user on 2018-10-26 08:12:04
Other Links: manifest | tags
Context
2018-10-26
18:17
Display invisible objects in editor check-in: 7eae9b600e user: user tags: trunk
08:12
Implement scrollbars check-in: 633696a6f5 user: user tags: trunk
06:47
A few minor corrections, including displaying width/height of level in editor and allowing loading levels by index. check-in: 01830be55a user: user tags: trunk
Changes

Modified heromesh.h from [5ea05aa2a2] to [a8db97cff3].

85
86
87
88
89
90
91


92
93
94
95
96
97
98
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+
+







extern int left_margin;

void draw_picture(int x,int y,Uint16 img);
void draw_text(int x,int y,const unsigned char*t,int bg,int fg);
void draw_cell(int x,int y);
const char*screen_prompt(const char*txt);
void load_pictures(void);

int scrollbar(int*cur,int page,int max,SDL_Event*ev,SDL_Rect*re);

// == class ==

#define CF_PLAYER 0x01
#define CF_INPUT 0x02
#define CF_COMPATIBLE 0x04
#define CF_QUIZ 0x08

Modified main.c from [fed1a85264] to [71afcff0a8].

593
594
595
596
597
598
599

600
601
602
603
604
605
606
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607







+








static void test_mode(void) {
  Uint32 n=0;
  SDLKey k;
  SDL_Event ev;
  char buf[32];
  const UserCommand*uc;
  int i;
  set_cursor(XC_tcross);
  SDL_LockSurface(screen);
  draw_text(0,0,"Hello, World!",0xF0,0xFF);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_KEYDOWN:
631
632
633
634
635
636
637


638
639
640
641
642
643
644
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647







+
+







          goto keytest;
        case SDLK_p:
          sqlite3_exec(userdb,"SELECT * FROM `PICTURES`;",test_sql_callback,0,0);
          break;
        case SDLK_q:
          exit(0);
          break;
        case SDLK_s:
          goto scrolltest;
        case SDLK_t:
          puts(screen_prompt("Testing screen_prompt()")?:"No output.");
          break;
      }
      break;
    case SDL_MOUSEBUTTONDOWN:
      draw_picture(ev.button.x,ev.button.y,n);
677
678
679
680
681
682
683



































684
685
686
687
688
689
690
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        default: printf("<Unknown>\n");
      }
      break;
    case SDL_QUIT:
      exit(0);
      break;
  }
  fatal("An error occurred waiting for events.\n");
scrolltest:
  SDL_FillRect(screen,0,0xF2);
  i=0;
  scrollbar(&i,10,n,0,0);
  draw_picture(16,screen->h/10,1);
  draw_picture(16,(2*screen->h)/10,2);
  draw_picture(16,(3*screen->h)/10,3);
  SDL_Flip(screen);
  set_cursor(XC_arrow);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_KEYDOWN:
      if(ev.key.keysym.sym==SDLK_SPACE) exit(0);
      break;
    case SDL_MOUSEBUTTONDOWN:
    case SDL_MOUSEBUTTONUP:
      scrollbar(&i,10,n,&ev,0);
      printf("scroll %d %d\n",i,n);
      break;
    case SDL_MOUSEMOTION:
      if(!scrollbar(&i,10,n,&ev,0)) set_cursor(XC_arrow);
      break;
    case SDL_VIDEOEXPOSE:
      SDL_FillRect(screen,0,0xF2);
      scrollbar(&i,10,n,&ev,0);
      draw_picture(16,screen->h/10,1);
      draw_picture(16,(2*screen->h)/10,2);
      draw_picture(16,(3*screen->h)/10,3);
      SDL_Flip(screen);
      break;
    case SDL_QUIT:
      exit(0);
      break;
  }
  fatal("An error occurred waiting for events.\n");
}

static void do_sql_mode(void) {
  int m=sqlite3_limit(userdb,SQLITE_LIMIT_SQL_LENGTH,-1);
  char*txt;
  int n=0;
  int c;

Modified picture.c from [7850e1bb3d] to [ffd397fc76].

425
426
427
428
429
430
431

















































































425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
  } else {
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
  }
  SDL_EnableUNICODE(1);
  optionquery[1]=Q_margin;
  left_margin=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"65",0,10);
}

// Widgets

static void draw_scrollbar(int*cur,int page,int max,int x0,int y0,int x1,int y1) {
  Uint8*pix=screen->pixels;
  Uint16 pitch=screen->pitch;
  int x,y,m0,m1;
  double f;
  f=(y1-y0)/(double)(max+page);
  if(*cur<0) *cur=0; else if(*cur>max) *cur=max;
  m0=*cur*f+y0;
  m1=(*cur+page)*f+y0;
  pix+=y0*pitch;
  SDL_LockSurface(screen);
  for(y=y0;y<y1;y++) {
    for(x=x0;x<x1;x++) pix[x]=y<m0?0xFF:y>m1?0xFF:(y^x)&1?0xF0:0xFF;
    pix[x1]=0xFF;
    pix+=pitch;
  }
  SDL_UnlockSurface(screen);
}

int scrollbar(int*cur,int page,int max,SDL_Event*ev,SDL_Rect*re) {
  int x0=re?re->x:0;
  int y0=re?re->y:0;
  int x1=re?re->x+12:12;
  int y1=re?re->y+re->h:screen->h;
  int y;
  double f;
  switch(ev?ev->type:SDL_VIDEOEXPOSE) {
    case SDL_MOUSEMOTION:
      if(ev->motion.x<x0 || ev->motion.x>x1 || ev->motion.y<y0 || ev->motion.y>=y1) return 0;
      if(ev->motion.state&SDL_BUTTON(2)) {
        y=ev->motion.y;
        goto move;
      } else if(ev->motion.state&SDL_BUTTON(1)) {
        set_cursor(XC_sb_up_arrow);
      } else if(ev->motion.state&SDL_BUTTON(3)) {
        set_cursor(XC_sb_down_arrow);
      } else {
        set_cursor(XC_sb_v_double_arrow);
      }
      return 1;
    case SDL_MOUSEBUTTONDOWN:
      if(ev->button.x<x0 || ev->button.x>x1 || ev->button.y<y0 || ev->button.y>=y1) return 0;
      if(ev->button.button==2) {
        y=ev->button.y;
        goto move;
      } else if(ev->button.button==1) {
        set_cursor(XC_sb_up_arrow);
      } else if(ev->button.button==3) {
        set_cursor(XC_sb_down_arrow);
      }
      return 1;
    case SDL_MOUSEBUTTONUP:
      if(ev->button.x<x0 || ev->button.x>x1 || ev->button.y<y0 || ev->button.y>=y1) return 0;
      f=(y1-y0)/(double)page;
      y=(ev->button.y-y0+0.5)/f;
      if(ev->button.button==1) {
        *cur+=y;
      } else if(ev->button.button==3) {
        *cur-=y;
      }
      draw_scrollbar(cur,page,max,x0,y0,x1,y1);
      SDL_Flip(screen);
      set_cursor(XC_sb_v_double_arrow);
      return 1;
    case SDL_VIDEOEXPOSE:
      draw_scrollbar(cur,page,max,x0,y0,x1,y1);
      return 0;
    default:
      return 0;
  }
  move:
  f=(y1-y0)/(double)(max+page);
  *cur=(y-y0+0.5)/f;
  draw_scrollbar(cur,page,max,x0,y0,x1,y1);
  SDL_Flip(screen);
  set_cursor(XC_sb_right_arrow);
  return 1;
}