Subversion Repositories Kolibri OS

Rev

Rev 4364 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
  3.  *
  4.  * Framebuffer windowing toolkit bitmaped image widget
  5.  *
  6.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  7.  *
  8.  * NetSurf is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; version 2 of the License.
  11.  *
  12.  * NetSurf is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20.  
  21. #include <stdbool.h>
  22. #include <stdlib.h>
  23.  
  24. #include <libnsfb.h>
  25. #include <libnsfb_plot.h>
  26.  
  27. #include "desktop/browser.h"
  28.  
  29. #include "framebuffer/gui.h"
  30. #include "framebuffer/fbtk.h"
  31. #include "framebuffer/image_data.h"
  32.  
  33. #include "utils/log.h"
  34. #include <menuet/os.h>
  35.  
  36. #include "widget.h"
  37.  
  38. #ifdef DBG
  39. #undef DBG
  40. #endif
  41. //#define DBG(s) __menuet__debug_out(s) /* For the debug messages in BOARD */
  42. #define DBG(s) LOG((s))            /* So that we see debug in Netsurf's LOG files */
  43.  
  44.  
  45. static int
  46. fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi)
  47. {
  48.         /* LOG(("REDRAW BITMAP")); */
  49.         //DBG("REDRAW BITMAP");
  50.         nsfb_bbox_t bbox;
  51.         nsfb_bbox_t rect;
  52.         nsfb_t *nsfb;
  53.  
  54.         /* LOG(("REDRAW BITMAP 1 ")); */
  55.         //DBG("REDRAW BITMAP 1");
  56.  
  57.  
  58.         nsfb = fbtk_get_nsfb(widget);
  59.  
  60.         /* LOG(("REDRAW BITMAP 2")); */
  61.         //DBG("REDRAW BITMAP 2");
  62.  
  63.  
  64.         fbtk_get_bbox(widget, &bbox);
  65.  
  66.         rect = bbox;
  67.  
  68.         /* LOG(("REDRAW BITMAP 3 ")); */
  69.         //DBG("REDRAW BITMAP 3");
  70.  
  71.  
  72.         nsfb_claim(nsfb, &bbox);
  73.  
  74.         /* LOG(("REDRAW BITMAP 4")); */
  75.         //DBG("REDRAW BITMAP 4");
  76.  
  77.         /* clear background */
  78.         if ((widget->bg & 0xFF000000) != 0) {
  79.                 /* transparent polygon filling isnt working so fake it */
  80.                
  81.                         /* LOG(("REDRAW BITMAP 5")); */
  82.         //DBG("REDRAW BITMAP 5");
  83.  
  84.                 nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
  85.         }
  86.  
  87.         /* LOG(("REDRAW BITMAP 6")); */
  88.         //DBG("REDRAW BITMAP 6\n");
  89.  
  90.         /* plot the image */
  91.        
  92.         /* LOG(("STUB: DON'T REAL DRAW")); */
  93.         //DBG("STUB: DON'T REAL DRAW\n");
  94.        
  95.        
  96.         /* LOG(("pixdata is %x", (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata)); */
  97.         /* LOG(("pixdata is w:%d h:%d",widget->u.bitmap.bitmap->width, */
  98.         /*               widget->u.bitmap.bitmap->height)); */
  99.        
  100.         //hmm
  101.        
  102.         //int zap;
  103.         //if (widget->u.bitmap.bitmap->width % 4 != 0) {
  104.         //      zap = widget->u.bitmap.bitmap->width + 2; }
  105.        
  106.         //nsfb_plot_rectangle_fill(nsfb, &rect, 0xFFFFFF);
  107.        
  108.        
  109.         nsfb_plot_bitmap(nsfb,
  110.                          &rect,
  111.                          (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata,
  112.                          //0, 0, 0,
  113.                          widget->u.bitmap.bitmap->width,
  114.                          widget->u.bitmap.bitmap->height,
  115.                          widget->u.bitmap.bitmap->width,
  116.                          !widget->u.bitmap.bitmap->opaque);
  117.        
  118.        
  119.                
  120.        
  121.        
  122.         /* LOG(("REDRAW BITMAP 7")); */
  123.         //DBG("REDRAW BITMAP 7\n");
  124.  
  125.         nsfb_update(nsfb, &bbox);
  126.  
  127.         /* LOG(("REDRAW BITMAP OK\n")); */
  128.         //DBG("REDRAW BITMAP OK\n");
  129.  
  130.         return 0;
  131. }
  132.  
  133. /* exported function documented in fbtk.h */
  134. void
  135. fbtk_set_bitmap(fbtk_widget_t *widget, struct fbtk_bitmap *image)
  136. {
  137.         /* LOG(("SET BITMAP")); */
  138.         //DBG("set BITMAP");
  139.         if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_BITMAP))
  140.                 return;
  141.  
  142.         widget->u.bitmap.bitmap = image;
  143.  
  144.         fbtk_request_redraw(widget);
  145. }
  146.  
  147. /* exported function documented in fbtk.h */
  148. fbtk_widget_t *
  149. fbtk_create_bitmap(fbtk_widget_t *parent,
  150.                    int x,
  151.                    int y,
  152.                    int width,
  153.                    int height,
  154.                    colour c,
  155.                    struct fbtk_bitmap *image)
  156. {
  157.         /* LOG(("CREATE BITMAP")); */
  158.         //DBG("cr BITMAP");
  159.         fbtk_widget_t *neww;
  160.  
  161.         neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_BITMAP, x, y, width, height);
  162.  
  163.         neww->bg = c;
  164.         neww->mapped = true;
  165.         neww->u.bitmap.bitmap = image;
  166.  
  167.         fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_bitmap, NULL);
  168.  
  169.         return neww;
  170. }
  171.  
  172. /* exported function documented in fbtk.h */
  173. fbtk_widget_t *
  174. fbtk_create_button(fbtk_widget_t *parent,
  175.                    int x,
  176.                    int y,
  177.                    int width,
  178.                    int height,
  179.                    colour c,
  180.                    struct fbtk_bitmap *image,
  181.                    fbtk_callback click,
  182.                    void *pw)
  183. {
  184.         fbtk_widget_t *neww;
  185.  
  186.         /* LOG(("CREATE BUTTON BITMAP")); */
  187.         //DBG("cr bb BITMAP");
  188.         neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_BITMAP, x, y, width, height);
  189.  
  190.         neww->bg = c;
  191.         neww->mapped = true;
  192.         neww->u.bitmap.bitmap = image;
  193.  
  194.         fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_bitmap, NULL);
  195.         fbtk_set_handler(neww, FBTK_CBT_CLICK, click, pw);
  196.         fbtk_set_handler(neww, FBTK_CBT_POINTERENTER, fbtk_set_ptr, &hand_image);
  197.  
  198.         return neww;
  199. }
  200.  
  201. /*
  202.  * Local Variables:
  203.  * c-basic-offset:8
  204.  * End:
  205.  */
  206.